bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
dc_motor.h
Go to the documentation of this file.
1#ifndef BITSIM_ACTUATORS_DC_MOTOR_H
2#define BITSIM_ACTUATORS_DC_MOTOR_H
3
8
9#include <limits>
10#include <memory>
11#include <string>
12
13namespace bitsim
14{
15namespace actuators
16{
17
32{
33 public:
35
39 static std::shared_ptr<DCMotor>
41 const std::string &name = consts::INVALID_STR);
42
43 explicit DCMotor(std::shared_ptr<backends::DCMotorBackendBase> backend,
44 const std::string &name = consts::INVALID_STR);
45
51
55 real_t target_speed() const noexcept { return target_speed_; }
56
61 real_t max_speed() const noexcept { return max_speed_; }
62
66 void step(real_t dt) { backend_->step(dt); }
67
71 void step(real_t dt, const ShaftState &shaft) { backend_->step(dt, shaft); }
72
76 real_t angle() const { return backend_->angle(); }
77
81 real_t speed() const { return backend_->speed(); }
82
87 real_t encoder_angle() const { return backend_->encoder_angle(); }
88
93 real_t torque() const { return backend_->torque(); }
94
98 OutputType output_type() const noexcept { return backend_->output_type(); }
99
100 bool is_ready() const { return backend_->is_ready(); }
101
102 const std::string &name() const noexcept { return name_; }
103 const std::string &backend_type_str() const noexcept { return backend_->backend_type_str(); }
104 std::shared_ptr<backends::DCMotorBackendBase> backend_ptr() const noexcept { return backend_; }
105
106 private:
107 std::shared_ptr<backends::DCMotorBackendBase> backend_;
108 std::string name_;
109 real_t target_speed_{0.0};
110 real_t max_speed_{std::numeric_limits<real_t>::max()};
111};
112
113} // namespace actuators
114} // namespace bitsim
115
116#endif // BITSIM_ACTUATORS_DC_MOTOR_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
real_t max_speed() const noexcept
Definition dc_motor.h:61
void step(real_t dt)
Advance the motor by dt. A model moves its own shaft.
Definition dc_motor.h:66
bool is_ready() const
Definition dc_motor.h:100
static std::shared_ptr< DCMotor > create_simulated(const backends::DCMotorParameters &parameters=backends::DCMotorParameters(), const std::string &name=consts::INVALID_STR)
A motor with a SIM_DCMotorBackend.
Definition dc_motor.cpp:11
real_t torque() const
Definition dc_motor.h:93
void set_speed(real_t speed)
Set the target speed of the output shaft [rad/s]. It is clamped to the maximum speed.
Definition dc_motor.cpp:27
backends::DCMotorBackendBase::OutputType OutputType
Definition dc_motor.h:34
const std::string & backend_type_str() const noexcept
Definition dc_motor.h:103
real_t encoder_angle() const
Definition dc_motor.h:87
const std::string & name() const noexcept
Definition dc_motor.h:102
OutputType output_type() const noexcept
Definition dc_motor.h:98
real_t target_speed() const noexcept
Definition dc_motor.h:55
real_t angle() const
Definition dc_motor.h:76
std::shared_ptr< backends::DCMotorBackendBase > backend_ptr() const noexcept
Definition dc_motor.h:104
void set_max_speed(real_t max_speed)
Limit the target speed to [-max_speed, max_speed].
Definition dc_motor.cpp:33
void step(real_t dt, const ShaftState &shaft)
Advance the motor by dt, with the shaft moved by a physics engine.
Definition dc_motor.h:71
DCMotor(std::shared_ptr< backends::DCMotorBackendBase > backend, const std::string &name=consts::INVALID_STR)
Definition dc_motor.cpp:18
real_t speed() const
Definition dc_motor.h:81
OutputType
Definition dc_motor_backend_base.h:41
Definition dc_motor_backend_base.h:11
const std::string INVALID_STR
Invalid string.
Definition bitsim_consts.h:21
Definition dc_motor_backend_base.h:9
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