Blender V2.61 - r43446

ConstraintSet.hpp

Go to the documentation of this file.
00001 /*
00002  * ConstraintSet.hpp
00003  *
00004  *  Created on: Jan 5, 2009
00005  *      Author: rubensmits
00006  */
00007 
00008 #ifndef CONSTRAINTSET_HPP_
00009 #define CONSTRAINTSET_HPP_
00010 
00011 #include "kdl/frames.hpp"
00012 #include "eigen_types.hpp"
00013 #include "Cache.hpp"
00014 #include <vector>
00015 
00016 namespace iTaSC {
00017 
00018 enum ConstraintAction {
00019     ACT_NONE=       0,
00020     ACT_VALUE=      1,
00021     ACT_VELOCITY=   2,
00022     ACT_TOLERANCE=  4,
00023     ACT_FEEDBACK=   8,
00024     ACT_ALPHA=      16
00025 };
00026 
00027 struct ConstraintSingleValue {
00028     unsigned int id;    // identifier of constraint value, depends on constraint
00029     unsigned int action;// action performed, compbination of ACT_..., set on return
00030     const double y;     // actual constraint value
00031     const double ydot;  // actual constraint velocity
00032     double yd;          // current desired constraint value, changed on return
00033     double yddot;       // current desired constraint velocity, changed on return
00034     ConstraintSingleValue(): id(0), action(0), y(0.0), ydot(0.0) {}
00035 };
00036 
00037 struct ConstraintValues {
00038     unsigned int id;    // identifier of group of constraint values, depend on constraint
00039     unsigned short number;      // number of constraints in list
00040     unsigned short action;      // action performed, ACT_..., set on return
00041     double alpha;       // constraint activation coefficient, should be [0..1]
00042     double tolerance;   // current desired tolerance on constraint, same unit than yd, changed on return
00043     double feedback;    // current desired feedback on error, in 1/sec, changed on return
00044     struct ConstraintSingleValue* values;
00045     ConstraintValues(): id(0), number(0), action(0), values(NULL) {}
00046 };
00047 
00048 class ConstraintSet;
00049 typedef bool (*ConstraintCallback)(const Timestamp& timestamp, struct ConstraintValues* const _values, unsigned int _nvalues, void* _param);
00050 
00051 class ConstraintSet {
00052 protected:
00053     unsigned int m_nc;
00054     e_scalar m_maxDeltaChi;
00055     e_matrix m_Cf;
00056     e_vector m_Wy,m_y,m_ydot;
00057     e_vector6 m_chi,m_chidot,m_S,m_temp,m_tdelta;
00058     e_matrix6 m_Jf,m_U,m_V,m_B,m_Jf_inv;
00059     KDL::Frame m_internalPose,m_externalPose;
00060     ConstraintCallback m_constraintCallback;
00061     void* m_constraintParam;
00062     void* m_poseParam;
00063     bool m_toggle;
00064     bool m_substep;
00065     double m_threshold;
00066     unsigned int m_maxIter;
00067 
00068     friend class Scene;
00069     virtual void modelUpdate(KDL::Frame& _external_pose,const Timestamp& timestamp);
00070     virtual void updateKinematics(const Timestamp& timestamp)=0;
00071     virtual void pushCache(const Timestamp& timestamp)=0;
00072     virtual void updateJacobian()=0;
00073     virtual void updateControlOutput(const Timestamp& timestamp)=0;
00074     virtual void initCache(Cache *_cache) = 0;
00075     virtual bool initialise(KDL::Frame& init_pose);
00076     virtual void reset(unsigned int nc,double accuracy,unsigned int maximum_iterations);
00077     virtual bool closeLoop();
00078     virtual double getMaxTimestep(double& timestep);
00079 
00080 
00081 public:
00082     ConstraintSet(unsigned int nc,double accuracy,unsigned int maximum_iterations);
00083     ConstraintSet();
00084     virtual ~ConstraintSet();
00085 
00086     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00087 
00088     virtual bool registerCallback(ConstraintCallback _function, void* _param)
00089     {
00090         m_constraintCallback = _function;
00091         m_constraintParam = _param;
00092         return true;
00093     }
00094 
00095     virtual const e_vector& getControlOutput()const{return m_ydot;};
00096     virtual const ConstraintValues* getControlParameters(unsigned int* _nvalues) = 0;
00097     virtual bool setControlParameters(ConstraintValues* _values, unsigned int _nvalues, double timestep=0.0) = 0;
00098     bool setControlParameter(int id, ConstraintAction action, double value, double timestep=0.0);
00099 
00100     virtual const e_matrix6& getJf() const{return m_Jf;};
00101     virtual const KDL::Frame& getPose() const{return m_internalPose;};
00102     virtual const e_matrix& getCf() const{return m_Cf;};
00103 
00104     virtual const e_vector& getWy() const {return m_Wy;};
00105     virtual void setWy(const e_vector& Wy_in){m_Wy = Wy_in;};
00106     virtual void setJointVelocity(const e_vector chidot_in){m_chidot = chidot_in;};
00107 
00108     virtual unsigned int getNrOfConstraints(){return m_nc;};
00109     void substep(bool _substep) {m_substep=_substep;}
00110     bool substep() {return m_substep;}
00111 };
00112 
00113 }
00114 
00115 #endif /* CONSTRAINTSET_HPP_ */