RC-car remotely controlled from a computer. A demonstration of the power of Pytelemetry/telemetry. MIT Licensing.
Dependencies: BufferedSerial FRDM-TFC mbed telemetry
Example of the 'Telemetry' library, a portable communication library for embedded devices. The PC-side of this code is hosted a github.com/Overdrivr/telemetry-examples
This code uses the car from the Freescale Cup competition initially dedicated to be a line-following racing car, and turns it into a full-blown radio-controlled car.
It is using a Bluetooth serial module to provide wireless connectivity. See the repository at github.com/Overdrivr/telemetry-examples for complete instructions on wiring everthing together.
Repo : TO BE DONE
main.cpp
- Committer:
- Overdrivr
- Date:
- 2016-02-16
- Revision:
- 0:c5e974040f21
- Child:
- 1:5a07069e17b6
File content as of revision 0:c5e974040f21:
#include "mbed.h" #include "FRDM-TFC/TFC.h" #include "telemetry/driver.hpp" DigitalOut led(LED1); struct TM_state { float direction; float throttle; }; void process(TM_state* carState, TM_msg* msg); int main() { TM_state carState; carState.direction = 0; carState.throttle = 0; Telemetry TM(&carState); TM.sub(process); led = 1; TFC_Init(); Timer servo_timer; Timer motor_timer; Timer tm_timer; Timer print_timer; servo_timer.start(); motor_timer.start(); tm_timer.start(); print_timer.start(); TFC_HBRIDGE_ENABLE; for(;;) { // update telemetry if(tm_timer.read_ms() > 50) { tm_timer.reset(); TM.update(); } // update servo control if(servo_timer.read_ms() > 10) { servo_timer.reset(); TFC_SetServo(0, carState.direction); } // update motor control if(motor_timer.read_ms() > 5) { motor_timer.reset(); TFC_SetMotorPWM(carState.throttle , carState.throttle); } // publish car state & blink a led if(print_timer.read_ms() > 500) { print_timer.reset(); TM.pub_f32("direction",carState.direction); TM.pub_f32("throttle",carState.throttle); led = (led == 0) ? 1 : 0; } } } void process(TM_state* carState, TM_msg* msg) { float value = 0.f; if(strcmp(msg->topic,"direction") == 0) { if(emplace_f32(msg,&value)) { if(value > 1.f) value = 1.f; if(value < -1.f) value = -1.f; carState->direction = value; } } else if(strcmp(msg->topic,"throttle") == 0) { if(emplace_f32(msg,&value)) { if(value > 1.f) value = 1.f; if(value < -1.f) value = -1.f; carState->throttle = value; } } }