|
2 | 2 |
|
3 | 3 | void PyWalkWrapper::spin_some() { rclcpp::spin_some(node_); } |
4 | 4 |
|
5 | | -PyWalkWrapper::PyWalkWrapper(std::string ns, std::vector<py::bytes> parameter_msgs, bool force_smooth_step_transition) { |
| 5 | +PyWalkWrapper::PyWalkWrapper(std::string ns, std::vector<py::bytes> walk_parameter_msgs, |
| 6 | + std::vector<py::bytes> moveit_parameter_msgs, bool force_smooth_step_transition) { |
6 | 7 | // initialize rclcpp if not already done |
7 | 8 | if (!rclcpp::contexts::get_global_default_context()->is_valid()) { |
8 | 9 | rclcpp::init(0, nullptr); |
9 | 10 | } |
10 | 11 |
|
11 | | - // create parameters from serialized messages |
12 | | - std::vector<rclcpp::Parameter> cpp_parameters = {}; |
13 | | - for (auto ¶meter_msg : parameter_msgs) { |
14 | | - cpp_parameters.push_back( |
15 | | - rclcpp::Parameter::from_parameter_msg(fromPython<rcl_interfaces::msg::Parameter>(parameter_msg))); |
16 | | - } |
17 | | - |
18 | | - node_ = rclcpp::Node::make_shared(ns + "walking"); |
19 | | - walk_node_ = std::make_shared<bitbots_quintic_walk::WalkNode>(node_, ns, cpp_parameters); |
| 12 | + // internal function to deserialize the parameter messages |
| 13 | + auto deserialize_parameters = [](std::vector<py::bytes> parameter_msgs) { |
| 14 | + std::vector<rclcpp::Parameter> cpp_parameters = {}; |
| 15 | + for (auto ¶meter_msg : parameter_msgs) { |
| 16 | + cpp_parameters.push_back( |
| 17 | + rclcpp::Parameter::from_parameter_msg(fromPython<rcl_interfaces::msg::Parameter>(parameter_msg))); |
| 18 | + } |
| 19 | + return cpp_parameters; |
| 20 | + }; |
| 21 | + |
| 22 | + // Create a node object |
| 23 | + // Even tho we use python bindings instead of ros's dds, we still need a node object for logging and parameter |
| 24 | + // handling Because the walking is not started using the launch infrastructure and an appropriate parameter file, we |
| 25 | + // need to manually set the parameters |
| 26 | + node_ = rclcpp::Node::make_shared( |
| 27 | + "walking", ns, rclcpp::NodeOptions().parameter_overrides(deserialize_parameters(walk_parameter_msgs))); |
| 28 | + |
| 29 | + // Create the walking object |
| 30 | + // We pass it the node we created. But the walking also creates a helper node for moveit (otherwise dynamic |
| 31 | + // reconfigure does not work, because moveit does some bullshit with their parameter declarations leading dynamic |
| 32 | + // reconfigure not working). This way the walking parameters are isolated from the moveit parameters, allowing dynamic |
| 33 | + // reconfigure to work. Therefore we need to pass the moveit parameters to the walking. |
| 34 | + walk_node_ = |
| 35 | + std::make_shared<bitbots_quintic_walk::WalkNode>(node_, ns, deserialize_parameters(moveit_parameter_msgs)); |
20 | 36 | set_robot_state(0); |
21 | 37 | walk_node_->initializeEngine(); |
22 | 38 | walk_node_->getEngine()->setForceSmoothStepTransition(force_smooth_step_transition); |
@@ -197,7 +213,7 @@ PYBIND11_MODULE(libpy_quintic_walk, m) { |
197 | 213 | using namespace bitbots_quintic_walk; |
198 | 214 |
|
199 | 215 | py::class_<PyWalkWrapper, std::shared_ptr<PyWalkWrapper>>(m, "PyWalkWrapper") |
200 | | - .def(py::init<std::string, std::vector<py::bytes>, bool>()) |
| 216 | + .def(py::init<std::string, std::vector<py::bytes>, std::vector<py::bytes>, bool>()) |
201 | 217 | .def("step", &PyWalkWrapper::step) |
202 | 218 | .def("step_relative", &PyWalkWrapper::step_relative) |
203 | 219 | .def("step_open_loop", &PyWalkWrapper::step_open_loop) |
|
0 commit comments