Skip to main content
Version: 7

Using MoveIt Pro's Websocket Interface

External system diagram

After you have built an application with MoveIt Pro, you may need to integrate it with a higher layer system, typically if you want to run application code that can be ROS agnostic.

We use the Ros Bridge Protocol to communicate between the MoveIt Pro Runtime and MoveIt Pro Frontend. If you are building a system that needs to interact with MoveIt Pro, we recommend using the websocket interface with any of the following popular libraries:

Setup

The MoveIt Pro Runtime runs a rosbridge server listening on port 3201. To connect to it across your network, expose that port in your robot's firewall settings.

The following examples are in Python but could be implemented in any of the languages above.

Running an Objective

To run an Objective from your application, you only need to know its name and send a request to the /execute_objective service.

For example, to communicate with MoveIt Pro from a Python script you can install the roslibpy library:

pip install roslibpy

Here is an example Python script that will start the "Close Gripper" Objective, wait for the response, and then print the response. Note that you will need to know the IP address of your robot if not running on the same machine.

import roslibpy

# Connect a client to the rosbridge running on the robot
# Replace the host with the IP of your robot
client = roslibpy.Ros(host='localhost', port=3201)
client.run()

# Setup the execute objective service
execute_objective = roslibpy.Service(
client,
'/execute_objective',
'moveit_studio_sdk_msgs/srv/ExecuteObjective'
)

# Create a request to run the objective
request = roslibpy.ServiceRequest({"objective_name": "Close Gripper"})

# Call the service and print the response
response = execute_objective.call(request)
print(response)

Running Objectives Synchronously VS Asynchronously

We can extend the above example to run multiple objectives in sequence.

# Create a request to run the objective
request = roslibpy.ServiceRequest({"objective_name": "Close Gripper"})

# Call the service and print the response
response = execute_objective.call(request)
print(response)

# Repeat for the Open Gripper objective
request = roslibpy.ServiceRequest({"objective_name": "Open Gripper"})
response = execute_objective.call(request)
print(response)

We can also run an objective asynchronously to not block other application logic.

# Create a callback with a completed Event
from threading import Event
completed = Event()
def callback(response):
print(f"Response: {response}")
completed.set()

# Create a request to run the objective
request1 = roslibpy.ServiceRequest({"objective_name": "Close Gripper"})

# Call the service asynchronously with the callback functions
execute_objective.call(request1, callback=callback)

# Wait for completed to be set
completed.wait(timeout=30)

client.terminate()
warning

Running multiple objectives asynchronously is not possible, as the currently running objective will cancel if another objective is ran.

Through the rosbridge protocol you have access to the full ROS messaging system inside MoveIt Pro. Some examples of projects you could build using this interface:

  • Webapp UI
  • Machine Learning Image Pipeline
  • Multi-Robot Coordination
  • Factory Controller
  • Mobile App

Websockets are useful when you need to interact with a ROS based robot system across a network.