19 #include <dynamic-graph/all-commands.h>
20 #include <dynamic-graph/command-bind.h>
21 #include <dynamic-graph/factory.h>
23 #include <sot/core/debug.hh>
24 #include <sot/core/stop-watch.hh>
28 namespace talos_balance {
29 namespace dg = ::dynamicgraph;
31 using namespace dg::command;
33 #define INPUT_SIGNALS \
34 m_phaseSIN << m_gainSwingSIN << m_gainStanceSIN << m_gainDoubleSIN \
35 << m_dfzAdmittanceSIN << m_vdcFrequencySIN << m_vdcDampingSIN \
36 << m_swingAdmittanceSIN << m_wrenchRightDesSIN \
37 << m_wrenchLeftDesSIN << m_wrenchRightSIN << m_wrenchLeftSIN \
38 << m_posRightDesSIN << m_posLeftDesSIN << m_posRightSIN \
41 #define INNER_SIGNALS m_dz_ctrlSOUT << m_dz_posSOUT
43 #define OUTPUT_SIGNALS \
44 m_vRightSOUT << m_vLeftSOUT << m_gainRightSOUT << m_gainLeftSOUT
52 "FootForceDifferenceController");
58 const std::string&
name)
60 CONSTRUCT_SIGNAL_IN(phase, int),
72 CONSTRUCT_SIGNAL_IN(posRightDes, MatrixHomogeneous),
73 CONSTRUCT_SIGNAL_IN(posLeftDes, MatrixHomogeneous),
74 CONSTRUCT_SIGNAL_IN(posRight, MatrixHomogeneous),
75 CONSTRUCT_SIGNAL_IN(posLeft, MatrixHomogeneous),
76 CONSTRUCT_SIGNAL_INNER(dz_ctrl, double,
78 << m_vdcDampingSIN << m_wrenchRightDesSIN
79 << m_wrenchLeftDesSIN << m_wrenchRightSIN
80 << m_wrenchLeftSIN << m_posRightSIN
82 CONSTRUCT_SIGNAL_INNER(dz_pos, double,
84 << m_posRightDesSIN << m_posLeftDesSIN
85 << m_posRightSIN << m_posLeftSIN),
87 m_phaseSIN << m_dz_ctrlSINNER << m_dz_posSINNER
88 << m_swingAdmittanceSIN
91 m_phaseSIN << m_dz_ctrlSINNER << m_dz_posSINNER
92 << m_swingAdmittanceSIN
96 m_phaseSIN << m_gainSwingSIN << m_gainStanceSIN << m_gainDoubleSIN),
99 m_phaseSIN << m_gainSwingSIN << m_gainStanceSIN << m_gainDoubleSIN),
101 m_initSucceeded(false) {
107 docCommandVoid0(
"Initialize the entity.")));
110 makeDirectGetter(*
this, &
m_eps,
111 docDirectGetter(
"Get force threshold",
"double")));
114 makeDirectSetter(*
this, &
m_eps,
115 docDirectSetter(
"Set force threshold",
"double")));
125 for (
int i = 0; i < 3; i++)
138 if (!m_initSucceeded) {
139 SEND_WARNING_STREAM_MSG(
"Can't compute dz_ctrl before initialization!");
144 const double&
vdcDamping = m_vdcDampingSIN(iter);
146 const Eigen::VectorXd& wrenchRightDes = m_wrenchRightDesSIN(iter);
147 const Eigen::VectorXd& wrenchLeftDes = m_wrenchLeftDesSIN(iter);
148 const Eigen::VectorXd& wrenchRight = m_wrenchRightSIN(iter);
149 const Eigen::VectorXd& wrenchLeft = m_wrenchLeftSIN(iter);
151 const MatrixHomogeneous& posRight = m_posRightSIN(iter);
152 const MatrixHomogeneous& posLeft = m_posLeftSIN(iter);
154 const double RTz = posRight.translation()[2];
155 const double LTz = posLeft.translation()[2];
157 const double RFz_d = wrenchRightDes[2];
158 const double LFz_d = wrenchLeftDes[2];
160 const double RFz = wrenchRight[2];
161 const double LFz = wrenchLeft[2];
163 const double dz_ctrl =
dfzAdmittance * ((LFz_d - RFz_d) - (LFz - RFz)) -
172 if (!m_initSucceeded) {
173 SEND_WARNING_STREAM_MSG(
"Can't compute dz_pos before initialization!");
179 const MatrixHomogeneous& posRightDes = m_posRightDesSIN(iter);
180 const MatrixHomogeneous& posLeftDes = m_posLeftDesSIN(iter);
181 const MatrixHomogeneous& posRight = m_posRightSIN(iter);
182 const MatrixHomogeneous& posLeft = m_posLeftSIN(iter);
184 const double RTz_d = posRightDes.translation()[2];
185 const double LTz_d = posLeftDes.translation()[2];
187 const double RTz = posRight.translation()[2];
188 const double LTz = posLeft.translation()[2];
190 const double dz_pos =
vdcFrequency * ((LTz_d + RTz_d) - (LTz + RTz));
198 if (!m_initSucceeded) {
199 SEND_WARNING_STREAM_MSG(
"Can't compute vRight before initialization!");
202 if (s.size() != 6) s.resize(6);
204 const double& dz_ctrl = m_dz_ctrlSINNER(iter);
205 const double& dz_pos = m_dz_posSINNER(iter);
206 const int& phase = m_phaseSIN(iter);
211 s[2] = 0.5 * (dz_pos + dz_ctrl);
212 }
else if (m_swingAdmittanceSIN.isPlugged() && phase > 0) {
213 const Eigen::VectorXd& wrenchRight = m_wrenchRightSIN(iter);
222 if (!m_initSucceeded) {
223 SEND_WARNING_STREAM_MSG(
"Can't compute vLeft before initialization!");
226 if (s.size() != 6) s.resize(6);
228 const double& dz_ctrl = m_dz_ctrlSINNER(iter);
229 const double& dz_pos = m_dz_posSINNER(iter);
230 const int& phase = m_phaseSIN(iter);
235 s[2] = 0.5 * (dz_pos - dz_ctrl);
236 }
else if (m_swingAdmittanceSIN.isPlugged() && phase < 0) {
237 const Eigen::VectorXd& wrenchLeft = m_wrenchLeftSIN(iter);
246 if (!m_initSucceeded) {
247 SEND_WARNING_STREAM_MSG(
"Can't compute gainRight before initialization!");
251 const int& phase = m_phaseSIN(iter);
252 const double&
gainSwing = m_gainSwingSIN(iter);
253 const double&
gainStance = m_gainStanceSIN(iter);
254 const double&
gainDouble = m_gainDoubleSIN(iter);
267 if (!m_initSucceeded) {
268 SEND_WARNING_STREAM_MSG(
"Can't compute gainLeft before initialization!");
272 const int& phase = m_phaseSIN(iter);
273 const double&
gainSwing = m_gainSwingSIN(iter);
274 const double&
gainStance = m_gainStanceSIN(iter);
275 const double&
gainDouble = m_gainDoubleSIN(iter);
294 os <<
"FootForceDifferenceController " << getName();
296 getProfiler().report_all(3, os);
297 }
catch (ExceptionSignal e) {