Cheetah Software  1.0
ContactSpringDamper< T > Class Template Reference

#include <ContactSpringDamper.h>

+ Inheritance diagram for ContactSpringDamper< T >:
+ Collaboration diagram for ContactSpringDamper< T >:

Public Member Functions

 ContactSpringDamper (FloatingBaseModel< T > *model)
 
virtual ~ContactSpringDamper ()
 
virtual void UpdateExternalForces (T K, T D, T dt)
 
virtual void UpdateQdot (FBModelState< T > &state)
 
- Public Member Functions inherited from ContactConstraint< T >
 ContactConstraint (FloatingBaseModel< T > *model)
 
virtual ~ContactConstraint ()
 
void AddCollision (Collision< T > *collision)
 
const vectorAligned< Vec3< T > > & getContactPosList ()
 
const Vec3< T > & getGCForce (size_t idx)
 

Protected Member Functions

void _groundContactWithOffset (T K, T D)
 
- Protected Member Functions inherited from ContactConstraint< T >
void _groundContactWithOffset (T K, T D)
 
size_t _CheckContact ()
 

Protected Attributes

size_t _nGC
 
vectorAligned< Vec2< T > > deflectionRate
 
vectorAligned< Vec2< T > > _tangentialDeflections
 
- Protected Attributes inherited from ContactConstraint< T >
vectorAligned< Vec2< T > > deflectionRate
 
vectorAligned< Vec2< T > > _tangentialDeflections
 
size_t _nContact
 
size_t _nCollision
 
FloatingBaseModel< T > * _model
 
std::vector< Collision< T > * > _collision_list
 
std::vector< size_t > _idx_list
 
std::vector< T > _cp_resti_list
 
std::vector< T > _cp_mu_list
 
std::vector< T > _cp_penetration_list
 
vectorAligned< Vec3< T > > _cp_force_list
 
vectorAligned< Vec3< T > > _cp_local_force_list
 
vectorAligned< Vec3< T > > _cp_pos_list
 
vectorAligned< Mat3< T > > _cp_frame_list
 

Detailed Description

template<typename T>
class ContactSpringDamper< T >

Definition at line 12 of file ContactSpringDamper.h.

Constructor & Destructor Documentation

template<typename T >
ContactSpringDamper< T >::ContactSpringDamper ( FloatingBaseModel< T > *  model)
inline

Definition at line 14 of file ContactSpringDamper.h.

References ContactSpringDamper< T >::_nGC, ContactSpringDamper< T >::_tangentialDeflections, and ContactSpringDamper< T >::deflectionRate.

15  : ContactConstraint<T>(model) {
16  _nGC = CC::_model->_nGroundContact;
17  for (size_t i(0); i < _nGC; ++i) {
19  }
20  deflectionRate.resize(_nGC);
21  }
typename Eigen::Matrix< T, 2, 1 > Vec2
Definition: cppTypes.h:22
vectorAligned< Vec2< T > > deflectionRate
vectorAligned< Vec2< T > > _tangentialDeflections
template<typename T >
virtual ContactSpringDamper< T >::~ContactSpringDamper ( )
inlinevirtual

Definition at line 23 of file ContactSpringDamper.h.

References ContactSpringDamper< T >::UpdateExternalForces().

23 {}

+ Here is the call graph for this function:

Member Function Documentation

template<typename T >
void ContactSpringDamper< T >::_groundContactWithOffset ( K,
D 
)
protected
Parameters
KGround stiffness
DGround damping

subfunction computing contact forces

Definition at line 42 of file ContactSpringDamper.cpp.

