GCOP
1.0
|
00001 // This file is part of libgcop, a library for Geometric Control, Optimization, and Planning (GCOP) 00002 // 00003 // Copyright (C) 2004-2014 Marin Kobilarov <marin(at)jhu.edu> 00004 // 00005 // This Source Code Form is subject to the terms of the Mozilla 00006 // Public License v. 2.0. If a copy of the MPL was not distributed 00007 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00008 00009 #ifndef GCOP_MBS_H 00010 #define GCOP_MBS_H 00011 00012 #include "body3d.h" 00013 #include "joint.h" 00014 #include "mbsmanifold.h" 00015 #include "function.h" 00016 #include "mbscspace.h" 00017 #include "mbstspace.h" 00018 #include <exception> // std::exception 00019 #include <stdexcept> 00020 00021 namespace gcop { 00022 00023 using namespace std; 00024 using namespace Eigen; 00025 00033 class Mbs : public System<MbsState> { 00034 00035 public: 00036 00037 Mbs(int nb, int c, bool fixed = false); 00038 00039 virtual ~Mbs(); 00040 00041 void Init(); 00042 00043 double Step(MbsState& xb, double t, const MbsState& xa, 00044 const VectorXd &u, double h, const VectorXd *p = 0, 00045 MatrixXd *A = 0, MatrixXd *B = 0, MatrixXd *C = 0); 00046 00047 00048 double EulerStep(MbsState& xb, double t, const MbsState& xa, 00049 const VectorXd &u, double h, 00050 MatrixXd *A = 0, MatrixXd *B = 0); 00051 00052 00053 double HeunStep(MbsState& xb, double t, const MbsState& xa, 00054 const VectorXd &u, double h, 00055 MatrixXd *A = 0, MatrixXd *B = 0); 00056 00057 double TrapStep(MbsState& xb, double t, const MbsState& xa, 00058 const VectorXd &u, double h, 00059 MatrixXd *A, MatrixXd *B); 00060 00061 00062 void NE(VectorXd &e, const VectorXd &vdr, 00063 MbsState &xb, 00064 double t, const MbsState &xa, 00065 const VectorXd &u, double h); 00066 00067 00077 void ID(VectorXd &f, 00078 double t, const MbsState &x, 00079 const VectorXd &u); 00080 00087 void Bias(VectorXd &b, 00088 double t, const MbsState &x) const; 00089 00098 void DBias(VectorXd &b, 00099 double t, 00100 const MbsState &xb, 00101 const MbsState &xa, double h); 00102 00108 void FK(MbsState &x); 00109 00119 void KStep(MbsState &xb, const MbsState &xa, double h, bool impl = true); 00120 00121 void NewtonEulerJacobian(MatrixXd &De, const MbsState &xb, const MbsState &xa, double h); 00122 00128 void Mass(MatrixXd &M, const MbsState &x) const; 00129 00138 void Acc(VectorXd &a, double t, const MbsState& x, const VectorXd &u, double h); 00139 00150 virtual void Force(VectorXd &f, double t, const MbsState &x, const VectorXd &u, 00151 MatrixXd *A = 0, MatrixXd *B = 0); 00152 00153 void Rec(MbsState &x, double h); 00154 00155 void ClampPose(MbsState &x, int i) const; 00156 00157 void CheckLimits(MbsState &x, int i, double h) const; 00158 00159 void GetImpulse(double f, const MbsState &x, int i, double h) const; 00160 00161 void ClampVelocity(MbsState &x) const; 00162 00163 void print(const MbsState &x) const; 00164 00165 int nb; 00166 00167 bool fixed; 00168 00169 vector<Body3d<>> links; 00170 00171 vector<Joint> joints; 00172 00173 vector<Matrix6d> Ips; 00174 00175 vector<int> pis; 00176 vector<vector<int> > cs; 00177 00178 Vector3d ag; 00179 00180 VectorXd damping; 00181 00182 VectorXd lbK; 00183 VectorXd lbD; 00184 VectorXd ubK; 00185 VectorXd ubD; 00186 VectorXd fsl; 00187 VectorXd fsu; 00188 00189 int basetype; 00190 static const int FIXEDBASE = 0; 00191 static const int FLOATBASE = 1; 00192 static const int AIRBASE = 2; 00193 00194 SE3 &se3; 00195 00196 int method; 00197 static const int EULER = 1; 00198 static const int HEUN = 2; 00199 static const int TRAP = 3; 00200 int iters; 00201 00202 bool debug; 00203 }; 00204 } 00205 00206 #endif