m3Dpi robot, based on the Pololu 3pi and m3pi. m3Dpi has multiple distance sensors, gyroscope, compass and accelerometer sensor to be fully aware of its environment. With the addition of xbee or nrf24n01 module it has wireless communication capabilities.
Dependencies: m3Dpi mbed-rtos mbed MbedJSONValue
Diff: main.cpp
- Revision:
- 10:a5f43326e0b0
- Parent:
- 9:5292bf545459
--- a/main.cpp Wed Dec 16 13:27:43 2015 +0000 +++ b/main.cpp Thu Dec 17 14:51:19 2015 +0000 @@ -41,50 +41,44 @@ void read_commands_thread(void const *args) { - if(robot.xbee.readable()){ + while(robot.xbee.readable()){ char command = robot.xbee.getc(); switch(command){ case 'l': // Left - if(direction == 'f'){ - l_wheel += 0.1; - }else{ - l_wheel -= 0.1; - } + l_wheel = -0.10; + r_wheel = 0.10; break; case 'r': // Right - if(direction == 'f'){ - r_wheel += 0.1; - }else{ - r_wheel -= 0.1; - } + l_wheel = 0.10; + r_wheel = -0.10; break; case 'f': // Frontward - r_wheel += 0.1; - l_wheel += 0.1; - direction = 'f'; + l_wheel = 0.1; + r_wheel = 0.1; break; case 'b': // Backward - r_wheel -= 0.1; - l_wheel -= 0.1; - direction = 'b'; + l_wheel = -0.1; + r_wheel = -0.1; break; case 's': // Brake + l_wheel = 0; r_wheel = 0; - l_wheel = 0; - direction = 'f'; break; default: - pc.printf("Unknown command %c.\n", command); + robot.xbee.printf("Unknown command %c.\n", command); } - - robot.left_motor(l_wheel); - robot.right_motor(r_wheel); + robot.left_motor(l_wheel); + robot.right_motor(r_wheel); } + + // Stop if the robot doesn't receive anything in 100 ms. + l_wheel = 0; + r_wheel = 0; } int main() @@ -94,8 +88,8 @@ RtosTimer readSensorsThread(read_sensors_thread, osTimerPeriodic); readSensorsThread.start(1000); - RtosTimer readCommandsThread(read_commands_thread, osTimerPeriodic); - readCommandsThread.start(50); + Thread readCommandsThread(read_commands_thread); + //readCommandsThread.start(100); Thread::wait(osWaitForever); } \ No newline at end of file