Code to run the microcontrollers on the R5 competition bot
Dependencies: LineSensors mbed
Diff: DriveController.cpp
- Revision:
- 15:150ec9448efc
- Parent:
- 14:7a4cf2ed2499
diff -r 7a4cf2ed2499 -r 150ec9448efc DriveController.cpp --- a/DriveController.cpp Wed Apr 15 14:40:08 2015 +0000 +++ b/DriveController.cpp Sat Apr 18 02:54:55 2015 +0000 @@ -1,4 +1,5 @@ #include "DriveController.h" +#include "navcontroller.h" #define MOTOR_SCALE 0.5 #define CORRECTION_SCALE 0.15 @@ -8,23 +9,23 @@ DriveController::DriveController() : i2c(PTC2, PTC1), treadSpeed1(PTB0), treadSpeed2(PTB1), treadDirection1(PTE20), treadDirection2(PTE21), sensors(PTC7, PTC0, PTC3, PTC4, PTC5, PTC6, PTC10, PTC11, PTC9, PTC8, PTA5, PTA4, PTA12, PTD4, PTA2, PTA1, PTC12, PTC13, - PTC16, PTC17, PTD1, PTD0, PTD5, PTD13) + PTC16, PTC17, PTD1, PTD0, PTD5, PTD13), com1(PTC13), com2(PTC12) { - + } void DriveController::go() { sensors.setThreshold(); - wait(10); + // wait(10); treadSpeed1.period_us(50); //setting pwm period for all wheels to 20khz treadSpeed2.period_us(50); //spinTest(); - while(true) //test loop + /*while(true) //test loop { move(); wait(0.5); @@ -34,9 +35,9 @@ wait(0.5); rotate('R'); wait(0.5); - } + }*/ - /*while(true) + while(true) { getCommand(); @@ -52,7 +53,7 @@ } sendComplete(); - }*/ + } } void DriveController::move(char direction) @@ -197,7 +198,7 @@ { status = i2c.receive(); - if(status == 2) //if status is WriteGeneral + if(status == I2CSlave::WriteAddressed) //if status is WriteAddressed { command = i2c.read(); received = true; @@ -205,11 +206,6 @@ } } -void DriveController::sendComplete() -{ - i2c.write(1); -} - void DriveController::spinTest() { treadDirection1 = 1;