bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
mqtt_ultrasound_backend.h
Go to the documentation of this file.
1#ifndef BITSIM_SENSORS_BACKENDS_MQTT_ULTRASOUND_BACKEND_H
2#define BITSIM_SENSORS_BACKENDS_MQTT_ULTRASOUND_BACKEND_H
3
4#include "bitsim/bitsim_config.h"
5
6#ifdef BITSIM_MQTT
7
13
14#include <string>
15
16namespace bitsim
17{
18namespace sensors::backends
19{
20
38{
39 public:
43 static const std::string BACKEND_TYPE;
44
50
56
62
67 void load(const nlohmann::json &j) override;
68
73 {
74 channel_.set_config(config);
75 }
76
80 void connect() { channel_.connect(); }
81
87 std::vector<real_t> read_values() override;
88
94 bool receive(const std::string &text);
95
99 bool is_alive() const { return channel_.is_alive(); }
100
104 const MQTT_SensorChannel &channel() const noexcept { return channel_; }
105
111 void set_position(const RealColVec3d &pos) { position_ = pos; }
112
116 const RealColVec3d &position() const { return position_; }
117
121 const UltrasoundMessage &last_value_read() const { return last_message_; }
122
123 private:
124 bool accept_(const std::string &text);
125
126 MQTT_SensorChannel channel_;
127
131 RealColVec3d position_{RealColVec3d::Zero()};
132
136 UltrasoundMessage last_message_;
137 bool has_message_{false};
138};
139
140} // namespace sensors::backends
141} // namespace bitsim
142#endif
143#endif // BITSIM_SENSORS_BACKENDS_MQTT_ULTRASOUND_BACKEND_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
Definition mqtt_subscriber.h:24
The topic a sensor on a board publishes its readings to.
Definition mqtt_sensor_channel.h:34
const RealColVec3d & position() const
Definition mqtt_ultrasound_backend.h:116
MQTT_UltrasonicBackend()
A backend that subscribes on its own, see connect(). Give it a topic with set_channel_config() or loa...
Definition mqtt_ultrasound_backend.cpp:16
const UltrasoundMessage & last_value_read() const
Definition mqtt_ultrasound_backend.h:121
bool is_alive() const
Definition mqtt_ultrasound_backend.h:99
void load(const nlohmann::json &j) override
Read the settings, see RangeSensorBackendBase::load(). Also reads broker, topic and timeout [s],...
Definition mqtt_ultrasound_backend.cpp:32
void connect()
Connect to the broker, unless the subscriber already is.
Definition mqtt_ultrasound_backend.h:80
std::vector< real_t > read_values() override
Take the readings that have arrived.
Definition mqtt_ultrasound_backend.cpp:70
static const std::string BACKEND_TYPE
The type of the backend.
Definition mqtt_ultrasound_backend.h:43
const MQTT_SensorChannel & channel() const noexcept
Definition mqtt_ultrasound_backend.h:104
void set_channel_config(const MQTT_SensorChannel::Config &config)
Set where the readings come from. Call it before connect().
Definition mqtt_ultrasound_backend.h:72
void set_position(const RealColVec3d &pos)
Set the position of the sensor on the robot. The backend does not use it.
Definition mqtt_ultrasound_backend.h:111
bool receive(const std::string &text)
Take one message, as read_values() does for each message that arrives. Use it to feed the backend wit...
Definition mqtt_ultrasound_backend.cpp:45
RangeSensorBackendBase(const std::string &backend_type)
Constructor.
Definition range_sensor_backend_base.h:128
Definition camera_backend_base.h:19
Definition dc_motor_backend_base.h:9
Eigen::Vector3d RealColVec3d
3D column vector
Definition bitsim_types.h:137
Models a message from an ultrasound sensor:
Definition ultrasound.h:29