9 #include <dynamic-graph/all-commands.h>
10 #include <dynamic-graph/factory.h>
12 #include <sot/core/debug.hh>
13 #include <sot/core/stop-watch.hh>
17 #define CALIB_ITER_TIME \
18 1000 // Iteration needed for sampling and averaging the FT sensors while
23 namespace talos_balance {
26 using namespace dynamicgraph::command;
27 using namespace dg::sot::talos_balance;
29 #define INPUT_SIGNALS m_rightWristForceInSIN << m_leftWristForceInSIN << m_qSIN
30 #define INNER_SIGNALS m_rightWeightSINNER << m_leftWeightSINNER
31 #define OUTPUT_SIGNALS m_rightWristForceOutSOUT << m_leftWristForceOutSOUT
54 m_robot_util(RefVoidRobotUtil()),
59 m_initSucceeded(false),
60 m_removeWeight(false) {
66 docCommandVoid1(
"Initialize the entity.",
67 "Robot reference (string)")));
71 docCommandVoid2(
"Set the data of the right hand",
72 "Vector of default forces in Newton",
73 "Vector of the weight lever arm")));
77 docCommandVoid2(
"Set the data of the left hand",
78 "Vector of default forces in Newton",
79 "Vector of the weight lever arm")));
80 addCommand(
"calibrateWristSensor",
82 docCommandVoid0(
"Calibrate the wrist sensors")));
84 addCommand(
"setRemoveWeight",
87 docCommandVoid1(
"set RemoveWeight",
"desired removeWeight")));
91 dgADD_OSTREAM_TO_RTLOG(std::cout);
92 std::string localName(robotRef);
93 if (!isNameInRobotUtil(localName)) {
105 pinocchio::urdf::buildModel(
m_robot_util->m_urdf_filename,
106 pinocchio::JointModelFreeFlyer(),
m_model);
113 SEND_MSG(
"Entity Initialized", MSG_TYPE_INFO);
121 if (!m_initSucceeded) {
122 SEND_WARNING_STREAM_MSG(
123 "Cannot compute signal rightWeight before initialization!");
126 if (s.size() != 6) s.resize(6);
128 const Vector &
q = m_qSIN(iter);
129 assert(
q.size() == m_model.nq &&
"Unexpected size of signal q");
132 pinocchio::framesForwardKinematics(m_model, *m_data,
q);
133 const pinocchio::SE3 &sensorPlacement = m_data->oMf[m_rightSensorId];
135 Eigen::Vector3d leverArm = sensorPlacement.rotation() * m_rightLeverArm;
137 m_rightHandWeight[3] = leverArm(1) * m_rightHandWeight(2);
138 m_rightHandWeight[4] = -leverArm(0) * m_rightHandWeight(2);
140 Eigen::Matrix<double, 6, 1> weight;
143 sensorPlacement.rotation().transpose() * m_rightHandWeight.head<3>();
145 sensorPlacement.rotation().transpose() * m_rightHandWeight.tail<3>();
153 if (!m_initSucceeded) {
154 SEND_WARNING_STREAM_MSG(
155 "Cannot compute signal rightWeight before initialization!");
158 if (s.size() != 6) s.resize(6);
160 const Vector &
q = m_qSIN(iter);
161 assert(
q.size() == m_model.nq &&
"Unexpected size of signal q");
163 pinocchio::framesForwardKinematics(m_model, *m_data,
q);
164 const pinocchio::SE3 &sensorPlacement = m_data->oMf[m_leftSensorId];
166 Eigen::Vector3d leverArm = sensorPlacement.rotation() * m_leftLeverArm;
168 m_leftHandWeight[3] = leverArm(1) * m_leftHandWeight(2);
169 m_leftHandWeight[4] = -leverArm(0) * m_leftHandWeight(2);
171 Eigen::Matrix<double, 6, 1> weight;
174 sensorPlacement.rotation().transpose() * m_leftHandWeight.head<3>();
176 sensorPlacement.rotation().transpose() * m_leftHandWeight.tail<3>();
184 if (!m_initSucceeded) {
185 SEND_WARNING_STREAM_MSG(
"Cannot compute signal sum before initialization!");
188 if (s.size() != 6) s.resize(6);
189 const Vector &rightWristForce = m_rightWristForceInSIN(iter);
190 assert(rightWristForce.size() == 6 &&
191 "Unexpected size of signal rightWristForceIn, should be 6.");
192 const Vector &rightWeight = m_rightWeightSINNER(iter);
193 assert(rightWeight.size() == 6 &&
194 "Unexpected size of signal rightWeight, should be 6.");
197 if (m_rightCalibrationIter > 0) {
198 m_right_FT_offset_calibration_sum += rightWristForce;
199 m_right_weight_calibration_sum += rightWeight;
200 m_rightCalibrationIter--;
201 }
else if (m_rightCalibrationIter == 0) {
202 SEND_INFO_STREAM_MSG(
"Calibrating ft sensors...");
203 m_right_FT_offset = m_right_FT_offset_calibration_sum /
CALIB_ITER_TIME;
205 m_rightCalibrationIter--;
208 s = rightWristForce - m_right_FT_offset;
210 if (m_removeWeight) {
217 if (!m_initSucceeded) {
218 SEND_WARNING_STREAM_MSG(
"Cannot compute signal sum before initialization!");
221 if (s.size() != 6) s.resize(6);
222 const Vector &leftWristForce = m_leftWristForceInSIN(iter);
223 assert(leftWristForce.size() == 6 &&
224 "Unexpected size of signal leftWristForceIn, should be 6.");
225 const Vector &leftWeight = m_leftWeightSINNER(iter);
226 assert(leftWeight.size() == 6 &&
227 "Unexpected size of signal leftWeight, should be 6.");
230 if (m_leftCalibrationIter > 0) {
231 m_left_FT_offset_calibration_sum += leftWristForce;
232 m_left_weight_calibration_sum += leftWeight;
233 m_leftCalibrationIter--;
234 }
else if (m_leftCalibrationIter == 0) {
237 m_leftCalibrationIter--;
240 s = leftWristForce - m_left_FT_offset;
242 if (m_removeWeight) {
253 SEND_WARNING_STREAM_MSG(
254 "Cannot set right hand weight before initialization!");
264 SEND_WARNING_STREAM_MSG(
265 "Cannot set left hand weight before initialization!");
273 SEND_WARNING_STREAM_MSG(
274 "Sampling FT sensor for offset calibration... Robot should be in the "
275 "air, with horizontal hand.");
293 os <<
"FtWristCalibration " << getName();
295 getProfiler().report_all(3, os);
296 }
catch (ExceptionSignal e) {