bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
Loading...
Searching...
No Matches
motion_model_base.h
Go to the documentation of this file.
1#ifndef MOTION_MODEL_BASE_H
2#define MOTION_MODEL_BASE_H
3
5#include "bitrl/bitrl_types.h"
6
7#include "boost/noncopyable.hpp"
8#include <memory>
9#include <string>
10#include <vector>
11
12namespace bitrl
13{
14namespace dynamics
15{
16
22template <typename StateTp, typename MatrixDescriptor, typename InputTp>
23class MotionModelDynamicsBase : private boost::noncopyable
24{
25 public:
26 typedef StateTp state_type;
28 typedef InputTp input_type;
29 typedef MatrixDescriptor matrix_descriptor_type;
30 typedef typename matrix_descriptor_type::matrix_type matrix_type;
31 typedef typename matrix_descriptor_type::vector_type vector_type;
32
36 static const uint_t state_dimension = StateTp::dimension;
37
41 virtual ~MotionModelDynamicsBase() = default;
42
47 virtual state_type &evaluate(const input_type &input) = 0;
48
52 const state_type &get_state() const { return state_; }
53
58
63 std::vector<std::string_view> get_state_variables_names() const { return state_.get_names(); }
64
65 matrix_type &get_matrix(const std::string &name)
66 {
67 return matrix_description_.get_matrix(name);
68 }
69 const matrix_type &get_matrix(const std::string &name) const
70 {
71 return matrix_description_.get_matrix(name);
72 }
73 void set_matrix(const std::string &name, const matrix_type &mat)
74 {
75 matrix_description_.set_matrix(name, mat);
76 }
77
78 vector_type &get_vector(const std::string &name)
79 {
80 return matrix_description_.get_vector(name);
81 }
82 const vector_type &get_vector(const std::string &name) const
83 {
84 return matrix_description_.get_vector(name);
85 }
86 void set_vector(const std::string &name, const vector_type &vec)
87 {
88 matrix_description_.set_vector(name, vec);
89 }
90
95
101
106 bool has_matrix(const std::string &name) const { return matrix_description_.has_matrix(name); }
107
111 real_t get_state_property(const std::string &name) const { return state_.get(name); }
112
116 void set_state_property(const std::string &name, real_t value) { state_.set(name, value); }
117
119 void set_state_name_value(uint_t i, const std::string &name, real_t val)
120 {
121 state_.set(i, {name, val});
122 }
123
127 void set_state_name_value(uint_t i, const std::pair<std::string, real_t> &val)
128 {
129 state_.set(i, val);
130 }
131
135 void set_time_step(real_t dt) { dt_ = dt; }
136
141 real_t get_time_step() const { return dt_; }
142
147 real_t get_tolerance() const { return tol_; }
148
153 void set_tolerance(real_t tol) { tol_ = tol; }
154
155 protected:
157 explicit MotionModelDynamicsBase(bool update_description_matrices_on_evaluate = true);
158
161 bool update_description_matrices_on_evaluate = true);
162
169
174
180
185
190};
191
192template <typename StateTp, typename MatrixDescriptor, typename InputTp>
194 bool update_description_matrices_on_evaluate)
195 : state_(), matrix_description_(),
196 update_description_matrices_on_evaluate_(update_description_matrices_on_evaluate), dt_(0.0),
197 tol_(bitrl::consts::TOLERANCE)
198{
199}
200
201template <typename StateTp, typename MatrixDescriptor, typename InputTp>
204 &init_state,
205 bool update_description_matrices_on_evaluate)
206 : state_(init_state), matrix_description_(),
207 update_description_matrices_on_evaluate_(update_description_matrices_on_evaluate), dt_(0.0),
208 tol_(bitrl::consts::TOLERANCE)
209{
210}
211
212} // namespace dynamics
213} // namespace bitrl
214
215#endif // MOTION_MODEL_BASE_H
Base class for deriving motion models. Motion models describe the dynamics or kinematics of a rigid b...
Definition motion_model_base.h:24
void set_matrix_update_flag(bool f)
set the matrix update flag
Definition motion_model_base.h:94
StateTp state_type
Definition motion_model_base.h:26
InputTp input_type
Definition motion_model_base.h:28
matrix_descriptor_type::matrix_type matrix_type
Definition motion_model_base.h:30
void set_matrix(const std::string &name, const matrix_type &mat)
Definition motion_model_base.h:73
matrix_descriptor_type::vector_type vector_type
Definition motion_model_base.h:31
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:127
virtual ~MotionModelDynamicsBase()=default
Destructor.
MotionModelDynamicsBase(bool update_description_matrices_on_evaluate=true)
Constructor.
Definition motion_model_base.h:193
const state_type & get_state() const
Read access to the state.
Definition motion_model_base.h:52
matrix_type & get_matrix(const std::string &name)
Definition motion_model_base.h:65
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:153
const vector_type & get_vector(const std::string &name) const
Definition motion_model_base.h:82
state_type output_type
Definition motion_model_base.h:27
static const uint_t state_dimension
The dimension of the state.
Definition motion_model_base.h:36
MatrixDescriptor matrix_descriptor_type
Definition motion_model_base.h:29
real_t get_time_step() const
get_time_step Returns the sampling time the dynamics model is using
Definition motion_model_base.h:141
void set_state_name_value(uint_t i, const std::string &name, real_t val)
Set the state names.
Definition motion_model_base.h:119
void set_vector(const std::string &name, const vector_type &vec)
Definition motion_model_base.h:86
vector_type & get_vector(const std::string &name)
Definition motion_model_base.h:78
real_t get_tolerance() const
get_tolerance Returns the general tolerance used in the calculations
Definition motion_model_base.h:147
void set_state_property(const std::string &name, real_t value)
Set the name-th value of the state.
Definition motion_model_base.h:116
bool update_description_matrices_on_evaluate_
flag indicating the update of the matrices the model is using to describe itself
Definition motion_model_base.h:179
state_type state_
The object describing the state of the object of which its dynamics are described/modeled by this Mot...
Definition motion_model_base.h:168
void set_time_step(real_t dt)
Set the time step.
Definition motion_model_base.h:135
real_t dt_
The time step the integrator uses.
Definition motion_model_base.h:184
bool has_matrix(const std::string &name) const
Returns true if the matrix with the given name already exists.
Definition motion_model_base.h:106
virtual state_type & evaluate(const input_type &input)=0
Updates and returns the value of the state given the input.
const matrix_type & get_matrix(const std::string &name) const
Definition motion_model_base.h:69
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:63
MotionModelDynamicsBase(const state_type &init_state, bool update_description_matrices_on_evaluate=true)
Constructor.
real_t tol_
tolerance
Definition motion_model_base.h:189
matrix_descriptor_type matrix_description_
matrix descriptor
Definition motion_model_base.h:173
state_type & get_state()
Read/write access to the state.
Definition motion_model_base.h:57
bool allows_matrix_updates() const
Set the flag for updating or not the matrices describing the model.
Definition motion_model_base.h:100
real_t get_state_property(const std::string &name) const
Returns the state property with the given name.
Definition motion_model_base.h:111
Definition bitrl_consts.h:14
double real_t
real_t
Definition bitrl_types.h:23
std::size_t uint_t
uint_t
Definition bitrl_types.h:43