-
Notifications
You must be signed in to change notification settings - Fork 66
Set error if bumper stays permanently triggered #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
greymfm
merged 1 commit into
Ardumower:master
from
Svol0:svol0-1.0.287_bumper-error-if-stays-triggered
Aug 10, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Ardumower Sunray | ||
| // Copyright (c) 2013-2020 by Alexander Grau, Grau GmbH | ||
| // Licensed GPLv3 for open source use | ||
| // or Grau GmbH Commercial License for commercial use (http://grauonline.de/cms2/?page_id=153) | ||
|
|
||
| #include "bumper.h" | ||
| #include "config.h" | ||
| #include "robot.h" | ||
| #include <Arduino.h> | ||
|
|
||
| volatile bool inputLeftPressed = false; | ||
| volatile bool inputRightPressed = false; | ||
|
|
||
| volatile bool outputLeftPressed = false; | ||
| volatile bool outputRightPressed = false; | ||
|
|
||
| unsigned long leftPressedOnDelay = 0; // on delay timer (BUMPER_TRIGGER_DELAY) for the bumper inputs | ||
| unsigned long rightPressedOnDelay = 0; | ||
|
|
||
| unsigned long bumperStayActivTime = 0; // duration, the bumper stays triggered | ||
| unsigned long lastCallBumperObstacle = 0; // last call for bumper.obstacle | ||
|
|
||
|
|
||
| void Bumper::begin(){ | ||
| bumperDriver.begin(); | ||
|
|
||
| leftPressedOnDelay = millis(); | ||
| rightPressedOnDelay = millis(); | ||
| } | ||
|
|
||
| void Bumper::run() { | ||
| if (BUMPER_ENABLE){ | ||
| bumperDriver.run(); | ||
|
|
||
| inputLeftPressed = bumperDriver.getLeftBumper(); | ||
| inputRightPressed = bumperDriver.getRightBumper(); | ||
| bool bumperLeft = false; | ||
| bool bumperRight = false; | ||
|
|
||
| // delay for the bumper inputs | ||
| if (inputLeftPressed){ | ||
| if (millis() >= (leftPressedOnDelay + BUMPER_TRIGGER_DELAY)) bumperLeft = true; | ||
| } else leftPressedOnDelay = millis(); | ||
|
|
||
| if (inputRightPressed){ | ||
| if (millis() >= (rightPressedOnDelay + BUMPER_TRIGGER_DELAY)) bumperRight = true; | ||
| } else rightPressedOnDelay = millis(); | ||
|
|
||
| if (millis() > (linearMotionStartTime + BUMPER_DEADTIME)){ | ||
| outputLeftPressed = bumperLeft; | ||
| outputRightPressed = bumperRight; | ||
| } else outputLeftPressed = outputRightPressed = false; | ||
|
|
||
| // check if bumper stays triggered for a long time periode (maybe blocked) | ||
| if ((bumperRight || bumperLeft) && (BUMPER_MAX_TRIGGER_TIME > 0)){ | ||
| if ((abs(motor.linearSpeedSet) >= 0.05) || (abs(motor.angularSpeedSet) >= 0.05)) { // if no movement, bumperStayActivTime paused | ||
| bumperStayActivTime = bumperStayActivTime + (millis()-lastCallBumperObstacle); | ||
| } | ||
| if ((bumperStayActivTime) > (BUMPER_MAX_TRIGGER_TIME * 1000)){ // maximum trigger time reached -> set error | ||
| if (stateOp != OP_ERROR){ | ||
| stateSensor = SENS_BUMPER; | ||
| CONSOLE.println("ERROR BUMPER BLOCKED - BUMPER_MAX_TRIGGER_TIME exceeded. See config.h for further information"); | ||
| setOperation(OP_ERROR); | ||
| } | ||
| } | ||
| } else bumperStayActivTime = 0; | ||
| lastCallBumperObstacle = millis(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| bool Bumper::obstacle(){ | ||
| if (BUMPER_ENABLE){ | ||
| return (outputLeftPressed || outputRightPressed); | ||
| } | ||
| else return false; | ||
| } | ||
|
|
||
| // send separated signals without delay to sensortest | ||
| bool Bumper::testLeft(){ | ||
| return (inputLeftPressed); | ||
| } | ||
|
|
||
| bool Bumper::testRight(){ | ||
| return (inputRightPressed); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Ardumower Sunray | ||
| // Copyright (c) 2013-2020 by Alexander Grau, Grau GmbH | ||
| // Licensed GPLv3 for open source use | ||
| // or Grau GmbH Commercial License for commercial use (http://grauonline.de/cms2/?page_id=153) | ||
|
|
||
|
|
||
| #ifndef BUMPER_H | ||
| #define BUMPER_H | ||
|
|
||
| class Bumper { | ||
| public: | ||
| void begin(); | ||
| void run(); | ||
| bool obstacle(); | ||
| bool testLeft(); // for sensortest | ||
| bool testRight(); // for sensortest | ||
| protected: | ||
| }; | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.