メインページ | ネームスペース一覧 | クラス階層 | 構成 | Directories | ファイル一覧 | ネームスペースメンバ | 構成メンバ | ファイルメンバ | 関連ページ

PHJointMulti.h

00001 #ifndef PH_JOINTMULTI_H
00002 #define PH_JOINTMULTI_H
00003 
00004 #include <Physics/PHJoint.h>
00005 
00006 namespace Spr{;
00007 
00008 /// 他自由度の関節の基本クラス
00009 template <int NDOF>
00010 class PHJointMulti:public PHJointBase{
00011 public:
00012     typedef PTM::TVector<NDOF, double> AVec;
00013     AVec torque;                            ///<    トルク
00014     AVec accel;                             ///<    関節加速度
00015     AVec delta_position;                    ///<    変位の変分
00016     AVec velocity;                          ///<    速度
00017     void AddTorque(AVec t){ torque+=t; }    ///<    トルクを追加
00018     void SetTorque(AVec t){ torque=t; }     ///<    トルクを設定
00019     AVec GetTorque(){ return torque; }      ///<    トルクを取得
00020     AVec GetVelocity(){ return velocity; }  ///<    関節速度を取得
00021     /// 関節の自由度
00022     virtual int GetJointDof(){ return NDOF; }
00023     /// 関節速度の取得
00024     virtual double GetJointVelocity(int i){ return velocity[i]; }
00025     /// 関節加速度の取得
00026     virtual double GetJointAccel(int i){ return accel[i]; }
00027     /// 関節トルクの取得
00028     virtual double GetJointTorque(int i){ return torque[i]; }
00029     /// 関節トルクの設定
00030     virtual void SetJointTorque(double v, int i){ torque[i] = v; }
00031     /// 関節トルクを加える
00032     virtual void AddJointTorque(double v, int i){ torque[i] += v; }
00033     /// articulated inertia & ZA-force
00034     void CompArticulatedInertia(double dt){
00035         //  子ジョイントのIa,Zaの計算.
00036         PHJointBase::CompArticulatedInertia(dt);
00037         Iss = (S_tr * Ia * S).inv();
00038         //親ノードのZa,Iaに自分のZa,Iaを積み上げる
00039         //Ia
00040         OfParent(&PHJointMulti::Ia) += 
00041             pXc_Mat_cXp( Ia - (Ia * S*Iss*S_tr * Ia) );
00042         //Za
00043         OfParent(&PHJointMulti::Za) += 
00044             pXc_Vec( Z_plus_Ia_c + Ia*S*Iss*(torque - S_tr*Z_plus_Ia_c) );
00045     }
00046     /** 派生クラスのIntegrate() が呼び出す関数.
00047         派生クラスのIntegrate()の例:
00048         void Integrate(double dt){
00049             PreIntegrate(dt);
00050             //  ここで,delta_position から,関節の姿勢を計算.
00051             PropagateState();
00052             PHJointBase::Integrate(dt);
00053         }
00054     */
00055     void PreIntegrate(SGScene* scene){
00056         double dt = scene->GetTimeStep();
00057         a_p = cXp_Vec(OfParent(&PHJointMulti::a));
00058 
00059         if (intType == SYMPLETIC){
00060             //  x(dt) = x(0) + dt*v(0)/m
00061             //  v(dt) = v(0) + dt*f(dt)
00062             //加速度を計算
00063             accel = Iss*(torque - S_tr*(Z_plus_Ia_c + Ia*a_p));
00064             //速度を積分
00065             velocity += accel * scene->GetTimeStep();
00066             //位置を積分する準備
00067             delta_position = velocity * scene->GetTimeStep();
00068         }else{
00069             //加速度を計算
00070             accel = Iss*(torque - S_tr*(Z_plus_Ia_c + Ia*a_p));
00071             //位置を積分する準備
00072             delta_position = (velocity + 0.5 * accel * dt) * dt;
00073             //速度を積分
00074             velocity += accel * dt;
00075         }
00076         velocity *= scene->GetVelocityLossPerStep();
00077         //重心周りの加速度(子ノードの積分で使用する)
00078         a = a_p + c + S*accel;
00079         if (velocity.norm() > PHJOINT_MAX_VELOCITY){
00080             DSTR << "The velocity of " << GetName() << ":" << velocity << "was limited" << std::endl;
00081             if (_finite(velocity[0]) ){
00082                 velocity = PHJOINT_MAX_VELOCITY * velocity.unit();
00083             }else{
00084                 velocity.clear();
00085             }
00086         }
00087     }
00088     void CalcAccel(double dt){              ///<    このジョイントの加速度計算.詳細は基本クラスのコメントを参照.
00089         GetParent()->CalcAccel(dt); //  親の加速度を計算
00090         a_p = cXp_Vec(OfParent(&PHJointMulti::a));
00091         //加速度を計算
00092         accel = Iss*(torque - S_tr*(Z_plus_Ia_c + Ia*a_p));
00093         //重心周りの加速度(子ノードの積分で使用する)
00094         a = a_p + c + S*accel;
00095     }
00096 protected:
00097     typedef PTM::TMatrixCol<6, NDOF, double>    SMat;
00098     typedef PTM::TMatrixCol<NDOF, 6, double>    SMatTr;
00099     SMat S;                                 ///<    spatial joint axis in Fc coord.
00100     SMatTr S_tr;                            ///<    S' Sの独自の転地.
00101     PTM::TMatrixCol<NDOF, NDOF, double> Iss;///<    S'IaS のキャッシュ
00102     virtual void Reset(){
00103         accel.clear();
00104         torque.clear();
00105         PHJointBase::Reset();
00106     }
00107 /*
00108     /// 状態の読み出し
00109     virtual void LoadState(const SGBehaviorStates& states);
00110     /// 状態の保存
00111     virtual void SaveState(SGBehaviorStates& states) const;
00112 */  
00113     virtual void ClearTorqueRecursive(){
00114         PHJointBase::ClearTorqueRecursive();
00115         torque.clear();
00116     }
00117 };
00118 
00119 
00120 /** ボールジョイント,軸は子剛体側に固定される.*/
00121 class PHJointBall:public PHJointMulti<3>{
00122     double massFactor;
00123 public:
00124     SGOBJECTDEF(PHJointBall);
00125     Quaterniond position;                   ///<    関節の向き
00126     Vec3d center;           //  可動域の中心
00127     double minDot;          //  可動範囲
00128     double minTwist;            //  ひねりの可動範囲
00129     double maxTwist;            //  ひねりの可動範囲
00130     double conelimitK;      //  可動域制御のバネ係数
00131     double conelimitB;      //  可動域制御のダンパ係数
00132 
00133     PHJointBall();
00134     /// 関節位置の取得
00135     virtual double GetJointPosition(int i){ return position.rotation()[i]; }
00136 
00137 protected:
00138     virtual void Integrate(SGScene* scene);
00139     virtual void CompJointAxis();
00140     virtual void CompRelativePosition();
00141     virtual void CompRelativeVelocity();
00142     virtual void CompCoriolisAccel();
00143     virtual void Loaded(SGScene* s);
00144     virtual double MassFactor();
00145     /// 状態の読み出し
00146     virtual void LoadState(const SGBehaviorStates& states);
00147     /// 状態の保存
00148     virtual void SaveState(SGBehaviorStates& states) const;
00149 };
00150 
00151 /** ユニバーサルジョイント,軸は子剛体側に固定される x軸と y軸が動く.*/
00152 class PHJointUniversal:public PHJointMulti<2>{
00153 public:
00154     SGOBJECTDEF(PHJointUniversal);
00155     Vec2d position;                 ///<    関節の向き
00156     /// 関節位置の取得
00157     virtual double GetJointPosition(int i){ return position[i]; }
00158 
00159     virtual void Integrate(SGScene* scene);
00160     virtual void CompJointAxis();
00161     virtual void CompRelativePosition();
00162     virtual void CompRelativeVelocity();
00163     virtual void CompCoriolisAccel();
00164     /// 状態の読み出し
00165     virtual void LoadState(const SGBehaviorStates& states);
00166     /// 状態の保存
00167     virtual void SaveState(SGBehaviorStates& states) const;
00168 };
00169 
00170 }
00171 #endif

Springheadに対してSun Apr 16 01:57:54 2006に生成されました。  doxygen 1.4.1