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

Committer:
Overdrivr
Date:
Wed Feb 17 20:43:59 2016 +0000
Revision:
0:4fbaf36176b6
Child:
1:eeaf7cbb5582
Initial commit with telemetry set-up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Overdrivr 0:4fbaf36176b6 1 #include "telemetry/driver.hpp"
Overdrivr 0:4fbaf36176b6 2 #include "FRDM-TFC/TFC.h"
Overdrivr 0:4fbaf36176b6 3
Overdrivr 0:4fbaf36176b6 4 struct TM_state
Overdrivr 0:4fbaf36176b6 5 {
Overdrivr 0:4fbaf36176b6 6 float throttle;
Overdrivr 0:4fbaf36176b6 7 };
Overdrivr 0:4fbaf36176b6 8
Overdrivr 0:4fbaf36176b6 9 void process(TM_state * state, TM_msg * msg);
Overdrivr 0:4fbaf36176b6 10
Overdrivr 0:4fbaf36176b6 11 int main()
Overdrivr 0:4fbaf36176b6 12 {
Overdrivr 0:4fbaf36176b6 13 TFC_Init();
Overdrivr 0:4fbaf36176b6 14 TM_state state;
Overdrivr 0:4fbaf36176b6 15
Overdrivr 0:4fbaf36176b6 16 Telemetry tm(&state,115200);
Overdrivr 0:4fbaf36176b6 17 tm.sub(process);
Overdrivr 0:4fbaf36176b6 18
Overdrivr 0:4fbaf36176b6 19 Timer refresh_timer;
Overdrivr 0:4fbaf36176b6 20 refresh_timer.start();
Overdrivr 0:4fbaf36176b6 21 TFC_HBRIDGE_ENABLE;
Overdrivr 0:4fbaf36176b6 22 for( ; ; )
Overdrivr 0:4fbaf36176b6 23 {
Overdrivr 0:4fbaf36176b6 24 if(refresh_timer.read_ms() > 100)
Overdrivr 0:4fbaf36176b6 25 {
Overdrivr 0:4fbaf36176b6 26 tm.pub_f32("left",TFC_ReadMotorCurrent(0));
Overdrivr 0:4fbaf36176b6 27 tm.pub_f32("right",TFC_ReadMotorCurrent(1));
Overdrivr 0:4fbaf36176b6 28 tm.pub_f32("pot0",TFC_ReadPot(0));
Overdrivr 0:4fbaf36176b6 29 tm.pub_f32("pot1",TFC_ReadPot(1));
Overdrivr 0:4fbaf36176b6 30 tm.pub_f32("throttle",state.throttle);
Overdrivr 0:4fbaf36176b6 31 tm.pub_f32("bat",TFC_ReadBatteryVoltage());
Overdrivr 0:4fbaf36176b6 32
Overdrivr 0:4fbaf36176b6 33 TFC_SetMotorPWM(state.throttle ,state.throttle);
Overdrivr 0:4fbaf36176b6 34 tm.update();
Overdrivr 0:4fbaf36176b6 35 }
Overdrivr 0:4fbaf36176b6 36 }
Overdrivr 0:4fbaf36176b6 37 }
Overdrivr 0:4fbaf36176b6 38
Overdrivr 0:4fbaf36176b6 39 void process(TM_state * state, TM_msg * msg)
Overdrivr 0:4fbaf36176b6 40 {
Overdrivr 0:4fbaf36176b6 41 if(msg->type == TM_float32)
Overdrivr 0:4fbaf36176b6 42 {
Overdrivr 0:4fbaf36176b6 43 float th = 0;
Overdrivr 0:4fbaf36176b6 44 if(emplace_f32(msg,&th))
Overdrivr 0:4fbaf36176b6 45 {
Overdrivr 0:4fbaf36176b6 46 state->throttle = th;
Overdrivr 0:4fbaf36176b6 47 }
Overdrivr 0:4fbaf36176b6 48 }
Overdrivr 0:4fbaf36176b6 49 }