Ravelin
SForce.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 SFORCE
8 #error This class is not to be included by the user directly. Use SForced.h or SForcef.h instead.
9 #endif
10 
11 class SAXIS;
12 
14 class SFORCE : public SVECTOR6
15 {
16  friend class SMOMENTUM;
17 
18  public:
20  SFORCE(boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) : SVECTOR6(pose) {}
21 
23  SFORCE(boost::shared_ptr<POSE3> pose) : SVECTOR6(pose) {}
24 
26  explicit SFORCE(const SVECTOR6& w) : SVECTOR6(w.get_upper(), w.get_lower(), w.pose) { }
27 
29  SFORCE(REAL fx, REAL fy, REAL fz, REAL tx, REAL ty, REAL tz, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) : SVECTOR6(fx, fy, fz, tx, ty, tz, pose) {};
30 
32  SFORCE(REAL fx, REAL fy, REAL fz, REAL tx, REAL ty, REAL tz, boost::shared_ptr<POSE3> pose) : SVECTOR6(fx, fy, fz, tx, ty, tz, pose) {};
33 
35  SFORCE(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) {}
36 
38  SFORCE(const REAL* array, boost::shared_ptr<POSE3> pose) : SVECTOR6(array[0], array[1], array[2], array[3], array[4], array[5], pose) {}
39 
41  SFORCE(const VECTOR3& f, const VECTOR3& t, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) : SVECTOR6(f, t, pose) {}
42 
44  SFORCE(const VECTOR3& f, const VECTOR3& t, boost::shared_ptr<POSE3> pose) : SVECTOR6(f, t, pose) {}
45 
47  static SFORCE zero(boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) { SFORCE w(pose); w.set_zero(); return w; }
48 
50  static SFORCE zero(boost::shared_ptr<POSE3> pose) { SFORCE w(pose); w.set_zero(); return w; }
51 
52  template <class V>
53  static SFORCE from_vector(const V& v, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>())
54  {
55  const unsigned SPATIAL_DIM = 6;
56  if (v.size() != SPATIAL_DIM)
57  throw MissizeException();
58  SFORCE w(pose);
59  REAL* wdata = w.data();
60  const REAL* vdata = v.data();
61  CBLAS::copy(SPATIAL_DIM, vdata, v.inc(), wdata, 1);
62  return w;
63  }
64 
65  template <class V>
66  static SFORCE from_vector(const V& v, boost::shared_ptr<POSE3> pose)
67  {
68  const unsigned SPATIAL_DIM = 6;
69  if (v.size() != SPATIAL_DIM)
70  throw MissizeException();
71  SFORCE w(pose);
72  REAL* wdata = w.data();
73  const REAL* vdata = v.data();
74  CBLAS::copy(SPATIAL_DIM, vdata, v.inc(), wdata, 1);
75  return w;
76  }
77 
78  REAL dot(const SVELOCITY& v) const;
79  REAL dot(const SAXIS& s) const;
80  void set_force(const VECTOR3& f) { set_upper(f); }
81  void set_torque(const VECTOR3& t) { set_lower(t); }
82  VECTOR3 get_force() const { return get_upper(); }
83  VECTOR3 get_torque() const { return get_lower(); }
84  SFORCE& operator=(const SFORCE& source) { SVECTOR6::operator=(source); return *this; }
85  SFORCE& operator=(const SVECTOR6& source) { SVECTOR6::operator=(source); return *this; }
86  SFORCE& operator+=(const SMOMENTUM& v);
87  SFORCE& operator-=(const SMOMENTUM& v);
88 
90  SFORCE operator-() const
91  {
92  SFORCE v;
93  v._data[0] = -_data[0];
94  v._data[1] = -_data[1];
95  v._data[2] = -_data[2];
96  v._data[3] = -_data[3];
97  v._data[4] = -_data[4];
98  v._data[5] = -_data[5];
99  v.pose = pose;
100 
101  return v;
102  }
103 
104  SFORCE& operator-=(const SFORCE& v)
105  {
106  #ifndef NEXCEPT
107  if (pose != v.pose)
108  throw FrameException();
109  #endif
110 
111  _data[0] -= v._data[0];
112  _data[1] -= v._data[1];
113  _data[2] -= v._data[2];
114  _data[3] -= v._data[3];
115  _data[4] -= v._data[4];
116  _data[5] -= v._data[5];
117 
118  return *this;
119  }
120 
121  SFORCE& operator+=(const SFORCE& v)
122  {
123  #ifndef NEXCEPT
124  if (pose != v.pose)
125  throw FrameException();
126  #endif
127 
128  _data[0] += v._data[0];
129  _data[1] += v._data[1];
130  _data[2] += v._data[2];
131  _data[3] += v._data[3];
132  _data[4] += v._data[4];
133  _data[5] += v._data[5];
134 
135  return *this;
136  }
137 
138  SFORCE operator+(const SFORCE& v) const { SFORCE x = *this; x += v; return x; }
139  SFORCE operator-(const SFORCE& v) const { SFORCE x = *this; x -= v; return x; }
140  SFORCE operator+(const SMOMENTUM& v) const { SFORCE x = *this; x += v; return x; }
141  SFORCE operator-(const SMOMENTUM& v) const { SFORCE x = *this; x -= v; return x; }
142  SFORCE operator*(REAL scalar) const { SFORCE v = *this; v*= scalar; return v;}
143  SFORCE operator/(REAL scalar) const { SFORCE v = *this; v/= scalar; return v;}
144 /*
145  SFORCE& resize(unsigned rows, unsigned columns) { assert (rows == 6 && columns == 1); return *this; }
146  SFORCE& resize(unsigned rows) { assert (rows == 6); return *this; }
147 */
148 }; // end class
149 
150 inline std::ostream& operator<<(std::ostream& out, const SFORCE& w)
151 {
152  out << "Wrench (force = " << w.get_force() << ", torque = " << w.get_torque() << ") frame: " << w.pose;
153  return out;
154 }
155 
void set_lower(const VECTOR3 &lower)
Sets the lower 3-dimensional vector.
Definition: SVector6.cpp:241
SFORCE(const VECTOR3 &f, const VECTOR3 &t, boost::shared_ptr< POSE3 > pose)
Constructs a spatial force using given force and torque and pose.
Definition: SForce.h:44
SFORCE(boost::shared_ptr< POSE3 > pose)
Constructs a spatial force with zero force and torque components.
Definition: SForce.h:23
SFORCE operator-() const
Returns the negation of this vector.
Definition: SForce.h:90
A spatial (six dimensional) momentum.
Definition: SMomentum.h:12
SFORCE(boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a spatial force with zero force and torque components.
Definition: SForce.h:20
boost::shared_ptr< const POSE3 > pose
The frame that this vector is defined in.
Definition: SVector6.h:96
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 SFORCE zero(boost::shared_ptr< POSE3 > pose)
Constructs a zero spatial force.
Definition: SForce.h:50
SFORCE(const VECTOR3 &f, const VECTOR3 &t, boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a spatial force using given force and torque and pose.
Definition: SForce.h:41
static SFORCE zero(boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a zero spatial force.
Definition: SForce.h:47
SVECTOR6 & operator=(const SVECTOR6 &source)
Copies this vector from another SVECTOR6.
Definition: SVector6.cpp:257
A spatial velocity (a twist)
Definition: SVelocity.h:15
SFORCE(REAL fx, REAL fy, REAL fz, REAL tx, REAL ty, REAL tz, boost::shared_ptr< POSE3 > pose)
Constructs a spatial force using six values- first three force, second three torque- and a pose...
Definition: SForce.h:32
A 6-dimensional floating-point vector for use with spatial algebra.
Definition: SVector6.h:22
SFORCE(const SVECTOR6 &w)
Constructs a spatial force from the SVector6.
Definition: SForce.h:26
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
SFORCE(const REAL *array, boost::shared_ptr< POSE3 > pose)
Constructs a spatial force using six values- first three force, second three torque0 and a pose...
Definition: SForce.h:38
A spatial force (a wrench)
Definition: SForce.h:14
SFORCE(const REAL *array, boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a spatial force using six values- first three force, second three torque0 and a pose...
Definition: SForce.h:35
SFORCE(REAL fx, REAL fy, REAL fz, REAL tx, REAL ty, REAL tz, boost::shared_ptr< const POSE3 > pose=boost::shared_ptr< const POSE3 >())
Constructs a spatial force using six values- first three force, second three torque- and a pose...
Definition: SForce.h:29