Roboid Control for C++ 0.4
Loading...
Searching...
No Matches
UltrasonicSensor.h
1#pragma once
2
3#include "Things/TouchSensor.h"
4
5namespace RoboidControl {
6namespace Arduino {
7
10 public:
11 struct Configuration {
12 int trigger;
13 int echo;
14 };
15
16 UltrasonicSensor(Configuration config, Thing* parent = Thing::LocalRoot());
17
18 // parameters
19
21 // float touchDistance = 0.2f;
22
23 // state
24
26 float distance = 0;
30 float GetDistance();
31
33 virtual void Update(bool recursive = false) override;
34
35 protected:
37 unsigned char pinTrigger = 0;
39 unsigned char pinEcho = 0;
40
41 public:
42 class TouchSensor;
43};
44
45#pragma region Touch sensor
46
47class UltrasonicSensor::TouchSensor : public RoboidControl::TouchSensor {
48 public:
49 TouchSensor(UltrasonicSensor::Configuration config,
50 Thing* parent = Thing::LocalRoot());
51
52 float touchDistance = 0.2f;
53
55 virtual void Update(bool recursive = false) override;
56
57 protected:
58 UltrasonicSensor ultrasonic;
59};
60
61#pragma region Touch sensor
62
63} // namespace Arduino
64} // namespace RoboidControl
An HC-SR04 ultrasonic distance sensor.
Definition UltrasonicSensor.h:9
unsigned char pinEcho
The pin number of the echo signal.
Definition UltrasonicSensor.h:39
float distance
The distance at which the object is considered to be touched.
Definition UltrasonicSensor.h:26
unsigned char pinTrigger
The pin number of the trigger signal.
Definition UltrasonicSensor.h:37
float GetDistance()
erform an ultrasonic 'ping' to determine the distance to the nearest object
Definition UltrasonicSensor.cpp:20
virtual void Update(bool recursive=false) override
Definition UltrasonicSensor.cpp:55
A thing is the primitive building block.
Definition Thing.h:20
static Thing * LocalRoot()
The root thing for the local participant.
Definition Thing.cpp:23
A sensor which can detect touches.
Definition TouchSensor.h:8