bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
mqtt_imu_backend.h
Go to the documentation of this file.
1#ifndef BITSIM_SENSORS_BACKENDS_MQTT_IMU_BACKEND_H
2#define BITSIM_SENSORS_BACKENDS_MQTT_IMU_BACKEND_H
3
4#include "bitsim/bitsim_config.h"
5
6#ifdef BITSIM_MQTT
7
12
13#include <string>
14#include <vector>
15
16namespace bitsim
17{
18namespace sensors::backends
19{
20
35class MQTT_IMUBackend final : public IMUBackendBase
36{
37 public:
38 static const std::string BACKEND_TYPE;
39
45
46 explicit MQTT_IMUBackend(const MQTT_SensorChannel::Config &config);
47
52 explicit MQTT_IMUBackend(network::MqttSubscriber &subscriber);
53
58 void load(const nlohmann::json &j) override;
59
61 {
62 channel_.set_config(config);
63 }
64
68 void connect() { channel_.connect(); }
69
75 std::vector<real_t> read_values() override;
76
82 bool receive(const std::string &text);
83
84 bool is_alive() const { return channel_.is_alive(); }
85
86 const MQTT_SensorChannel &channel() const noexcept { return channel_; }
87
88 const IMUMessage &last_value_read() const noexcept { return last_message_; }
89
90 private:
91 bool accept_(const std::string &text);
92
93 MQTT_SensorChannel channel_;
94 IMUMessage last_message_;
95};
96
97} // namespace sensors::backends
98} // namespace bitsim
99
100#endif
101#endif // BITSIM_SENSORS_BACKENDS_MQTT_IMU_BACKEND_H
Definition mqtt_subscriber.h:24
IMUBackendBase(const std::string &backend_type)
Definition imu_backend_base.h:92
void connect()
Connect to the broker, unless the subscriber already is.
Definition mqtt_imu_backend.h:68
static const std::string BACKEND_TYPE
Definition mqtt_imu_backend.h:38
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_imu_backend.cpp:40
const MQTT_SensorChannel & channel() const noexcept
Definition mqtt_imu_backend.h:86
std::vector< real_t > read_values() override
Take the readings that have arrived.
Definition mqtt_imu_backend.cpp:64
MQTT_IMUBackend()
A backend that subscribes on its own, see connect(). Give it a topic with set_channel_config() or loa...
Definition mqtt_imu_backend.cpp:18
const IMUMessage & last_value_read() const noexcept
Definition mqtt_imu_backend.h:88
void set_channel_config(const MQTT_SensorChannel::Config &config)
Definition mqtt_imu_backend.h:60
void load(const nlohmann::json &j) override
Read the settings, see IMUBackendBase::load(). Also reads broker, topic and timeout [s],...
Definition mqtt_imu_backend.cpp:31
bool is_alive() const
Definition mqtt_imu_backend.h:84
The topic a sensor on a board publishes its readings to.
Definition mqtt_sensor_channel.h:34
Definition camera_backend_base.h:19
Definition dc_motor_backend_base.h:9
Models a message from an inertial measurement unit with a three axis accelerometer and a three axis g...
Definition imu.h:31