ForwardDynamics.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * National Institute of Advanced Industrial Science and Technology (AIST)
8  */
14 #include "ForwardDynamics.h"
15 #include "Body.h"
16 #include "Link.h"
17 #include "Sensor.h"
18 
19 using namespace hrp;
20 
21 
23  : body(body)
24 {
25  g.setZero();
26  timeStep = 0.005;
27 
29  sensorsEnabled = false;
30 }
31 
32 
34 {
35 
36 }
37 
38 
40 {
41  timeStep = ts;
42 }
43 
44 
46 {
47  this->g = g;
48 }
49 
50 
52 {
54 }
55 
56 
58 {
60 }
61 
62 
64 {
65  sensorsEnabled = on;
66 }
67 
68 
71  const Vector3& p0, const Matrix33& R0,
72  const Vector3& w, const Vector3& vo, double dt)
73 {
74  using ::std::numeric_limits;
75 
76  double norm_w = w.norm();
77 
78  if(norm_w < numeric_limits<double>::epsilon() ) {
79  out_p = p0 + vo * dt;
80  out_R = R0;
81  } else {
82  double th = norm_w * dt;
83  Vector3 w_n(w / norm_w);
84  Vector3 vo_n(vo / norm_w);
85  Matrix33 rot = rodrigues(w_n, th);
86 
87  out_p = rot * p0 + (Matrix33::Identity() - rot) * w_n.cross(vo_n) + w_n * w_n.transpose() * vo_n * th;
88  out_R.noalias() = rot * R0;
89  }
90 }
91 
92 
94 {
95  body->clearSensorValues();
96 
97  if(sensorsEnabled){
99  }
100 }
101 
102 
104 {
105  int n;
106 
107  n = body->numSensors(Sensor::RATE_GYRO);
108  for(int i=0; i < n; ++i){
109  RateGyroSensor* sensor = body->sensor<RateGyroSensor>(i);
110  Link* link = sensor->link;
111  sensor->w = sensor->localR.transpose() * link->R.transpose() * link->w;
112  }
113 
114  n = body->numSensors(Sensor::ACCELERATION);
115  for(int i=0; i < n; ++i){
116  updateAccelSensor(body->sensor<AccelSensor>(i));
117  }
118 
119 }
120 
121 
123 {
124  Link* link = sensor->link;
125  vector2* x = sensor->x;
126 
127  Vector3 o_Vgsens(link->R * (link->R.transpose() * link->w).cross(sensor->localPos) + link->v);
128 
129  if(sensor->isFirstUpdate){
130  sensor->isFirstUpdate = false;
131  for(int i=0; i < 3; ++i){
132  x[i](0) = o_Vgsens(i);
133  x[i](1) = 0.0;
134  }
135  } else {
136  // kalman filtering
137  for(int i=0; i < 3; ++i){
138  x[i] = A * x[i] + o_Vgsens(i) * B;
139  }
140  }
141 
142  Vector3 o_Agsens(x[0](1), x[1](1), x[2](1));
143  o_Agsens += g;
144 
145  sensor->dv.noalias() = sensor->localR.transpose() * link->R.transpose() * o_Agsens;
146 }
147 
148 
150 {
151  int n = body->numSensors(Sensor::ACCELERATION);
152  if(n > 0){
153  for(int i=0; i < n; ++i){
154  AccelSensor* sensor = body->sensor<AccelSensor>(i);
155  if(sensor){
156  sensor->isFirstUpdate = true;
157  }
158  }
159 
160  // Kalman filter design
161  static const double n_input = 100.0; // [N]
162  static const double n_output = 0.001; // [m/s]
163 
164  // Analytical solution of Kalman filter (continuous domain)
165  // s.kajita 2003 Jan.22
166 
167  matrix22 Ac;
168  Ac << -sqrt(2*n_input/n_output), 1.0,
169  -n_input/n_output, 0.0;
170 
171  vector2 Bc(sqrt(2*n_input/n_output), n_input/n_output);
172 
173  A = matrix22::Identity();
174  matrix22 An(matrix22::Identity());
175  matrix22 An2;
176  B = timeStep * Bc;
177  vector2 Bn(B);
178  vector2 Bn2;
179 
180  double factorial[14];
181  double r = 1.0;
182  factorial[1] = r;
183  for(int i=2; i <= 13; ++i){
184  r += 1.0;
185  factorial[i] = factorial[i-1] * r;
186  }
187 
188  for(int i=1; i <= 12; i++){
189  An2.noalias() = Ac * An;
190  An = timeStep * An2;
191  A += (1.0 / factorial[i]) * An;
192 
193  Bn2.noalias() = Ac * Bn;
194  Bn = timeStep * Bn2;
195  B += (1.0 / factorial[i+1]) * Bn;
196  }
197  }
198 }
hrp::ForwardDynamics::initializeSensors
virtual void initializeSensors()
Definition: ForwardDynamics.cpp:93
hrp::ForwardDynamics::body
BodyPtr body
Definition: ForwardDynamics.h:71
hrp::Sensor::localR
Matrix33 localR
Definition: hrplib/hrpModel/Sensor.h:60
i
png_uint_32 i
Definition: png.h:2732
hrp::rodrigues
Matrix33 rodrigues(const Vector3 &axis, double q)
Definition: Eigen3d.h:27
hrp::ForwardDynamics::updateAccelSensor
void updateAccelSensor(AccelSensor *sensor)
Definition: ForwardDynamics.cpp:122
hrp::ForwardDynamics::SE3exp
static void SE3exp(Vector3 &out_p, Matrix33 &out_R, const Vector3 &p0, const Matrix33 &R0, const Vector3 &w, const Vector3 &vo, double dt)
update position/orientation using spatial velocity
Definition: ForwardDynamics.cpp:70
Sensor.h
hrp::ForwardDynamics::initializeAccelSensors
void initializeAccelSensors()
Definition: ForwardDynamics.cpp:149
autoplay.n
n
Definition: autoplay.py:12
hrp::ForwardDynamics::ForwardDynamics
EIGEN_MAKE_ALIGNED_OPERATOR_NEW ForwardDynamics(BodyPtr body)
Definition: ForwardDynamics.cpp:22
hrp
Definition: ColdetModel.h:28
hrp::AccelSensor::x
vector2 x[3]
Definition: hrplib/hrpModel/Sensor.h:111
hrp::ForwardDynamics::updateSensorsFinal
virtual void updateSensorsFinal()
Definition: ForwardDynamics.cpp:103
hrp::ForwardDynamics::A
matrix22 A
Definition: ForwardDynamics.h:87
hrp::Sensor::RATE_GYRO
@ RATE_GYRO
Definition: hrplib/hrpModel/Sensor.h:34
hrp::ForwardDynamics::vector2
Eigen::Vector2d vector2
Definition: ForwardDynamics.h:86
hrp::Sensor::link
Link * link
Definition: hrplib/hrpModel/Sensor.h:59
hrp::ForwardDynamics::B
vector2 B
Definition: ForwardDynamics.h:88
hrp::ForwardDynamics::integrationMode
enum hrp::ForwardDynamics::@2 integrationMode
hrp::Vector3
Eigen::Vector3d Vector3
Definition: EigenTypes.h:11
hrp::ForwardDynamics::timeStep
double timeStep
Definition: ForwardDynamics.h:73
hrp::Sensor::localPos
Vector3 localPos
Definition: hrplib/hrpModel/Sensor.h:61
hrp::ForwardDynamics::matrix22
Eigen::Matrix2d matrix22
Definition: ForwardDynamics.h:85
hrp::ForwardDynamics::RUNGEKUTTA_METHOD
@ RUNGEKUTTA_METHOD
Definition: ForwardDynamics.h:76
hrp::RateGyroSensor::w
Vector3 w
Definition: hrplib/hrpModel/Sensor.h:88
hrp::AccelSensor
Definition: hrplib/hrpModel/Sensor.h:95
hrp::ForwardDynamics::~ForwardDynamics
virtual ~ForwardDynamics()
Definition: ForwardDynamics.cpp:33
hrp::ForwardDynamics::sensorsEnabled
bool sensorsEnabled
Definition: ForwardDynamics.h:74
hrp::ForwardDynamics::g
Vector3 g
Definition: ForwardDynamics.h:72
hrp::BodyPtr
boost::shared_ptr< Body > BodyPtr
Definition: Body.h:315
hrp::ForwardDynamics::EULER_METHOD
@ EULER_METHOD
Definition: ForwardDynamics.h:76
hrp::ForwardDynamics::setGravityAcceleration
void setGravityAcceleration(const Vector3 &g)
Definition: ForwardDynamics.cpp:45
hrp::ForwardDynamics::setRungeKuttaMethod
void setRungeKuttaMethod()
Definition: ForwardDynamics.cpp:57
hrp::Sensor::ACCELERATION
@ ACCELERATION
Definition: hrplib/hrpModel/Sensor.h:35
ForwardDynamics.h
Body.h
hrp::Matrix33
Eigen::Matrix3d Matrix33
Definition: EigenTypes.h:12
hrp::ForwardDynamics::setTimeStep
void setTimeStep(double timeStep)
Definition: ForwardDynamics.cpp:39
hrp::ForwardDynamics::enableSensors
void enableSensors(bool on)
Definition: ForwardDynamics.cpp:63
hrp::AccelSensor::isFirstUpdate
bool isFirstUpdate
Definition: hrplib/hrpModel/Sensor.h:112
hrp::ForwardDynamics::setEulerMethod
void setEulerMethod()
Definition: ForwardDynamics.cpp:51
hrp::RateGyroSensor
Definition: hrplib/hrpModel/Sensor.h:82
hrp::AccelSensor::dv
Vector3 dv
Definition: hrplib/hrpModel/Sensor.h:104


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Wed Sep 7 2022 02:51:02