Ravelin
SVelocity.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 SVELOCITY
8 #error This class is not to be included by the user directly. Use SVelocityf.h or SVelocityd.h instead.
9 #endif
10 
11 class SFORCE;
12 class SMOMENTUM;
13 
15 class SVELOCITY : public SVECTOR6
16 {
17  public:
19  SVELOCITY(boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) : SVECTOR6(pose) {}
20 
22  SVELOCITY(boost::shared_ptr<POSE3> pose) : SVECTOR6(pose) {}
23 
25  explicit SVELOCITY(const SVECTOR6& v) : SVECTOR6(v.get_upper(), v.get_lower(), v.pose) {}
26 
28  SVELOCITY(REAL ax, REAL ay, REAL az, REAL lx, REAL ly, REAL lz, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) : SVECTOR6(ax, ay, az, lx, ly, lz, pose) {};
29 
31  SVELOCITY(REAL ax, REAL ay, REAL az, REAL lx, REAL ly, REAL lz, boost::shared_ptr<POSE3> pose) : SVECTOR6(ax, ay, az, lx, ly, lz, pose) {};
32 
34  SVELOCITY(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) {}
35 
37  SVELOCITY(const REAL* array, boost::shared_ptr<POSE3> pose) : SVECTOR6(array[0], array[1], array[2], array[3], array[4], array[5], pose) {}
38 
40  SVELOCITY(const VECTOR3& angular, const VECTOR3& linear, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) : SVECTOR6(angular, linear, pose) {}
41 
43  SVELOCITY(const VECTOR3& angular, const VECTOR3& linear, boost::shared_ptr<POSE3> pose) : SVECTOR6(angular, linear, pose) {}
44 
46  static SVELOCITY zero(boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) { SVELOCITY t(pose); t.set_zero(); return t; }
47 
49  static SVELOCITY zero(boost::shared_ptr<POSE3> pose) { SVELOCITY t(pose); t.set_zero(); return t; }
50 
51  template <class V>
52  V& transpose_to_vector(V& v) const
53  {
54  const unsigned SPATIAL_DIM = 6;
55  v.resize(SPATIAL_DIM);
56  REAL* vdata = v.data();
57  const REAL* d = data();
58  vdata[0] = d[3]; vdata[1] = d[4]; vdata[2] = d[5];
59  vdata[3] = d[0]; vdata[4] = d[1]; vdata[5] = d[2];
60  return v;
61  }
62 
63  template <class V>
64  static SVELOCITY from_vector(const V& v, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>())
65  {
66  const unsigned SPATIAL_DIM = 6;
67  if (v.size() != SPATIAL_DIM)
68  throw MissizeException();
69  SVELOCITY t(pose);
70  REAL* tdata = t.data();
71  const REAL* vdata = v.data();
72  CBLAS::copy(SPATIAL_DIM, vdata, v.inc(), tdata, 1);
73  return t;
74  }
75 
76  template <class V>
77  static SVELOCITY from_vector(const V& v, boost::shared_ptr<POSE3> pose)
78  {
79  const unsigned SPATIAL_DIM = 6;
80  if (v.size() != SPATIAL_DIM)
81  throw MissizeException();
82  SVELOCITY t(pose);
83  REAL* tdata = t.data();
84  const REAL* vdata = v.data();
85  CBLAS::copy(SPATIAL_DIM, vdata, v.inc(), tdata, 1);
86  return t;
87  }
88 
89  REAL dot(const SFORCE& f) const;
90  REAL dot(const SMOMENTUM& m) const;
91  void set_linear(const VECTOR3& lin) { set_lower(lin); }
92  void set_angular(const VECTOR3& ang) { set_upper(ang); }
93  VECTOR3 get_angular() const { return get_upper(); }
94  VECTOR3 get_linear() const { return get_lower(); }
95  SVELOCITY& operator=(const SVELOCITY& source) { SVECTOR6::operator=(source); return *this; }
96  SVELOCITY& operator=(const SVECTOR6& source) { SVECTOR6::operator=(source); return *this; }
97  SVELOCITY cross(const SVELOCITY& v) const;
98  SFORCE cross(const SMOMENTUM& m) const;
99 
102  {
103  SVELOCITY v;
104  v._data[0] = -_data[0];
105  v._data[1] = -_data[1];
106  v._data[2] = -_data[2];
107  v._data[3] = -_data[3];
108  v._data[4] = -_data[4];
109  v._data[5] = -_data[5];
110  v.pose = pose;
111 
112  return v;
113  }
114 
115  SVELOCITY& operator-=(const SVELOCITY& v)
116  {
117  #ifndef NEXCEPT
118  if (pose != v.pose)
119  throw FrameException();
120  #endif
121 
122  _data[0] -= v._data[0];
123  _data[1] -= v._data[1];
124  _data[2] -= v._data[2];
125  _data[3] -= v._data[3];
126  _data[4] -= v._data[4];
127  _data[5] -= v._data[5];
128 
129  return *this;
130  }
131 
132  SVELOCITY& operator+=(const SVELOCITY& v)
133  {
134  #ifndef NEXCEPT
135  if (pose != v.pose)
136  throw FrameException();
137  #endif
138 
139  _data[0] += v._data[0];
140  _data[1] += v._data[1];
141  _data[2] += v._data[2];
142  _data[3] += v._data[3];
143  _data[4] += v._data[4];
144  _data[5] += v._data[5];
145 
146  return *this;
147  }
148 
149  SVELOCITY operator+(const SVELOCITY& v) const { SVELOCITY x = *this; x += v; return x; }
150  SVELOCITY operator-(const SVELOCITY& v) const { SVELOCITY x = *this; x -= v; return x; }
151  SVELOCITY operator*(REAL scalar) const { SVELOCITY v = *this; v*= scalar; return v; }
152  SVELOCITY operator/(REAL scalar) const { SVELOCITY v = *this; v/= scalar; return v; }
153 /*
154  SVELOCITY& operator/=(REAL scalar) { return operator*=((REAL) 1.0/scalar); }
155  SVELOCITY& operator*=(REAL scalar);
156  SVELOCITY& resize(unsigned rows, unsigned columns) { assert (rows == 6 && columns == 1); return *this; }
157  SVELOCITY& resize(unsigned rows) { assert (rows == 6); return *this; }
158 */
159 }; // end class
160 
161 inline std::ostream& operator<<(std::ostream& out, const SVELOCITY& t)
162 {
163  out << "velocity (linear= " << t.get_linear() << ", angular= " << t.get_angular() << ") frame: " << t.pose;
164  return out;
165 }
166 
void set_lower(const VECTOR3 &lower)
Sets the lower 3-dimensional vector.
Definition: SVector6.cpp:241
SVELOCITY(REAL ax, REAL ay, REAL az, REAL lx, REAL ly, REAL lz, boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a velocity from six values (first three linear, next three angular) and a pose...
Definition: SVelocity.h:28
SVELOCITY cross(const SVELOCITY &v) const
Returns the spatial cross product between two velocity vectors.
Definition: SVelocity.cpp:38
SVELOCITY(boost::shared_ptr< POSE3 > pose)
Constructs a velocity with zero linear and zero angular components.
Definition: SVelocity.h:22
static SVELOCITY zero(boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Returns a zero velocity.
Definition: SVelocity.h:46
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
SVELOCITY(REAL ax, REAL ay, REAL az, REAL lx, REAL ly, REAL lz, boost::shared_ptr< POSE3 > pose)
Constructs a velocity from six values (first three linear, next three angular) and a pose...
Definition: SVelocity.h:31
void set_upper(const VECTOR3 &upper)
Sets the upper 3-dimensional vector.
Definition: SVector6.cpp:249
static SVELOCITY zero(boost::shared_ptr< POSE3 > pose)
Returns a zero velocity.
Definition: SVelocity.h:49
VECTOR3 get_upper() const
Gets the upper 3-dimensional vector.
Definition: SVector6.cpp:235
SVELOCITY(const SVECTOR6 &v)
Constructs a velocity from a SVector6.
Definition: SVelocity.h:25
SVECTOR6 & operator=(const SVECTOR6 &source)
Copies this vector from another SVECTOR6.
Definition: SVector6.cpp:257
A spatial velocity (a twist)
Definition: SVelocity.h:15
A 6-dimensional floating-point vector for use with spatial algebra.
Definition: SVector6.h:22
SVELOCITY(boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a velocity with zero linear and zero angular components.
Definition: SVelocity.h:19
VECTOR3 get_lower() const
Gets the lower 3-dimensional vector.
Definition: SVector6.cpp:229
SVELOCITY(const VECTOR3 &angular, const VECTOR3 &linear, boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a velocity from linear and angular components and a pose.
Definition: SVelocity.h:40
A three-dimensional floating point vector used for representing points and vectors in 3D with associa...
Definition: Vector3.h:15
SVELOCITY(const REAL *array, boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a velocity from six values (first three angular, next three linear) and a pose...
Definition: SVelocity.h:34
A spatial force (a wrench)
Definition: SForce.h:14
SVELOCITY(const VECTOR3 &angular, const VECTOR3 &linear, boost::shared_ptr< POSE3 > pose)
Constructs a velocity from linear and angular components and a pose.
Definition: SVelocity.h:43
SVELOCITY(const REAL *array, boost::shared_ptr< POSE3 > pose)
Constructs a velocity from six values (first three angular, next three linear) and a pose...
Definition: SVelocity.h:37
SVELOCITY operator-() const
Returns the negation of this vector.
Definition: SVelocity.h:101
REAL dot(const SFORCE &f) const
Computes the dot product between a velocity and a force.
Definition: SVelocity.cpp:23