-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented collision avoidance methods using switches and proximity
- Loading branch information
PacoRmzA
committed
May 20, 2022
1 parent
6bb71b4
commit dbf0725
Showing
1 changed file
with
27 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,12 +1,34 @@ | ||
#ifndef COLLISION_AVOIDANCE_H | ||
#define COLLISION_AVOIDANCE_H | ||
|
||
#include "proximity.h" | ||
#include "hbridge.h" | ||
//TODO: implement limit switches, required for this code | ||
#include "delays.h" | ||
#define NINETYDEG_TURN_TIME 1000 //FIXME: Test and correct this value | ||
#include "limit_switch.h" | ||
#define CLOSEST_ALLOWED_DISTANCE 5 | ||
|
||
int collisionDetectionInit(void); | ||
int collisionDetected(void); | ||
int tooCloseToWall(void); | ||
|
||
int collisionDetectionInit() { | ||
proximity_init(); | ||
limit_switch_init(); | ||
} | ||
|
||
int collisionDetected() { | ||
int state = 0x0; | ||
if (!hasNOT_collided(SWITCH_FRONT)) state |= 1; | ||
else if (!hasNOT_collided(SWITCH_LEFT)) state |= 2; | ||
else if (!hasNOT_collided(SWITCH_RIGHT)) state |= 4; | ||
return state; | ||
} | ||
|
||
int tooCloseToWall() { | ||
int state = 0x0; | ||
double leftSensor,rightSensor; | ||
leftSensor = proximity_read_average(8,20); | ||
rightSensor = proximity_read_average(9, 20); | ||
if (leftSensor < CLOSEST_ALLOWED_DISTANCE) state |= 1; | ||
else if (rightSensor < CLOSEST_ALLOWED_DISTANCE) state |= 2; | ||
return state; | ||
} | ||
|
||
#endif |