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 Python bindings for ControllerClient #384

Merged
merged 3 commits into from
Aug 16, 2023

Conversation

mmurooka
Copy link
Member

This is just an introduction to a new feature I am experimenting with right now. I thought it was interesting and will submit a PR, but it may not necessarily need to be merged.

I thought it would be useful If we could send commands (walking, reaching, etc.) of mc_rtc controller from a Python script or interpreter, and I realized this by using Python bindings in ControllerClient. This PR adds that bindings.

This allows the Python interpreter to send walking and gripper opening/closing commands, as shown in the video below, using BaselineWalkingController as an example. (BaselineWalkingController does not require any changes for this purpose.) In addition to calling it from the interpreter, it will be easy to determine the destination of a walk based on the results of a deep learning model and send walking commands in a Python script.

BWC-PythonClient-20230815.mp4

Here is the ControllerClient wrapper for Python.

import mc_rtc
import mc_control

def setup():
    global cli
    cli = mc_control.ControllerClient(b"ipc:///tmp/mc_rtc_pub.ipc", b"ipc:///tmp/mc_rtc_rep.ipc")

def walk(x, y, theta):
    global cli
    elem = mc_control.ElementId([b"BWC", b"GuiWalk"], b"Walk")
    config = mc_rtc.Configuration()
    config.add("goal x [m]", x)
    config.add("goal y [m]", y)
    config.add("goal theta [deg]", theta)
    config.add("number of last footstep", 0)
    cli.send_request(elem, config)

def openGripper():
    global cli
    elem = mc_control.ElementId([b"Global", b"Grippers", b"jvrc1", b"r_gripper"], b"Open")
    cli.send_request(elem)

def closeGripper():
    elem = mc_control.ElementId([b"Global", b"Grippers", b"jvrc1", b"r_gripper"], b"Close")
    cli.send_request(elem)


cdef class ControllerClient(object):
def __cinit__(self, sub_conn_uri, push_conn_uri, timeout = 0.0):
self.impl = new c_mc_control.ControllerClient(sub_conn_uri, push_conn_uri, timeout)
Copy link
Member

Choose a reason for hiding this comment

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

The same encode trick can be used here for sub_conn_uri and push_conn_uri

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in b44c05a

@gergondet
Copy link
Member

Thanks @mmurooka

I think that except for the usability issue with passing bytes instead of strings, which can be worked around using the encode trick I mentionned, this can be merged as-is for a first usable product.

Co-authored-by: Pierre Gergondet <pierre.gergondet+github@gmail.com>
@mmurooka mmurooka changed the title [WIP] Add Python bindings for ControllerClient Add Python bindings for ControllerClient Aug 15, 2023
@mmurooka
Copy link
Member Author

Thanks @gergondet I updated it to allow strings

@gergondet gergondet merged commit a0e2841 into jrl-umi3218:master Aug 16, 2023
20 checks passed
@mmurooka mmurooka deleted the python-client branch August 16, 2023 02:25
gergondet added a commit that referenced this pull request Sep 6, 2023
Added
---

- [bindings] Add bindings for ControllerClient (#384)
- [mc_rtc] Allow to override existing log entries (#383)
- [mc_rtc] Allow "chunky" XY plot updates (#386)
- [mc_solver] ConstraintSet now has an update mechanism (#381)
- [Samples: CoM] Support the Pepper robot

Changes
---

- [StabilizerTask] Improve force distribution and CoP horizon reference (#375)
- [mc_rbdyn] Convex objects are now automatically updated (#385)
- [mc_solver] Collision constraint automatically display distance arrows when the distance falls below the interaction distance (#381)

Fixes
---

- [bindings] Fix build for Cython >= 3.0.0
- [cmake] Fix issue with yaml-cpp >= 0.8.0
- [mc_control] Fix logging of plugin performances (#383)
- [mc_observers] KinematicInertial uses function from state-observation (#388)
- [mc_rbdyn] Fix loading of devices with canonical robots (#379)
- [mc_rbdyn] Fix compilation with geos >= 3.12.0
- [Replay] Fix output replay on fixed-based robots
- [Replay] Avoid precision issue when comparing controller timestep with replay timestep
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.

None yet

2 participants