19 #ifndef __se3_force_hpp__ 20 #define __se3_force_hpp__ 23 #include "pinocchio/spatial/fwd.hpp" 24 #include "pinocchio/macros.hpp" 25 #include "pinocchio/spatial/se3.hpp" 46 template<
class Derived>
51 typedef Derived Derived_t;
52 SPATIAL_TYPEDEF_TEMPLATE(Derived_t);
55 Derived_t & derived() {
return *
static_cast<Derived_t*
>(
this); }
56 const Derived_t& derived()
const {
return *
static_cast<const Derived_t*
>(
this); }
64 ConstAngular_t
angular()
const {
return derived().angular_impl(); }
71 ConstLinear_t
linear()
const {
return derived().linear_impl(); }
74 Angular_t
angular() {
return derived().angular_impl(); }
77 Linear_t
linear() {
return derived().linear_impl(); }
85 void angular(
const Vector3 & n) { derived().angular_impl(n); }
92 void linear(
const Vector3 & f) { derived().linear_impl(f); }
102 const Vector6 &
toVector()
const {
return derived().toVector_impl(); }
105 Vector6 &
toVector() {
return derived().toVector_impl(); }
111 operator Vector6 ()
const {
return toVector(); }
123 bool operator== (
const Derived_t & other)
const {
return derived().isEqual(other);}
127 bool operator!=(
const Derived_t & other)
const {
return !(*
this == other); }
131 bool isApprox(
const Derived & other,
const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
const 132 {
return derived().isApprox_impl(other, prec); }
137 Derived_t &
operator= (
const Derived_t & other) {
return derived().__equl__(other); }
143 Derived_t &
operator+= (
const Derived_t & phi) {
return derived().__pequ__(phi); }
149 Derived_t &
operator-= (
const Derived_t & phi) {
return derived().__mequ__(phi); }
153 Derived_t
operator+(
const Derived_t & phi)
const {
return derived().__plus__(phi); }
157 Derived_t
operator*(
double a)
const {
return derived().__mult__(a); }
161 Derived_t
operator-()
const {
return derived().__minus__(); }
165 Derived_t
operator-(
const Derived_t & phi)
const {
return derived().__minus__(phi); }
169 Scalar
dot(
const Motion & m)
const {
return static_cast<Derived_t*
>(
this)->
dot(m); }
183 Derived_t
se3Action(
const SE3 & m)
const {
return derived().se3Action_impl(m); }
198 void disp(std::ostream & os)
const { derived().disp_impl(os); }
199 friend std::ostream & operator << (std::ostream & os, const ForceBase<Derived_t> & X)
208 template<
typename T,
int U>
212 typedef Eigen::Matrix<T,3,1,U> Vector3;
213 typedef Eigen::Matrix<T,4,1,U> Vector4;
214 typedef Eigen::Matrix<T,6,1,U> Vector6;
215 typedef Eigen::Matrix<T,3,3,U> Matrix3;
216 typedef Eigen::Matrix<T,4,4,U> Matrix4;
217 typedef Eigen::Matrix<T,6,6,U> Matrix6;
218 typedef typename Vector6::template FixedSegmentReturnType<3>::Type Linear_t;
219 typedef typename Vector6::template FixedSegmentReturnType<3>::Type Angular_t;
220 typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstLinear_t;
221 typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstAngular_t;
222 typedef Matrix6 ActionMatrix_t;
223 typedef Eigen::Quaternion<T,U> Quaternion_t;
242 template<
typename _Scalar,
int _Options>
247 friend class ForceBase< ForceTpl< _Scalar, _Options > >;
248 SPATIAL_TYPEDEF_TEMPLATE(ForceTpl);
249 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
251 ForceTpl() : data() {}
253 template<
typename F3,
typename N3>
254 ForceTpl(
const Eigen::MatrixBase<F3> & f,
const Eigen::MatrixBase<N3> & n)
256 EIGEN_STATIC_ASSERT_VECTOR_ONLY(F3);
257 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(F3,3);
258 EIGEN_STATIC_ASSERT_VECTOR_ONLY(N3);
259 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(N3,3);
263 template<
typename F6>
264 explicit ForceTpl(
const Eigen::MatrixBase<F6> & f)
267 EIGEN_STATIC_ASSERT_VECTOR_ONLY(F6);
268 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(F6,6);
271 template<
typename S2,
int O2>
276 static ForceTpl Zero() {
return ForceTpl(Linear_t::Zero(), Angular_t::Zero()); }
277 static ForceTpl Random() {
return ForceTpl(Linear_t::Random(), Angular_t::Random()); }
279 ForceTpl & setZero () { data.setZero ();
return *
this; }
280 ForceTpl & setRandom () { data.setRandom ();
return *
this; }
282 const Vector6 & toVector_impl()
const {
return data; }
283 Vector6 & toVector_impl() {
return data; }
285 void disp_impl(std::ostream & os)
const 287 os <<
" f = " << linear_impl().transpose() << std::endl
288 <<
" tau = " << angular_impl().transpose() << std::endl;
294 Vector3 Rf (m.rotation()*linear_impl());
295 return ForceTpl(Rf,m.translation().cross(Rf)+m.rotation()*angular_impl());
299 ForceTpl se3ActionInverse_impl(
const SE3 & m)
const 301 return ForceTpl(m.rotation().transpose()*linear_impl(),
302 m.rotation().transpose()*(angular_impl() - m.translation().cross(linear_impl())) );
305 bool isEqual (
const ForceTpl & other)
const {
return data == other.data; }
308 template<
typename S2,
int O2>
315 template<
typename F6>
316 ForceTpl &
operator= (
const Eigen::MatrixBase<F6> & phi)
318 EIGEN_STATIC_ASSERT_VECTOR_ONLY(F6);
319 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(F6,6);
324 ForceTpl & __equl__(
const ForceTpl & other) { data = other.data;
return *
this; }
325 ForceTpl & __pequ__ (
const ForceTpl & phi) { data += phi.data;
return *
this; }
326 ForceTpl & __mequ__ (
const ForceTpl & phi) { data -= phi.data;
return *
this; }
327 ForceTpl __plus__(
const ForceTpl & phi)
const {
return ForceTpl(data + phi.data); }
328 ForceTpl __mult__(
const double a)
const {
return ForceTpl(a*data); }
329 ForceTpl __minus__()
const {
return ForceTpl(-data); }
330 ForceTpl __minus__(
const ForceTpl & phi)
const {
return ForceTpl(data - phi.data); }
332 bool isApprox_impl(
const ForceTpl & other,
const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
const 333 {
return data.isApprox(other.data, prec); }
336 ConstAngular_t
angular_impl()
const {
return data.template segment<3> (ANGULAR); }
338 Angular_t
angular_impl() {
return data.template segment<3> (ANGULAR); }
340 void angular_impl(
const Vector3 & n) { data.template segment<3> (ANGULAR) = n; }
342 ConstLinear_t
linear_impl()
const {
return data.template segment<3> (LINEAR);}
344 Linear_t
linear_impl() {
return data.template segment<3> (LINEAR);}
346 void linear_impl(
const Vector3 & f) { data.template segment<3> (LINEAR) = f; }
348 Scalar
dot(
const Motion & m)
const {
return data.dot(m.toVector()); }
357 #endif // ifndef __se3_force_hpp__ Derived_t se3Action(const SE3 &m) const
Transform from A to B coordinates the Force represented by *this such that .
Linear_t linear()
Return the linear part of the force vector.
Derived_t operator-() const
Vector6 & toVector()
Return the force.
Derived_t operator*(double a) const
void linear_impl(const Vector3 &f)
Set the linear part of the force vector.
Angular_t angular()
Return the angular part of the force vector.
Concreate Class representing a force.
ConstLinear_t linear_impl() const
Return the linear part of the force vector.
const Vector6 & toVector() const
Return the force.
void angular_impl(const Vector3 &n)
Set the angular part of the force vector.
Derived_t & operator+=(const Derived_t &phi)
Replaces *this by *this + other.
Derived_t & operator=(const Derived_t &other)
Copies the Derived Force into *this.
ConstAngular_t angular() const
Return the angular part of the force vector.
Derived_t operator-(const Derived_t &phi) const
ForceTpl se3Action_impl(const SE3 &m) const
af = aXb.act(bf)
ConstAngular_t angular_impl() const
Return the angular part of the force vector.
void linear(const Vector3 &f)
Set the linear part of the force vector.
Derived_t operator+(const Derived_t &phi) const
Linear_t linear_impl()
Return the linear part of the force vector.
bool operator==(const Derived_t &other) const
bool isApprox(const Derived &other, const Scalar &prec=Eigen::NumTraits< Scalar >::dummy_precision()) const
Base interface for forces representation.
Derived_t se3ActionInverse(const SE3 &m) const
Transform from B to A coordinates the Force represented by *this such that .
Derived_t & operator-=(const Derived_t &phi)
Replaces *this by *this - other.
Scalar dot(const Motion &m) const
ConstLinear_t linear() const
Return the linear part of the force vector.
void angular(const Vector3 &n)
Set the angular part of the force vector.
Angular_t angular_impl()
Return the angular part of the force vector.
bool operator!=(const Derived_t &other) const