Ravelin
SMomentum.h
1 /****************************************************************************
2  * Copyright 2013 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef SMOMENTUM
8 #error This class is not to be included by the user directly. Use SMomentumd.h or SMomentumf.h instead.
9 #endif
10 
12 class SMOMENTUM : public SVECTOR6
13 {
14  friend class SFORCE;
15 
16  public:
18  SMOMENTUM(boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) : SVECTOR6(pose) {}
19 
21  SMOMENTUM(boost::shared_ptr<POSE3> pose) : SVECTOR6(pose) {}
22 
24  explicit SMOMENTUM(const SVECTOR6& w) : SVECTOR6(w.get_upper(), w.get_lower(), w.pose) { }
25 
27  SMOMENTUM(REAL lx, REAL ly, REAL lz, REAL ax, REAL ay, REAL az, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) : SVECTOR6(lx, ly, lz, ax, ay, az, pose) {};
28 
30  SMOMENTUM(REAL lx, REAL ly, REAL lz, REAL ax, REAL ay, REAL az, boost::shared_ptr<POSE3> pose) : SVECTOR6(lx, ly, lz, ax, ay, az, pose) {};
31 
33  SMOMENTUM(const REAL* array, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) : SVECTOR6(array[0], array[1], array[2], array[3], array[4], array[5], pose) {}
34 
36  SMOMENTUM(const REAL* array, boost::shared_ptr<POSE3> pose) : SVECTOR6(array[0], array[1], array[2], array[3], array[4], array[5], pose) {}
37 
39  SMOMENTUM(const VECTOR3& l, const VECTOR3& a, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) : SVECTOR6(l, a, pose) {}
40 
42  SMOMENTUM(const VECTOR3& l, const VECTOR3& a, boost::shared_ptr<POSE3> pose) : SVECTOR6(l, a, pose) {}
43 
45  static SMOMENTUM zero(boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) { SMOMENTUM w(pose); w.set_zero(); return w; }
46 
48  static SMOMENTUM zero(boost::shared_ptr<POSE3> pose) { SMOMENTUM w(pose); w.set_zero(); return w; }
49 
50  template <class V>
51  static SMOMENTUM from_vector(const V& v, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>())
52  {
53  const unsigned SPATIAL_DIM = 6;
54  if (v.size() != SPATIAL_DIM)
55  throw MissizeException();
56  SMOMENTUM w(pose);
57  REAL* wdata = w.data();
58  const REAL* vdata = v.data();
59  CBLAS::copy(SPATIAL_DIM, vdata, v.inc(), wdata, 1);
60  return w;
61  }
62 
63  template <class V>
64  static SMOMENTUM from_vector(const V& v, boost::shared_ptr<POSE3> pose)
65  {
66  const unsigned SPATIAL_DIM = 6;
67  if (v.size() != SPATIAL_DIM)
68  throw MissizeException();
69  SMOMENTUM w(pose);
70  REAL* wdata = w.data();
71  const REAL* vdata = v.data();
72  CBLAS::copy(SPATIAL_DIM, vdata, v.inc(), wdata, 1);
73  return w;
74  }
75 
76  void set_linear(const VECTOR3& l) { set_upper(l); }
77  void set_angular(const VECTOR3& a) { set_lower(a); }
78  VECTOR3 get_linear() const { return get_upper(); }
79  VECTOR3 get_angular() const { return get_lower(); }
80  SMOMENTUM& operator=(const SMOMENTUM& source) { SVECTOR6::operator=(source); return *this; }
81  SMOMENTUM& operator=(const SFORCE& source) { SVECTOR6::operator=(source); return *this; }
82  SMOMENTUM& operator=(const SVECTOR6& source) { SVECTOR6::operator=(source); return *this; }
83  REAL dot(const SVELOCITY& s) const;
84  SMOMENTUM& operator-=(const SFORCE& v);
85  SMOMENTUM& operator+=(const SFORCE& v);
86 
89  {
90  SMOMENTUM v;
91  v._data[0] = -_data[0];
92  v._data[1] = -_data[1];
93  v._data[2] = -_data[2];
94  v._data[3] = -_data[3];
95  v._data[4] = -_data[4];
96  v._data[5] = -_data[5];
97  v.pose = pose;
98 
99  return v;
100  }
101 
102  SMOMENTUM& operator-=(const SMOMENTUM& v)
103  {
104  #ifndef NEXCEPT
105  if (pose != v.pose)
106  throw FrameException();
107  #endif
108 
109  _data[0] -= v._data[0];
110  _data[1] -= v._data[1];
111  _data[2] -= v._data[2];
112  _data[3] -= v._data[3];
113  _data[4] -= v._data[4];
114  _data[5] -= v._data[5];
115 
116  return *this;
117  }
118 
119  SMOMENTUM& operator+=(const SMOMENTUM& v)
120  {
121  #ifndef NEXCEPT
122  if (pose != v.pose)
123  throw FrameException();
124  #endif
125 
126  _data[0] += v._data[0];
127  _data[1] += v._data[1];
128  _data[2] += v._data[2];
129  _data[3] += v._data[3];
130  _data[4] += v._data[4];
131  _data[5] += v._data[5];
132 
133  return *this;
134  }
135 
136  SMOMENTUM operator+(const SMOMENTUM& v) const { SMOMENTUM x = *this; x += v; return x; }
137  SMOMENTUM operator+(const SFORCE& v) const { SMOMENTUM x = *this; x += v; return x; }
138  SMOMENTUM operator-(const SMOMENTUM& v) const { SMOMENTUM x = *this; x -= v; return x; }
139  SMOMENTUM operator-(const SFORCE& v) const { SMOMENTUM x = *this; x -= v; return x; }
140  SMOMENTUM operator*(REAL scalar) const { SMOMENTUM v = *this; v*= scalar; return v; }
141  SMOMENTUM operator/(REAL scalar) const { SMOMENTUM v = *this; v/= scalar; return v; }
142 /*
143  SMOMENTUM& resize(unsigned rows, unsigned columns) { assert (rows == 6 && columns == 1); return *this; }
144  SMOMENTUM& resize(unsigned rows) { assert (rows == 6); return *this; }
145 */
146 }; // end class
147 
148 inline std::ostream& operator<<(std::ostream& out, const SMOMENTUM& w)
149 {
150  out << "Momentum (linear = " << w.get_linear() << ", angular = " << w.get_angular() << ") frame: " << w.pose;
151  return out;
152 }
153 
void set_lower(const VECTOR3 &lower)
Sets the lower 3-dimensional vector.
Definition: SVector6.cpp:241
A spatial (six dimensional) momentum.
Definition: SMomentum.h:12
boost::shared_ptr< const POSE3 > pose
The frame that this vector is defined in.
Definition: SVector6.h:96
SMOMENTUM(const REAL *array, boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a spatial momentum using six values- first three linear, second three angular and a pose...
Definition: SMomentum.h:33
void set_upper(const VECTOR3 &upper)
Sets the upper 3-dimensional vector.
Definition: SVector6.cpp:249
VECTOR3 get_upper() const
Gets the upper 3-dimensional vector.
Definition: SVector6.cpp:235
static SMOMENTUM zero(boost::shared_ptr< POSE3 > pose)
Constructs a zero spatial momentum.
Definition: SMomentum.h:48
SVECTOR6 & operator=(const SVECTOR6 &source)
Copies this vector from another SVECTOR6.
Definition: SVector6.cpp:257
SMOMENTUM(REAL lx, REAL ly, REAL lz, REAL ax, REAL ay, REAL az, boost::shared_ptr< POSE3 > pose)
Constructs a spatial momentum using six values- first three linear, second three angular- and a pose...
Definition: SMomentum.h:30
A spatial velocity (a twist)
Definition: SVelocity.h:15
SMOMENTUM(const REAL *array, boost::shared_ptr< POSE3 > pose)
Constructs a spatial momentum using six values- first three linear, second three angular and a pose...
Definition: SMomentum.h:36
A 6-dimensional floating-point vector for use with spatial algebra.
Definition: SVector6.h:22
static SMOMENTUM zero(boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a zero spatial momentum.
Definition: SMomentum.h:45
VECTOR3 get_lower() const
Gets the lower 3-dimensional vector.
Definition: SVector6.cpp:229
A three-dimensional floating point vector used for representing points and vectors in 3D with associa...
Definition: Vector3.h:15
SMOMENTUM(REAL lx, REAL ly, REAL lz, REAL ax, REAL ay, REAL az, boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a spatial momentum using six values- first three linear, second three angular- and a pose...
Definition: SMomentum.h:27
A spatial force (a wrench)
Definition: SForce.h:14
SMOMENTUM(boost::shared_ptr< POSE3 > pose)
Constructs a spatial momentum with zero linear and angular components.
Definition: SMomentum.h:21
SMOMENTUM(const VECTOR3 &l, const VECTOR3 &a, boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a spatial momentum using given linear and angular and pose.
Definition: SMomentum.h:39
SMOMENTUM operator-() const
Returns the negation of this vector.
Definition: SMomentum.h:88
SMOMENTUM(const VECTOR3 &l, const VECTOR3 &a, boost::shared_ptr< POSE3 > pose)
Constructs a spatial momentum using given linear and angular and pose.
Definition: SMomentum.h:42
SMOMENTUM(boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a spatial momentum with zero linear and angular components.
Definition: SMomentum.h:18
SMOMENTUM(const SVECTOR6 &w)
Constructs a spatial momentum from the SVector6.
Definition: SMomentum.h:24