30 #ifndef EXOTICA_CORE_DYNAMICS_SOLVER_H_ 31 #define EXOTICA_CORE_DYNAMICS_SOLVER_H_ 38 #include <exotica_core/dynamics_solver_initializer.h> 40 #define REGISTER_DYNAMICS_SOLVER_TYPE(TYPE, DERIV) EXOTICA_CORE_REGISTER(exotica::DynamicsSolver, TYPE, DERIV) 54 template <
typename T,
int NX,
int NU>
72 virtual void AssignScene(std::shared_ptr<Scene> scene_in);
75 virtual void SetDt(
double dt_in);
78 virtual StateVector
f(
const StateVector& x,
const ControlVector& u) = 0;
81 virtual StateVector
F(
const StateVector& x,
const ControlVector& u);
87 const StateDerivative&
get_Fx()
const;
90 const ControlDerivative&
get_Fu()
const;
93 const StateDerivative&
get_fx()
const;
96 const ControlDerivative&
get_fu()
const;
99 virtual StateDerivative
fx(
const StateVector& x,
const ControlVector& u);
102 virtual ControlDerivative
fu(
const StateVector& x,
const ControlVector& u);
105 StateDerivative
fx_fd(
const StateVector& x,
const ControlVector& u);
108 ControlDerivative
fu_fd(
const StateVector& x,
const ControlVector& u);
123 virtual Eigen::Tensor<T, 3>
fxx(
const StateVector&
x,
const ControlVector& u);
124 virtual Eigen::Tensor<T, 3>
fuu(
const StateVector& x,
const ControlVector& u);
125 virtual Eigen::Tensor<T, 3>
fxu(
const StateVector& x,
const ControlVector& u);
131 StateVector
Simulate(
const StateVector& x,
const ControlVector& u, T t);
136 virtual StateVector
StateDelta(
const StateVector& x_1,
const StateVector& x_2)
138 assert(x_1.size() == x_2.size());
149 virtual Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
dStateDelta(
const StateVector& x_1,
const StateVector& x_2,
const ArgumentPosition first_or_second)
151 assert(x_1.size() == x_2.size());
166 assert(x_1.size() == x_2.size());
226 virtual void Integrate(
const StateVector& x,
const StateVector& dx,
const double dt, StateVector& xout);
256 virtual StateVector
SimulateOneStep(
const StateVector& x,
const ControlVector& u);
272 #endif // EXOTICA_CORE_DYNAMICS_SOLVER_H_
Eigen::MatrixXd fu_
Internal storage of differential dynamics partial derivative fu computed by ComputeDerivatives.
Integrator integrator_
Chosen integrator. Defaults to Euler (RK1).
Eigen::MatrixXd dStateDelta_
virtual Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > dStateDelta(const StateVector &x_1, const StateVector &x_2, const ArgumentPosition first_or_second)
Return the difference of the StateDelta operation between two state vectors. The ArgumentPosition arg...
const bool & get_has_second_order_derivatives() const
Returns whether second-order derivatives are available.
void set_control_limits(Eigen::VectorXdRefConst control_limits_low, Eigen::VectorXdRefConst control_limits_high)
Sets the control limits.
const StateDerivative & get_Fx() const
Returns derivative Fx computed by ComputeDerivatives.
Eigen::MatrixXd fx_
Internal storage of differential dynamics partial derivative fx computed by ComputeDerivatives.
Eigen::VectorXd raw_control_limits_low_
Eigen::Tensor< T, 3 > fuu_default_
int num_controls_
Number of controls in the dynamic system.
Eigen::Ref< Eigen::VectorXd > VectorXdRef
StateVector Simulate(const StateVector &x, const ControlVector &u, T t)
Simulates the dynamic system from starting state x using control u for t seconds. ...
const ControlDerivative & get_Fu() const
Returns derivative Fu computed by ComputeDerivatives.
int get_num_velocities() const
Returns number of velocities.
virtual StateVector F(const StateVector &x, const ControlVector &u)
State transition function. This internally computes the differential dynamics and applies the chosen ...
const bool & get_has_state_limits() const
Returns whether state limits are available.
virtual ControlVector InverseDynamics(const StateVector &state)
Returns a control vector corresponding to the state vector assuming zero acceleration.
virtual StateVector SimulateOneStep(const StateVector &x, const ControlVector &u)
Integrates the dynamic system from state x with controls u applied for one timestep dt using the sele...
T get_dt() const
Returns integration timestep dt.
Integrator get_integrator() const
Returns used integration scheme.
T dt_
Internal timestep used for integration. Defaults to 10ms.
Eigen::MatrixXd control_limits_
ControlLimits. Default is empty vector.
int get_num_positions() const
Returns number of positions.
virtual StateVector StateDelta(const StateVector &x_1, const StateVector &x_2)
Return the difference of two state vectors. Used when e.g. angle differences need to be wrapped from ...
bool has_state_limits_
Whether the solver specifies state limits.
Eigen::VectorXd raw_control_limits_high_
int get_num_controls() const
Returns number of controls.
int get_num_state() const
Returns size of state space (nx)
const Eigen::MatrixXd & get_control_limits()
Returns the control limits vector.
virtual StateVector f(const StateVector &x, const ControlVector &u)=0
Forward dynamics. This computes the differential dynamics.
Eigen::Tensor< T, 3 > fxu_default_
virtual Hessian ddStateDelta(const StateVector &x_1, const StateVector &x_2, const ArgumentPosition first_or_second)
virtual void SetDt(double dt_in)
Sets the timestep dt to be used for integration.
std::shared_ptr< exotica::DynamicsSolver > DynamicsSolverPtr
int num_positions_
Number of positions in the dynamic system.
bool second_order_derivatives_initialized_
Whether fxx, fxu and fuu have been initialized to 0.
Eigen::Array< Eigen::MatrixXd, Eigen::Dynamic, 1 > Hessian
virtual Eigen::Matrix< T, Eigen::Dynamic, 1 > GetPosition(Eigen::VectorXdRefConst x_in)
Returns the position-part of the state vector to update the scene. For types including SE(3) and rota...
virtual void Integrate(const StateVector &x, const StateVector &dx, const double dt, StateVector &xout)
Integrates without performing dynamics.
virtual void ComputeDerivatives(const StateVector &x, const ControlVector &u)
Computes derivatives fx, fu, Fx, Fu [single call for efficiency, derivatives can be retrieved with ge...
virtual ~AbstractDynamicsSolver()
int num_state_
Size of state space (num_positions + num_velocities)
Eigen::Matrix< T, NU, 1 > ControlVector
Convenience definition for a ControlVector (dimension NU x 1)
Eigen::Tensor< T, 3 > fxx_default_
int num_velocities_
Number of velocities in the dynamic system.
virtual void AssignScene(std::shared_ptr< Scene > scene_in)
Passes the Scene of the PlanningProblem to the DynamicsSolver.
virtual void InstantiateBase(const Initializer &init)
Instantiates the base properties of the DynamicsSolver.
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Convenience wrapper for storing references to sub-matrices/vectors.
bool control_limits_initialized_
ArgumentPosition
Argument position. Used as parameter to refer to an argument.
Eigen::MatrixXd Fu_
Internal storage of state transition partial derivative Fu computed by ComputeDerivatives.
const StateDerivative & get_fx() const
Returns derivative fx computed by ComputeDerivatives.
Eigen::Matrix< T, NX, NX > StateDerivative
Convenience definition for a StateDerivative.
void SetIntegrator(const std::string &integrator_in)
Sets integrator type based on request string.
void InitializeSecondOrderDerivatives()
Eigen::VectorXd state_limits_upper_
Upper state limits (configuration and velocity)
bool has_second_order_derivatives_
Whether this solver provides second order derivatives. If false (default), assumed to be all zeros...
virtual Eigen::Tensor< T, 3 > fxu(const StateVector &x, const ControlVector &u)
void StateDelta(const StateVector &x_1, const StateVector &x_2, Eigen::VectorXdRef xout)
const ControlDerivative & get_fu() const
Returns derivative fu computed by ComputeDerivatives.
virtual StateDerivative fx(const StateVector &x, const ControlVector &u)
Derivative of the forward dynamics w.r.t. the state.
Eigen::Matrix< T, NX, NU > ControlDerivative
Convenience definition for a ControlDerivative.
AbstractDynamicsSolver< double, Eigen::Dynamic, Eigen::Dynamic > DynamicsSolver
void set_integrator(Integrator integrator_in)
Sets integrator type.
int get_num_state_derivative() const
Returns size of derivative vector of state space (ndx)
ControlDerivative fu_fd(const StateVector &x, const ControlVector &u)
Derivative of the forward dynamics w.r.t. the control [finite differencing].
Eigen::MatrixXd Fx_
Internal storage of state transition partial derivative Fx computed by ComputeDerivatives.
virtual Eigen::Tensor< T, 3 > fuu(const StateVector &x, const ControlVector &u)
Eigen::VectorXd state_limits_lower_
Lower state limits (configuration and velocity)
void ClampToStateLimits(Eigen::Ref< Eigen::VectorXd > state_in)
Clamps the passed in state to the state limits.
virtual Eigen::Tensor< T, 3 > fxx(const StateVector &x, const ControlVector &u)
StateDerivative fx_fd(const StateVector &x, const ControlVector &u)
Derivative of the forward dynamics w.r.t. the state [finite differencing].
int num_state_derivative_
Size of the tangent vector to the state space (2 * num_velocities)
virtual ControlDerivative fu(const StateVector &x, const ControlVector &u)
Derivative of the forward dynamics w.r.t. the control.
Eigen::Matrix< T, NX, 1 > StateVector
Convenience definition for a StateVector containing both position and velocity (dimension NX x 1) ...