4#ifndef __multicontact_api_python_scenario_contact_phase_hpp__
5#define __multicontact_api_python_scenario_contact_phase_hpp__
7#include <pinocchio/fwd.hpp>
9#include <ndcurves/python/python_definitions.h>
11#include <boost/python/suite/indexing/map_indexing_suite.hpp>
12#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
13#include <eigenpy/eigenpy.hpp>
23namespace bp = boost::python;
25template <
typename ContactPhase>
27 :
public bp::def_visitor<ContactPhasePythonVisitor<ContactPhase> > {
28 typedef typename ContactPhase::Scalar
Scalar;
30 typedef typename ContactPhase::SE3
SE3;
34 typedef typename ContactPhase::point3_t
point3_t;
35 typedef typename ContactPhase::point6_t
point6_t;
36 typedef typename ContactPhase::pointX_t
pointX_t;
44 ContactPhase::isConsistent, 0, 1)
46 template <class PyClass>
47 void visit(PyClass& cl)
const {
48 cl.def(bp::init<>(bp::arg(
""),
"Default constructor."))
49 .def(bp::init<Scalar, Scalar>(bp::args(
"t_init",
"t_final"),
50 "Constructor with time interval."))
51 .def(bp::init<ContactPhase>(bp::arg(
"other"),
"Copy contructor."))
53 "The time at the begining of this contact phase.")
55 "The time at the end of this contact phase.")
57 "The duration this contact phase.")
61 bp::make_getter(&ContactPhase::m_c_init,
62 bp::return_value_policy<bp::return_by_value>()),
63 bp::make_setter(&ContactPhase::m_c_init),
64 "Initial 3D position of the center of mass for this contact phase")
67 bp::make_getter(&ContactPhase::m_dc_init,
68 bp::return_value_policy<bp::return_by_value>()),
69 bp::make_setter(&ContactPhase::m_dc_init),
70 "Initial linear velocity of the center of mass for this contact "
74 bp::make_getter(&ContactPhase::m_ddc_init,
75 bp::return_value_policy<bp::return_by_value>()),
76 bp::make_setter(&ContactPhase::m_ddc_init),
77 "Initial linear acceleration of the center of mass for this "
81 bp::make_getter(&ContactPhase::m_L_init,
82 bp::return_value_policy<bp::return_by_value>()),
83 bp::make_setter(&ContactPhase::m_L_init),
84 "Initial angular momentum for this contact phase")
87 bp::make_getter(&ContactPhase::m_dL_init,
88 bp::return_value_policy<bp::return_by_value>()),
89 bp::make_setter(&ContactPhase::m_dL_init),
90 "Initial angular momentum derivative for this contact phase")
93 bp::make_getter(&ContactPhase::m_q_init,
94 bp::return_value_policy<bp::return_by_value>()),
95 bp::make_setter(&ContactPhase::m_q_init),
96 "Initial whole body configuration of this phase")
99 bp::make_getter(&ContactPhase::m_c_final,
100 bp::return_value_policy<bp::return_by_value>()),
101 bp::make_setter(&ContactPhase::m_c_final),
102 "Final 3D position of the center of mass for this contact phase")
105 bp::make_getter(&ContactPhase::m_dc_final,
106 bp::return_value_policy<bp::return_by_value>()),
107 bp::make_setter(&ContactPhase::m_dc_final),
108 "Final linear velocity of the center of mass for this contact "
112 bp::make_getter(&ContactPhase::m_ddc_final,
113 bp::return_value_policy<bp::return_by_value>()),
114 bp::make_setter(&ContactPhase::m_ddc_final),
115 "Final linear acceleration of the center of mass for this contact "
119 bp::make_getter(&ContactPhase::m_L_final,
120 bp::return_value_policy<bp::return_by_value>()),
121 bp::make_setter(&ContactPhase::m_L_final),
122 "Final angular momentum for this contact phase")
125 bp::make_getter(&ContactPhase::m_dL_final,
126 bp::return_value_policy<bp::return_by_value>()),
127 bp::make_setter(&ContactPhase::m_dL_final),
128 "Final angular momentum derivative for this contact phase")
131 bp::make_getter(&ContactPhase::m_q_final,
132 bp::return_value_policy<bp::return_by_value>()),
133 bp::make_setter(&ContactPhase::m_q_final),
134 "Final whole body configuration of this phase")
135 .def_readwrite(
"q_t", &ContactPhase::m_q)
136 .def_readwrite(
"dq_t", &ContactPhase::m_dq)
137 .def_readwrite(
"ddq_t", &ContactPhase::m_ddq)
138 .def_readwrite(
"tau_t", &ContactPhase::m_tau)
139 .def_readwrite(
"c_t", &ContactPhase::m_c)
140 .def_readwrite(
"dc_t", &ContactPhase::m_dc)
141 .def_readwrite(
"ddc_t", &ContactPhase::m_ddc)
142 .def_readwrite(
"L_t", &ContactPhase::m_L)
143 .def_readwrite(
"dL_t", &ContactPhase::m_dL)
144 .def_readwrite(
"wrench_t", &ContactPhase::m_wrench)
145 .def_readwrite(
"zmp_t", &ContactPhase::m_zmp)
146 .def_readwrite(
"root_t", &ContactPhase::m_root)
149 "Return a pointer to the contact force trajectory for this "
151 "Throw a ValueError if the effector is not in contact.")
153 bp::arg(
"effector_name"),
154 "Return a pointer to the contact normal force trajectory for this "
156 "Throw a ValueError if the effector is not in contact.")
158 bp::arg(
"effector_name"),
159 "Return a pointer to the effector trajectory (in SE3) for this "
161 "Throw a ValueError if the effector is in contact.")
163 bp::return_internal_reference<>(),
164 "Return the ContactPatch object for this effector.\n"
165 "Throw a ValueError if the effector is not in contact.")
168 "Return a CONST dict EffectorName:ContactPatch")
170 "Return a CONST dict EffectorName:contact force")
172 "Return a CONST dict EffectorName:contact normal force")
174 "Return a CONST dict EffectorName:effector trajectory")
176 .def(
"addContactForceTrajectory",
177 &ContactPhase::addContactForceTrajectory,
178 bp::args(
"effector_name",
"trajectory"),
179 "Add a trajectory to the map of contact forces.\n"
180 "If a trajectory already exist for this effector, it is "
182 "Throw invalid_argument if eeName is not defined in contact for "
184 "Return false if a trajectory already existed (and have been "
185 "overwrited) true otherwise.")
186 .def(
"addContactNormalForceTrajectory",
187 &ContactPhase::addContactNormalForceTrajectory,
188 bp::args(
"effector_name",
"trajectory"),
189 "Add a trajectory to the map of contact normal forces.\n"
190 "If a trajectory already exist for this effector, it is "
192 "Throw a ValueError if eeName is not defined in contact for this "
194 "Throw a ValueError if trajectory is not of dimension 1.\n"
195 "Return false if a trajectory already existed (and have been "
196 "overwrited) true otherwise.")
197 .def(
"addEffectorTrajectory", &ContactPhase::addEffectorTrajectory,
198 bp::args(
"effector_name",
"trajectory"),
199 "Add a trajectory to the map of effector trajectories.\n"
200 "If a trajectory already exist for this effector, it is "
202 "Throw a ValueError if eeName is defined in contact for this "
204 "Return false if a trajectory already existed (and have been "
205 "overwrited) true otherwise.")
207 .def(
"addContact", &ContactPhase::addContact,
208 bp::args(
"effector_name",
"patch"),
209 "Add a new contact patch for effector_name to this contact phase\n"
210 "If a contact phase already exist for this effector, it is "
212 "If an end effector trajectory exist for this contact, it is "
214 "Return false if a contact for this effector already existed (and "
215 "have been overwrited) true otherwise.")
216 .def(
"removeContact", &ContactPhase::removeContact,
217 bp::arg(
"effector_name"),
218 "Remove the contact for effector_name.\n"
219 "This will also remove the contact_patch, all the contact_forces "
220 "and contact_normal_forces related to "
222 "Return true if the effector was in contact, false otherwise")
223 .def(
"numContacts", &ContactPhase::numContacts,
224 "Returns the number of active contacts.")
225 .def(
"isEffectorInContact", &ContactPhase::isEffectorInContact,
226 bp::arg(
"effector_name"),
227 "Returns True if the given effector_name is in contact for this "
228 "phase, False otherwise.")
230 "Returns the names of the effectors in contact.")
231 .def(
"effectorHaveAtrajectory", &ContactPhase::effectorHaveAtrajectory,
232 bp::arg(
"effector_name"),
233 "Returns True if the given effector_name have an "
234 "effector_trajectory defined in this phase, False "
237 "Returns the names of the effectors for which an end effector "
238 "trajectory have been defined in this phase.")
239 .def(
"isConsistent", &ContactPhase::isConsistent,
240 isConsistent_overloads(bp::arg(
"throw_if_invalid"),
241 "isConsistent check if all the members of "
242 "the phase are consistent together.\n"
243 "if throw_if_invalid == True it raise an "
244 "error instead of returning False."))
246 "return the list of effectors in contact in '*this' but not in "
249 "getContactsCreated return the list of effectors in contact in "
250 "'to' but not in contact in '*this'")
253 "return the list of effectors in contact both in 'to' and '*this' "
254 "but not at the same placement")
257 "return the list of all the effectors whose contacts differ "
258 "between *this and to")
260 bp::args(
"COM_positions",
"COM_velocities",
"COM_accelerations",
262 "set the c,dc and ddc curves from a list of discrete"
263 "COM positions, velocity and accelerations.\n"
264 "The trajectories are build with first order polynomials "
265 "connecting each discrete points given.\n"
266 "This method also set the initial/final values for c, dc and ddc "
267 "from the first and last discrete point "
270 bp::args(
"AM_values",
"AM_derivatives",
"times"),
271 "set the L and d_L curves from a list of discrete Angular "
272 "velocity values and their derivatives.\n"
273 "The trajectories are build with first order polynomials "
274 "connecting each discrete points given.\n"
275 "This method also set the initial/final values for L, and dL from "
276 "the first and last discrete point "
279 bp::args(
"Joints_poisitions",
"Joints_velocities",
280 "Joints_accelerations",
"times"),
281 "set the q,dq and ddq curves from a list of discrete joints "
282 "positions, velocity and accelerations."
283 "The trajectories are build with first order polynomials "
284 "connecting each discrete points given.\n"
285 "This method also set initial/final values for q from the first "
286 "and last discrete point given.\n")
287 .def(bp::self == bp::self)
288 .def(bp::self != bp::self)
289 .def(
"copy", &
copy,
"Returns a copy of *this.");
292 static void expose(
const std::string& class_name) {
293 std::string doc =
"Contact Phase";
294 bp::class_<ContactPhase>(class_name.c_str(), doc.c_str(), bp::no_init)
299 ENABLE_SPECIFIC_MATRIX_TYPE(
point3_t);
300 ENABLE_SPECIFIC_MATRIX_TYPE(
point6_t);
301 ENABLE_SPECIFIC_MATRIX_TYPE(
pointX_t);
307 return self.timeInitial();
310 self.timeInitial(time);
314 self.timeFinal(time);
323 const std::string& eeName) {
324 return self.contactForces(eeName);
327 const std::string& eeName) {
328 return self.contactNormalForces(eeName);
331 const std::string& eeName) {
332 return self.effectorTrajectories(eeName);
335 const std::string& eeName) {
336 return self.contactPatch(eeName);
345 typename std::vector<T>::const_iterator iter;
346 boost::python::list list;
347 for (iter = vector.begin(); iter != vector.end(); ++iter) {
353 return toPythonList<std::string>(self.effectorsInContact());
356 return toPythonList<std::string>(self.effectorsWithTrajectory());
359 const ContactPhase& to) {
360 return toPythonList<std::string>(self.getContactsBroken(to));
363 const ContactPhase& to) {
364 return toPythonList<std::string>(self.getContactsCreated(to));
367 const ContactPhase& to) {
368 return toPythonList<std::string>(self.getContactsRepositioned(to));
371 const ContactPhase& to) {
372 return toPythonList<std::string>(self.getContactsVariations(to));
381 typename std::map<std::string, T>::const_iterator iter;
383 for (iter = map.begin(); iter != map.end(); ++iter) {
384 dict[iter->first] = iter->second;
390 return toPythonDict<ContactPatch>(self.contactPatches());
393 return toPythonDict<curve_ptr>(self.contactForces());
396 return toPythonDict<curve_ptr>(self.contactNormalForces());
399 return toPythonDict<curve_SE3_ptr>(self.effectorTrajectories());
408 ndcurves::vectorFromEigenArray<pointX_list_t, t_pointX_t>(points);
410 ndcurves::vectorFromEigenArray<pointX_list_t, t_pointX_t>(
413 ndcurves::vectorFromEigenArray<pointX_list_t, t_pointX_t>(
414 points_second_derivative);
416 ndcurves::vectorFromEigenVector<time_waypoints_t, t_time_t>(
418 self.setCOMtrajectoryFromPoints(points_list, points_derivative_list,
419 points_second_derivative_list,
430 ndcurves::vectorFromEigenArray<pointX_list_t, t_pointX_t>(points);
432 ndcurves::vectorFromEigenArray<pointX_list_t, t_pointX_t>(
435 ndcurves::vectorFromEigenArray<pointX_list_t, t_pointX_t>(
436 points_second_derivative);
438 ndcurves::vectorFromEigenVector<time_waypoints_t, t_time_t>(
440 self.setJointsTrajectoryFromPoints(points_list, points_derivative_list,
441 points_second_derivative_list,
451 ndcurves::vectorFromEigenArray<pointX_list_t, t_pointX_t>(points);
453 ndcurves::vectorFromEigenArray<pointX_list_t, t_pointX_t>(
456 ndcurves::vectorFromEigenVector<time_waypoints_t, t_time_t>(
458 self.setAMtrajectoryFromPoints(points_list, points_derivative_list,
463 static ContactPhase
copy(
const ContactPhase& self) {
464 return ContactPhase(self);