... | ... | @@ -2,8 +2,7 @@ The `SensorManager` component manages all the sensors connected to the board. |
|
|
|
|
|
Sensors are periodically sampled and their corresponding callback is called, so that further operations can be performed on the retrieved data.
|
|
|
|
|
|
# Main Components
|
|
|
|
|
|
# Main Elements
|
|
|
### Sensor
|
|
|
|
|
|
The `Sensor.h` header file contains the base classes used to define sensors: every new sensor must inherit from one of them.
|
... | ... | @@ -45,25 +44,24 @@ The sensor will be added only if both the initialization and the test succeed. |
|
|
|
|
|
When `start()` is called, the `SensorManager` initializes the `TaskScheduler`: for each `SensorSampler`, it adds to the scheduler the `sampleAndCallback()` method to be called periodically according to the sampler's frequency.
|
|
|
|
|
|
# Overall Behavior
|
|
|
# Component Behavior
|
|
|
It might seem tricky and complex, so in order to simplify the understanding we can schematize the component's behavior.
|
|
|
|
|
|
### Flowchart
|
|
|
|
|
|
TODO
|
|
|
|
|
|
We outline three phases:
|
|
|
1. In the first phase sensors are added to the `SensorManager`, that assigns them to the correct `SensorSampler`, along with the corresponding callback.
|
|
|
2. When the `SensorManager` is started, for each sampler it schedules a periodic task, according to the required frequency.
|
|
|
3. From that point on, the `TaskScheduler` periodically calls the `SensorSampler` objects. When called, each sampler performs the sampling of all the sensors it manages and for each of them calls the associated callback.
|
|
|
|
|
|
# Module Structure
|
|
|

|
|
|
|
|
|
# Component Structure
|
|
|
For simplicity, each arrow in the diagram describes an action and reports the phase number that action belongs to (according to the above defined phases).
|
|
|
|
|
|

|
|
|
|
|
|
# Example
|
|
|
### Step 1: Creating a sensor
|
|
|
For more details see how to write a sensor driver.
|
|
|
```cpp
|
|
|
#include <cmath>
|
|
|
#include "Common.h"
|
... | ... | @@ -77,7 +75,7 @@ class TestSensor : public virtual Sensor |
|
|
public:
|
|
|
TestSensor() : sample(0) {}
|
|
|
|
|
|
~TestSensor() {}
|
|
|
~TestSensor() {}SensorManager
|
|
|
|
|
|
bool init() override
|
|
|
{
|
... | ... | |