-
Notifications
You must be signed in to change notification settings - Fork 76
Obstacle Detection Module
Our obstacle detection module is composed of three components:
9 directions. First one is none (i.e. no obstacle). 8 Directions: starting at North in front of the robot, going in clockwise direction.
- detects which direction the arms are being pushed in
- if both arms pushed backwards, obstacle in front
- if both arms pushed forward, obstacle behind and etc.
- calculates direction based on arm displacement
- only accounts for one obstacle, if arms pushed into opposite discretions we do nothing because we are unable to detect where the obstacle is
- used when running directly into robots, otherwise not very useful.
method: run()
-
runs every frame
-
obstacleDistance[] -> tells us distance of obstacles from where we are in each of 8 directions
-
obstacleDetectors[] -> tells us what module detected the obstacle (sonars, arms, vision) in each of 8 directions
-
variables usingArms, usingSonars, usingVision let us turn off methods of detection for particular robots, e.g. V5s have unreliable sonars
-
JSON file that sets usingArms, usingSonars, usingVision can be found in ObstacleModule.h
-
if usingArms, processArms method is run; returns which direction the obstacle is in (enums in Obstacle.proto). returns position, distance and which detector *Obstacle.proto message used for obstacle detection in general *if usingSonars do the same thing for sonars
Information from Sonars and Arms is combined into one entity, information from vision represents a separate entity.
- if anything is turned off, we will use whatever information we have available
method: processSonars()
-
add sonar readings to right and leftSonar lists
-
if usingRightSonar and size of rightSonars is more than buffer, pop from rightSonars; same logic applies for the left. This is done so that we only look at the most recent 20 readings
-
if using sonars, set right and left variables to the average value of the respective list. Otherwise the values are the upper sonar threshold and they won't be used
-
if both left and right within threshold, lastSonar reading (global variable) is the average of left and right
-
Division by 2 using bitshifts: number>>1
-
Compute Average with bitshifts: a>>1 + b>>1
-
then the obstacle is to the north, and distance is average of left and right readings
-
if right sonar is picking something up --> obstacle to NorthEast. Distance = right reading
-
if left sonar is picking something up --> obstacle is to NorthWest. Distance = left reading
-
Once we've updated obstacleDistances and obstacleDetectors from arms, sensors and vision
We set the outportal messages, if distance is zero, ignore it: otherwise we have some obstacle detected
If we have an obstacle we create a temp obstacle and add it to the FieldObstacles message. Set position (i.e. direction) to the current index; set distance to distance at the current index; set detector to detector at current index and then set the message.