// Declare Global variables int main(void) { // Set up Create and module initializeCommandModule(); powerOnRobot(); // Is the Robot on byteTx(CmdStart); // Start the create baud(Baud57600); // Set the baud rate for the Create and Command Module defineSongs(); // Define some songs so that we know the robot is on. byteTx(CmdControl); // Deprecated form of safe mode. I use it because it will // turn of all LEDs, so it's essentially a reset. byteTx(CmdFull); // We are operating in FULL mode. // Play the reset song and wait while it plays. byteTx(CmdPlay); byteTx(RESET_SONG); delayMs(750); // Turn the power button on to something. turnOnPowerButtonLight(); delayMs(20); // Infinite operation loop int timerLoop = 0; const int timerLimit = 15; initializeUSBBuffer(); initializeRobotBuffer(); initializeSensorArray(); setLEDs(BOTHLED, FULL); enableReports(); enableSensors(); while(1) { pollSensors(); if(timerLoop == timerLimit){ compileReport(); sendUSBBuffer(); timerLoop = 0; delayMs(1); } timerLoop++; pollRemoteSensors(); pollRemote(); executeCommand(); delayMs(5); } }
// Declare Global variables int main(void) { // Set up Create and module initializeCommandModule(); powerOnRobot(); // Is the Robot on byteTx(CmdStart); // Start the create baud(Baud57600); // Set the baud rate for the Create and Command Module defineSongs(); // Define some songs so that we know the robot is on. byteTx(CmdControl); // Deprecated form of safe mode. I use it because it will // turn of all LEDs, so it's essentially a reset. byteTx(CmdFull); // We are operating in FULL mode. // Play the reset song and wait while it plays. byteTx(CmdPlay); byteTx(RESET_SONG); delayMs(750); // Turn the power button on to something. delayMs(20); initializeUSBBuffer(); initializeRobotBuffer(); initializeSensorArray(); setLEDs(BOTHLED, FULL); enableReports(); enableSensors(); int fakeTimer = 0; // Infinite operation loop while(1) { if (fakeTimer == 4) { compileReport(); sendUSBBuffer(); fakeTimer = 0; } pollSensors(); delayMs(250); fakeTimer++; } }
int main() { // Set up Create and module initializeCommandModule(); powerOnRobot(); // Is the Robot on byteTx(CmdStart); // Start the create baud(Baud57600); // Set the baud rate for the Create and Command Module defineSongs(); // Define some songs so that we know the robot is on. byteTx(CmdControl); // Deprecated form of safe mode. I use it because it will // turn of all LEDs, so it's essentially a reset. byteTx(CmdFull); // We are operating in FULL mode. // CSCE 274 students: I would make sure the robot stops. // As a precaution for the robot and your grade. //Doesn't need to stop for task 1 since it doesn't move. // Play the reset song and wait while it plays. byteTx(CmdPlay); byteTx(RESET_SONG); delayMs(750); // Turn the power button on to something. I like red, but here is green. // CSCE 274 students: The following should (will) be a function that you write. changePowerLightRed(); //power light now red // Initialize global variables uint8_t bumpbyte, bumpLeft, bumpRight; int rightLEDonInt = 0; int leftLEDonInt = 1; //call initial functions //setup LEDs setupRightLED(); setupLeftLED(); leftLEDon(); //start with left LED on // Infinite operation loop for(;;) { while (!bumpRight && !bumpLeft) { //no bumps //no bumps are rightLED on if (rightLEDonInt == 1 && leftLEDonInt == 0 && !bumpRight && !bumpLeft) { rightLEDoff(); rightLEDonInt = 0; leftLEDon(); leftLEDonInt = 1; } //no bumps and left LED on else if (rightLEDonInt == 0 && leftLEDonInt == 1 && !bumpRight && !bumpLeft) { rightLEDon(); rightLEDonInt = 1; leftLEDoff(); leftLEDonInt = 0; } //no bumps and LEDs off else if (rightLEDonInt == 0 && leftLEDonInt == 0 && !bumpRight && !bumpLeft) { rightLEDon(); rightLEDonInt = 1; }//no bumps and both LEDs on else if (rightLEDonInt == 1 && leftLEDonInt == 1 && !bumpRight && !bumpLeft) { leftLEDon(); leftLEDonInt = 1; } delayMs(100); //delay for tenth of a second //update bump sensors byteTx(CmdSensors); byteTx(SenOverC); bumpbyte = byteRx(); bumpRight = bumpbyte & (1 << 0); bumpLeft = bumpbyte & (1 << 1); } //update bump sensors again byteTx(CmdSensors); byteTx(SenOverC); bumpbyte = byteRx(); bumpRight = bumpbyte & (1 << 0); bumpLeft = bumpbyte & (1 << 1); //turn on LEDs according to bump sensors if (bumpRight) { rightLEDon(); rightLEDonInt = 1; } else { rightLEDoff(); rightLEDonInt = 0; } if (bumpLeft) { leftLEDon(); leftLEDonInt = 1; } else { leftLEDoff(); leftLEDonInt = 0; } delayMs(10); if(UserButtonPressed) { powerOffRobot(); exit(1); } } }
// Declare Global variables int main(void) { // Set up Create and module initializeCommandModule(); powerOnRobot(); // Is the Robot on byteTx(CmdStart); // Start the create baud(Baud57600); // Set the baud rate for the Create and Command Module defineSongs(); // Define some songs so that we know the robot is on. byteTx(CmdControl); // Deprecated form of safe mode. I use it because it will // turn of all LEDs, so it's essentially a reset. byteTx(CmdFull); // We are operating in FULL mode. // Play the reset song and wait while it plays. byteTx(CmdPlay); byteTx(RESET_SONG); delayMs(750); // Turn the power button on to something. initializeSensors(); // Sets up sensors. delayMs(200); // Gives the robot time to process. allowDriving(); // Enables Driving. enableOrders(); // Enables driveOrders() initializePlanner(); // Sets up the planner. decidePlanState(); // Decide on an initial state of the planner. disableIntegral(); // Integral term only used for state MAKETURN. //int16_t speed = DRIVESPEED; // Standard speed. delayMs(500); // Gives the robot time to process all of the above before continuing. // Infinite operation loop while(1) { compileSensors(); // Build the sensor Struct. Automatic Polling. decidePlanState(); delayMs(50); // The above operations are time-consuming, so wait. switch (getPlanState()) { case FINDWALL: debugLEDOff(); delayMs(10); break; case REPOSITION: buildInfrared(); buoyLights(); doDocking(); break; case STOP: driveOrders(0, 0, 50); debugLEDOff(); delayMs(10); break; default: debugLEDOff(); // Turn on the lights. delayMs(10); break; } } }
int main (void) { uint8_t leds_cnt = 99; uint8_t leds_state = 0; uint8_t leds_on = 1; int16_t turn_angle = 0; uint8_t turn_dir = 1; uint8_t turning = 0; uint8_t backing_up = 0; // Set up Create and module initialize(); LEDBothOff; powerOnRobot(); byteTx(CmdStart); baud(Baud28800); defineSongs(); byteTx(CmdControl); byteTx(CmdFull); // Stop just as a precaution patrol_room(0, RadStraight); // Play the reset song and wait while it plays byteTx(CmdPlay); byteTx(RESET_SONG); delayAndUpdateSensors(750); for(;;) { if(++leds_cnt >= 100) { leds_cnt = 0; leds_on = !leds_on; if(leds_on) { byteTx(CmdLeds); byteTx(LEDsBoth); byteTx(128); byteTx(255); LEDBothOff; } else { byteTx(CmdLeds); byteTx(0x00); byteTx(0); byteTx(0); LEDBothOn; } } delayAndUpdateSensors(10); if(UserButtonPressed) { // Play start song and wait byteTx(CmdPlay); byteTx(START_SONG); delayAndUpdateSensors(2813); // Drive around until a button or unsafe condition is detected while(!(UserButtonPressed) && (!sensors[SenCliffL]) && (!sensors[SenCliffFL]) && (!sensors[SenCliffFR]) && (!sensors[SenCliffR]) && (!sensors[SenChAvailable]) ) { // Keep turning until the specified angle is reached if(turning) { if(backing_up) { if((-distance) > 5) backing_up = 0; patrol_room(-200, RadStraight); } else { if(turn_dir) { if(angle > turn_angle) turning = 0; patrol_room(200, RadCCW); } else { if((-angle) > turn_angle) turning = 0; patrol_room(200, RadCW); } } } else if(sensors[SenBumpDrop] & BumpEither) // Check for a bump { // Set the turn parameters and reset the angle if(sensors[SenBumpDrop] & BumpLeft) turn_dir = 0; else turn_dir = 1; backing_up = 1; turning = 1; distance = 0; angle = 0; turn_angle = randomAngle(); // Play the bump song byteTx(CmdPlay); byteTx(BUMP_SONG); } else { // Otherwise, patrol_room straight patrol_room(300, RadStraight); } // Flash the leds in sequence if(++leds_cnt >= 10) { leds_cnt = 0; if(turning) { // Flash backward while turning if(leds_state == 0) leds_state = 4; else leds_state--; } else { if(leds_state == 4) leds_state = 0; else leds_state++; } if(leds_state == 0) { // robot Power LED Amber byteTx(CmdLeds); byteTx(0x00); byteTx(128); byteTx(255); LEDBothOff; } else if(leds_state == 1) { // Play LED on byteTx(CmdLeds); byteTx(LEDPlay); byteTx(0); byteTx(0); LEDBothOff; } else if(leds_state == 2) { // Advance LED on byteTx(CmdLeds); byteTx(LEDAdvance); byteTx(0); byteTx(0); LEDBothOff; } else if(leds_state == 3) { // Robot LEDs off, CM left LED on byteTx(CmdLeds); byteTx(0x00); byteTx(0); byteTx(0); LED2On; LED1Off; } else if(leds_state == 4) { // Robot LEDs off, CM right LED on byteTx(CmdLeds); byteTx(0x00); byteTx(0); byteTx(0); LED1On; LED2Off; } } // wait a little more than one robot tick for sensors to update delayAndUpdateSensors(20); } // Stop driving patrol_room(0, RadStraight); // Play end song and wait delayAndUpdateSensors(500); byteTx(CmdPlay); byteTx(END_SONG); delayAndUpdateSensors(2438); } } }