Skip to content
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

reduce bumper sensitivity #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sunray/config_example.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ Also, you may choose the serial port below for serial monitor output (CONSOLE).
// #define BUMPER_ENABLE true
#define BUMPER_ENABLE false
#define BUMPER_DEADTIME 1000 // linear motion dead-time (ms) after bumper is allowed to trigger
#define BUMPER_TRIGGER_DELAY 2000 // bumper must be active for (ms) to trigger


// ----- battery charging current measurement (INA169) --------------
Expand Down Expand Up @@ -514,4 +515,3 @@ Also, you may choose the serial port below for serial monitor output (CONSOLE).
// 2. Locate file 'packages/arduino/hardware/sam/xxxxx/cores/arduino/RingBuffer.h

#define SERIAL_BUFFER_SIZE 1024

2 changes: 1 addition & 1 deletion sunray/robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ MPU9250_DMP imu;
AmRobotDriver robotDriver;
AmMotorDriver motorDriver;
AmBatteryDriver batteryDriver;
AmBumperDriver bumper;
AmBumperDriver bumper(BUMPER_TRIGGER_DELAY);
AmStopButtonDriver stopButton;
AmRainSensorDriver rainDriver;
#endif
Expand Down
20 changes: 12 additions & 8 deletions sunray/src/driver/AmRobotDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ volatile int odomTicksLeft = 0;
volatile int odomTicksRight = 0;


volatile bool leftPressed = false;
volatile bool rightPressed = false;
volatile uint32_t leftTriggeredSince = 0;
volatile uint32_t rightTriggeredSince = 0;


bool faultActive = LOW;
Expand Down Expand Up @@ -281,11 +281,11 @@ void AmBatteryDriver::keepPowerOn(bool flag){

// ------------------------------------------------------------------------------------
void BumperLeftInterruptRoutine(){
leftPressed = (digitalRead(pinBumperLeft) == LOW);
leftTriggeredSince = digitalRead(pinBumperLeft) == LOW ? millis() : 0;
}

void BumperRightInterruptRoutine(){
rightPressed = (digitalRead(pinBumperRight) == LOW);
rightTriggeredSince = digitalRead(pinBumperRight) == LOW ? millis() : 0;
}


Expand All @@ -297,14 +297,18 @@ void AmBumperDriver::begin(){
}

void AmBumperDriver::getTriggeredBumper(bool &leftBumper, bool &rightBumper){
leftBumper = leftPressed;
rightBumper = rightPressed;
const uint32_t now = millis();
leftBumper = leftTriggeredSince != 0 && (now - leftTriggeredSince) > triggerTime;
rightBumper = rightTriggeredSince != 0 && (now - rightTriggeredSince) > triggerTime;
}

bool AmBumperDriver::obstacle(){
return (leftPressed || rightPressed);
bool left, right;
getTriggeredBumper(left, right);

return left || right;
}


void AmBumperDriver::run(){
}
Expand Down
7 changes: 5 additions & 2 deletions sunray/src/driver/AmRobotDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ class AmBatteryDriver : public BatteryDriver {
};

class AmBumperDriver: public BumperDriver {
public:
private:
uint32_t triggerTime;
public:
AmBumperDriver(uint32_t _triggerTime) : triggerTime(_triggerTime) {}
void begin() override;
void run() override;
bool obstacle() override;

// get triggered bumper
void getTriggeredBumper(bool &leftBumper, bool &rightBumper) override;
void getTriggeredBumper(bool &leftBumper, bool &rightBumper) override;
};


Expand Down