19 #include <dynamic-graph/all-commands.h>
20 #include <dynamic-graph/factory.h>
24 #include <pinocchio/multibody/liegroup/special-euclidean.hpp>
25 #include <sot/core/debug.hh>
26 #include <sot/core/stop-watch.hh>
31 namespace talos_balance {
33 namespace dg = ::dynamicgraph;
35 using namespace dg::command;
38 #define PROFILE_SIMPLE_STATE_INTEGRATOR_COMPUTATION \
39 "SimpleStateIntegrator computation "
41 #define INPUT_SIGNALS m_controlSIN
43 #define OUTPUT_SIGNALS m_stateSOUT << m_velocitySOUT
51 "SimpleStateIntegrator");
65 std::string docstring;
69 " Set integration timestep value\n"
71 addCommand(
"init",
new command::Setter<SimpleStateIntegrator, double>(
76 " Set state vector value\n"
78 addCommand(
"setState",
79 new command::Setter<SimpleStateIntegrator, Vector>(
84 " Set velocity vector value\n"
86 addCommand(
"setVelocity",
87 new command::Setter<SimpleStateIntegrator, Vector>(
106 using Eigen::AngleAxisd;
107 using Eigen::Matrix3d;
108 using Eigen::QuaternionMapd;
109 using Eigen::Vector3d;
111 typedef pinocchio::SpecialEuclideanOperationTpl<3, double> SE3;
112 Eigen::Matrix<double, 7, 1> qin, qout;
113 qin.head<3>() = state.head<3>();
115 QuaternionMapd quat(qin.tail<4>().data());
116 quat = AngleAxisd(state(5), Vector3d::UnitZ()) *
117 AngleAxisd(state(4), Vector3d::UnitY()) *
118 AngleAxisd(state(3), Vector3d::UnitX());
120 SE3().integrate(qin, control.head<6>() *
dt, qout);
122 Matrix3d rotationMatrix =
123 QuaternionMapd(qout.tail<4>().data()).toRotationMatrix();
125 Vector3d rollPitchYaw;
128 state.head<3>() = qout.head<3>();
129 state.segment<3>(3) << rollPitchYaw;
133 const Eigen::Matrix3d& rotationMatrix, Eigen::Vector3d& rollPitchYaw) {
134 double m = sqrt(rotationMatrix(2, 1) * rotationMatrix(2, 1) +
135 rotationMatrix(2, 2) * rotationMatrix(2, 2));
136 double p = atan2(-rotationMatrix(2, 0), m);
138 if (fabs(fabs(p) - M_PI / 2.) < 0.001) {
140 y = -atan2(rotationMatrix(0, 1), rotationMatrix(1, 1));
142 y = atan2(rotationMatrix(1, 0), rotationMatrix(0, 0));
143 r = atan2(rotationMatrix(2, 1), rotationMatrix(2, 2));
145 rollPitchYaw << r, p,
y;
149 m_velocitySOUT.setConstant(velocity_);
150 m_velocitySOUT.setTime(iter + 1);
154 const size_t sz = control.size();
155 if ((
size_t)(s.size()) != sz) s.resize(sz);
156 if ((
size_t)(state_.size()) != sz)
157 throw std::runtime_error(
"Mismatching state and control size");
158 if ((
size_t)(velocity_.size()) != sz)
159 throw std::runtime_error(
"Mismatching velocity and control size");
163 integrateRollPitchYaw(state_, control, timestep_);
164 state_.tail(sz - 6) += control.tail(sz - 6) * timestep_;
183 os <<
"SimpleStateIntegrator " << getName();
185 getProfiler().report_all(3, os);
186 }
catch (ExceptionSignal e) {