Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add remapping argument to MoveItPy initialization #3367

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

KazuyaOguma18
Copy link
Contributor

Description

Previously, the topics started by MoveItPy could not be remapped.
To address this, I added an argument for remapping, allowing remapping to be handled within Python scripts.

Ideally, I wanted MoveItPy to support remapping via the remappings option specified in the launch file. However, due to the design philosophy of rclpy, this seems difficult. As a compromise, I have ensured that remapping can at least be performed via an argument.

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • Extend the tutorials / documentation reference
  • Document API changes relevant to the user in the MIGRATION.md notes
  • Create tests, which fail without this PR reference
  • Include a screenshot if changing a GUI
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

@KazuyaOguma18
Copy link
Contributor Author

Hi @sea-bass @henningkayser @peterdavidfagan ,
I'm having trouble figuring out what's causing the CI failure.
I've looked into it, but I haven't been able to pinpoint the issue.

Would you be able to take a look when you have some time?
Any insights would be greatly appreciated.
Thanks!

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, I wanted MoveItPy to support remapping via the remappings option specified in the launch file. However, due to the design philosophy of rclpy, this seems difficult.

Can you please elaborate on this? What's the difficulty?
I see this more as a design flaw of the MoveItPy constructor.
py_binding_tools allows any arguments (including remapping args).
I always wanted to rewrite MoveItPy to use py_binding_tools, but never found time for it...

@@ -62,7 +64,7 @@ void initMoveitPy(py::module& m)

.def(py::init([](const std::string& node_name, const std::string& name_space,
const std::vector<std::string>& launch_params_filepaths, const py::object& config_dict,
bool provide_planning_service) {
bool provide_planning_service, const py::object& remappings) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use a std::map as argument here. This simplifies casting code below.
Wrapping the map into std::optional allows to handle None values.

Suggested change
bool provide_planning_service, const py::object& remappings) {
bool provide_planning_service, const std::optional<std::map<std::string, std::string>>& remappings) {

Comment on lines +90 to +104
if (py::isinstance<py::list>(remappings))
{
for (auto item : remappings)
{
py::tuple item_tuple = item.cast<py::tuple>();
if (item_tuple.size() != 2)
{
throw std::runtime_error("Remapping must be a list of tuples with 2 elements");
}
launch_arguments.push_back("--remap");
launch_arguments.push_back(item_tuple[0].cast<std::string>() +
":=" + item_tuple[1].cast<std::string>());
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (py::isinstance<py::list>(remappings))
{
for (auto item : remappings)
{
py::tuple item_tuple = item.cast<py::tuple>();
if (item_tuple.size() != 2)
{
throw std::runtime_error("Remapping must be a list of tuples with 2 elements");
}
launch_arguments.push_back("--remap");
launch_arguments.push_back(item_tuple[0].cast<std::string>() +
":=" + item_tuple[1].cast<std::string>());
}
}
if (remappings.has_value())
{
for (const auto &[key, value]: remappings)
{
launch_arguments.push_back("--remap");
launch_arguments.push_back(key + ":=" + value);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants