A demo on NXP KL25Z of the telemetry library to publish some sensor data that can be read/plotted on the computer using pytelemetrycli (https://github.com/Overdrivr/pytelemetrycli) Published data: "touch" -> capacitive slider output value "acc:x" -> x channel of the accelerometer "acc:y" -> y channel "acc:z" -> z channel
Dependencies: BufferedSerial MMA8451Q mbed telemetry tsi_sensor
Diff: main.cpp
- Revision:
- 1:b63db8e76533
- Parent:
- 0:d38b884af46a
- Child:
- 2:9bf273ead1b0
--- a/main.cpp Thu Feb 11 08:59:40 2016 +0000 +++ b/main.cpp Mon Feb 22 21:58:19 2016 +0000 @@ -1,41 +1,50 @@ #include "mbed.h" -#include "telemetry/driver.hpp" +#include "telemetry/Telemetry.h" #include "tsi_sensor.h" #include "MMA8451Q.h" #define MMA8451_I2C_ADDRESS (0x1d<<1) -DigitalOut led(LED1); +/* + Example of the 'Telemetry' library, a portable communication library for embedded devices. + + This code fetches all the data from the KL25Z bord and publishes it on different topics : + + The available data is the following : + * Accelerometer X + * Accelerometer Y + * Accelerometer Z + * Capacitive slider + + 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 +*/ -struct TM_state { - float throttle; -}; -void process(TM_state* state, TM_msg* msg); +DigitalOut led(LED1); int main() { - // Instance the structure holding our application tuning parameters - TM_state state; - state.throttle = 0; - - // Instance Telemetry - Telemetry TM(&state); - // Connect our process function - TM.sub(process); - + Telemetry TM(115200); + // Some sensors to read TSIAnalogSlider tsi(PTB16,PTB17,40); MMA8451Q acc(PTE25, PTE24); led = 1; + // Some timers Timer tm_timer; Timer print_timer; Timer led_timer; tm_timer.start(); print_timer.start(); + led_timer.start(); + + // To store accelerometer values + int16_t axis[3]; for(;;) { @@ -53,15 +62,11 @@ print_timer.reset(); TM.pub_f32("touch",tsi.readPercentage()); - int16_t axis[3]; acc.getAccAllAxis(axis); - TM.pub_i16("acc:x",axis[0]); - TM.pub_i16("acc:y",axis[1]); - TM.pub_i16("acc:z",axis[2]); - - TM.pub_f32("throttle",state.throttle); - + TM.pub_i16("acc/x",axis[0]); + TM.pub_i16("acc/y",axis[1]); + TM.pub_i16("acc/z",axis[2]); } if(led_timer.read_ms() > 500) @@ -70,19 +75,4 @@ led = (led == 0) ? 1 : 0; } } -} - -void process(TM_state* state, TM_msg* msg) -{ - float value = 0.f; - - // If the received frame topic matches "throttle" - if(strcmp(msg->topic,"throttle") == 0) - { - // If the payload type matches float32 - if(emplace_f32(msg,&value)) - { - state->throttle = value; - } - } } \ No newline at end of file