5#include "TinyRobotics/communication/Message.h"
6#include "TinyRobotics/communication/MessageSource.h"
7#include "TinyRobotics/units/Distance.h"
9namespace tinyrobotics {
12
13
14
15
16
17
18
19
20
21
22
23
24
25
29
30
31
33 : threshold(threshold) {}
37
38
39
40
41
42
43 void update(
float ax,
float ay,
float az) {
44 float magnitude = std::sqrt(ax * ax + ay * ay + az * az);
45 float delta = lastMagnitude - magnitude;
46 if (delta > threshold) {
47 Message<
float> msg(MessageContent::Obstacle, 0.0f, Unit::Meters);
48 msg.origin = MessageOrigin::IMU;
51 lastMagnitude = magnitude;
55
56
62 float lastMagnitude = 0.0f;
Simple obstacle detector using accelerometer data.
Definition: AccelerometerObstacleDetector.h:26
AccelerometerObstacleDetector(float threshold=3.0f)
Construct with a deceleration threshold.
Definition: AccelerometerObstacleDetector.h:32
void setThreshold(float t)
Set the deceleration threshold (m/s^2).
Definition: AccelerometerObstacleDetector.h:57
void update(float ax, float ay, float az)
Update the detector with new acceleration values. Checks for sudden deceleration.
Definition: AccelerometerObstacleDetector.h:43
Base class for message sources in the TinyRobotics communication framework.
Definition: MessageSource.h:35
Generic message structure for communication, parameterized by value type.
Definition: Message.h:72