zmp-from-forces.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012,
3  * Florent Lamiraux
4  *
5  * CNRS
6  *
7  */
8 
9 #include <dynamic-graph/entity.h>
10 #include <dynamic-graph/factory.h>
14 
16 #include <sstream>
17 #include <vector>
18 
19 namespace sot {
20 namespace dynamic {
24 using dynamicgraph::sigtime_t;
27 
28 class ZmpFromForces : public Entity {
30 
31  public:
32  static const unsigned int footNumber = 2;
33  ZmpFromForces(const std::string& name)
34  : Entity(name), zmpSOUT_(CLASS_NAME + "::output(Vector)::zmp") {
35  zmpSOUT_.setFunction(boost::bind(&ZmpFromForces::computeZmp, this, _1, _2));
37  for (unsigned int i = 0; i < footNumber; i++) {
38  std::ostringstream forceName, positionName;
39  forceName << CLASS_NAME << "::input(vector6)::force_" << i;
40  positionName << CLASS_NAME << "::input(MatrixHomo)::sensorPosition_" << i;
41  forcesSIN_[i] = new SignalPtr<Vector, sigtime_t>(0, forceName.str());
43  new SignalPtr<MatrixHomogeneous, sigtime_t>(0, positionName.str());
48  }
49  }
50  virtual std::string getDocString() const {
51  std::string docstring =
52  "Compute ZMP from force sensor measures and positions\n"
53  "\n"
54  " Takes 4 signals as input:\n"
55  " - force_0: wrench measured by force sensor 0 as a 6 dimensional "
56  "vector\n"
57  " - force_0: wrench measured by force sensor 1 as a 6 dimensional "
58  "vector\n"
59  " - sensorPosition_0: position of force sensor 0\n"
60  " - sensorPosition_1: position of force sensor 1\n"
61  " \n"
62  " compute the Zero Momentum Point of the contact forces as measured "
63  "by the \n"
64  " input signals under the asumptions that the contact points between "
65  "the\n"
66  " robot and the environment are located in the same horizontal "
67  "plane.\n";
68  return docstring;
69  }
70 
71  private:
72  Vector& computeZmp(Vector& zmp, int time) {
73  double fnormal = 0;
74  double sumZmpx = 0;
75  double sumZmpy = 0;
76  double sumZmpz = 0;
77  zmp.resize(3);
78 
79  for (unsigned int i = 0; i < footNumber; ++i) {
80  const Vector& f = forcesSIN_[i]->access(time);
81  // Check that force is of dimension 6
82  if (f.size() != 6) {
83  zmp.fill(0.);
84  return zmp;
85  }
87  double fx = M(0, 0) * f(0) + M(0, 1) * f(1) + M(0, 2) * f(2);
88  double fy = M(1, 0) * f(0) + M(1, 1) * f(1) + M(1, 2) * f(2);
89  double fz = M(2, 0) * f(0) + M(2, 1) * f(1) + M(2, 2) * f(2);
90 
91  if (fz > 0) {
92  double Mx = M(0, 0) * f(3) + M(0, 1) * f(4) + M(0, 2) * f(5) +
93  M(1, 3) * fz - M(2, 3) * fy;
94  double My = M(1, 0) * f(3) + M(1, 1) * f(4) + M(1, 2) * f(5) +
95  M(2, 3) * fx - M(0, 3) * fz;
96  fnormal += fz;
97  sumZmpx -= My;
98  sumZmpy += Mx;
99  sumZmpz += fz * M(2, 3);
100  }
101  }
102  if (fnormal != 0) {
103  zmp(0) = sumZmpx / fnormal;
104  zmp(1) = sumZmpy / fnormal;
105  zmp(2) = sumZmpz / fnormal;
106  } else {
107  zmp.fill(0.);
108  }
109  return zmp;
110  }
111  // Force as measured by force sensor on the foot
115 }; // class ZmpFromForces
116 } // namespace dynamic
117 } // namespace sot
signal-ptr.h
signal-time-dependent.h
dynamicgraph::sot::MatrixHomogeneous
Eigen::Transform< double, 3, Eigen::Affine > SOT_CORE_EXPORT MatrixHomogeneous
dynamicgraph::SignalPtr
sot::dynamic::ZmpFromForces::footNumber
static const unsigned int footNumber
Definition: zmp-from-forces.h:32
matrix-geometry.hh
i
int i
dynamicgraph::Entity
dynamicgraph::Signal::access
virtual const T & access(const Time &t)
dynamicgraph::Entity::name
std::string name
f
void f(void)
sot::dynamic::ZmpFromForces::DYNAMIC_GRAPH_ENTITY_DECL
DYNAMIC_GRAPH_ENTITY_DECL()
sot::dynamic::ZmpFromForces::forcesSIN_
SignalPtr< Vector, sigtime_t > * forcesSIN_[footNumber]
Definition: zmp-from-forces.h:112
sot::dynamic::ZmpFromForces
Definition: zmp-from-forces.h:28
dynamicgraph::SignalTimeDependent::addDependency
virtual void addDependency(const SignalBase< Time > &signal)
sot::dynamic::ZmpFromForces::zmpSOUT_
SignalTimeDependent< Vector, sigtime_t > zmpSOUT_
Definition: zmp-from-forces.h:114
M
M
dynamicgraph::Vector
Eigen::VectorXd Vector
linear-algebra.h
dynamicgraph::SignalTimeDependent
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< int > &signals)
sot::dynamic::ZmpFromForces::sensorPositionsSIN_
SignalPtr< MatrixHomogeneous, sigtime_t > * sensorPositionsSIN_[footNumber]
Definition: zmp-from-forces.h:113
sot::dynamic::ZmpFromForces::ZmpFromForces
ZmpFromForces(const std::string &name)
Definition: zmp-from-forces.h:33
MatrixHomogeneous
Eigen::Transform< double, 3, Eigen::Affine > MatrixHomogeneous
sot::dynamic::ZmpFromForces::computeZmp
Vector & computeZmp(Vector &zmp, int time)
Definition: zmp-from-forces.h:72
sot
Definition: zmp-from-forces.cpp:11
sot::dynamic::ZmpFromForces::getDocString
virtual std::string getDocString() const
Definition: zmp-from-forces.h:50


sot-dynamic-pinocchio
Author(s): Olivier Stasse
autogenerated on Fri Jul 28 2023 02:10:01