00001 #ifndef PH_JOINTPID_H
00002 #define PH_JOINTPID_H
00003
00004 #include <Physics/PHJoint1D.h>
00005 #include <Physics/PHJointMulti.h>
00006
00007 namespace Spr{;
00008
00009 class PHJointPid:public SGBehaviorEngine{
00010 protected:
00011
00012 float lastGoal;
00013
00014 float integratedError;
00015 public:
00016 SGOBJECTDEF(PHJointPid);
00017
00018 UTRef<PHJointBase> joint;
00019
00020 int axis;
00021
00022 float goal;
00023
00024 float dGoal;
00025
00026 float proportional, differential, integral;
00027
00028 int type;
00029
00030 float pTorque, dTorque, iTorque;
00031
00032
00033 float GetProportionalTorque(){ return pTorque; }
00034 float GetDifferentialTorque(){ return dTorque; }
00035 float GetIntegralTorque(){ return iTorque; }
00036
00037
00038 void SetPGoal(float p_goal){ goal = p_goal;}
00039 void SetDGoal(float d_goal){ dGoal = d_goal;}
00040
00041
00042 PHJointPid():type(0), proportional(0), differential(0), integral(0), goal(0), dGoal(FLT_MAX), lastGoal(0), integratedError(0), axis(0){}
00043
00044 void Print(std::ostream& os) const;
00045
00046 static PHJointPid* Find(PHJoint1D* j, SGScene* scene);
00047
00048 virtual int GetPriority() const { return SGBP_FORCEGENERATOR; }
00049
00050 virtual void Clear(SGScene* s){ joint=NULL; }
00051
00052
00053 virtual void LoadState(const SGBehaviorStates& states);
00054
00055 virtual void SaveState(SGBehaviorStates& states) const;
00056
00057 void Step(SGScene* s);
00058
00059
00060 double GetJointTorque(){ return joint->GetJointTorque(axis); }
00061
00062 size_t NReferenceObjects();
00063 SGObject* ReferenceObject(size_t i);
00064 bool AddChildObject(SGObject* o, SGScene* s);
00065 bool DelChildObject(SGObject* o, SGScene* s);
00066 protected:
00067 };
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 class PHJointBallPid:public SGBehaviorEngine{
00080 protected:
00081
00082 Quaterniond lastGoal;
00083
00084 Vec3f integratedError;
00085 public:
00086 SGOBJECTDEF(PHJointBallPid);
00087
00088 UTRef<PHJointBall> joint;
00089
00090 Quaternionf goal;
00091
00092 Vec3f dGoal;
00093
00094 float proportional, differential, integral;
00095
00096 Vec3f pTorque, dTorque, iTorque;
00097
00098
00099 Vec3f GetProportionalTorque(){ return pTorque; }
00100 Vec3f GetDifferentialTorque(){ return dTorque; }
00101 Vec3f GetIntegralTorque(){ return iTorque; }
00102
00103
00104 PHJointBallPid():proportional(0), differential(0), integral(0), dGoal(FLT_MAX,0,0){}
00105
00106 static PHJointBallPid* Find(PHJointBall* j, SGScene* scene);
00107
00108 virtual int GetPriority() const { return SGBP_FORCEGENERATOR; }
00109
00110 virtual void Clear(SGScene* s){ joint=NULL; }
00111
00112
00113 virtual void LoadState(const SGBehaviorStates& states);
00114
00115 virtual void SaveState(SGBehaviorStates& states) const;
00116
00117 void Step(SGScene* s);
00118
00119
00120 Vec3f GetJointTorque(){ return joint->GetTorque(); }
00121
00122 size_t NReferenceObjects();
00123 SGObject* ReferenceObject(size_t i);
00124 bool AddChildObject(SGObject* o, SGScene* s);
00125 bool DelChildObject(SGObject* o, SGScene* s);
00126
00127 virtual void Print(std::ostream& os) const;
00128
00129 };
00130
00131
00132 }
00133
00134 #endif