aligator  0.15.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Loading...
Searching...
No Matches
state-error.hpp
Go to the documentation of this file.
1#pragma once
2
7
8namespace aligator {
9
10namespace detail {
11
16template <typename _Scalar, unsigned int arg>
17struct StateOrControlErrorResidual;
18
20template <typename _Scalar>
21struct StateOrControlErrorResidual<_Scalar, 0> : UnaryFunctionTpl<_Scalar> {
22 using Scalar = _Scalar;
25 using Data = StageFunctionDataTpl<Scalar>;
26 using Manifold = ManifoldAbstractTpl<Scalar>;
27 using VectorSpace = VectorSpaceTpl<Scalar, Eigen::Dynamic>;
28 using PolyManifold = xyz::polymorphic<Manifold>;
29
30 PolyManifold space_;
31 VectorXs target_;
32
33 StateOrControlErrorResidual(const PolyManifold &xspace, const int nu,
34 const ConstVectorRef &target)
35 : Base(xspace->ndx(), nu, xspace->ndx())
36 , space_(xspace)
37 , target_(target) {
38 validate();
39 }
40
41 template <typename U, typename std::enable_if_t<
43 StateOrControlErrorResidual(U &&xspace, const int nu,
44 const ConstVectorRef &target)
45 : Base(xspace.ndx(), nu, xspace.ndx())
46 , space_{std::forward<U>(xspace)}
47 , target_(target) {
48 validate();
49 }
50
51 void evaluate(const ConstVectorRef &x, Data &data) const override {
52 space_->difference(target_, x, data.value_);
53 }
54
55 void computeJacobians(const ConstVectorRef &x, Data &data) const override {
56 space_->Jdifference(target_, x, data.Jx_, 1);
57 }
58
59protected:
60 void validate() const {
61 if (!space_->isNormalized(target_)) {
63 "Target parameter invalid (not a viable element of state manifold.)");
64 }
65 }
66};
67
68template <typename _Scalar, unsigned int arg>
69struct StateOrControlErrorResidual : StageFunctionTpl<_Scalar> {
70 static_assert(arg == 1, "arg value must be 1");
71 using Scalar = _Scalar;
73 using Base = StageFunctionTpl<Scalar>;
74 using Data = StageFunctionDataTpl<Scalar>;
75 using Manifold = ManifoldAbstractTpl<Scalar>;
76 using VectorSpace = VectorSpaceTpl<Scalar, Eigen::Dynamic>;
77
78 xyz::polymorphic<Manifold> space_;
79 VectorXs target_;
80
83 template <typename U,
84 typename = std::enable_if_t<!is_polymorphic_of_v<Manifold, U>>>
85 StateOrControlErrorResidual(const int ndx, U &&uspace,
86 const ConstVectorRef &target)
87 : Base(ndx, uspace.nx(), uspace.ndx())
88 , space_(std::forward<U>(uspace))
89 , target_(target) {
90 validate();
91 }
92
93 StateOrControlErrorResidual(const int ndx,
94 const xyz::polymorphic<Manifold> &uspace,
95 const ConstVectorRef &target)
96 : Base(ndx, uspace->nx(), uspace->ndx())
97 , space_(uspace)
98 , target_(target) {
99 validate();
100 }
101
102 StateOrControlErrorResidual(const int ndx, const int nu)
103 : Base(ndx, nu, nu)
104 , space_(VectorSpace(nu))
105 , target_(space_->neutral()) {}
106
109 StateOrControlErrorResidual(const int ndx, const ConstVectorRef &target)
110 : StateOrControlErrorResidual(ndx, (int)target.size()) {
111 target_ = target;
112 }
113
114 void evaluate(const ConstVectorRef &, const ConstVectorRef &u,
115 Data &data) const override {
116 switch (arg) {
117 case 1:
118 space_->difference(target_, u, data.value_);
119 break;
120 default:
121 break;
122 }
123 }
124
125 void computeJacobians(const ConstVectorRef &, const ConstVectorRef &u,
126 Data &data) const override {
127 switch (arg) {
128 case 1:
129 space_->Jdifference(target_, u, data.Ju_, 1);
130 break;
131 default:
132 break;
133 }
134 }
135
136protected:
137 void validate() const {
138 if (!space_->isNormalized(target_)) {
140 "Target parameter invalid (not a viable element of state manifold.)");
141 }
142 }
143};
144
145} // namespace detail
146
151template <typename Scalar>
152struct StateErrorResidualTpl : detail::StateOrControlErrorResidual<Scalar, 0> {
153 using Base = detail::StateOrControlErrorResidual<Scalar, 0>;
154 using Base::Base;
155};
156
157template <typename Scalar>
159 : detail::StateOrControlErrorResidual<Scalar, 1> {
160 using Base = detail::StateOrControlErrorResidual<Scalar, 1>;
161 using Base::Base;
162};
163
164} // namespace aligator
165
166#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
167#include "aligator/modelling/state-error.txx"
168#endif
#define ALIGATOR_RUNTIME_ERROR(...)
Definition exceptions.hpp:7
Base definitions for ternary functions.
#define ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
Definition math.hpp:8
xyz::polymorphic< Manifold > PolyManifold
Main package namespace.
constexpr bool is_polymorphic_of_v
Definition fwd.hpp:68
detail::StateOrControlErrorResidual< Scalar, 1 > Base
const int nu
Control dimension.
StageFunctionTpl(const int ndx, const int nu, const int nr)
detail::StateOrControlErrorResidual< Scalar, 0 > Base
#define ALIGATOR_UNARY_FUNCTION_INTERFACE(Scalar)