180 likes | 318 Views
Control. Some Material taken from RobotSubsumption.pdf. Remember Where Are We Going?. Sumo-Bot competitions. Controlling Robot Movement Based on QTI Readings. #include <Servo.h> // Include servo library // pin designations int LeftQTI = 8; int RightQTI = 2;
E N D
Control Some Material taken from RobotSubsumption.pdf
Remember Where Are We Going? Sumo-Bot competitions
Controlling Robot Movement Based on QTI Readings #include <Servo.h> // Include servo library // pin designations int LeftQTI = 8; int RightQTI = 2; int leftServoPin = 12; int rightServoPin = 3; // program parameters int moveTime = 500; int turnTime = 800; int debug = 0; // previously established average QTI readings const int LeftDark = 1000; const int RightDark = 1000; const int LeftWhite = 60; const int RightWhite = 60;
Code // Threshold for strong light and dark differences int LeftThreshold = LeftWhite * 2; int RightThreshold = RightWhite * 2; // declare servo objects Servo servoLeft; Servo servoRight; void setup() { pinMode(leftServoPin, OUTPUT); pinMode(rightServoPin, OUTPUT); servoLeft.attach(leftServoPin); servoRight.attach(rightServoPin); Serial.begin(9600); }
Code void loop() // Main loop auto-repeats { long tLeft = rcTime(LeftQTI); // Left rcTime -> tLeft long tRight = rcTime(RightQTI); // Right rcTime -> tRight if (debug == 1) { Serial.print(tLeft); Serial.print(" "); Serial.println(tRight); }
Code if((tLeft < LeftThreshold) && (tRight < RightThreshold)) { maneuver(-200, -200, moveTime); } else if(tLeft < LeftThreshold) { maneuver(-200, -200, moveTime); maneuver(-200, 200, turnTime); } else if(tRight < RightThreshold) { maneuver(-200, -200, moveTime); maneuver(200, -200, turnTime); } else { maneuver(200, 200, 20); } } rcTime() and maneuver() not shown
Read QTIs backup turn right turn left go forward Finite State Machine (FSM) Representation both high left low right low both low
Controlling Robot Movement Based on Proximity Measurement void loop () { sonar.fire(); double forwardDistance = sonar.inches(); int irLeft = irDetect(LeftLED, LeftDec, 38000); int irRight = irDetect(RightLED, RightDec, 38000); if (forwardDistance>0 && forwardDistance<MAX_DISTANCE) { maneuver(200, 200, forwardTime); } else if(irLeft == 0) { maneuver(200, -200, SearchTurnTime); } else if(irRight == 0) { maneuver(-200, 200, SearchTurnTime); } else { maneuver(200, 200, 20); } }
No Obj Obj left Obj right Obj forward Read IR & Sonar Go forward turn right turn left go forward Finite State Machine (FSM) Representation
go forward turn left turn right backup Read QTIs How to Put It Together? No Obj Obj left Obj right Obj forward Read IR & sonar Go forward turn right turn left go forward both high left low right low both low
Possible Problems • Jerky or halting movement • Chase object over boundary • Never detect opponent • More?
Possible Solution • Subsumption Architecture A programming process by which one behavior subsumes, or over-rides another based on an explicit priority that we have defined. First described by Dr. Rodney Brooks in "A robust layered control system for a mobile robot,” IEEE Journal of Robotics and Automation., RA-2, April, 14-23, 1986. • FSM with exit conditions
Go forward Go backwards turn teft turn right read IR & sonar and set nextState variable read QTIs and set nextState variable check nextState variable and branch FSM
backup turn right turn left go forward read QTIs and set nextState variable check nextState variable and branch Read IR Alternative FSM Go forward turn right turn left go forward
Program High-Level Outline • Declare pin assignments, constants and variables • Initialize thresholds • Wait the required start delay • Read boundary line sensors and move accordingly • If the boundary line is not detected, read proximity sensors and move accordingly • Repeat steps 4 and 5 until completion
Main Loop if((tLeft < LeftThreshold) && (tRight < RightThreshold)) { maneuver(-200, -200, backwardTime); } else if(tLeft < LeftThreshold) { maneuver(-200, -200, backwardTime); maneuver(-200, 200, LineTurnTime); } else if(tRight < RightThreshold) { maneuver(-200, -200, backwardTime); maneuver(200, -200, LineTurnTime); } else { maneuver(200, 200, 20); searchForOpponent(); }
SearchForOpponent() void searchForOpponent() { sonar.fire(); double forwardDistance = sonar.inches(); int irLeft = irDetect(LeftLED, LeftDec, 38000); int irRight = irDetect(RightLED, RightDec, 38000); if (forwardDistance>0 && forwardDistance<MAX_DISTANCE) { maneuver(200, 200, forwardTime); } else if(irLeft == 0) { maneuver(200, -200, SearchTurnTime); } else if(irRight == 0) { maneuver(-200, 200, SearchTurnTime); } else { maneuver(200, 200, 20); } }
Possible Enhancements • Optimize the position of the sensors • Optimize your mechanical design for fighting • Design against being pushed out of the ring • Optimize the code to maximize bot performance • Evaluate tradeoffs in movement choices and sensor reading