Joint.h

00001 /****************************************************************************
00002  * Copyright 2005 Evan Drumwright
00003  * This library is distributed under the terms of the GNU General Public 
00004  * License (found in COPYING).
00005  ****************************************************************************/
00006 
00007 #ifndef _JOINT_H
00008 #define _JOINT_H
00009 
00010 #include <boost/weak_ptr.hpp>
00011 #include <boost/shared_ptr.hpp>
00012 #include <Physsim/Base.h>
00013 #include <Physsim/Vector3.h>
00014 #include <Physsim/SMatrixN.h>
00015 #include <Physsim/Visualizable.h>
00016 
00017 namespace Physsim {
00018 
00019 class VisualizationData;
00020 
00022 
00025 class Joint : public Visualizable
00026 {
00027         public:
00028                 enum DOFs { DOF_1=0, DOF_2=1, DOF_3=2, DOF_4=3, DOF_5=4, DOF_6=5 };
00029 
00030                 Joint();
00031                 Joint(boost::weak_ptr<RigidBody> inboard, boost::weak_ptr<RigidBody> outboard);
00032                 virtual ~Joint() {}
00033                 virtual void clone(BasePtr& cloned, bimap<BasePtr, BasePtr>* obj_map = NULL) const;
00034                 virtual bool is_struct_identical(BaseConstPtr object) const;
00035                 virtual void load_state(BaseConstPtr object, bimap<BasePtr, BasePtr>* correspondence = NULL);
00036                 virtual void save_state(BasePtr object, bimap<BasePtr, BasePtr>* correspondence = NULL) const;
00037                 void set_q(const VectorN& q);
00038                 void set_qd(const VectorN& qd);
00039                 void add_force(const VectorN& force);
00040                 void reset_force();             
00041                 virtual const SMatrixN& get_spatial_axes(ReferenceFrameType type);
00042                 void reset_spatial_axis();
00043                 Vector3 get_position_global() const;
00044                 VectorN get_scaled_force();
00045                 VectorN compute_joint_friction_forces() const;
00046                 virtual void save_to_xml(XMLTreePtr node, std::list<BaseConstPtr>& shared_objects) const;
00047                 virtual void load_from_xml(XMLTreeConstPtr node, std::map<std::string, BasePtr>& id_map);
00048                 virtual void set_inboard_link(RigidBodyPtr link);
00049                 virtual void set_outboard_link(RigidBodyPtr link);
00050 
00052                 virtual bool is_singular_config() const = 0;
00053 
00055                 JointPtr get_this() { return boost::dynamic_pointer_cast<Joint>(shared_from_this()); }
00056 
00058                 JointConstPtr get_this() const { return boost::dynamic_pointer_cast<const Joint>(shared_from_this()); }
00059 
00060 
00062 //              virtual unsigned num_constraint_eqns() const = 0;
00063 
00065 
00075 //              virtual MatrixN get_constraint_jacobian() = 0;
00076 
00078 
00083 //              virtual MatrixN get_constraint_jacobian_dot() = 0;
00084 
00086 
00090 //              virtual double eval_constraint_eqn(unsigned i) const = 0;
00091 
00093 
00097 //              virtual double eval_constraint_dot_eqn(unsigned i) const = 0;
00098 
00100                 virtual const SMatrixN& get_spatial_axes_deriv(ReferenceFrameType type) = 0;
00101 
00103                 virtual const Matrix4& get_transform() = 0;
00104 
00106                 virtual void update_spatial_axes() = 0;
00107 
00109                 virtual void determine_Q() = 0;
00110 
00112                 virtual unsigned get_num_dof() const = 0;
00113         
00115                 const VectorN& get_max_force() const { return _maxforce; }
00116 
00118                 const VectorN& get_q() const { return _q; }
00119 
00121                 const VectorN& get_qd() const { return _qd; }
00122 
00124                 const VectorN& get_qdd() const { return _qdd; }
00125 
00127 
00130                 const VectorN& get_low_limit() const { return _lolimit; }
00131 
00133 
00136                 const VectorN& get_high_limit() const { return _hilimit; }
00137 
00139 
00142                 Real get_joint_limit_rcoeff() const { return _joint_limit_rcoeff; }
00143                 
00145 
00148                 Real get_joint_limit_kp() const { return _joint_limit_kp; }
00149                 
00151 
00154                 Real get_joint_limit_kv() const { return _joint_limit_kv; }
00155         
00157 
00160                 const VectorN& get_joint_viscous_mu() const { return _fv; }
00161 
00163 
00166                 const VectorN& get_joint_coulomb_mu() const { return _fc; }
00167         
00169                 boost::weak_ptr<RigidBody> get_inboard_link() const { return _inboard_link; }
00170 
00172                 boost::weak_ptr<RigidBody> get_outboard_link() const { return _outboard_link;}
00173 
00175                 const VectorN& get_force() const { return _force; }
00176 
00177 
00179                 void set_joint_limit_rcoeff(Real joint_limit_rcoeff) { assert(joint_limit_rcoeff >= 0 && joint_limit_rcoeff <= 1); _joint_limit_rcoeff = joint_limit_rcoeff; } 
00180                 
00182 
00185                 void set_joint_limit_kp(Real kp) { assert(kp >= 0); _joint_limit_kp = kp; }
00186                 
00188 
00191                 void set_joint_limit_kv(Real kv) { assert(kv >= 0); _joint_limit_kv = kv; }
00192                 
00194                 void set_max_force(const VectorN& maxforce) { assert(maxforce.size() == get_num_dof()); _maxforce = maxforce; }
00195 
00197                 void set_qdd(const VectorN& qdd) { assert(qdd.size() == get_num_dof()); _qdd = qdd; }
00198 
00200 
00204                 void set_joint_viscous_mu(const VectorN& mu) { assert(mu.size() == get_num_dof()); assert(VectorN::dot(mu, VectorN::one(get_num_dof())) >= 0); _fv = mu; }
00205 
00207 
00211                 void set_joint_coulomb_mu(const VectorN& mu) { assert(mu.size() == get_num_dof()); assert(VectorN::dot(mu, VectorN::one(get_num_dof())) >= 0); _fc = mu; }
00212 
00214 
00217                 void set_low_limit(const VectorN& lolimit) { assert(lolimit.size() == get_num_dof()); _lolimit = lolimit; }
00218 
00220 
00223                 void set_high_limit(const VectorN& hilimit) { assert(hilimit.size() == get_num_dof()); _hilimit = hilimit; }
00224 
00226 
00230                 boost::weak_ptr<ArticulatedBody> get_articulated_body() { return _abody; }
00231 
00233 
00237                 void set_articulated_body(ArticulatedBodyPtr abody) { _abody = abody; }
00238 
00239         protected:
00240 
00242 
00246                 void init_data();
00247 
00248                 SMatrixN _si;
00249                 SMatrixNPtr _s0;
00250                 
00251         private:
00252 
00253                 VectorN _lolimit, _hilimit;
00254                 VectorN _maxforce;
00255                 VectorN _q;
00256                 VectorN _qd;
00257                 VectorN _qdd;
00258                 VectorN _fc;
00259                 VectorN _fv;
00260                 boost::weak_ptr<RigidBody> _inboard_link;
00261                 boost::weak_ptr<RigidBody> _outboard_link;
00262                 boost::weak_ptr<ArticulatedBody> _abody;
00263                 VectorN _force;
00264                 Real _joint_limit_rcoeff;
00265                 Real _joint_limit_kp;
00266                 Real _joint_limit_kv;
00267 }; // end class
00268 } // end namespace
00269 
00270 #endif
00271 

Generated on Wed Oct 24 14:54:21 2007 for Physsim by  doxygen 1.5.1