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

Add initial support for calling ROS2 services from Rust nodes #439

Merged
merged 7 commits into from
Mar 26, 2024

Conversation

phil-opp
Copy link
Collaborator

  • Implement message generation for ROS2 services in Rust API
  • Update rust-ros2-dataflow example with ROS2 service call

Notes

  • I also tried to use the synchronous service API of the ros2-client crate, but I ran into issues (see Issues with ros2_service_client example Atostek/ros2-client#24)
  • The service detection requires a background event loop provided by the Spinner type. This spinner needs to be run in parallel to the main thread. The easiest way to do that is to create a multi-threaded executor and spawn it there. For example, using the ThreadPool executor provided by the futures crate:
    let pool = futures::executor::ThreadPool::new()?;
    
    let spinner = ros_node.spinner();
    pool.spawn(async {
        if let Err(err) = spinner.spin().await {
            eprintln!("ros2 spinner failed: {err:?}");
        }
    })
    .context("failed to spawn ros2 spinner")?;
    If you're already using an async runtime such as tokio or smol, you can spawn the spinner there as well (provided that you're using a multi-threaded executor).
  • The generated type format might still change because we want to support service calls from C++ nodes as well. The cxx crate, which we use for bridging Rust to C++ code, doesn't work with generics, so we have to find another way.
  • We might want to provide direct service support in our node API. For example, we might want to spawn the spinner thread already in the library or provide a way to merge service responses into the event stream.

phil-opp added 4 commits March 7, 2024 13:01
Call the `add_two_ints` service and check the result. This requires that the following command is executed in a separate terminal before:

`ros2 run examples_rclcpp_minimal_service service_main`
@phil-opp phil-opp changed the base branch from main to benchmark March 20, 2024 13:23
@phil-opp phil-opp changed the base branch from benchmark to main March 20, 2024 13:23
@phil-opp
Copy link
Collaborator Author

(There was an issue that the latest commit didn't show up in the PR. I fixed that issue by temporarily switching the base branch.)

@phil-opp phil-opp marked this pull request as ready for review March 20, 2024 14:02
Copy link
Collaborator

@haixuanTao haixuanTao left a comment

Choose a reason for hiding this comment

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

Thank you!

@phil-opp phil-opp merged commit 32dcfaa into main Mar 26, 2024
17 checks passed
@phil-opp phil-opp deleted the ros2-services branch March 26, 2024 11:50
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