GCOP
1.0
|
00001 #ifndef GCOP_BULLETRCCAR_H 00002 #define GCOP_BULLETRCCAR_H 00003 00004 #include "system.h" 00005 #include "rccar.h" 00006 #include <BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h> 00007 #include <BulletDynamics/Dynamics/btRigidBody.h> 00008 #include <btBulletDynamicsCommon.h> 00009 #include "bulletworld.h" 00010 00011 namespace gcop { 00012 00013 using namespace std; 00014 using namespace Eigen; 00015 00016 typedef Matrix<double, 4, 2> Matrix42d; 00017 typedef Matrix<double, 4, Dynamic> Matrix4pd; 00018 //typedef Matrix<double, 6, 1> Vector6d; 00019 00020 00021 00035 class Bulletrccar : public Rccar 00036 { 00037 public: 00038 00041 struct CarState{ 00042 btTransform cartransform; 00043 btVector3 carlinearvel; 00044 btVector3 carangularvel; 00045 }; 00046 00051 Bulletrccar(BulletWorld& m_world, vector<double> *zs_ = 0); 00052 00055 ~Bulletrccar() 00056 { 00057 if(m_carChassis) 00058 { 00059 //m_world.m_dynamicsWorld->removeRigidBody(m_carChassis); 00060 00061 delete m_carChassis; 00062 } 00063 00064 delete m_vehicleRayCaster; 00065 00066 m_world.m_dynamicsWorld->removeVehicle(m_vehicle); 00067 delete m_vehicle; 00068 00069 delete m_wheelShape; 00070 00071 delete initialstate; 00072 00073 00074 //m_world.Reset(); 00075 } 00076 00079 double Step(Vector4d &xb, double t, const Vector4d &xa, 00080 const Vector2d &u, double h, const VectorXd *p, 00081 Matrix4d *A = 0, Matrix42d *B = 0, Matrix4pd *C = 0); 00082 00083 double Step(Vector4d &xb, const Vector2d &u, 00084 double h, const VectorXd *p = 0, 00085 Matrix4d *A = 0, Matrix42d *B = 0, Matrix4pd *C = 0); 00086 00087 double Step(Vector4d &xb, const Vector2d &u, 00088 double h, const VectorXd *p, 00089 const Vector4d &w, Matrix4d *A = 0, Matrix42d *B = 0, 00090 Matrix4pd *C = 0, Matrix4d *D = 0); 00091 00092 bool Reset(const Vector4d &x, double t = 0); 00093 00097 void setinitialstate(const CarState &inputstate, Vector4d &x); 00098 void setinitialstate(Vector4d &x); 00099 00102 bool NoiseMatrix(Matrix4d &Q, double t, const Vector4d &x, const Vector2d &u, double dt, const VectorXd *p); 00103 00104 int rightIndex; 00105 int upIndex; 00106 int forwardIndex; 00107 00108 double carmass; 00109 btVector3 car_halfdims; 00110 00111 double gEngineForce ; 00112 double gBreakingForce; 00113 00114 double maxEngineForce; 00115 double maxBreakingForce; 00116 00117 double gVehicleSteering; 00118 double steeringClamp; 00119 double velocityClamp; 00120 double wheelRadius; 00121 double wheelWidth; 00122 double wheelFriction; 00123 double suspensionStiffness; 00124 double suspensionDamping; 00125 double suspensionCompression; 00126 double rollInfluence;//< Decides whether the car will topple or not 00127 btScalar suspensionRestLength; 00128 btScalar m_defaultContactProcessingThreshold; 00129 00130 btVector3 wheelDirectionCS0; 00131 btVector3 wheelAxleCS; 00132 00133 //Parameters for the car: 00134 double gain_cmdvelocity; 00135 double kp_torque; 00136 double kp_steer; 00137 double initialz; 00138 00139 btTransform offsettrans; 00140 btTransform offsettransinv; 00141 00142 //Additional Hidden state for publishing/rendering trajectories: 00143 vector<double> *zs; 00144 int count_zs; 00145 00146 //Hacky way of ensuring the vehicle_velocity is reset after every reset 00147 bool reset_drivevel; 00148 00149 //Bullet classes for holding car 00150 btRigidBody* m_carChassis; 00151 btCollisionShape* chassisShape; 00152 btRaycastVehicle* m_vehicle; 00153 btCollisionShape* m_wheelShape; 00154 btRaycastVehicle::btVehicleTuning m_tuning; 00155 btVehicleRaycaster* m_vehicleRayCaster; 00156 BulletWorld &m_world;//< Parent world to which the car belongs 00157 CarState *initialstate; 00158 }; 00159 } 00160 00161 00162 #endif