A demonstration of the telemetry library (https://github.com/Overdrivr/Telemetry) to transfert to the desktop various data from the FRDM-TFC shield
Dependencies: BufferedSerial FRDM-TFC-HBRIDGE mbed telemetry
Example of the 'Telemetry' library, a portable communication library for embedded devices.
This code fetches all the data from the Freescale Cup RC-car. It relies on a more advanced shield library that is able to read current feedback from HBridges.
The available data is the following :
- Potentiometer 0
- Potentiometer 1
- 4-bit DIP switch
- Battery level
- current inside HBridge A
- current inside HBridge B
You can use the Pytelemetry Command Line Interface to open plots, visualize the received data, and communicate with the car.
See https://github.com/Overdrivr/pytelemetrycli
Diff: main.cpp
- Revision:
- 0:4fbaf36176b6
- Child:
- 1:eeaf7cbb5582
diff -r 000000000000 -r 4fbaf36176b6 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Feb 17 20:43:59 2016 +0000 @@ -0,0 +1,49 @@ +#include "telemetry/driver.hpp" +#include "FRDM-TFC/TFC.h" + +struct TM_state +{ + float throttle; +}; + +void process(TM_state * state, TM_msg * msg); + +int main() +{ + TFC_Init(); + TM_state state; + + Telemetry tm(&state,115200); + tm.sub(process); + + Timer refresh_timer; + refresh_timer.start(); + TFC_HBRIDGE_ENABLE; + for( ; ; ) + { + if(refresh_timer.read_ms() > 100) + { + tm.pub_f32("left",TFC_ReadMotorCurrent(0)); + tm.pub_f32("right",TFC_ReadMotorCurrent(1)); + tm.pub_f32("pot0",TFC_ReadPot(0)); + tm.pub_f32("pot1",TFC_ReadPot(1)); + tm.pub_f32("throttle",state.throttle); + tm.pub_f32("bat",TFC_ReadBatteryVoltage()); + + TFC_SetMotorPWM(state.throttle ,state.throttle); + tm.update(); + } + } +} + +void process(TM_state * state, TM_msg * msg) +{ + if(msg->type == TM_float32) + { + float th = 0; + if(emplace_f32(msg,&th)) + { + state->throttle = th; + } + } +} \ No newline at end of file