From f92bab1418e29ad63393a8ae452fde079f58b37a Mon Sep 17 00:00:00 2001 From: paleziart <paleziart@laas.fr> Date: Fri, 19 Aug 2022 10:07:57 +0200 Subject: [PATCH] Rebase changes to python bindings from flying branch --- python/FootTrajectoryGenerator.cpp | 7 +++++-- python/Gait.cpp | 6 ++++++ python/Joystick.cpp | 33 ++++++++++++++++++------------ python/Params.cpp | 6 +++++- python/StatePlanner.cpp | 7 ++++--- python/WbcWrapper.cpp | 2 ++ 6 files changed, 42 insertions(+), 19 deletions(-) diff --git a/python/FootTrajectoryGenerator.cpp b/python/FootTrajectoryGenerator.cpp index 79fce1a2..1e3e110e 100644 --- a/python/FootTrajectoryGenerator.cpp +++ b/python/FootTrajectoryGenerator.cpp @@ -21,8 +21,11 @@ struct FootTrajectoryGeneratorVisitor .def("update", &FootTrajectoryGenerator::update, bp::args("k", "targetFootstep"), "Compute target location of footsteps from Python.\n") - .def("get_elapsed_durations", &FootTrajectoryGenerator::getT0s, "Get the current timings of the flying feet.\n") - .def("get_phase_durations", &FootTrajectoryGenerator::getTswing, "Get the flying period of the feet.\n"); + .def("get_elapsed_durations", &FootTrajectoryGenerator::getT0s, + "Get the current timings of the flying feet.\n") + .def("get_phase_durations", &FootTrajectoryGenerator::getTswing, "Get the flying period of the feet.\n") + .def("get_trajectory_to_target", &FootTrajectoryGenerator::getTrajectoryToTarget, bp::args("j"), + "Get the whole swing trajectory from current position to target on the ground.\n"); } static void expose() { diff --git a/python/Gait.cpp b/python/Gait.cpp index e22f8a7f..63d1a47c 100644 --- a/python/Gait.cpp +++ b/python/Gait.cpp @@ -10,15 +10,21 @@ struct GaitVisitor : public bp::def_visitor<GaitVisitor<Gait>> { .def("get_past_gait", &Gait::getPastGait, "Get past gait matrix.\n") .def("get_gait_matrix", &Gait::getCurrentGait, "Get gait matrix.\n") + .def("get_gait_coeff", &Gait::getCurrentGaitCoeff, bp::args("i", "j"), "Get gait coefficient.\n") .def("get_desired_gait", &Gait::getDesiredGait, "Get desired gait matrix.\n") .def("is_new_step", &Gait::isNewPhase, "True if new phase of the gait.\n") .def("is_static", &Gait::getIsStatic, "True if static gait.\n") + .def("get_phase_duration", &Gait::getPhaseDuration, bp::args("i", "j", "value"), "Get phase duration.\n") + .def("get_remaining_time", &Gait::getRemainingTime, "Get remaining time of the last computed phase.\n") .def("initialize", &Gait::initialize, bp::args("params"), "Initialize Gait from Python.\n") .def("update", &Gait::update, bp::args("k", "k_mpc", "joystickCode"), "Update current gait matrix from Python.\n") + .def("set_new_phase", &Gait::setNewPhase, bp::args("value"), "Set value of newPhase_ from Python.\n") + .def("set_late", &Gait::setLate, bp::args("i"), "Set value of isLate_ from Python.\n") + .add_property("matrix", bp::make_function(&Gait::getCurrentGait, bp::return_value_policy<bp::return_by_value>())); } diff --git a/python/Joystick.cpp b/python/Joystick.cpp index f22aad4c..047f2331 100644 --- a/python/Joystick.cpp +++ b/python/Joystick.cpp @@ -8,21 +8,28 @@ struct JoystickVisitor : public bp::def_visitor<JoystickVisitor<Joystick>> { void visit(PyClassJoystick& cl) const { cl.def(bp::init<>(bp::arg(""), "Default constructor.")) - .def("initialize", &Joystick::initialize, bp::args("params"), "Initialize Joystick from Python.\n") + .def("initialize", &Joystick::initialize, bp::args("params"), "Initialize Joystick from Python.\n") - .def("update_v_ref", &Joystick::update_v_ref, bp::args("k", "gait_is_static"), "Update joystick values.") + .def("update_v_ref", &Joystick::update_v_ref, bp::args("k", "gait_is_static"), "Update joystick values.") + .def("handle_v_switch", &Joystick::handle_v_switch_py, bp::args("k", "k_switch", "v_switch"), + "Run security check.\n") + + .def("update_for_analysis", &Joystick::update_for_analysis, + bp::args("des_vel_analysis", "N_analysis", "N_steady"), "Set test velocity profile.\n") - .def("get_p_ref", &Joystick::getPRef, "Get Reference Position") - .def("get_v_ref", &Joystick::getVRef, "Get Reference Velocity") - .def("get_joystick_code", &Joystick::getJoystickCode, "Get Joystick Code") - .def("get_start", &Joystick::getStart, "Get Joystick Start") - .def("get_stop", &Joystick::getStop, "Get Joystick Stop") - .def("get_cross", &Joystick::getCross, "Get Joystick Cross status") - .def("get_circle", &Joystick::getCircle, "Get Joystick Circle status") - .def("get_triangle", &Joystick::getTriangle, "Get Joystick Triangle status") - .def("get_square", &Joystick::getSquare, "Get Joystick Square status") - .def("get_l1", &Joystick::getL1, "Get Joystick L1 status") - .def("get_r1", &Joystick::getR1, "Get Joystick R1 status"); + .def("get_p_ref", &Joystick::getPRef, "Get Reference Position") + .def("get_v_ref", &Joystick::getVRef, "Get Reference Velocity") + .def("get_joystick_code", &Joystick::getJoystickCode, "Get Joystick Code") + .def("get_start", &Joystick::getStart, "Get Joystick Start") + .def("get_stop", &Joystick::getStop, "Get Joystick Stop") + .def("get_cross", &Joystick::getCross, "Get Joystick Cross status") + .def("get_circle", &Joystick::getCircle, "Get Joystick Circle status") + .def("get_triangle", &Joystick::getTriangle, "Get Joystick Triangle status") + .def("get_square", &Joystick::getSquare, "Get Joystick Square status") + .def("get_l1", &Joystick::getL1, "Get Joystick L1 status") + .def("get_r1", &Joystick::getR1, "Get Joystick R1 status") + .def("get_profile_duration", &Joystick::getProfileDuration, "Get duration of current velocity profile") + .def("get_last_reached_velocity", &Joystick::getLastReachedVelocity, bp::args("k"), + "Get last reached velocity.\n"); } static void expose() { bp::class_<Joystick>("Joystick", bp::no_init).def(JoystickVisitor<Joystick>()); } diff --git a/python/Params.cpp b/python/Params.cpp index d8db929f..60104fbd 100644 --- a/python/Params.cpp +++ b/python/Params.cpp @@ -8,7 +8,10 @@ struct ParamsVisitor : public bp::def_visitor<ParamsVisitor<Params>> { void visit(PyClassParams& cl) const { cl.def(bp::init<>(bp::arg(""), "Default constructor.")) - .def("initialize", &Params::initialize, bp::args("file_path"), "Initialize Params from Python.\n") + .def("read_yaml", &Params::read_yaml, bp::args("file_path"), + "Read yaml file to retrieve parameters from Python.\n") + .def("convert_gait_vec", &Params::convert_gait_vec, "Convert gait vector into matrix.\n") + .def("initialize", &Params::initialize, "Initialize Params from Python.\n") // Read Params from Python .def_readwrite("config_file", &Params::config_file) @@ -32,6 +35,7 @@ struct ParamsVisitor : public bp::def_visitor<ParamsVisitor<Params>> { .def_readwrite("Kff_main", &Params::Kff_main) .def_readwrite("osqp_w_states", &Params::osqp_w_states) .def_readwrite("osqp_w_forces", &Params::osqp_w_forces) + .def_readwrite("gait_vec", &Params::gait_vec) .def_readonly("gait", &Params::get_gait) .def_readonly("t_switch", &Params::get_t_switch) .def_readonly("v_switch", &Params::get_v_switch) diff --git a/python/StatePlanner.cpp b/python/StatePlanner.cpp index 40a04612..3958ff39 100644 --- a/python/StatePlanner.cpp +++ b/python/StatePlanner.cpp @@ -9,9 +9,10 @@ struct StatePlannerVisitor : public bp::def_visitor<StatePlannerVisitor<StatePla cl.def(bp::init<>(bp::arg(""), "Default constructor.")) .def("get_reference_states", &StatePlanner::getReferenceStates, "Get xref matrix.\n") - .def("initialize", &StatePlanner::initialize, bp::args("params"), "Initialize StatePlanner from Python.\n") - .def("compute_reference_states", &StatePlanner::computeReferenceStates, bp::args("q", "v", "b_vref"), - "Run StatePlanner from Python.\n"); + .def("initialize", &StatePlanner::initialize, bp::args("params", "gaitIn"), + "Initialize StatePlanner from Python.\n") + .def("compute_reference_states", &StatePlanner::computeReferenceStates, + bp::args("k", "q", "v", "b_vref", "fsteps"), "Run StatePlanner from Python.\n"); } static void expose() { diff --git a/python/WbcWrapper.cpp b/python/WbcWrapper.cpp index 7a47b75f..05cd469b 100644 --- a/python/WbcWrapper.cpp +++ b/python/WbcWrapper.cpp @@ -23,6 +23,8 @@ struct WbcWrapperVisitor : public bp::def_visitor<WbcWrapperVisitor<WbcWrapper>> .def_readonly("vdes", &WbcWrapper::get_vdes) .def_readonly("tau_ff", &WbcWrapper::get_tau_ff) .def_readonly("ddq_cmd", &WbcWrapper::get_ddq_cmd) + .def_readonly("dq_cmd", &WbcWrapper::get_dq_cmd) + .def_readonly("q_cmd", &WbcWrapper::get_q_cmd) .def_readonly("f_with_delta", &WbcWrapper::get_f_with_delta) .def_readonly("ddq_with_delta", &WbcWrapper::get_ddq_with_delta) .def_readonly("nle", &WbcWrapper::get_nle) -- GitLab