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

main.cpp

Committer:
Overdrivr
Date:
2016-02-17
Revision:
0:4fbaf36176b6
Child:
1:eeaf7cbb5582

File content as of revision 0:4fbaf36176b6:

#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;   
        }
    }   
}