bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
diff_drive_dynamics.h
Go to the documentation of this file.
1#ifndef BITSIM_DYNAMICS_DIFF_DRIVE_DYNAMICS_H
2#define BITSIM_DYNAMICS_DIFF_DRIVE_DYNAMICS_H
3
8
9#include <any>
10#include <array>
11#include <map>
12
13namespace bitsim
14{
15namespace dynamics
16{
17
37class DiffDriveDynamics : public MotionModelDynamicsBase<SysState<3>, DynamicsMatrixDescriptor,
38 std::map<std::string, std::any>>
39{
40 public:
45 enum class DynamicVersion
46 {
50 };
51
56 std::map<std::string, std::any>>::state_type;
57
62 std::map<std::string, std::any>>::input_type;
63
68 std::map<std::string, std::any>>::matrix_type;
69
74 std::map<std::string, std::any>>::vector_type;
75
79 static SysState<3> integrate_state_v1(const SysState<3> &state, real_t tol, real_t dt, real_t v,
80 real_t w, const std::array<real_t, 2> &errors);
81
85 static SysState<3> integrate_state_v2(const SysState<3> &state, real_t dt, real_t v, real_t w,
86 const std::array<real_t, 2> &errors);
87
91 static SysState<3> integrate_state_v3(const SysState<3> &state, real_t r, real_t l, real_t dt,
92 real_t w1, real_t w2,
93 const std::array<real_t, 2> &errors);
94
99 static SysState<3> integrate(const SysState<3> &state, const input_type &input,
100 const DynamicVersion version);
101
106 bool update_description_matrices_on_evaluate = true);
107
111 explicit DiffDriveDynamics(state_type &&state);
112
117 virtual state_type &evaluate(const input_type &input) override;
118
122 void integrate(const input_type &input);
123
127 real_t get_x_position() const { return this->state_.get("X"); }
128
132 void set_x_position(real_t x) { this->state_.set("X", x); }
133
137 real_t get_y_position() const { return this->state_.get("Y"); }
138
142 void set_y_position(real_t y) { this->state_.set("Y", y); }
143
147 real_t get_orientation() const { return this->state_.get("Theta"); }
148
152 void set_orientation(real_t theta) { this->state_.set("Theta", theta); }
153
157 real_t get_velocity() const { return v_; }
158
162 real_t get_angular_velocity() const { return w_; }
163
168 void update_matrices(const input_type &input);
169
174 void initialize_matrices(const input_type &input);
175
176 private:
181 real_t v_;
182
186 real_t w_;
187
191 DynamicVersion type_;
192};
193
194} // namespace dynamics
195
196} // namespace bitsim
197
198#endif // BITSIM_DYNAMICS_DIFF_DRIVE_DYNAMICS_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
real_t get_y_position() const
Read the y-coordinate.
Definition diff_drive_dynamics.h:137
void set_x_position(real_t x)
Set the x-coordinate.
Definition diff_drive_dynamics.h:132
void initialize_matrices(const input_type &input)
Initialize the matrices describing the the dynamics.
Definition diff_drive_dynamics.cpp:217
static SysState< 3 > integrate_state_v2(const SysState< 3 > &state, real_t dt, real_t v, real_t w, const std::array< real_t, 2 > &errors)
integrate_state_v2
Definition diff_drive_dynamics.cpp:57
MotionModelDynamicsBase< SysState< 3 >, DynamicsMatrixDescriptor, std::map< std::string, std::any > >::vector_type vector_type
vector_t
Definition diff_drive_dynamics.h:73
real_t get_velocity() const
get_velocity Returns the velocity used for integration
Definition diff_drive_dynamics.h:157
MotionModelDynamicsBase< SysState< 3 >, DynamicsMatrixDescriptor, std::map< std::string, std::any > >::input_type input_type
input_t The type of the input for solving the dynamics
Definition diff_drive_dynamics.h:61
void set_y_position(real_t y)
Set the y-coordinate.
Definition diff_drive_dynamics.h:142
static SysState< 3 > integrate_state_v3(const SysState< 3 > &state, real_t r, real_t l, real_t dt, real_t w1, real_t w2, const std::array< real_t, 2 > &errors)
integrate_state_v3
Definition diff_drive_dynamics.cpp:74
real_t get_x_position() const
Read the x-coordinate.
Definition diff_drive_dynamics.h:127
static SysState< 3 > integrate_state_v1(const SysState< 3 > &state, real_t tol, real_t dt, real_t v, real_t w, const std::array< real_t, 2 > &errors)
integrate_state_v1
Definition diff_drive_dynamics.cpp:33
real_t get_orientation() const
Read the y-coordinate.
Definition diff_drive_dynamics.h:147
real_t get_angular_velocity() const
get_velocity Returns the angular velocity used for integration
Definition diff_drive_dynamics.h:162
virtual state_type & evaluate(const input_type &input) override
Evaluate the new state using the given input it also updates the various matrices if needed.
Definition diff_drive_dynamics.cpp:211
void set_orientation(real_t theta)
Set the orientation.
Definition diff_drive_dynamics.h:152
DynamicVersion
The DynamicVersion enum. Helper enum to disambiguate the two supplied configurations.
Definition diff_drive_dynamics.h:46
@ V1
Definition diff_drive_dynamics.h:47
@ V3
Definition diff_drive_dynamics.h:49
@ V2
Definition diff_drive_dynamics.h:48
MotionModelDynamicsBase< SysState< 3 >, DynamicsMatrixDescriptor, std::map< std::string, std::any > >::matrix_type matrix_type
matrix_t Matrix type that describes the dynamics
Definition diff_drive_dynamics.h:67
DiffDriveDynamics(DynamicVersion type=DynamicVersion::V1, bool update_description_matrices_on_evaluate=true)
Constructor.
Definition diff_drive_dynamics.cpp:132
void update_matrices(const input_type &input)
updates the matrices used to describe this motion model
Definition diff_drive_dynamics.cpp:239
static SysState< 3 > integrate(const SysState< 3 > &state, const input_type &input, const DynamicVersion version)
integrate Factory method to apply the different integration methods
Definition diff_drive_dynamics.cpp:90
MotionModelDynamicsBase< SysState< 3 >, DynamicsMatrixDescriptor, std::map< std::string, std::any > >::state_type state_type
The type of the state handled by this dynamics object.
Definition diff_drive_dynamics.h:55
The DynamicsMatrixDescriptor class. Helper class to model the matrix representon of dynamical systems...
Definition dynamics_matrix_descriptor.h:19
SysState utility class describing the state of a system.
Definition system_state.h:25
Models of how things move: wheeled robots, a bicycle, a quadrotor and a fixed wing aircraft,...
Definition bicycle_vehicle_model_dynamics.cpp:10
Definition dc_motor_backend_base.h:9
double real_t
real_t
Definition bitsim_types.h:20