@@ -15,20 +15,32 @@ void ObstacleController::Reset() {
1515 delay = current_time;
1616}
1717
18- Result ObstacleController::DoWork () {
19-
20- clearWaypoints = true ;
21- set_waypoint = true ;
22- result.PIDMode = CONST_PID ;
18+ // Avoid crashing into objects detected by the ultraound
19+ void ObstacleController::avoidObstacle () {
20+
21+ // obstacle on right side
22+ if (right < 0.8 || center < 0.8 || left < 0.8 ) {
23+ result.type = precisionDriving;
2324
24- if (centerSeen){
25+ result. pd . cmdAngular = -K_angular;
2526
27+ result.pd .setPointVel = 0.0 ;
28+ result.pd .cmdVel = 0.0 ;
29+ result.pd .setPointYaw = 0 ;
30+ }
31+ }
2632
33+ // A collection zone was seen in front of the rover and we are not carrying a target
34+ // so avoid running over the collection zone and possibly pushing cubes out.
35+ void ObstacleController::avoidCollectionZone () {
36+
2737 result.type = precisionDriving;
2838
2939 result.pd .cmdVel = 0.0 ;
3040
31- if (countLeft < countRight) {
41+ // Decide which side of the rover sees the most april tags and turn away
42+ // from that side
43+ if (count_left_collection_zone_tags < count_right_collection_zone_tags) {
3244 result.pd .cmdAngular = K_angular;
3345 } else {
3446 result.pd .cmdAngular = -K_angular;
@@ -37,21 +49,21 @@ Result ObstacleController::DoWork() {
3749 result.pd .setPointVel = 0.0 ;
3850 result.pd .cmdVel = 0.0 ;
3951 result.pd .setPointYaw = 0 ;
40-
41- }
42- else {
52+ }
4353
4454
45- // obstacle on right side
46- if (right < 0.8 || center < 0.8 || left < 0.8 ) {
47- result.type = precisionDriving;
55+ Result ObstacleController::DoWork () {
4856
49- result.pd .cmdAngular = -K_angular;
57+ clearWaypoints = true ;
58+ set_waypoint = true ;
59+ result.PIDMode = CONST_PID ;
5060
51- result.pd .setPointVel = 0.0 ;
52- result.pd .cmdVel = 0.0 ;
53- result.pd .setPointYaw = 0 ;
54- }
61+ // The obstacle is an april tag marking the collection zone
62+ if (collection_zone_seen){
63+ avoidCollectionZone ();
64+ }
65+ else {
66+ avoidObstacle ();
5567 }
5668
5769 if (can_set_waypoint) {
@@ -73,15 +85,15 @@ Result ObstacleController::DoWork() {
7385}
7486
7587
76- void ObstacleController::SetSonarData (float sonarleft, float sonarcenter, float sonarright) {
88+ void ObstacleController::setSonarData (float sonarleft, float sonarcenter, float sonarright) {
7789 left = sonarleft;
7890 right = sonarright;
7991 center = sonarcenter;
8092
8193 ProcessData ();
8294}
8395
84- void ObstacleController::SetCurrentLocation (Point currentLocation) {
96+ void ObstacleController::setCurrentLocation (Point currentLocation) {
8597 this ->currentLocation = currentLocation;
8698}
8799
@@ -91,7 +103,7 @@ void ObstacleController::ProcessData() {
91103 long int Tdifference = current_time - timeSinceTags;
92104 float Td = Tdifference/1e3 ;
93105 if (Td >= 0.5 ) {
94- centerSeen = false ;
106+ collection_zone_seen = false ;
95107 phys= false ;
96108 if (!obstacleAvoided)
97109 {
@@ -100,9 +112,9 @@ void ObstacleController::ProcessData() {
100112 }
101113
102114 // Process sonar info
103- if (ignoreCenter ){
104- if (center > reactivateCenterThreshold ){
105- ignoreCenter = false ;
115+ if (ignore_center_sonar ){
116+ if (center > reactivate_center_sonar_threshold ){
117+ ignore_center_sonar = false ;
106118 }
107119 else {
108120 center = 3 ;
@@ -124,7 +136,7 @@ void ObstacleController::ProcessData() {
124136 }
125137
126138
127- if (centerSeen || phys)
139+ if (collection_zone_seen || phys)
128140 {
129141 obstacleDetected = true ;
130142 obstacleAvoided = false ;
@@ -136,29 +148,49 @@ void ObstacleController::ProcessData() {
136148 }
137149}
138150
139- void ObstacleController::SetTagData (vector<TagPoint> tags){
140- float cameraOffsetCorrection = 0.020 ; // meters;
141- centerSeen = false ;
142- countLeft = 0 ;
143- countRight = 0 ;
151+ // Report April tags seen by the rovers camera so it can avoid
152+ // the collection zone
153+ // Added relative pose information so we know whether the
154+ // top of the AprilTag is pointing towards the rover or away.
155+ // If the top of the tags are away from the rover then treat them as obstacles.
156+ void ObstacleController::setTagData (vector<Tag> tags){
157+ collection_zone_seen = false ;
158+ count_left_collection_zone_tags = 0 ;
159+ count_right_collection_zone_tags = 0 ;
144160
145161 // this loop is to get the number of center tags
146162 if (!targetHeld) {
147163 for (int i = 0 ; i < tags.size (); i++) {
148- if (tags[i].id == 256 ) {
149-
150- // checks if tag is on the right or left side of the image
151- if (tags[i].x + cameraOffsetCorrection > 0 ) {
152- countRight++;
164+ if (tags[i].getID () == 256 ) {
153165
154- } else {
155- countLeft++;
156- }
157- centerSeen = true ;
166+ collection_zone_seen = checkForCollectionZoneTags ( tags );
158167 timeSinceTags = current_time;
159168 }
160169 }
161170 }
171+ }
172+
173+ bool ObstacleController::checkForCollectionZoneTags ( vector<Tag> tags ) {
174+
175+ for ( auto & tag : tags ) {
176+
177+ // Check the orientation of the tag. If we are outside the collection zone the yaw will be positive so treat the collection zone as an obstacle. If the yaw is negative the robot is inside the collection zone and the boundary should not be treated as an obstacle. This allows the robot to leave the collection zone after dropping off a target.
178+ if ( tag.calcYaw () > 0 )
179+ {
180+ // checks if tag is on the right or left side of the image
181+ if (tag.getPositionX () + camera_offset_correction > 0 ) {
182+ count_right_collection_zone_tags++;
183+
184+ } else {
185+ count_left_collection_zone_tags++;
186+ }
187+ }
188+
189+ }
190+
191+
192+ // Did any tags indicate that the robot is inside the collection zone?
193+ return count_left_collection_zone_tags + count_right_collection_zone_tags > 0 ;
162194
163195}
164196
@@ -191,16 +223,17 @@ bool ObstacleController::HasWork() {
191223 return !obstacleAvoided;
192224}
193225
194- void ObstacleController::SetIgnoreCenter (){
195- ignoreCenter = true ; // ignore center ultrasound
226+ // ignore center ultrasound
227+ void ObstacleController::setIgnoreCenterSonar (){
228+ ignore_center_sonar = true ;
196229}
197230
198- void ObstacleController::SetCurrentTimeInMilliSecs ( long int time )
231+ void ObstacleController::setCurrentTimeInMilliSecs ( long int time )
199232{
200233 current_time = time;
201234}
202235
203- void ObstacleController::SetTargetHeld () {
236+ void ObstacleController::setTargetHeld () {
204237 targetHeld = true ;
205238
206239
0 commit comments