RCArticulatedBody.h

00001 
00002 /****************************************************************************
00003  * Copyright 2005 Evan Drumwright
00004  * This library is distributed under the terms of the GNU General Public 
00005  * License (found in COPYING).
00006  ****************************************************************************/
00007 
00008 #ifndef _RC_ARTICULATED_BODY_H
00009 #define _RC_ARTICULATED_BODY_H
00010 
00011 #include <pthread.h>
00012 #include <map>
00013 #include <list>
00014 #include <vector>
00015 #include <ext/hash_map>
00016 #include <boost/shared_ptr.hpp>
00017 #include <Physsim/Constants.h>
00018 #include <Physsim/HashClasses.h>
00019 #include <Physsim/SVector6.h>
00020 #include <Physsim/Vector3.h>
00021 #include <Physsim/Matrix3.h>
00022 #include <Physsim/ArticulatedBody.h>
00023 #include <Physsim/RigidBody.h>
00024 
00025 namespace Physsim {
00026 
00027 class FSABAlgorithm;
00028 class Joint;
00029 class RCArticulatedBodyFwdDynAlgo;
00030 
00032 
00047 class RCArticulatedBody : public ArticulatedBody
00048 {
00049         public:
00050                 RCArticulatedBody();
00051                 RCArticulatedBody(const RCArticulatedBody& source);
00052                 virtual ~RCArticulatedBody() {}
00053                 virtual void clone(BasePtr& cloned, bimap<BasePtr, BasePtr>* obj_map = NULL) const;
00054                 virtual bool is_struct_identical(BaseConstPtr object) const;
00055                 virtual void load_state(BaseConstPtr object, bimap<BasePtr, BasePtr>* correspondence = NULL);
00056                 virtual void save_state(BasePtr object, bimap<BasePtr, BasePtr>* correspondence = NULL) const;
00057                 void set_links(const std::vector<RigidBodyPtr>& links);
00058                 RigidBodyPtr find_link(const std::string& linkname) const;
00059                 JointPtr find_joint(const std::string& jointname) const;
00060                 void add_link(RigidBodyPtr link);
00061                 virtual VectorN get_state_deriv();
00062                 virtual VectorN get_state();
00063                 virtual void set_state(const VectorN& state);
00064                 MatrixN calc_jacobian_column(JointPtr joint, const Vector3& point);
00065                 MatrixNN calc_jacobian_floating_base(const VectorN& point);
00066                 virtual std::list<RigidBodyPtr> get_rigid_bodies() const;
00067                 virtual void reset_accumulators();
00068                 virtual std::list<sorted_pair<RigidBodyPtr> > get_adjacent_links() const;
00069                 void add_joint(JointPtr joint);
00070                 void set_joints(const std::vector<JointPtr > joints);
00071                 void update_link_transforms() const;            
00072                 void update_link_velocities();
00073                 void apply_impulse(const Vector3& j, const Vector3& k, const Vector3& p, RigidBodyPtr link);
00074                 virtual void compile();
00075                 virtual void calc_fwd_dyn();
00076                 virtual void update_visualization();
00077                 virtual void load_from_xml(XMLTreeConstPtr node, std::map<std::string, BasePtr>& id_map);
00078                 virtual void save_to_xml(XMLTreePtr node, std::list<BaseConstPtr>& shared_objects) const;
00079                 RCArticulatedBodyPtr get_this() { return boost::dynamic_pointer_cast<RCArticulatedBody>(shared_from_this()); }
00080                 RCArticulatedBodyConstPtr get_this() const { return boost::dynamic_pointer_cast<const RCArticulatedBody>(shared_from_this()); }
00081 
00082                 // NOTE: the following three methods are currently disabled, pending
00083                 // my decision on whether to keep them...               
00084                 virtual bool joint_limit_collision(Real collision_tolerance) const { return false; }
00085                 virtual void correct_joint_limit_collisions(Real collision_tolerance) {}
00086                 virtual void correct_joint_limit_violations() {}
00087 
00089                 RigidBodyPtr get_base_link() const { return _links.front(); }
00090 
00092                 const std::vector<RigidBodyPtr>& get_links() const { return _links; }
00093 
00095                 const std::vector<JointPtr>& get_joints() const { return _joints; }
00096 
00098                 bool is_floating_base() const { return _floating_base; }
00099 
00101                 void set_floating_base(bool flag) { _floating_base = flag; }
00102 
00104                 RigidBodyPtr get_base() const { return _links.front(); }
00105 
00107 
00110                 void set_computation_ref_frame(ReferenceFrameType type) { _computation_frame_type = type; }
00111                 
00113                 ReferenceFrameType get_computation_ref_frame() const { return _computation_frame_type; }
00114 
00116                 boost::shared_ptr<RCArticulatedBodyFwdDynAlgo> get_forward_dynamics_algorithm() const { return _fdyn_algorithm; }       
00117                 
00119                 void set_forward_dynamics_algorithm(boost::shared_ptr<RCArticulatedBodyFwdDynAlgo> algorithm) { _fdyn_algorithm = algorithm; }  
00120 
00121         private:
00122 
00124                 VectorN _state_deriv;
00125 
00127                 std::vector<JointPtr> _joints;
00128 
00130                 std::vector<RigidBodyPtr> _links;
00131         
00133                 std::map<RigidBodyConstPtr, unsigned> _link_idx_map;
00134 
00136                 bool _floating_base;
00137                 
00139                 boost::shared_ptr<RCArticulatedBodyFwdDynAlgo> _fdyn_algorithm;
00140 
00142                 ReferenceFrameType _computation_frame_type;
00143 }; // end class
00144 
00145 } // end namespace
00146 #endif
00147 

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