2018 revision to classic DataBus AVC code.
Dependencies: LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell
Updater.h@15:35c40765f7c3, 2018-12-13 (annotated)
- Committer:
- shimniok
- Date:
- Thu Dec 13 00:30:59 2018 +0000
- Revision:
- 15:35c40765f7c3
- Parent:
- 14:1dd83e626153
- Child:
- 25:b8176ebb96c6
start updater in its own thread
Who changed what in which revision?
User | Revision | Line number | New 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 | #include "L3G4200D.h" |
shimniok | 11:8ec858b7c6d1 | 6 | |
shimniok | 15:35c40765f7c3 | 7 | /** Periodically reads sensor data |
shimniok | 15:35c40765f7c3 | 8 | * This class executes an update function at a configurable interval to read |
shimniok | 15:35c40765f7c3 | 9 | * and update sensor data. The class makes use of EventQueue and Event for |
shimniok | 15:35c40765f7c3 | 10 | * task scheduling and runs events on the mbed_highprio_event_queue |
shimniok | 15:35c40765f7c3 | 11 | */ |
shimniok | 12:3cd91e150d9c | 12 | class Updater: private mbed::NonCopyable<Updater> { |
shimniok | 11:8ec858b7c6d1 | 13 | public: |
shimniok | 14:1dd83e626153 | 14 | /// Return singleton instance |
shimniok | 11:8ec858b7c6d1 | 15 | static Updater *instance(); |
shimniok | 14:1dd83e626153 | 16 | |
shimniok | 15:35c40765f7c3 | 17 | /** Sets the interval for running updater() |
shimniok | 15:35c40765f7c3 | 18 | * @param interval_ms is the interval in milliseconds |
shimniok | 15:35c40765f7c3 | 19 | */ |
shimniok | 15:35c40765f7c3 | 20 | void setInterval(int interval_ms); |
shimniok | 15:35c40765f7c3 | 21 | |
shimniok | 15:35c40765f7c3 | 22 | /** Start the updater running |
shimniok | 15:35c40765f7c3 | 23 | * @note Makes use of RTOS EventQueue and Event. The function runs in an |
shimniok | 15:35c40765f7c3 | 24 | * infinite loop so best to start in a separate thread or from main thread |
shimniok | 15:35c40765f7c3 | 25 | * when done with everything else. |
shimniok | 15:35c40765f7c3 | 26 | */ |
shimniok | 15:35c40765f7c3 | 27 | void start(); |
shimniok | 15:35c40765f7c3 | 28 | |
shimniok | 14:1dd83e626153 | 29 | /** Get gyro values |
shimniok | 14:1dd83e626153 | 30 | * @return g array of x, y, and z gyro values |
shimniok | 14:1dd83e626153 | 31 | * @return dt time since data last updated |
shimniok | 14:1dd83e626153 | 32 | */ |
shimniok | 13:5566df1250f1 | 33 | void gyro(int g[3], float& dt); |
shimniok | 14:1dd83e626153 | 34 | |
shimniok | 14:1dd83e626153 | 35 | /** Get encoder count |
shimniok | 14:1dd83e626153 | 36 | * @return encoder count since last call |
shimniok | 14:1dd83e626153 | 37 | */ |
shimniok | 14:1dd83e626153 | 38 | int encoder(); |
shimniok | 14:1dd83e626153 | 39 | |
shimniok | 11:8ec858b7c6d1 | 40 | private: |
shimniok | 14:1dd83e626153 | 41 | /// Basic constructor (singleton) |
shimniok | 14:1dd83e626153 | 42 | Updater() {} |
shimniok | 14:1dd83e626153 | 43 | |
shimniok | 14:1dd83e626153 | 44 | /// Update all sensors |
shimniok | 14:1dd83e626153 | 45 | void update(); |
shimniok | 14:1dd83e626153 | 46 | |
shimniok | 14:1dd83e626153 | 47 | Timer *t; // timer used to measure dt |
shimniok | 14:1dd83e626153 | 48 | int _gyro[3]; // gyro raw |
shimniok | 14:1dd83e626153 | 49 | int _ecount; // encoder count |
shimniok | 13:5566df1250f1 | 50 | float _dt; |
shimniok | 15:35c40765f7c3 | 51 | int _interval; |
shimniok | 11:8ec858b7c6d1 | 52 | int thisTime; |
shimniok | 11:8ec858b7c6d1 | 53 | int lastTime; |
shimniok | 11:8ec858b7c6d1 | 54 | }; |
shimniok | 11:8ec858b7c6d1 | 55 | |
shimniok | 11:8ec858b7c6d1 | 56 | #endif |