int main(void) { //setting up the timer and leds setup(); //gives the robot time to accept the commands to make squares delayMs(1000); //sets the play and advance LEDs off and the power LED to red robotLED(off, robotPowerRed, robotPowerOn); while (1) { delayMs(100); // Ask the robot about its bump sensors. byteTx(opReadSensors); // Opcode for "Read sensors" byteTx(packetButtons); // Sensor packet 7: Bumps and wheel drops // Read the one-byte response and extract the relevant bits. uint8_t buttons = byteRx(); uint8_t playButton = buttons & (1 << 0); uint8_t advanceButton = buttons & (1 << 2); //makes a square counterclockwise of legnth 250 mm at velocity 300 mm/s if(advanceButton) { //turn on the advance LED on the robot and sets the power LED to delayMs(500); //turns on the advance LED and sets the power LED to green robotLED(robotAdvanceLED, robotPowerGreen, robotPowerOn); //makes a square countercolokwise with sides = 250mm at 300 mm/s makeSquareCCW(300, 250); } //makes a square clockwise of legnth 250 mm at velocity 300 mm/s if(playButton) { //turn on the play LED on the robot and sets the power LED to green delayMs(500); //turn on the play LED and sets the power LED to green robotLED(robotPlayLED, robotPowerGreen, robotPowerOn); //makes a square colokwise with sides = 250mm at 300 mm/s makeSquareCW(300, 250); } //turns off the play LED and sets the pwer LED to red robotLED(off, robotPowerRed, robotPowerOn); } }
int main() { // Disable interrupts. ("Clear interrupt bit") cli(); // One-time setup operations. setupSerialPort(); setupRightLED(); setupLeftLED(); setupTimer(); // Enable interrupts. ("Set interrupt bit") sei(); byteTx(128); // Start the open interface. byteTx(132); // Switch to full Mode while(2+2==4) { delayMs(100); // Ask the robot about its bump sensors. byteTx(142); // Opcode for "Read sensors" byteTx(7); // Sensor packet 7: Bumps and wheel drops // Read the one-byte response and extract the relevant bits. uint8_t bumps = byteRx(); uint8_t bumpRight = bumps & (1 << 0); uint8_t bumpLeft = bumps & (1 << 1); // Set the command module LEDs based on this sensor data. if(bumpLeft) { leftLEDon(); } else { leftLEDoff(); } if(bumpRight) { rightLEDon(); } else { rightLEDoff(); } } }
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); } } }