signals-cpp
Loading...
Searching...
No Matches
State.h
Go to the documentation of this file.
1#pragma once
2#include "signals/Signal.h"
3
4using namespace Eigen;
5
32template<typename T, typename PoseTypeSpec, size_t PoseDim, typename TwistTypeSpec, size_t TwistDim>
33struct State
34{
35 using PoseType = typename PoseTypeSpec::Type;
36 using TwistType = typename TwistTypeSpec::Type;
37
46
50 State() {}
51
55 State(T* arr) : pose(arr), twist(arr + PoseDim) {}
56
60 State(const State& other)
61 {
62 this->pose = other.pose;
63 this->twist = other.twist;
64 }
65
69 static State identity()
70 {
71 State x;
72 x.pose = PoseTypeSpec::ZeroType();
73 x.twist = TwistTypeSpec::ZeroType();
74 return x;
75 }
76
80 static State nans()
81 {
82 State x;
83 x.pose = PoseTypeSpec::NansType();
84 x.twist = TwistTypeSpec::NansType();
85 return x;
86 }
87
91 T norm() const
92 {
93 const T poseNorm = PoseTypeSpec::Norm(pose);
94 const T twistNorm = TwistTypeSpec::Norm(twist);
95 return std::sqrt(poseNorm * poseNorm + twistNorm * twistNorm);
96 }
97
101 State& operator*=(const double& s)
102 {
103 pose *= s;
104 twist *= s;
105 return *this;
106 }
107
111 template<typename T2>
113 {
114 pose += r.pose;
115 twist += r.twist;
116 return *this;
117 }
118};
119
123template<typename T, typename PTS, size_t PD, typename TTS, size_t TD>
125{
127 lpr.pose += r.pose;
128 lpr.twist += r.twist;
129 return lpr;
130}
131
135template<typename T, typename PTS, size_t PD, typename TTS, size_t TD>
137{
139 lmr.pose = l.pose - r.pose;
140 lmr.twist = l.twist - r.twist;
141 return lmr;
142}
143
147template<typename T, typename PTS, size_t PD, typename TTS, size_t TD>
149{
151 lr.pose *= l;
152 lr.twist *= l;
153 return lr;
154}
155
159template<typename T, typename PTS, size_t PD, typename TTS, size_t TD>
161{
163 lr.pose *= r;
164 lr.twist *= r;
165 return lr;
166}
167
168template<typename T>
170
171template<typename T>
172inline std::ostream& operator<<(std::ostream& os, const ScalarStateType<T>& x)
173{
174 os << "ScalarStateType: pose=" << x.pose << "; twist=" << x.twist;
175 return os;
176}
177
181template<typename T>
183{
184 ScalarStateType<T> lr = l;
185 lr.pose /= r;
186 lr.twist /= r;
187 return lr;
188}
189
190template<typename T, size_t d>
192
193template<typename T, size_t d>
194inline std::ostream& operator<<(std::ostream& os, const VectorStateType<T, d>& x)
195{
196 os << "VectorStateType: pose=" << x.pose.transpose() << "; twist=" << x.twist.transpose();
197 return os;
198}
199
203template<typename T, size_t d>
205{
207 lr.pose /= r;
208 lr.twist /= r;
209 return lr;
210}
211
212template<typename T, typename ManifoldType, size_t PD, size_t TD>
214
215template<typename T, typename ManifoldType, size_t PD, size_t TD>
216inline std::ostream& operator<<(std::ostream& os, const ManifoldStateType<T, ManifoldType, PD, TD>& x)
217{
218 os << "VectorStateType: pose=" << x.pose << "; twist=" << x.twist;
219 return os;
220}
221
226template<typename T>
228{
233 static Type ZeroType()
234 {
235 return Type::identity();
236 }
237
240 static Type NansType()
241 {
242 return Type::nans();
243 }
244
249 static T Norm(const Type& a)
250 {
251 return a.norm();
252 }
253};
254
260template<typename T, size_t d>
262{
267 static Type ZeroType()
268 {
269 return Type::identity();
270 }
271
274 static Type NansType()
275 {
276 return Type::nans();
277 }
278
283 static T Norm(const Type& a)
284 {
285 return a.norm();
286 }
287};
288
296template<typename T, typename ManifoldType, size_t PD, size_t TD>
298{
303 static Type ZeroType()
304 {
305 return Type::identity();
306 }
307
310 static Type NansType()
311 {
312 return Type::nans();
313 }
314
319 static T Norm(const Type& a)
320 {
321 return a.norm();
322 }
323};
324
325template<typename T>
327
328template<typename T>
329inline std::ostream& operator<<(std::ostream& os, const ScalarStateSignal<T>& x)
330{
331 os << "ScalarStateSignal at t=" << x.t() << ": pose=" << x().pose << "; twist=" << x().twist;
332 return os;
333}
334
335template<typename T, size_t d>
337
338template<typename T, size_t d>
339inline std::ostream& operator<<(std::ostream& os, const VectorStateSignal<T, d>& x)
340{
341 os << "VectorStateSignal at t=" << x.t() << ": pose=" << x().pose.transpose()
342 << "; twist=" << x().twist.transpose();
343 return os;
344}
345
346template<typename T, typename ManifoldType, size_t PD, size_t TD>
348
349template<typename T, typename ManifoldType, size_t PD, size_t TD>
350inline std::ostream& operator<<(std::ostream& os, const ManifoldStateSignal<T, ManifoldType, PD, TD>& x)
351{
352 os << "ManifoldStateSignal at t=" << x.t() << ": pose=" << x().pose << "; twist=" << x().twist;
353 return os;
354}
355
356#define MAKE_VECTOR_STATES(Dimension) \
357 template<typename T> \
358 using Vector##Dimension##State = VectorStateType<T, Dimension>; \
359 template<typename T> \
360 using Vector##Dimension##StateSignal = VectorStateSignal<T, Dimension>; \
361 typedef Vector##Dimension##State<double> Vector##Dimension##dState; \
362 typedef Vector##Dimension##StateSignal<double> Vector##Dimension##dStateSignal;
363
364#define MAKE_MANIF_STATES(Manif, Dimension, TangentDimension) \
365 template<typename T> \
366 using Manif##State = ManifoldStateType<T, Manif<T>, Dimension, TangentDimension>; \
367 template<typename T> \
368 using Manif##StateSignal = ManifoldStateSignal<T, Manif<T>, Dimension, TangentDimension>; \
369 typedef Manif##State<double> Manif##dState; \
370 typedef Manif##StateSignal<double> Manif##dStateSignal;
371
372template<typename T>
State< T, VectorSignalSpec< T, d >, d, VectorSignalSpec< T, d >, d > VectorStateType
Definition State.h:191
Signal< T, ScalarStateSignalSpec< T >, ScalarStateSignalSpec< T > > ScalarStateSignal
Definition State.h:326
#define MAKE_MANIF_STATES(Manif, Dimension, TangentDimension)
Definition State.h:364
State< T, PTS, PD, TTS, TD > operator*(const double &l, const State< T, PTS, PD, TTS, TD > &r)
Scale the state (pose and twist) by a scalar.
Definition State.h:148
ScalarStateSignal< double > ScalardStateSignal
Definition State.h:375
ScalarState< double > ScalardState
Definition State.h:374
State< T, ScalarSignalSpec< T >, 1, ScalarSignalSpec< T >, 1 > ScalarStateType
Definition State.h:169
Signal< T, ManifoldStateSignalSpec< T, ManifoldType, PD, TD >, VectorStateSignalSpec< T, TD > > ManifoldStateSignal
Definition State.h:347
State< T, PTS, PD, TTS, TD > operator+(const State< T, PTS, PD, TTS, TD > &l, const State< T, TTS, TD, TTS, TD > &r)
Add a tangent space state (twist and derivative of twist) to the current state.
Definition State.h:124
State< T, TTS, TD, TTS, TD > operator-(const State< T, PTS, PD, TTS, TD > &l, const State< T, PTS, PD, TTS, TD > &r)
Subtract a tangent space state (twist and derivative of twist) from the current state.
Definition State.h:136
std::ostream & operator<<(std::ostream &os, const ScalarStateType< T > &x)
Definition State.h:172
ScalarStateType< T > ScalarState
Definition State.h:373
State< T, ManifoldSignalSpec< T, ManifoldType >, PD, VectorSignalSpec< T, TD >, TD > ManifoldStateType
Definition State.h:213
#define MAKE_VECTOR_STATES(Dimension)
Definition State.h:356
Signal< T, VectorStateSignalSpec< T, d >, VectorStateSignalSpec< T, d > > VectorStateSignal
Definition State.h:336
ScalarStateType< T > operator/(const ScalarStateType< T > &l, const double &r)
Scale the state (pose and twist) by a scalar.
Definition State.h:182
Template class for time-series signals with interpolation, extrapolation, and derivative capabilities...
Definition Signal.h:63
double t() const
Get the current time of the signal.
Definition Signal.h:151
Type specification for manifold state signals.
Definition State.h:298
static T Norm(const Type &a)
Compute the combined norm of a manifold state.
Definition State.h:319
static Type NansType()
Returns state with NaN values.
Definition State.h:310
static Type ZeroType()
Returns identity (zero) state.
Definition State.h:303
ManifoldStateType< T, ManifoldType, PD, TD > Type
Definition State.h:299
Type specification for scalar-valued signals.
Definition Signal.h:805
Type specification for scalar state signals.
Definition State.h:228
static Type ZeroType()
Returns identity (zero) state.
Definition State.h:233
static T Norm(const Type &a)
Compute the combined norm of a scalar state.
Definition State.h:249
ScalarStateType< T > Type
Definition State.h:229
static Type NansType()
Returns state with NaN values.
Definition State.h:240
Base type for all Model state representations.
Definition State.h:34
typename PoseTypeSpec::Type PoseType
Definition State.h:35
State & operator+=(const State< T2, ScalarSignalSpec< T >, TwistDim, ScalarSignalSpec< T >, TwistDim > &r)
Definition State.h:112
State(const State &other)
Definition State.h:60
typename TwistTypeSpec::Type TwistType
Definition State.h:36
State()
Initialize an empty state.
Definition State.h:50
State & operator*=(const double &s)
Definition State.h:101
Type specification for vector-valued signals.
Definition Signal.h:839
Type specification for vector state signals.
Definition State.h:262
VectorStateType< T, d > Type
Definition State.h:263
static Type NansType()
Returns state with NaN values.
Definition State.h:274
static T Norm(const Type &a)
Compute the combined norm of a vector state.
Definition State.h:283
static Type ZeroType()
Returns identity (zero) state.
Definition State.h:267