integrator-force-rk4.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 #include <dynamic-graph/factory.h>
12 
13 #include <sot/core/debug.hh>
14 
15 using namespace dynamicgraph::sot;
16 using namespace dynamicgraph;
18 
21  sotDEBUGIN(5);
22 
23  velocityDerivativeSOUT.setFunction(
24  boost::bind(&IntegratorForceRK4::computeDerivativeRK4, this, _1, _2));
25 
26  sotDEBUGOUT(5);
27 }
28 
30  sotDEBUGIN(5);
31 
32  sotDEBUGOUT(5);
33  return;
34 }
35 
36 /* --- SIGNALS -------------------------------------------------------------- */
37 /* --- SIGNALS -------------------------------------------------------------- */
38 /* --- SIGNALS -------------------------------------------------------------- */
39 
40 /* The derivative of the signal is such that: M v_dot + B v = f. We deduce:
41  * v_dot = M^-1 (f - Bv)
42  * Using RK4 method (doc: wikipedia ;) ): dv= dt/6 ( k1 + 2.k2 + 2.k3 + k4)
43  */
44 static const double rk_fact[4] = {1., 2., 2., 1.};
45 
47  dynamicgraph::Vector& res, const sigtime_t& time) {
48  sotDEBUGIN(15);
49 
50  const dynamicgraph::Vector& force = forceSIN(time);
51  const dynamicgraph::Matrix& massInverse = massInverseSIN(time);
52  const dynamicgraph::Matrix& friction = frictionSIN(time);
53  long int nf = force.size(), nv = friction.cols();
54  res.resize(nv);
55  res.fill(0);
56 
57  if (!velocityPrecSIN) {
59  zero.fill(0);
61  }
62  const dynamicgraph::Vector& vel = velocityPrecSIN(time);
63  double& dt = this->IntegratorForce::timeStep; // this is &
64 
65  sotDEBUG(15) << "force = " << force;
66  sotDEBUG(15) << "vel = " << vel;
67  sotDEBUG(25) << "Mi = " << massInverse;
68  sotDEBUG(25) << "B = " << friction;
69  sotDEBUG(25) << "dt = " << dt << std::endl;
70 
71  std::vector<dynamicgraph::Vector> v(4);
72  dynamicgraph::Vector ki(nv), fi(nf);
73  double sumFact = 0;
74  v[0] = vel;
75 
76  for (unsigned int i = 0; i < 4; ++i) {
77  sotDEBUG(35) << "v" << i << " = " << v[i];
78  fi = friction * v[i];
79  fi *= -1;
80  fi += force;
81  sotDEBUG(35) << "f" << i << " = " << fi;
82  ki = massInverse * fi;
83  sotDEBUG(35) << "k" << i << " = " << ki;
84  if (i + 1 < 4) {
85  v[i + 1] = ki;
86  v[i + 1] *= (dt / rk_fact[i + 1]);
87  v[i + 1] += vel;
88  }
89  ki *= rk_fact[i];
90  res += ki;
91  sotDEBUG(35) << "sum_k" << i << " = " << res;
92  sumFact += rk_fact[i];
93  }
94 
95  sotDEBUG(35) << "sum_ki = " << res;
96  res *= (1 / sumFact);
97 
98  sotDEBUGOUT(15);
99  return res;
100 }
dynamicgraph
nv
int nv(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
i
int i
debug.hh
dynamicgraph::Matrix
Eigen::MatrixXd Matrix
dynamicgraph::sot::IntegratorForceRK4::~IntegratorForceRK4
virtual ~IntegratorForceRK4(void)
Definition: integrator-force-rk4.cpp:29
dynamicgraph::sot::IntegratorForce::frictionSIN
dg::SignalPtr< dynamicgraph::Matrix, sigtime_t > frictionSIN
Definition: integrator-force.h:68
dynamic_pinocchio.kine_romeo.dt
int dt
Definition: kine_romeo.py:37
dynamicgraph::sot::IntegratorForce::timeStep
double timeStep
Definition: integrator-force.h:58
res
res
sotDEBUGOUT
#define sotDEBUGOUT(level)
sotDEBUGIN
#define sotDEBUGIN(level)
integrator-force-rk4.h
dynamicgraph::Vector
Eigen::VectorXd Vector
dynamicgraph::sot::IntegratorForce::velocityDerivativeSOUT
dg::SignalTimeDependent< dynamicgraph::Vector, sigtime_t > velocityDerivativeSOUT
Definition: integrator-force.h:74
rk_fact
static const double rk_fact[4]
Definition: integrator-force-rk4.cpp:44
dynamicgraph::sot
v
v
dynamicgraph::sot::IntegratorForceRK4::computeDerivativeRK4
dynamicgraph::Vector & computeDerivativeRK4(dynamicgraph::Vector &res, const sigtime_t &time)
Definition: integrator-force-rk4.cpp:46
dynamicgraph::sot::IntegratorForce::velocityPrecSIN
dg::SignalPtr< dynamicgraph::Vector, sigtime_t > velocityPrecSIN
Definition: integrator-force.h:72
zero
def zero(n)
dynamicgraph::sot::IntegratorForce
Definition: integrator-force.h:52
dynamicgraph::sot::IntegratorForce::forceSIN
dg::SignalPtr< dynamicgraph::Vector, sigtime_t > forceSIN
Definition: integrator-force.h:66
dynamicgraph::sot::IntegratorForce::massInverseSIN
dg::SignalPtr< dynamicgraph::Matrix, sigtime_t > massInverseSIN
Definition: integrator-force.h:67
dynamicgraph::sot::IntegratorForceRK4::IntegratorForceRK4
IntegratorForceRK4(const std::string &name)
Definition: integrator-force-rk4.cpp:19
compile.name
name
Definition: compile.py:22
dynamicgraph::sot::IntegratorForceRK4
Definition: integrator-force-rk4.h:53
dynamicgraph::sot::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(DoubleConstant, "DoubleConstant")
sotDEBUG
#define sotDEBUG(level)


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