Control Libraries 7.4.0
Loading...
Searching...
No Matches
IDynamicalSystem.cpp
1#include "dynamical_systems/IDynamicalSystem.hpp"
2
3#include "dynamical_systems/exceptions/EmptyBaseFrameException.hpp"
4#include "dynamical_systems/exceptions/NotImplementedException.hpp"
5
6#include "state_representation/exceptions/IncompatibleReferenceFramesException.hpp"
7#include "state_representation/exceptions/IncompatibleStatesException.hpp"
8#include "state_representation/space/joint/JointState.hpp"
9#include "state_representation/space/cartesian/CartesianState.hpp"
10
11using namespace state_representation;
12
13namespace dynamical_systems {
14template<class S>
16 throw exceptions::NotImplementedException("is_compatible(state) not implemented for this type of state.");
17}
18
19template<>
21 return !(state.get_reference_frame() != this->get_base_frame().get_name()
22 && state.get_reference_frame() != this->get_base_frame().get_reference_frame());
23}
24
25template<>
27 return true;
28}
29
30template<class S>
31S IDynamicalSystem<S>::evaluate(const S& state) const {
32 return this->compute_dynamics(state);
34
35template<>
37 if (this->get_base_frame().is_empty()) {
38 throw exceptions::EmptyBaseFrameException("The base frame of the dynamical system is empty.");
39 }
40 if (state.get_reference_frame() != this->get_base_frame().get_name()) {
41 if (state.get_reference_frame() != this->get_base_frame().get_reference_frame()) {
43 "The evaluated state " + state.get_name() + " in frame " + state.get_reference_frame()
44 + " is incompatible with the base frame of the dynamical system " + this->get_base_frame().get_name()
45 + " in frame " + this->get_base_frame().get_reference_frame() + "."
46 );
47 }
48 CartesianState result = this->get_base_frame().inverse() * state;
49 result = this->compute_dynamics(result);
50 return result.is_empty() ? result : this->get_base_frame() * result;
51 } else {
52 return this->compute_dynamics(state);
53 }
54}
55
56template<>
58 if (!this->is_compatible(state)) {
60 "The attractor and the provided state are not compatible."
61 );
62 }
63 return this->compute_dynamics(state);
64}
65
66}// namespace dynamical_systems
virtual bool is_compatible(const S &state) const
Check compatibility between a state and the dynamical system.
S evaluate(const S &state) const
Evaluate the value of the dynamical system at a given state.
Class to represent a state in Cartesian space.
CartesianState inverse() const
Compute the inverse of the current Cartesian state.
Class to define a state in joint space.
bool is_empty() const
Getter of the empty attribute.
Definition State.cpp:33
Systems of equations relating state variables to their derivatives.
Definition Circular.hpp:7
Core state variables and objects.