bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
sim_dc_motor_backend.h
Go to the documentation of this file.
1#ifndef BITSIM_ACTUATORS_BACKENDS_SIM_DC_MOTOR_BACKEND_H
2#define BITSIM_ACTUATORS_BACKENDS_SIM_DC_MOTOR_BACKEND_H
3
6#include "bitsim/extern/nlohmann/json/json.hpp"
7
8#include <string>
9
10namespace bitsim
11{
12namespace actuators::backends
13{
14
21{
26 real_t friction{1.0e-6};
29
30 // The speed controller, as the board runs it
36
41 void read(const nlohmann::json &j);
42
47
52};
53
71{
72 public:
73 static const std::string BACKEND_TYPE;
74
76
77 OutputType output_type() const noexcept override { return OutputType::TORQUE; }
78
79 void set_target_speed(real_t speed) override { target_speed_ = speed; }
80
81 void step(real_t dt) override;
82
83 void step(real_t dt, const ShaftState &shaft) override;
84
85 real_t angle() const override { return angle_; }
86
87 real_t speed() const override { return speed_; }
88
89 real_t torque() const override;
90
95 void set_load_torque(real_t torque) noexcept { load_torque_ = torque; }
96
100 real_t encoder_angle() const override;
101
105 real_t measured_speed() const noexcept { return measured_speed_; }
106
107 real_t current() const noexcept { return current_; }
108 real_t voltage() const noexcept { return voltage_; }
109 real_t target_speed() const noexcept { return target_speed_; }
110 const DCMotorParameters &parameters() const noexcept { return parameters_; }
111
112 private:
113 void control_(real_t dt);
114 void advance_(real_t dt, bool own_rotor);
115
116 DCMotorParameters parameters_;
117
118 real_t target_speed_{0.0};
119 real_t load_torque_{0.0};
120
121 // The motor
122 real_t current_{0.0};
123 real_t angle_{0.0};
124 real_t speed_{0.0};
125
126 // The controller
127 real_t voltage_{0.0};
128 real_t integral_{0.0};
129 real_t measured_speed_{0.0};
130 long last_counts_{0};
131 real_t since_control_{0.0};
132};
133
134} // namespace actuators::backends
135} // namespace bitsim
136
137#endif // BITSIM_ACTUATORS_BACKENDS_SIM_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
@ TORQUE
Definition dc_motor_backend_base.h:42
DCMotorBackendBase(const std::string &backend_type)
Definition dc_motor_backend_base.h:104
real_t angle() const override
Definition sim_dc_motor_backend.h:85
real_t encoder_angle() const override
Definition sim_dc_motor_backend.cpp:71
const DCMotorParameters & parameters() const noexcept
Definition sim_dc_motor_backend.h:110
real_t current() const noexcept
Definition sim_dc_motor_backend.h:107
static const std::string BACKEND_TYPE
Definition sim_dc_motor_backend.h:73
void set_target_speed(real_t speed) override
Set the target speed of the output shaft [rad/s].
Definition sim_dc_motor_backend.h:79
real_t speed() const override
Definition sim_dc_motor_backend.h:87
real_t measured_speed() const noexcept
Definition sim_dc_motor_backend.h:105
SIM_DCMotorBackend(const DCMotorParameters &parameters=DCMotorParameters())
Definition sim_dc_motor_backend.cpp:53
real_t voltage() const noexcept
Definition sim_dc_motor_backend.h:108
void set_load_torque(real_t torque) noexcept
The load on the output shaft when the motor moves its own rotor [N m]. It opposes positive rotation.
Definition sim_dc_motor_backend.h:95
void step(real_t dt) override
Advance the backend by dt. A model moves its own shaft.
Definition sim_dc_motor_backend.cpp:77
real_t torque() const override
Definition sim_dc_motor_backend.cpp:65
OutputType output_type() const noexcept override
Definition sim_dc_motor_backend.h:77
real_t target_speed() const noexcept
Definition sim_dc_motor_backend.h:109
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
The constants of a brushed DC gear motor with an encoder, and of the speed controller that runs it....
Definition sim_dc_motor_backend.h:21
real_t friction
viscous friction at the rotor [N m s/rad]
Definition sim_dc_motor_backend.h:26
real_t speed_ki
duty cycle per rad of error
Definition sim_dc_motor_backend.h:32
real_t control_period
[s]
Definition sim_dc_motor_backend.h:34
real_t gear_ratio
rotor turns per output turn
Definition sim_dc_motor_backend.h:27
void read(const nlohmann::json &j)
Read the parameters that are in the JSON object. The others keep their defaults.
Definition sim_dc_motor_backend.cpp:34
real_t resistance
armature resistance [Ohm]
Definition sim_dc_motor_backend.h:22
real_t speed_filter
time constant of the speed filter [s]
Definition sim_dc_motor_backend.h:33
real_t no_load_speed() const
Definition sim_dc_motor_backend.h:46
real_t supply_voltage
[V]
Definition sim_dc_motor_backend.h:28
real_t speed_kp
duty cycle per rad/s of error
Definition sim_dc_motor_backend.h:31
real_t inductance
armature inductance [H]
Definition sim_dc_motor_backend.h:23
real_t stall_torque() const
Definition sim_dc_motor_backend.h:51
real_t emf_constant
back-EMF and torque constant, at the rotor [V s/rad]
Definition sim_dc_motor_backend.h:24
uint_t encoder_counts
counts per output turn
Definition sim_dc_motor_backend.h:35
real_t rotor_inertia
[kg m^2]
Definition sim_dc_motor_backend.h:25