ros2 / rclpy

rclpy (ROS Client Library for Python)
Apache License 2.0
299 stars 224 forks source link

Question/Bug: rclpy in interactive python session #1091

Closed peterdavidfagan closed 1 year ago

peterdavidfagan commented 1 year ago

I am currently looking to setup an action client for a robot's gripper within an interactive Python session (Jupyter Notebook). I am running into issues in instantiating an action client I wrote see here.

I have also tried to manually create an action client within the notebook using the rclpy API, this has been possible however sending goals to the action server is not functioning.

I am now considering creating simple utility function in Python that execute commands from the ROS 2 command line interface (e.g. ros2 action send_goal <type> <name>). This solution doesn't seem like the cleanest solution to me, it would be nicer to be able to leverage existing Python APIs directly. I wished to post this issue to ask if there is a recommended workflow for this.

Ideally I want to be able to leverage the ROS 2 client libraries alongside a Python library for MoveIt that I am working on.

Update: I wrote a python wrapper for the cli interface and this works. It would be nice to learn more about the client libraries and their interactions with Python.

sloretz commented 1 year ago

I have also tried to manually create an action client within the notebook using the rclpy API, this has been possible however sending goals to the action server is not functioning.

I would expect sending goals to work fine from a Jupyter session. The ros2 action code uses rclpy.

Looking at the client you linked, I notice it doesn't wait for the reply to the goal being sent. Goals are sent to actions using a "send goal" service. That service returns pretty quickly to say if the server accepted the goal or not. The ros2 action command waits for that reply: https://github.com/ros2/ros2cli/blob/57c11d322bcd4471ca0f44a71d8bd3cd94489145/ros2action/ros2action/verb/send_goal.py#L108-L109

Maybe waiting for the reply would resolve the issue?

I'll close this for now, since I don't suspect a bug here. If that doesn't fix the issue then please open a question on https://answers.ros.org about it.

peterdavidfagan commented 1 year ago

Thanks @sloretz, I will follow to confirm resolution of this issue on my side. Apologies for the somewhat naive question and thank you for the detail your provided above.