sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
ankle-joint-selector.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018, Gepetto team, LAAS-CNRS
3  *
4  * This file is part of sot-talos-balance.
5  * sot-talos-balance is free software: you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation, either version 3 of
8  * the License, or (at your option) any later version.
9  * sot-talos-balance is distributed in the hope that it will be
10  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details. You should
13  * have received a copy of the GNU Lesser General Public License along
14  * with sot-talos-balance. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
18 
19 #include <dynamic-graph/all-commands.h>
20 #include <dynamic-graph/factory.h>
21 
22 #include <sot/core/debug.hh>
23 #include <sot/core/stop-watch.hh>
24 
25 namespace dynamicgraph {
26 namespace sot {
27 namespace talos_balance {
28 namespace dg = ::dynamicgraph;
29 using namespace dg;
30 using namespace dg::command;
31 
32 #define INPUT_SIGNALS \
33  m_phaseSIN << m_rightRollCoupledSIN << m_rightRollDecoupledSIN \
34  << m_rightPitchCoupledSIN << m_rightPitchDecoupledSIN \
35  << m_leftRollCoupledSIN << m_leftRollDecoupledSIN \
36  << m_leftPitchCoupledSIN << m_leftPitchDecoupledSIN
37 
38 #define OUTPUT_SIGNALS \
39  m_selecLeftSOUT << m_selecRightSOUT << m_rightRollSOUT << m_rightPitchSOUT \
40  << m_leftRollSOUT << m_leftPitchSOUT
41 
44 typedef AnkleJointSelector EntityClassName;
45 
46 /* --- DG FACTORY ---------------------------------------------------- */
47 DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(AnkleJointSelector, "AnkleJointSelector");
48 
49 /* ------------------------------------------------------------------- */
50 /* --- CONSTRUCTION -------------------------------------------------- */
51 /* ------------------------------------------------------------------- */
53  : Entity(name),
54  CONSTRUCT_SIGNAL_IN(phase, int),
55  CONSTRUCT_SIGNAL_IN(rightRollCoupled, dynamicgraph::Vector),
56  CONSTRUCT_SIGNAL_IN(rightRollDecoupled, dynamicgraph::Vector),
57  CONSTRUCT_SIGNAL_IN(rightPitchCoupled, dynamicgraph::Vector),
58  CONSTRUCT_SIGNAL_IN(rightPitchDecoupled, dynamicgraph::Vector),
59  CONSTRUCT_SIGNAL_IN(leftRollCoupled, dynamicgraph::Vector),
60  CONSTRUCT_SIGNAL_IN(leftRollDecoupled, dynamicgraph::Vector),
61  CONSTRUCT_SIGNAL_IN(leftPitchCoupled, dynamicgraph::Vector),
62  CONSTRUCT_SIGNAL_IN(leftPitchDecoupled, dynamicgraph::Vector),
63  CONSTRUCT_SIGNAL_OUT(selecLeft, Flags, m_phaseSIN),
64  CONSTRUCT_SIGNAL_OUT(selecRight, Flags, m_phaseSIN),
65  CONSTRUCT_SIGNAL_OUT(
66  rightRoll, dynamicgraph::Vector,
67  m_phaseSIN << m_rightRollCoupledSIN << m_rightRollDecoupledSIN),
68  CONSTRUCT_SIGNAL_OUT(
69  rightPitch, dynamicgraph::Vector,
70  m_phaseSIN << m_rightPitchCoupledSIN << m_rightPitchDecoupledSIN),
71  CONSTRUCT_SIGNAL_OUT(
72  leftRoll, dynamicgraph::Vector,
73  m_phaseSIN << m_leftRollCoupledSIN << m_leftRollDecoupledSIN),
74  CONSTRUCT_SIGNAL_OUT(
75  leftPitch, dynamicgraph::Vector,
76  m_phaseSIN << m_leftPitchCoupledSIN << m_leftPitchDecoupledSIN),
77  m_zeros(),
78  m_ones(true),
79  m_initSucceeded(false) {
80  Entity::signalRegistration(INPUT_SIGNALS << OUTPUT_SIGNALS);
81 
82  /* Commands. */
83  addCommand("init", makeCommandVoid1(*this, &AnkleJointSelector::init,
84  docCommandVoid1("Initialize the entity.",
85  "Number of joints")));
86 }
87 
88 void AnkleJointSelector::init(const int& n) {
89  m_n = n;
90  m_initSucceeded = true;
91 }
92 
93 /* ------------------------------------------------------------------- */
94 /* --- SIGNALS ------------------------------------------------------- */
95 /* ------------------------------------------------------------------- */
96 
97 DEFINE_SIGNAL_OUT_FUNCTION(selecLeft, Flags) {
98  if (!m_initSucceeded) {
99  SEND_WARNING_STREAM_MSG("Cannot compute selecLeft before initialization!");
100  return s;
101  }
102 
103  const int& phase = m_phaseSIN(iter);
104 
105  s = phase >= 0 ? m_ones : m_zeros;
106 
107  return s;
108 }
109 
110 DEFINE_SIGNAL_OUT_FUNCTION(selecRight, Flags) {
111  if (!m_initSucceeded) {
112  SEND_WARNING_STREAM_MSG("Cannot compute selecRight before initialization!");
113  return s;
114  }
115 
116  const int& phase = m_phaseSIN(iter);
117 
118  s = phase <= 0 ? m_ones : m_zeros;
119 
120  return s;
121 }
122 
124  if (!m_initSucceeded) {
125  SEND_WARNING_STREAM_MSG("Cannot compute leftRoll before initialization!");
126  return s;
127  }
128  if (s.size() != 1) s.resize(1);
129 
130  const int& phase = m_phaseSIN(iter);
131  const dg::Vector& leftRollCoupled = m_leftRollCoupledSIN(iter);
132  const dg::Vector& leftRollDecoupled = m_leftRollDecoupledSIN(iter);
133 
134  if (phase > 0)
135  s = leftRollDecoupled;
136  else if (phase == 0)
137  s = leftRollCoupled;
138  else
139  s.setZero();
140 
141  return s;
142 }
143 
145  if (!m_initSucceeded) {
146  SEND_WARNING_STREAM_MSG("Cannot compute leftPitch before initialization!");
147  return s;
148  }
149  if (s.size() != 1) s.resize(1);
150 
151  const int& phase = m_phaseSIN(iter);
152  const dg::Vector& leftPitchCoupled = m_leftPitchCoupledSIN(iter);
153  const dg::Vector& leftPitchDecoupled = m_leftPitchDecoupledSIN(iter);
154 
155  if (phase > 0)
156  s = leftPitchDecoupled;
157  else if (phase == 0)
158  s = leftPitchCoupled;
159  else
160  s.setZero();
161 
162  return s;
163 }
164 
166  if (!m_initSucceeded) {
167  SEND_WARNING_STREAM_MSG("Cannot compute rightRoll before initialization!");
168  return s;
169  }
170  if (s.size() != 1) s.resize(1);
171 
172  const int& phase = m_phaseSIN(iter);
173  const dg::Vector& rightRollCoupled = m_rightRollCoupledSIN(iter);
174  const dg::Vector& rightRollDecoupled = m_rightRollDecoupledSIN(iter);
175 
176  if (phase < 0)
177  s = rightRollDecoupled;
178  else if (phase == 0)
179  s = rightRollCoupled;
180  else
181  s.setZero();
182 
183  return s;
184 }
185 
187  if (!m_initSucceeded) {
188  SEND_WARNING_STREAM_MSG("Cannot compute rightPitch before initialization!");
189  return s;
190  }
191  if (s.size() != 1) s.resize(1);
192 
193  const int& phase = m_phaseSIN(iter);
194  const dg::Vector& rightPitchCoupled = m_rightPitchCoupledSIN(iter);
195  const dg::Vector& rightPitchDecoupled = m_rightPitchDecoupledSIN(iter);
196 
197  if (phase < 0)
198  s = rightPitchDecoupled;
199  else if (phase == 0)
200  s = rightPitchCoupled;
201  else
202  s.setZero();
203 
204  return s;
205 }
206 
207 /* --- COMMANDS ---------------------------------------------------------- */
208 
209 /* ------------------------------------------------------------------- */
210 /* --- ENTITY -------------------------------------------------------- */
211 /* ------------------------------------------------------------------- */
212 
213 void AnkleJointSelector::display(std::ostream& os) const {
214  os << "AnkleJointSelector " << getName();
215  try {
216  getProfiler().report_all(3, os);
217  } catch (ExceptionSignal e) {
218  }
219 }
220 
221 } // namespace talos_balance
222 } // namespace sot
223 } // namespace dynamicgraph
sot_talos_balance.test.appli_admittance_end_effector.sot
sot
Definition: appli_admittance_end_effector.py:117
ankle-joint-selector.hh
OUTPUT_SIGNALS
#define OUTPUT_SIGNALS
Definition: ankle-joint-selector.cpp:38
dynamicgraph
Definition: treeview.dox:24
dynamicgraph::sot::talos_balance::AnkleJointSelector::m_initSucceeded
bool m_initSucceeded
Definition: ankle-joint-selector.hh:96
dynamicgraph::sot::talos_balance::AnkleJointSelector::init
void init(const int &n)
Definition: ankle-joint-selector.cpp:88
dynamicgraph::sot::talos_balance::DEFINE_SIGNAL_OUT_FUNCTION
DEFINE_SIGNAL_OUT_FUNCTION(dq, dynamicgraph::Vector)
Definition: admittance-controller-end-effector.cpp:210
dynamicgraph::sot::talos_balance::AnkleJointSelector::AnkleJointSelector
EIGEN_MAKE_ALIGNED_OPERATOR_NEW AnkleJointSelector(const std::string &name)
Definition: ankle-joint-selector.cpp:52
dynamicgraph::sot::talos_balance::math::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: fwd.hh:36
INPUT_SIGNALS
#define INPUT_SIGNALS
Definition: ankle-joint-selector.cpp:32
dynamicgraph::sot::talos_balance::AnkleJointSelector::display
virtual void display(std::ostream &os) const
Definition: ankle-joint-selector.cpp:213
dynamicgraph::sot::talos_balance::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(AdmittanceControllerEndEffector, "AdmittanceControllerEndEffector")
dynamicgraph::sot::talos_balance::EntityClassName
AdmittanceControllerEndEffector EntityClassName
Definition: admittance-controller-end-effector.cpp:46
sot_talos_balance.test.appli_dcm_zmp_control.name
name
Definition: appli_dcm_zmp_control.py:298
dynamicgraph::sot::talos_balance::AnkleJointSelector::m_n
int m_n
Definition: ankle-joint-selector.hh:94