Ravelin
Joint.h
1 /****************************************************************************
2  * Copyright 2014 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0 license
4  ****************************************************************************/
5 
6 #ifndef JOINT
7 #error This class is not to be included by the user directly. Use Jointd.h or Jointf.h instead.
8 #endif
9 
10 class ARTICULATED_BODY;
11 class RIGIDBODY;
12 
14 class JOINT : public virtual_enable_shared_from_this<JOINT>
15 {
16  public:
17  enum ConstraintType { eUnknown, eExplicit, eImplicit };
18  enum DOFs { DOF_1=0, DOF_2=1, DOF_3=2, DOF_4=3, DOF_5=4, DOF_6=5 };
19 
20  JOINT();
21  virtual const std::vector<SVELOCITY>& get_spatial_axes();
22  void add_force(const VECTORN& force);
23  void reset_force();
24  ConstraintType get_constraint_type() const { return _constraint_type; }
25 
27  std::string joint_id;
28 
30  void set_constraint_type(ConstraintType type) { _constraint_type = type; }
31 
33 
37  boost::shared_ptr<ARTICULATED_BODY> get_articulated_body() { return (_abody.expired()) ? boost::shared_ptr<ARTICULATED_BODY>() : boost::shared_ptr<ARTICULATED_BODY>(_abody); }
38 
40 
44  void set_articulated_body(boost::shared_ptr<ARTICULATED_BODY> abody) { _abody = abody; }
45 
46 
47  virtual void set_inboard_link(boost::shared_ptr<RIGIDBODY> link, bool update_pose);
48  virtual void set_outboard_link(boost::shared_ptr<RIGIDBODY> link, bool update_pose);
49  void set_location(const VECTOR3& p, boost::shared_ptr<RIGIDBODY> inboard, boost::shared_ptr<RIGIDBODY> outboard);
50  VECTOR3 get_location(bool use_outboard = false) const;
51  virtual void set_inboard_pose(boost::shared_ptr<const POSE3> inboard_pose, bool update_joint_pose);
52  virtual void set_outboard_pose(boost::shared_ptr<POSE3> outboard_pose, bool update_joint_pose);
53  virtual void update_spatial_axes();
54  virtual void evaluate_constraints_dot(REAL C[]);
55  virtual void set_q_tare(const VECTORN& tare) { _q_tare = tare; }
56  virtual const VECTORN& get_q_tare() const { return _q_tare; }
57 
59  boost::shared_ptr<RIGIDBODY> get_inboard_link() const { return (_inboard_link.expired()) ? boost::shared_ptr<RIGIDBODY>() : boost::shared_ptr<RIGIDBODY>(_inboard_link); }
60 
62  boost::shared_ptr<RIGIDBODY> get_outboard_link() const { return (_outboard_link.expired()) ? boost::shared_ptr<RIGIDBODY>() : boost::shared_ptr<RIGIDBODY>(_outboard_link); }
63 
66 
69 
72 
74  unsigned get_index() const { return _joint_idx; }
75 
77 
81  void set_index(unsigned index) { _joint_idx = index; }
82 
84  unsigned get_constraint_index() const { return _constraint_idx; }
85 
87  void set_constraint_index(unsigned idx) { _constraint_idx = idx; }
88 
90 
94  void set_coord_index(unsigned index) { _coord_idx = index; }
95 
97  unsigned get_coord_index() const { return _coord_idx; }
98 
100  boost::shared_ptr<const POSE3> get_pose() const { return _F; };
101 
103  boost::shared_ptr<const POSE3> get_pose_from_outboard() const { return _Fb; };
104 
106 
109  virtual bool is_singular_config() const = 0;
110 
112  virtual unsigned num_constraint_eqns() const { return 6 - num_dof(); }
113 
115 
122  virtual void evaluate_constraints(REAL C[]) = 0;
123 
125 
128  virtual const std::vector<SVELOCITY>& get_spatial_axes_dot() = 0;
129 
131 
135  virtual boost::shared_ptr<const POSE3> get_induced_pose() = 0;
136 
138  virtual void determine_q(VECTORN& q) = 0;
139 
141  virtual unsigned num_dof() const = 0;
142 
145 
148 
150 
155  virtual void calc_constraint_jacobian(bool inboard, MATRIXN& Cq) = 0;
156 
158 
163  virtual void calc_constraint_jacobian_dot(bool inboard, MATRIXN& Cq) = 0;
164 
165  protected:
166  void calc_constraint_jacobian_numeric(bool inboard, MATRIXN& Cq);
167  bool transform_jacobian(MATRIXN& J, bool use_inboard, MATRIXN& output);
168  void invalidate_pose_vectors() { get_outboard_link()->invalidate_pose_vectors(); }
169  boost::shared_ptr<const POSE3> get_inboard_pose() { if (_inboard_link.expired()) return boost::shared_ptr<const POSE3>(); return get_inboard_link()->get_pose(); }
170  boost::shared_ptr<const POSE3> get_outboard_pose() { if (_outboard_link.expired()) return boost::shared_ptr<const POSE3>(); return get_outboard_link()->get_pose(); }
171 
173  boost::shared_ptr<POSE3> _Fprime;
174 
176  boost::shared_ptr<POSE3> _F;
177 
179  boost::shared_ptr<POSE3> _Fb;
180 
182 
186  virtual void init_data();
187 
189 
193  std::vector<SVELOCITY> _s;
194 
196 
203 
204  boost::weak_ptr<RIGIDBODY> _inboard_link;
205  boost::weak_ptr<RIGIDBODY> _outboard_link;
206  boost::weak_ptr<ARTICULATED_BODY> _abody;
207  ConstraintType _constraint_type;
208  unsigned _joint_idx;
209  unsigned _coord_idx;
210  unsigned _constraint_idx;
211 }; // end class
212 
213 
boost::shared_ptr< POSE3 > _F
The frame of this joint.
Definition: Joint.h:176
Abstract class for articulated bodies.
Definition: ArticulatedBody.h:15
boost::shared_ptr< POSE3 > _Fprime
The frame induced by the joint.
Definition: Joint.h:173
std::vector< SVELOCITY > _s
The spatial axes (in joint frame) for the joint.
Definition: Joint.h:193
void set_constraint_type(ConstraintType type)
Sets whether this constraint is implicit or explicit (or unknown)
Definition: Joint.h:30
VECTORN lambda
Constraint forces calculated by forward dynamics.
Definition: Joint.h:71
boost::shared_ptr< const POSE3 > get_pose_from_outboard() const
Gets the pose of this joint relative to the outboard pose (rather than the inboard pose as returned b...
Definition: Joint.h:103
VECTORN _q_tare
The stored "tare" value for the initial joint configuration.
Definition: Joint.h:202
void set_index(unsigned index)
Sets the joint index.
Definition: Joint.h:81
virtual void determine_q(VECTORN &q)=0
Abstract method to determine the value of Q (joint position) from current transforms.
virtual const std::vector< SVELOCITY > & get_spatial_axes()
Gets the spatial axes for this joint.
Definition: Joint.cpp:187
boost::shared_ptr< const POSE3 > get_pose() const
Gets the pose of this joint (relative to the inboard pose instead of the outboard pose as returned by...
Definition: Joint.h:100
VECTORN qd
The velocity of this joint.
Definition: Joint.h:147
bool transform_jacobian(MATRIXN &J, bool use_inboard, MATRIXN &output)
Transforms a Jacobian (if necessary)
Definition: Joint.cpp:198
std::string joint_id
The ID of this joint.
Definition: Joint.h:27
A generic, possibly non-square matrix.
Definition: MatrixN.h:18
void reset_force()
Resets the force on the joint.
Definition: Joint.cpp:26
boost::shared_ptr< ARTICULATED_BODY > get_articulated_body()
Gets the articulated body corresponding to this body.
Definition: Joint.h:37
Represents a single rigid body.
Definition: RigidBody.h:23
virtual void calc_constraint_jacobian_dot(bool inboard, MATRIXN &Cq)=0
Computes the time derivative of the constraint Jacobian for this joint with respect to the given body...
virtual void evaluate_constraints_dot(REAL C[])
Evaluates the time derivative of the constraint equations.
Definition: Joint.cpp:277
boost::shared_ptr< POSE3 > _Fb
The frame of this joint backward from the outboard link.
Definition: Joint.h:179
VECTOR3 get_location(bool use_outboard=false) const
Gets the location of this joint.
Definition: Joint.cpp:164
VECTORN qdd
The acceleration of this joint.
Definition: Joint.h:65
virtual boost::shared_ptr< const POSE3 > get_induced_pose()=0
Abstract method to get the local transform for this joint.
virtual unsigned num_constraint_eqns() const
Gets the number of constraint equations for this joint.
Definition: Joint.h:112
virtual void calc_constraint_jacobian(bool inboard, MATRIXN &Cq)=0
Computes the constraint Jacobian for this joint with respect to the given body.
VECTORN q
The position of this joint.
Definition: Joint.h:144
void set_coord_index(unsigned index)
Sets the coordinate index for this joint.
Definition: Joint.h:94
void set_articulated_body(boost::shared_ptr< ARTICULATED_BODY > abody)
Sets the articulated body corresponding to this body.
Definition: Joint.h:44
boost::shared_ptr< RIGIDBODY > get_outboard_link() const
Gets the outboard link for this joint.
Definition: Joint.h:62
unsigned get_coord_index() const
Gets the starting coordinate index for this joint.
Definition: Joint.h:97
virtual bool is_singular_config() const =0
Gets whether this joint is in a singular configuration.
unsigned get_index() const
Gets the joint index (returns UINT_MAX if not set)
Definition: Joint.h:74
A generic N-dimensional floating point vector.
Definition: VectorN.h:16
void add_force(const VECTORN &force)
Adds a force to the joint.
Definition: Joint.cpp:32
unsigned get_constraint_index() const
Gets the constraint index for this joint.
Definition: Joint.h:84
void set_constraint_index(unsigned idx)
Sets the constraint index for this joint.
Definition: Joint.h:87
void calc_constraint_jacobian_numeric(bool inboard, MATRIXN &Cq)
Computes the constraint jacobian with respect to a body numerically
Definition: Joint.cpp:224
A three-dimensional floating point vector used for representing points and vectors in 3D with associa...
Definition: Vector3.h:15
virtual void update_spatial_axes()
Abstract method to update the local spatial axes.
Definition: Joint.cpp:70
Defines a bilateral constraint (a joint)
Definition: Joint.h:14
virtual void init_data()
Method for initializing all variables in the joint.
Definition: Joint.cpp:82
JOINT()
Initializes the joint.
Definition: Joint.cpp:10
virtual void evaluate_constraints(REAL C[])=0
Evaluates the constraint equations for this joint.
VECTORN force
The actuator force (user/controller sets this)
Definition: Joint.h:68
virtual const std::vector< SVELOCITY > & get_spatial_axes_dot()=0
Abstract method to get the spatial axes derivatives for this joint.
boost::shared_ptr< RIGIDBODY > get_inboard_link() const
Gets the inboard link for this joint.
Definition: Joint.h:59
virtual unsigned num_dof() const =0
Gets the number of degrees-of-freedom for this joint.