bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
motion_model_base.h
Go to the documentation of this file.
1#ifndef BITSIM_DYNAMICS_MOTION_MODEL_BASE_H
2#define BITSIM_DYNAMICS_MOTION_MODEL_BASE_H
3
6
7#include "boost/noncopyable.hpp"
8#include <string>
9#include <vector>
10
11namespace bitsim
12{
17namespace dynamics
18{
19
25template <typename StateTp, typename MatrixDescriptor, typename InputTp>
26class MotionModelDynamicsBase : private boost::noncopyable
27{
28 public:
29 using state_type = StateTp;
31 using input_type = InputTp;
32 using matrix_descriptor_type = MatrixDescriptor;
35
39 static const uint_t state_dimension = StateTp::dimension;
40
44 virtual ~MotionModelDynamicsBase() = default;
45
50 virtual state_type &evaluate(const input_type &input) = 0;
51
55 const state_type &get_state() const { return state_; }
56
61
66 std::vector<std::string_view> get_state_variables_names() const { return state_.get_names(); }
67
68 matrix_type &get_matrix(const std::string &name)
69 {
70 return matrix_description_.get_matrix(name);
71 }
72 const matrix_type &get_matrix(const std::string &name) const
73 {
74 return matrix_description_.get_matrix(name);
75 }
76 void set_matrix(const std::string &name, const matrix_type &mat)
77 {
78 matrix_description_.set_matrix(name, mat);
79 }
80
81 vector_type &get_vector(const std::string &name)
82 {
83 return matrix_description_.get_vector(name);
84 }
85 const vector_type &get_vector(const std::string &name) const
86 {
87 return matrix_description_.get_vector(name);
88 }
89 void set_vector(const std::string &name, const vector_type &vec)
90 {
91 matrix_description_.set_vector(name, vec);
92 }
93
98
104
109 bool has_matrix(const std::string &name) const { return matrix_description_.has_matrix(name); }
110
114 real_t get_state_property(const std::string &name) const { return state_.get(name); }
115
119 void set_state_property(const std::string &name, real_t value) { state_.set(name, value); }
120
122 void set_state_name_value(uint_t i, const std::string &name, real_t val)
123 {
124 state_.set(i, {name, val});
125 }
126
130 void set_state_name_value(uint_t i, const std::pair<std::string, real_t> &val)
131 {
132 state_.set(i, val);
133 }
134
138 void set_time_step(real_t dt) { dt_ = dt; }
139
144 real_t get_time_step() const { return dt_; }
145
150 real_t get_tolerance() const { return tol_; }
151
156 void set_tolerance(real_t tol) { tol_ = tol; }
157
158 protected:
160 explicit MotionModelDynamicsBase(bool update_description_matrices_on_evaluate = true);
161
164 bool update_description_matrices_on_evaluate = true);
165
172
177
183
188
193};
194
195template <typename StateTp, typename MatrixDescriptor, typename InputTp>
197 bool update_description_matrices_on_evaluate)
199 update_description_matrices_on_evaluate_(update_description_matrices_on_evaluate), dt_(0.0),
200 tol_(bitsim::consts::TOLERANCE)
201{
202}
203
204template <typename StateTp, typename MatrixDescriptor, typename InputTp>
207 &init_state,
208 bool update_description_matrices_on_evaluate)
209 : state_(init_state), matrix_description_(),
210 update_description_matrices_on_evaluate_(update_description_matrices_on_evaluate), dt_(0.0),
211 tol_(bitsim::consts::TOLERANCE)
212{
213}
214
215} // namespace dynamics
216} // namespace bitsim
217
218#endif // BITSIM_DYNAMICS_MOTION_MODEL_BASE_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
DynVec< real_t > vector_type
Definition dynamics_matrix_descriptor.h:23
DynMat< real_t > matrix_type
Definition dynamics_matrix_descriptor.h:22
real_t get_time_step() const
get_time_step Returns the sampling time the dynamics model is using
Definition motion_model_base.h:144
std::vector< std::string_view > get_state_variables_names() const
get_state_variables_names. Returns the name of the variables in the state
Definition motion_model_base.h:66
state_type & get_state()
Read/write access to the state.
Definition motion_model_base.h:60
const state_type & get_state() const
Read access to the state.
Definition motion_model_base.h:55
const vector_type & get_vector(const std::string &name) const
Definition motion_model_base.h:85
bool allows_matrix_updates() const
Set the flag for updating or not the matrices describing the model.
Definition motion_model_base.h:103
matrix_type & get_matrix(const std::string &name)
Definition motion_model_base.h:68
MotionModelDynamicsBase(const state_type &init_state, bool update_description_matrices_on_evaluate=true)
Constructor.
real_t get_tolerance() const
get_tolerance Returns the general tolerance used in the calculations
Definition motion_model_base.h:150
virtual ~MotionModelDynamicsBase()=default
Destructor.
MotionModelDynamicsBase(bool update_description_matrices_on_evaluate=true)
Constructor.
Definition motion_model_base.h:196
virtual state_type & evaluate(const input_type &input)=0
Updates and returns the value of the state given the input.
void set_state_name_value(uint_t i, const std::pair< std::string, real_t > &val)
Set the state names.
Definition motion_model_base.h:130
void set_state_name_value(uint_t i, const std::string &name, real_t val)
Set the state names.
Definition motion_model_base.h:122
void set_matrix(const std::string &name, const matrix_type &mat)
Definition motion_model_base.h:76
real_t get_state_property(const std::string &name) const
Returns the state property with the given name.
Definition motion_model_base.h:114
void set_vector(const std::string &name, const vector_type &vec)
Definition motion_model_base.h:89
void set_time_step(real_t dt)
Set the time step.
Definition motion_model_base.h:138
const matrix_type & get_matrix(const std::string &name) const
Definition motion_model_base.h:72
void set_matrix_update_flag(bool f)
set the matrix update flag
Definition motion_model_base.h:97
typename matrix_descriptor_type::vector_type vector_type
Definition motion_model_base.h:34
bool has_matrix(const std::string &name) const
Returns true if the matrix with the given name already exists.
Definition motion_model_base.h:109
typename matrix_descriptor_type::matrix_type matrix_type
Definition motion_model_base.h:33
vector_type & get_vector(const std::string &name)
Definition motion_model_base.h:81
void set_tolerance(real_t tol)
set_tolerance Set the general tolerance used in the calculations. Default is KernelConsts::tolerance(...
Definition motion_model_base.h:156
void set_state_property(const std::string &name, real_t value)
Set the name-th value of the state.
Definition motion_model_base.h:119
Definition bitsim_consts.cpp:10
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
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20