bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
mqtt_dc_motor_backend.h
Go to the documentation of this file.
1#ifndef BITSIM_ACTUATORS_BACKENDS_MQTT_DC_MOTOR_BACKEND_H
2#define BITSIM_ACTUATORS_BACKENDS_MQTT_DC_MOTOR_BACKEND_H
3
4#include "bitsim/bitsim_config.h"
5
6#ifdef BITSIM_MQTT
7
11
12#include <memory>
13#include <optional>
14#include <string>
15
16namespace bitsim
17{
18namespace actuators::backends
19{
20
37{
38 public:
39 static const std::string BACKEND_TYPE;
40
46 MQTT_DCMotorBackend(std::shared_ptr<boards::DCMotorBoardBase> board, uint_t channel,
47 real_t bandwidth = 30.0);
48
49 OutputType output_type() const noexcept override { return OutputType::ANGLE; }
50
51 void set_target_speed(real_t speed) override;
52
53 void step(real_t dt) override;
54
55 void step(real_t dt, const ShaftState &) override { step(dt); }
56
57 real_t angle() const override { return estimate_; }
58
59 real_t speed() const override { return estimate_rate_; }
60
65 real_t encoder_angle() const override { return reported_angle_; }
66
70 bool is_ready() const override;
71
75 real_t reported_angle() const noexcept { return reported_angle_; }
76
80 real_t reported_speed() const noexcept { return reported_speed_; }
81
82 std::shared_ptr<boards::DCMotorBoardBase> board() const noexcept { return board_; }
83 uint_t channel() const noexcept { return channel_; }
84
85 private:
86 real_t predicted_angle_() const;
87
88 std::shared_ptr<boards::DCMotorBoardBase> board_;
89 uint_t channel_;
90 real_t bandwidth_;
91
92 std::optional<real_t> zero_;
93 real_t reported_angle_{0.0};
94 real_t reported_speed_{0.0};
95 real_t report_age_{0.0};
96
97 real_t estimate_{0.0};
98 real_t estimate_rate_{0.0};
99};
100
101} // namespace actuators::backends
102} // namespace bitsim
103
104#endif
105#endif // BITSIM_ACTUATORS_BACKENDS_MQTT_DC_MOTOR_BACKEND_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
OutputType
Definition dc_motor_backend_base.h:41
@ ANGLE
Definition dc_motor_backend_base.h:43
DCMotorBackendBase(const std::string &backend_type)
Definition dc_motor_backend_base.h:104
void set_target_speed(real_t speed) override
Set the target speed of the output shaft [rad/s].
Definition mqtt_dc_motor_backend.cpp:37
void step(real_t dt) override
Advance the backend by dt. A model moves its own shaft.
Definition mqtt_dc_motor_backend.cpp:49
uint_t channel() const noexcept
Definition mqtt_dc_motor_backend.h:83
real_t angle() const override
Definition mqtt_dc_motor_backend.h:57
real_t encoder_angle() const override
Definition mqtt_dc_motor_backend.h:65
static const std::string BACKEND_TYPE
Definition mqtt_dc_motor_backend.h:39
real_t speed() const override
Definition mqtt_dc_motor_backend.h:59
bool is_ready() const override
Definition mqtt_dc_motor_backend.cpp:42
void step(real_t dt, const ShaftState &) override
Advance the backend by dt, with the shaft moved by a physics engine. Backends with OutputType::ANGLE ...
Definition mqtt_dc_motor_backend.h:55
real_t reported_speed() const noexcept
Definition mqtt_dc_motor_backend.h:80
std::shared_ptr< boards::DCMotorBoardBase > board() const noexcept
Definition mqtt_dc_motor_backend.h:82
OutputType output_type() const noexcept override
Definition mqtt_dc_motor_backend.h:49
MQTT_DCMotorBackend(std::shared_ptr< boards::DCMotorBoardBase > board, uint_t channel, real_t bandwidth=30.0)
Definition mqtt_dc_motor_backend.cpp:23
real_t reported_angle() const noexcept
Definition mqtt_dc_motor_backend.h:75
Definition dc_motor_backend_base.h:23
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20
The state of the output shaft of a motor, as a simulator sees it.
Definition dc_motor_backend_base.h:17