42  {
43  for (size_t i = 0; i < CC::_nContact; i++) {
44  Vec3<T> v =
45  CC::_cp_frame_list[i].transpose() *
46  CC::_model->_vGC[CC::_idx_list[i]]; // velocity in plane coordinates
47  T z = CC::_cp_penetration_list[i]; // the penetration into the ground
48  T zd = v[2]; // the penetration velocity
49  T zr = std::sqrt(std::max(T(0), -z)); // sqrt penetration into the ground,
50  // or zero if we aren't penetrating
51  T normalForce =
52  zr *
53  (-K * z - D * zd); // normal force is spring-damper * sqrt(penetration)
54 
55  // set output force to zero for now.
56  CC::_cp_local_force_list[i][0] = 0;
57  CC::_cp_local_force_list[i][1] = 0;
58  CC::_cp_local_force_list[i][2] = 0;
59 
60  if (normalForce > 0) {
61  CC::_cp_local_force_list[i][2] =
62  normalForce; // set the normal force. This is in the plane's
63  // coordinates for now
64 
65  // first, assume sticking
66  // this means the tangential deformation happens at the speed of the foot.
67  deflectionRate[CC::_idx_list[i]] = v.template topLeftCorner<2, 1>();
68  Vec2<T> tangentialSpringForce =
69  K * zr *
70  _tangentialDeflections[CC::_idx_list[i]]; // tangential force due to
71  // "spring"
72  Vec2<T> tangentialForce =
73  -tangentialSpringForce -
74  D * zr * deflectionRate[CC::_idx_list[i]]; // add damping to get
75  // total tangential
76 
77  // check for slipping:
78  T slipForce = CC::_cp_mu_list[i] *
79  normalForce; // maximum force magnitude without slipping
80  T tangentialForceMagnitude =
81  tangentialForce
82  .norm(); // actual force magnitude if we assume sticking
83  T r = tangentialForceMagnitude / slipForce; // ratio of force/max_force
84 
85  if (r > 1) {
86  // we are slipping.
87  tangentialForce =
88  tangentialForce / r; // adjust tangential force to avoid slipping
89  deflectionRate[CC::_idx_list[i]] =
90  -(tangentialForce + tangentialSpringForce) / (D * zr);
91  }
92  // set forces
93  CC::_cp_local_force_list[i][0] = tangentialForce[0];
94  CC::_cp_local_force_list[i][1] = tangentialForce[1];
95  }
96  // move back into robot frame
97  CC::_cp_force_list[CC::_idx_list[i]] =
98  CC::_cp_frame_list[i] * CC::_cp_local_force_list[i];
99  }
100 }
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
typename Eigen::Matrix< T, 2, 1 > Vec2
Definition: cppTypes.h:22
vectorAligned< Vec2< T > > deflectionRate
vectorAligned< Vec2< T > > _tangentialDeflections
template<typename T >
void ContactSpringDamper< T >::UpdateExternalForces ( K,
D,
dt 
)
virtual

Run the ground contact model for a single collision plane on a list of ground contact points The ground is allowed to deform in the tangential direction, but not the normal direction. The ground also "remembers" its deformation between separate contact events. (however it does spring back pretty quickly)

Parameters
KGround stiffness
DGround damping
dtTimestep (used for deflection)

compute contact forces coinciding to the contact and update external force in a dynamics model.

Implements ContactConstraint< T >.

Definition at line 13 of file ContactSpringDamper.cpp.

References spatial::forceToSpatialForce().

13  {
14  CC::_nContact = CC::_CheckContact();
15  for (size_t i(0); i < _nGC; ++i) {
16  // first assume there's no contact, so the ground "springs back"
17  deflectionRate[i] = (-K / D) * _tangentialDeflections[i];
18  }
19  if (CC::_nContact > 0) {
21  for (size_t i(0); i < CC::_nContact; ++i) {
22  CC::_model->_externalForces.at(CC::_model->_gcParent[CC::_idx_list[i]]) +=
23  forceToSpatialForce(CC::_cp_force_list[CC::_idx_list[i]],
24  CC::_cp_pos_list[i]);
25  }
26  static int count(0);
27  ++count;
28  if (count > 5) {
29  // exit(0);
30  }
31  }
32 
33  for (size_t i(0); i < _nGC; ++i) {
35  }
36 }
auto forceToSpatialForce(const Eigen::MatrixBase< T > &f, const Eigen::MatrixBase< T2 > &p)
Definition: spatial.h:348
vectorAligned< Vec2< T > > deflectionRate
vectorAligned< Vec2< T > > _tangentialDeflections
void _groundContactWithOffset(T K, T D)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
virtual void ContactSpringDamper< T >::UpdateQdot ( FBModelState< T > &  state)
inlinevirtual

Used for impulse based contact constraint method

Parameters
state: full state of a floating system full state
Returns
state : update velocity

Implements ContactConstraint< T >.

Definition at line 36 of file ContactSpringDamper.h.

36  {
37  (void)state; /* Do nothing */
38  }

Member Data Documentation

template<typename T >
size_t ContactSpringDamper< T >::_nGC
protected

Definition at line 41 of file ContactSpringDamper.h.

template<typename T >
vectorAligned<Vec2<T> > ContactSpringDamper< T >::_tangentialDeflections
protected

Definition at line 50 of file ContactSpringDamper.h.

template<typename T >
vectorAligned<Vec2<T> > ContactSpringDamper< T >::deflectionRate
protected

Definition at line 49 of file ContactSpringDamper.h.


The documentation for this class was generated from the following files: