2018 revision to classic DataBus AVC code.

Dependencies:   LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell

Committer:
shimniok
Date:
Mon Jan 07 16:47:33 2019 +0000
Revision:
44:0d72a8a1288a
Parent:
32:eb673f6f5734
Rewrote TinyGPS -> NMEA, GPS::read() now returns struct

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 11:8ec858b7c6d1 1 #ifndef __UPDATER_H
shimniok 11:8ec858b7c6d1 2 #define __UPDATER_H
shimniok 11:8ec858b7c6d1 3
shimniok 11:8ec858b7c6d1 4 #include "mbed.h"
shimniok 11:8ec858b7c6d1 5
shimniok 15:35c40765f7c3 6 /** Periodically reads sensor data
shimniok 25:b8176ebb96c6 7 * This class reads and updates sensor data. Intended to be called at a fixed
shimniok 25:b8176ebb96c6 8 * interval.
shimniok 25:b8176ebb96c6 9 * @code
shimniok 25:b8176ebb96c6 10 * Updater *u = Updater::instance(); // beware of lifetime of this pointer
shimniok 25:b8176ebb96c6 11 * Thread updaterThread(osPriorityRealtime, 512, 0, "updater");
shimniok 25:b8176ebb96c6 12 * EventQueue *updaterQueue = mbed_highprio_event_queue();
shimniok 25:b8176ebb96c6 13 * Event<void()> event(updaterQueue, callback(u, &Updater::update));
shimniok 25:b8176ebb96c6 14 * event.period(20);
shimniok 25:b8176ebb96c6 15 * event.post(); // if lifetime of u not correct, this will hard fault
shimniok 25:b8176ebb96c6 16 * updaterThread.start(callback(updaterQueue, &EventQueue::dispatch_forever));
shimniok 25:b8176ebb96c6 17 *
shimniok 15:35c40765f7c3 18 */
shimniok 12:3cd91e150d9c 19 class Updater: private mbed::NonCopyable<Updater> {
shimniok 11:8ec858b7c6d1 20 public:
shimniok 14:1dd83e626153 21 /// Return singleton instance
shimniok 11:8ec858b7c6d1 22 static Updater *instance();
shimniok 14:1dd83e626153 23
shimniok 25:b8176ebb96c6 24 /// Attach a callback handler run each time updater() is run
shimniok 25:b8176ebb96c6 25 void attach(Callback<void()> cb);
shimniok 25:b8176ebb96c6 26
shimniok 25:b8176ebb96c6 27 /// Update all sensors
shimniok 25:b8176ebb96c6 28 void update();
shimniok 25:b8176ebb96c6 29
shimniok 32:eb673f6f5734 30 /** Get imu values
shimniok 32:eb673f6f5734 31 * @param g x, y, z gyro values to return
shimniok 32:eb673f6f5734 32 * @param a x, y, z accelerometer values to return
shimniok 32:eb673f6f5734 33 * @param m x, y, z magnetometer values to return
shimniok 32:eb673f6f5734 34 * @param dt time since data last updated
shimniok 32:eb673f6f5734 35 * @return g, a, m and dt
shimniok 32:eb673f6f5734 36 */
shimniok 32:eb673f6f5734 37 void imu(int g[3], int a[3], int m[3], float& dt);
shimniok 32:eb673f6f5734 38
shimniok 14:1dd83e626153 39 /** Get gyro values
shimniok 32:eb673f6f5734 40 * @param g x, y, z gyro values to return
shimniok 32:eb673f6f5734 41 * @param dt time since data last updated
shimniok 32:eb673f6f5734 42 * @return g and dt
shimniok 14:1dd83e626153 43 */
shimniok 13:5566df1250f1 44 void gyro(int g[3], float& dt);
shimniok 32:eb673f6f5734 45
shimniok 32:eb673f6f5734 46 /** Get accel values
shimniok 32:eb673f6f5734 47 * @param a x, y, z accelerometer values to return
shimniok 32:eb673f6f5734 48 * @param dt time since data last updated
shimniok 32:eb673f6f5734 49 * @return a and dt
shimniok 32:eb673f6f5734 50 */
shimniok 32:eb673f6f5734 51 void accel(int g[3], float& dt);
shimniok 14:1dd83e626153 52
shimniok 32:eb673f6f5734 53 /** Get magnetometer values
shimniok 32:eb673f6f5734 54 * @param m x, y, z magnetometer values to return
shimniok 32:eb673f6f5734 55 * @param dt time since data last updated
shimniok 32:eb673f6f5734 56 * @return m and dt
shimniok 32:eb673f6f5734 57 */
shimniok 32:eb673f6f5734 58 void mag(int g[3], float& dt);
shimniok 32:eb673f6f5734 59
shimniok 14:1dd83e626153 60 /** Get encoder count
shimniok 14:1dd83e626153 61 * @return encoder count since last call
shimniok 14:1dd83e626153 62 */
shimniok 14:1dd83e626153 63 int encoder();
shimniok 14:1dd83e626153 64
shimniok 11:8ec858b7c6d1 65 private:
shimniok 14:1dd83e626153 66 /// Basic constructor (singleton)
shimniok 25:b8176ebb96c6 67 Updater();
shimniok 14:1dd83e626153 68
shimniok 25:b8176ebb96c6 69 Callback<void()> _callback; // notification callback
shimniok 14:1dd83e626153 70 Timer *t; // timer used to measure dt
shimniok 14:1dd83e626153 71 int _gyro[3]; // gyro raw
shimniok 32:eb673f6f5734 72 int _accel[3]; // accelerometer raw
shimniok 32:eb673f6f5734 73 int _mag[3]; // magnetometer raw
shimniok 14:1dd83e626153 74 int _ecount; // encoder count
shimniok 13:5566df1250f1 75 float _dt;
shimniok 15:35c40765f7c3 76 int _interval;
shimniok 11:8ec858b7c6d1 77 int thisTime;
shimniok 11:8ec858b7c6d1 78 int lastTime;
shimniok 11:8ec858b7c6d1 79 };
shimniok 11:8ec858b7c6d1 80
shimniok 11:8ec858b7c6d1 81 #endif