Ejemplo n.º 1
0
/*
This function will follow the overlap of red and green until
	both bumps are detected.
*/
void followOverlap(void) {
	//do until bump
	do {
		//if sensing both, drive
		if (green && red) {
			rightLEDon();
			leftLEDon();
			drive(35);
		} else if (!green && red) { //only red, turn left
			leftLEDoff();
			rightLEDon();
			driveLR(-25, 25);
		} else if (!red && green) { //only green, turn right
			leftLEDon();
			rightLEDoff();
			driveLR(25, -25);
		} else { //no signal, drive (means close to dock)
			rightLEDoff();
			leftLEDoff();
			drive(35);
		}
		getBumps();
		getDockSenses();
		delayMs(50);
	} while (!bumpLeft || !bumpRight);
	stop();
}
int main(void) {
// 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.
// Toggle the LEDs once each second.
while(2+2==4) {
rightLEDon();
leftLEDoff();
byteTx(139); // Opcode for "Set LEDs"
byteTx(10); // Led bits: both on
byteTx(0); // Power led color: Fully green
byteTx(255); // Power led intensity
delayMs(1000);
rightLEDoff();
leftLEDon();
byteTx(139); // Opcode for "Set LEDs"
byteTx(0); // Led bits: both off
byteTx(255); // Power led color: Fully red
byteTx(255); // Power led intensity
delayMs(1000);
}
}
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();
}
}
}
Ejemplo n.º 4
0
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);
    }
  }
}