6 #include <dynamic-graph/factory.h>
8 #include <sot/core/debug.hh>
9 #include <sot/core/stop-watch.hh>
13 #include "pinocchio/algorithm/frames.hpp"
20 using namespace dynamicgraph::command;
22 using namespace pinocchio;
24 typedef dynamicgraph::sot::Vector6d
Vector6;
26 #define PROFILE_FREE_FLYER_COMPUTATION "Free-flyer position computation"
27 #define PROFILE_FREE_FLYER_VELOCITY_COMPUTATION \
28 "Free-flyer velocity computation"
30 #define INPUT_SIGNALS m_base6d_encodersSIN << m_joint_velocitiesSIN
31 #define OUTPUT_SIGNALS \
32 m_freeflyer_aaSOUT << m_base6dFromFoot_encodersSOUT << m_vSOUT
46 CONSTRUCT_SIGNAL_IN(base6d_encoders,
dynamicgraph::Vector),
47 CONSTRUCT_SIGNAL_IN(joint_velocities,
dynamicgraph::Vector),
48 CONSTRUCT_SIGNAL_INNER(kinematics_computations,
dynamicgraph::Vector,
51 m_base6dFromFoot_encodersSOUT),
52 CONSTRUCT_SIGNAL_OUT(base6dFromFoot_encoders,
dynamicgraph::Vector,
53 m_kinematics_computationsSINNER),
55 m_kinematics_computationsSINNER),
56 m_initSucceeded(false),
59 m_robot_util(RefVoidRobotUtil()) {
65 docCommandVoid1(
"Initialize the entity.",
66 "Robot reference (string)")));
71 docCommandVoid0(
"Display the robot util data set linked "
72 "with this free flyer locator.")));
82 std::string localName(robotRef);
83 if (isNameInRobotUtil(localName)) {
85 std::cerr <<
"m_robot_util:" <<
m_robot_util << std::endl;
88 "You should have an entity controller manager initialized before",
93 m_model =
new pinocchio::Model();
94 m_model->name.assign(
"EmptyRobot");
96 pinocchio::urdf::buildModel(
m_robot_util->m_urdf_filename,
97 pinocchio::JointModelFreeFlyer(), *
m_model);
112 }
catch (
const std::exception& e) {
113 std::cout << e.what();
115 "Init failed: Could load URDF :" +
m_robot_util->m_urdf_filename,
127 if (!m_initSucceeded) {
128 SEND_WARNING_STREAM_MSG(
129 "Cannot compute signal kinematics_computations before initialization!");
133 const Eigen::VectorXd& q = m_base6d_encodersSIN(iter);
134 const Eigen::VectorXd& dq = m_joint_velocitiesSIN(iter);
135 assert(q.size() ==
static_cast<Eigen::VectorXd::Index
>(
136 m_robot_util->m_nbJoints + 6) &&
137 "Unexpected size of signal base6d_encoder");
139 static_cast<Eigen::VectorXd::Index
>(m_robot_util->m_nbJoints) &&
140 "Unexpected size of signal joint_velocities");
143 m_robot_util->joints_sot_to_urdf(q.tail(m_robot_util->m_nbJoints),
144 m_q_pin.tail(m_robot_util->m_nbJoints));
145 m_robot_util->joints_sot_to_urdf(dq, m_v_pin.tail(m_robot_util->m_nbJoints));
148 pinocchio::forwardKinematics(*m_model, *m_data, m_q_pin, m_v_pin);
149 pinocchio::framesForwardKinematics(*m_model, *m_data);
155 if (!m_initSucceeded) {
156 SEND_WARNING_STREAM_MSG(
157 "Cannot compute signal base6dFromFoot_encoders before initialization!");
161 static_cast<Eigen::VectorXd::Index
>(m_robot_util->m_nbJoints + 6))
162 s.resize(m_robot_util->m_nbJoints + 6);
164 m_kinematics_computationsSINNER(iter);
168 const Eigen::VectorXd& q = m_base6d_encodersSIN(iter);
169 assert(q.size() ==
static_cast<Eigen::VectorXd::Index
>(
170 m_robot_util->m_nbJoints + 6) &&
171 "Unexpected size of signal base6d_encoder");
174 const pinocchio::SE3 iMo1(m_data->oMf[m_left_foot_id].inverse());
175 const pinocchio::SE3 iMo2(m_data->oMf[m_right_foot_id].inverse());
178 pinocchio::log3(iMo2.rotation())));
179 m_Mff = pinocchio::SE3(pinocchio::exp3(w),
180 0.5 * (iMo1.translation() + iMo2.translation()));
183 Eigen::Map<const Eigen::Vector3d> righ_foot_sole_xyz(
184 &m_robot_util->m_foot_util.m_Right_Foot_Sole_XYZ[0]);
186 m_q_sot.tail(m_robot_util->m_nbJoints) = q.tail(m_robot_util->m_nbJoints);
187 base_se3_to_sot(m_Mff.translation() - righ_foot_sole_xyz, m_Mff.rotation(),
198 m_base6dFromFoot_encodersSOUT(iter);
199 if (!m_initSucceeded) {
200 SEND_WARNING_STREAM_MSG(
201 "Cannot compute signal freeflyer_aa before initialization!");
206 if (s.size() != 6) s.resize(6);
208 const Eigen::AngleAxisd aa(m_Mff.rotation());
209 dynamicgraph::sot::Vector6d freeflyer;
210 freeflyer << m_Mff.translation(), aa.axis() * aa.angle();
213 Eigen::Map<const Eigen::Vector3d> righ_foot_sole_xyz(
214 &m_robot_util->m_foot_util.m_Right_Foot_Sole_XYZ[0]);
215 freeflyer.head<3>() -= righ_foot_sole_xyz;
222 if (!m_initSucceeded) {
223 SEND_WARNING_STREAM_MSG(
"Cannot compute signal v before initialization!");
227 static_cast<Eigen::VectorXd::Index
>(m_robot_util->m_nbJoints + 6))
228 s.resize(m_robot_util->m_nbJoints + 6);
230 m_kinematics_computationsSINNER(iter);
234 const Eigen::VectorXd& dq = m_joint_velocitiesSIN(iter);
236 static_cast<Eigen::VectorXd::Index
>(m_robot_util->m_nbJoints) &&
237 "Unexpected size of signal joint_velocities");
240 const Frame& f_lf = m_model->frames[m_left_foot_id];
241 const Motion v_lf_local = f_lf.placement.actInv(m_data->v[f_lf.parent]);
242 const Vector6 v_lf = m_data->oMf[m_left_foot_id].act(v_lf_local).toVector();
244 const Frame& f_rf = m_model->frames[m_right_foot_id];
245 const Motion v_rf_local = f_rf.placement.actInv(m_data->v[f_rf.parent]);
247 m_data->oMf[m_right_foot_id].act(v_rf_local).toVector();
249 m_v_sot.head<6>() = -0.5 * (v_lf + v_rf);
250 m_v_sot.tail(m_robot_util->m_nbJoints) = dq;
267 os <<
"FreeFlyerLocator " << getName();
269 getProfiler().report_all(3, os);
270 }
catch (ExceptionSignal e) {