8 #include <dynamic-graph/all-commands.h>
9 #include <dynamic-graph/factory.h>
11 #include <sot/core/debug.hh>
12 #include <sot/core/stop-watch.hh>
16 #define CALIB_ITER_TIME \
17 1000 // Iteration needed for sampling and averaging the FT sensors while
22 namespace talos_balance {
25 using namespace dynamicgraph::command;
26 using namespace dg::sot::talos_balance;
28 #define INPUT_SIGNALS m_right_foot_force_inSIN << m_left_foot_force_inSIN
29 #define OUTPUT_SIGNALS m_right_foot_force_outSOUT << m_left_foot_force_outSOUT
46 m_right_foot_force_inSIN),
48 m_left_foot_force_inSIN),
49 m_robot_util(RefVoidRobotUtil()),
50 m_initSucceeded(false) {
56 docCommandVoid1(
"Initialize the entity.",
57 "Robot reference (string)")));
58 addCommand(
"setRightFootWeight",
62 "Set the weight of the right foot underneath the sensor",
63 "Vector of default forces in Newton")));
64 addCommand(
"setLeftFootWeight",
68 "Set the weight of the left foot underneath the sensor",
69 "Vector of default forces in Newton")));
70 addCommand(
"calibrateFeetSensor",
72 docCommandVoid0(
"Calibrate the feet senors")));
76 dgADD_OSTREAM_TO_RTLOG(std::cout);
77 std::string localName(robotRef);
79 if (!isNameInRobotUtil(localName)) {
88 SEND_MSG(
"Entity Initialized", MSG_TYPE_INFO);
96 if (!m_initSucceeded) {
97 SEND_WARNING_STREAM_MSG(
"Cannot compute signal sum before initialization!");
100 if (s.size() != 6) s.resize(6);
102 const Vector &right_foot_force = m_right_foot_force_inSIN(iter);
104 assert(right_foot_force.size() == 6 &&
105 "Unexpected size of signal right_foot_force_in, should be 6.");
108 if (m_right_calibration_iter > 0) {
109 m_right_FT_offset_calibration_sum += right_foot_force;
110 m_right_calibration_iter--;
111 }
else if (m_right_calibration_iter == 0) {
112 SEND_INFO_STREAM_MSG(
"Calibrating ft sensors...");
118 s = right_foot_force - m_left_foot_weight - m_right_FT_offset;
124 if (!m_initSucceeded) {
125 SEND_WARNING_STREAM_MSG(
"Cannot compute signal sum before initialization!");
128 if (s.size() != 6) s.resize(6);
130 const Vector &left_foot_force = m_left_foot_force_inSIN(iter);
132 assert(left_foot_force.size() == 6 &&
133 "Unexpected size of signal left_foot_force_in, should be 6.");
136 if (m_left_calibration_iter > 0) {
137 m_left_FT_offset_calibration_sum += left_foot_force;
138 m_left_calibration_iter--;
139 }
else if (m_left_calibration_iter == 0) {
143 s = left_foot_force - m_left_foot_weight - m_left_FT_offset;
151 SEND_WARNING_STREAM_MSG(
152 "Cannot set right foot weight before initialization!");
160 SEND_WARNING_STREAM_MSG(
161 "Cannot set left foot weight before initialization!");
168 SEND_WARNING_STREAM_MSG(
169 "Sampling FT sensor for offset calibration... Robot should be in the "
170 "air, with horizontal feet.");
184 os <<
"FtCalibration " << getName();
186 getProfiler().report_all(3, os);
187 }
catch (ExceptionSignal e) {