//----------------------------------------------------------------- // File: PBot_MkIII_Sumo-C_VC6.osc // // Project: Sumo Program using PBot_MkIII_1.0_VC6 oUserClass // // Designer: Phil Malone, www.philbot.com // Details: http://www.philbot.com/projects/markIII_sumo // // Details: Mode C Seeker Unit. (Search Priority) // // Mode C is a "Seeker" 5 priority Sumo Stance. // // Priority 1: Avoid the Edge of the ring. // Priority 2: Push the opponent if BOTH eyes see him // Priority 3: Turn towards the opponent if ONE eye sees him. // Priority 4: Move forward if spinning doesn't work. // Priority 5: Spin to locate the opponent. // // Basic program flow is: // // 1) Wait 4 seconds // 2) Calibrate the line sensors // 3) Wait for last second to elapse // 4) Run the main action-priority loop // // Comments: // // This program is NOT fooled by an opponent that has a white line // on it's pusher bar. However it may be distracted by a bystander // and drive off the ring. Keep people away during combat !!! // // Version Date Comment // ------- --------- ------- // 1.00 8/22/2005 First release for VC6 // //----------------------------------------------------------------- // Create instance of MkIII Object. oUserClass BOT = New oUserClass("PBot_MkIII_1.0_VC6.osc"); // Create motion constants (based on specific Bot) Const FAST_FORWARD = 10; Const SLOW_FORWARD = 1; Const FAST_REVERSE = -10; Const SEEK_TIMEOUT = 50; // Five seconds // Main program Void Main(Void) { // Calibrate one second before Match While(BOT.ActionTimer > BOT.ONE_SECOND) ; // Wait for last second BOT.SumoCalibrate(); // Calibrate for Sumo BOT.EnableDiagnostics(); // Turn on status LEDs (optional) // Wait for last second to expire While(BOT.ActionTimer.NonZero) ; // Run main program loop forever. While (cvTrue) { // Run down the SUMO priority list // Priority 1: Avoid the border If (BOT.LeftLineWhite) { // If we see left line, backup & start spinning right BOT.Drive(FAST_REVERSE,FAST_REVERSE, 3); BOT.Drive(FAST_FORWARD,FAST_REVERSE, 0); ActionTimer.Value = SEEK_TIMEOUT; // Don't seek forever } Else If (BOT.RightLineWhite) { // If we see right line, backup and start spinning left BOT.Drive(FAST_REVERSE,FAST_REVERSE, 3); BOT.Drive(FAST_REVERSE,FAST_FORWARD, 0); ActionTimer.Value = SEEK_TIMEOUT; // Don't seek forever } // Priority 2: PUSH the opponent is BOTH eyes see him Else If (BOT.LeftEyeOn && BOT.RightEyeOn) { // Go forward, no time limit BOT.Drive(FAST_FORWARD,FAST_FORWARD, 0); } // Priority 3: Turn Towards the opponent is seen in ONE eye Else If (BOT.RightEyeOn) { // Turn right towards the target, no time limit BOT.Drive(FAST_FORWARD,SLOW_FORWARD, 0); } Else If (BOT.LeftEyeOn) { // Turn left towards the target, no time limit BOT.Drive(SLOW_FORWARD,FAST_FORWARD, 0); } // Priority 4: Go Straight if seeking times out Else If (ActionTimer == 0) { // Go forward, no time limit BOT.Drive(FAST_FORWARD,FAST_FORWARD, 0); } // Priority 5: Don't stop what you are doing Else { ; // No Change Need semi-colon here to prevent error } } }