int main(void) { int light_level = 0; Roach_Init(); printf("Welcome to the Roach Test\r\n"); printf("Bump states and light levels will be printed to the terminal every .1 seconds while also controlling the motor speed\r\n"); InitTimer(0, 2000); while (!IsTimerExpired(0)); while (1) { light_level = LightLevel() / 100; if (ReadFrontLeftBumper()) { LeftMtrSpeed(light_level); } if (ReadFrontRightBumper()) { RightMtrSpeed(light_level); } if (ReadRearLeftBumper()) { LeftMtrSpeed(light_level*-1); } if (ReadRearRightBumper()) { RightMtrSpeed(light_level*-1); } if(IsTimerExpired(0)==TIMER_EXPIRED){ printf("%d\t%d\t%d\t%d\t%d", ReadFrontLeftBumper(), ReadFrontRightBumper(), ReadRearLeftBumper(), ReadRearRightBumper(), LightLevel()); InitTimer(0, 100); } } return 0; }
//Function: RotateCCW: rotates the bot CCW. void RotateCCW(unsigned char newSpeed) { Serial.println("I'm rotating counterclockwise!"); LeftMtrSpeed(0); // motors not meant for instantaneous reverse so including a brief stop RightMtrSpeed(0); delayMicroseconds(10); LeftMtrSpeed(newSpeed); RightMtrSpeed(-0.5*newSpeed); }
//Function: TurnLeft: Turns left at given speed. void TurnLeft(unsigned char newSpeed) { Serial.println("I'm turning left!"); LeftMtrSpeed(0); // motors not meant for instantaneous reverse so including a brief stop RightMtrSpeed(0); delayMicroseconds(10); LeftMtrSpeed(0-newSpeed); RightMtrSpeed(newSpeed); }
//Function: Backward: motors move the BitBot backward void Backward(unsigned char newSpeed){ Serial.println("I'm going backward!"); LeftMtrSpeed(0); // motors not meant for instantaneous reverse so including a brief stop RightMtrSpeed(0); delayMicroseconds(10); LeftMtrSpeed(0-newSpeed); RightMtrSpeed(0-newSpeed); }
void DriveForward(char newSpeed){ LeftMtrSpeed(newSpeed); RightMtrSpeed(newSpeed); }
void DriveBackward(char newSpeed){ LeftMtrSpeed(-1 * newSpeed); RightMtrSpeed(-1 * newSpeed); }
//Function: Stop: stops the motors void Stop() { Serial.println("I'm stopping!"); LeftMtrSpeed(0); RightMtrSpeed(0); }
void SpinLeft(char newSpeed){ LeftMtrSpeed(1 * newSpeed); RightMtrSpeed(-1 * newSpeed); }