turning
Dependencies: Rectangle Servo TextLCD mbed
Fork of FollowMeBot by
Diff: iRobot/iRobot.cpp
- Revision:
- 3:de12b39ad805
- Parent:
- 1:6c399fc35deb
diff -r 0b362c662997 -r de12b39ad805 iRobot/iRobot.cpp --- a/iRobot/iRobot.cpp Thu Nov 21 00:02:05 2013 +0000 +++ b/iRobot/iRobot.cpp Mon Nov 25 19:55:12 2013 +0000 @@ -28,15 +28,15 @@ // Start - send start and safe mode, start streaming sensor data void iRobot::start() { - // device.printf("%c%c", Start, SafeMode); - device.putc(Start); - device.putc(SafeMode); + device.printf("%c%c", Start, SafeMode); + //device.putc(Start); + //device.putc(SafeMode); wait(.5); - // device.printf("%c%c%c", SensorStream, char(1), BumpsandDrops); + /* device.printf("%c%c%c", SensorStream, char(1), BumpsandDrops); device.putc(SensorStream); device.putc(1); device.putc(BumpsandDrops); - wait(.2); + wait(.2);*/ // Setup a serial interrupt function to receive data device.attach(this, &iRobot::receive_sensor); } @@ -72,6 +72,33 @@ char((speed_left>>8)&0xFF), char(speed_left&0xFF)); } +// Angle - The angle in degrees that iRobot Create has turned since the +//angle was last requested +int iRobot::getAngle() +{ + char angleBuff[2]; + device.printf("%c%c", Sensors, Angle); + device.gets(angleBuff, 2); + return atoi(angleBuff); +} + +// Turn Angle - The angle in degrees that iRobot Create has turned since the +//angle was last requested ccw is pos angle, cw is neg angle +void iRobot::turnAngle(int angle) +{ + char angleTurn[3]; + angleTurn[0] = waitAngle; + angleTurn[1] = angle >> 8; + angleTurn[2] = angle & 0xFF; + if(angle > 0){ + device.printf("%c%c%c%c",char(137), char(0), char(200), char(0), char(1)); + } + else if(angle < 0){ + device.printf("%c%c%c%c",char(137), char(0), char(200), char(255), char(255)); + } + device.printf("%c%c%c", angleTurn[0], angleTurn[1], angleTurn[2]); + wait(.05); +} // Charger - search and return to charger using IR beacons (if found) void iRobot::charger() { @@ -96,6 +123,7 @@ void iRobot::receive_sensor() { char start_character; + printf("reading\n"); // Loop just in case more than one character is in UART's receive FIFO buffer while (device.readable()) { switch (Sensor_byte_count) {