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