Cheetah Software  1.0
DynamicsSimulator.h
Go to the documentation of this file.
1 
8 #ifndef PROJECT_DYNAMICSSIMULATOR_H
9 #define PROJECT_DYNAMICSSIMULATOR_H
10 
11 #include "Collision/CollisionBox.h"
15 #include "FloatingBaseModel.h"
16 #include "Math/orientation_tools.h"
17 #include "spatial.h"
18 
19 using namespace ori;
20 using namespace spatial;
21 #include <eigen3/Eigen/Dense>
22 
23 
24 template <typename T>
26  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
28  Vec3<T> rpy; // body coordinates
29  double kp_lin;
30  double kd_lin;
31  double kp_ang;
32  double kd_ang;
34 };
35 
39 template <typename T>
41  public:
42  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
44  FloatingBaseModel<T>& model,
45  bool useSpringDamper = false);
46  void step(T dt, const DVec<T>& tau, T kp,
47  T kd);
48 
50  void runABA(const DVec<T>& tau) { _model.runABA(tau, _dstate); }
51 
53  void forwardKinematics() { _model.forwardKinematics(); }
54 
56  void integrate(T dt);
57 
61  void setState(const FBModelState<T>& state) {
62  _state = state;
63  _model.setState(state); // force recalculate dynamics
64  }
65 
66  void setHoming(const RobotHomingInfo<T>& homing) {
67  _homing = homing;
68  }
69 
74  const FBModelState<T>& getState() const { return _state; }
75 
80  const FBModelStateDerivative<T>& getDState() const { return _dstate; }
81 
88  _model._externalForces = forces;
89  }
90 
91  // ! Add a collision plane.
92  void addCollisionPlane(T mu, T rest, T height) {
93  _contact_constr->AddCollision(new CollisionPlane<T>(mu, rest, height));
94  }
95 
96  // ! Add a collision box
97  void addCollisionBox(T mu, T rest, T depth, T width, T height,
98  const Vec3<T>& pos, const Mat3<T>& ori) {
99  _contact_constr->AddCollision(
100  new CollisionBox<T>(mu, rest, depth, width, height, pos, ori));
101  }
102 
103  // ! Add a collision Mesh
104  void addCollisionMesh(T mu, T rest, T grid_size,
105  const Vec3<T>& left_corner_loc,
106  const DMat<T>& height_map) {
107  _contact_constr->AddCollision(
108  new CollisionMesh<T>(mu, rest, grid_size, left_corner_loc, height_map));
109  }
110 
111  size_t getNumBodies() { return _model._nDof; }
112 
113  const size_t& getTotalNumGC() { return _model._nGroundContact; }
114  const Vec3<T>& getContactForce(size_t idx) {
115  return _contact_constr->getGCForce(idx);
116  }
117 
118  const FloatingBaseModel<T>& getModel() { return _model; }
119 
120  private:
121  void updateCollisions(T dt, T kp, T kd);
125  vector<CollisionPlane<T>> _collisionPlanes;
129 
131 };
132 
133 #endif // PROJECT_DYNAMICSSIMULATOR_H
vector< CollisionPlane< T > > _collisionPlanes
void forwardKinematics()
Do forward kinematics for feet.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Vec3< T > position
typename Eigen::Matrix< T, 3, 3 > Mat3
Definition: cppTypes.h:54
typename Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > DMat
Definition: cppTypes.h:106
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
FBModelStateDerivative< T > _dstate
const Vec3< T > & getContactForce(size_t idx)
void setState(const FBModelState< T > &state)
Collision logic for a box.
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
void addCollisionMesh(T mu, T rest, T grid_size, const Vec3< T > &left_corner_loc, const DMat< T > &height_map)
const size_t & getTotalNumGC()
void setAllExternalForces(const vectorAligned< SVec< T >> &forces)
void setHoming(const RobotHomingInfo< T > &homing)
RobotHomingInfo< T > _homing
Collision logic for an infinite plane.
ContactConstraint< T > * _contact_constr
void runABA(const DVec< T > &tau)
Simulate forward one step.
const FBModelState< T > & getState() const
void addCollisionPlane(T mu, T rest, T height)
typename std::vector< T, Eigen::aligned_allocator< T >> vectorAligned
Definition: cppTypes.h:118
Virtual class of Contact Constraint logic.
const FBModelStateDerivative< T > & getDState() const
Collision logic for a mesh.
Utility functions for 3D rotations.
typename Eigen::Matrix< T, Eigen::Dynamic, 1 > DVec
Definition: cppTypes.h:102
FloatingBaseModel< T > & _model
FBModelState< T > _state
Update ground collision list.
const FloatingBaseModel< T > & getModel()
Implementation of Rigid Body Floating Base model data structure.
void addCollisionBox(T mu, T rest, T depth, T width, T height, const Vec3< T > &pos, const Mat3< T > &ori)
Utility functions for manipulating spatial quantities.