ros2-rust / ros2_rust

Rust bindings for ROS 2
Apache License 2.0
942 stars 127 forks source link

How to use c++ headers of other ros packages ? #263

Open whiteplatin opened 2 years ago

whiteplatin commented 2 years ago

Hello, is there a guide or has anyone used MoveIt2 with ros2_rust ?

Example: https://moveit.picknik.ai/humble/doc/tutorials/your_first_project/your_first_project.html

https://github.com/ros-planning/moveit2/blob/main/moveit_ros/planning_interface/move_group_interface/include/moveit/move_group_interface/move_group_interface.h

#include <memory>

#include <rclcpp/rclcpp.hpp>
#include <moveit/move_group_interface/move_group_interface.h>

int main(int argc, char * argv[])
{
  // Initialize ROS and create the Node
  rclcpp::init(argc, argv);
  auto const node = std::make_shared<rclcpp::Node>(
    "hello_moveit",
    rclcpp::NodeOptions().automatically_declare_parameters_from_overrides(true)
  );

  // Create a ROS logger
  auto const logger = rclcpp::get_logger("hello_moveit");

  // Next step goes here

  // Shutdown ROS
  rclcpp::shutdown();
  return 0;
}

Any ideas on how to get started ? Do I need to use cxx for example or can I take different route to use this with ros2_rust ?

nnmm commented 2 years ago

cc @tylerjw

In general, I don't think we're there yet. The two major options are (1) writing C wrappers for using either of C++/Rust in the other language or (2) trying out cxx.

What would you like to do more concretely?

tylerjw commented 2 years ago

Hello, this is something I really want and have been trying to make possible but right now it is relatively involved as @nnmm stated. I created this: https://github.com/tylerjw/add_cargo_library

which can make it easier to add cxx rust code into your C++ code. This does not automate creating bindings, you'll have to create that boundary layer yourself with cxx.

This also does not make MoveIt work with ros2-rust as ros2-rust is a rust client library and MoveIt depends on the C++ client library. There is no bridging of the types between these two libraries so you can't for example create a node in ros2-rust and pass it to MoveIt through cxx and have it do anything that useful with it.

However, MoveIt does have ROS interfaces through move_group so you could write rust code using ros2-rust that communicates using ROS to MoveIt through those interfaces. You can also write a C++ application that wraps some behavior you want to express in ROS interfaces and interact through those interfaces.

pmirabel commented 3 months ago

Hello! If anyone get here with the goal to interface ros2-rust and MoveIt!2, I think the better way to go is to wait for (or contribute to) action support.

However, MoveIt does have ROS interfaces through move_group so you could write rust code using ros2-rust that communicates using ROS to MoveIt through those interfaces.

Doing so would be tricky Because ros2-rust does not implement action yet and MoveIt!2 dropped the service interface for executing trajectories (to be confirmed, but I cannot see in the default capabilities file.