Skip to content

Tutorials: ROS Interface

Maxime Busy edited this page Feb 24, 2020 · 20 revisions

In this tutorial we will detail how to setup the qiBullet ROS wrapper, allowing to connect qiBullet to the ROS framework via a simple Python script. If you are not familiar with the ROS framework, you might want to take a look at some ROS tutorials before reading this one. The ROS wrapper for qiBullet has been tested on ROS Kinetic, ROS Indigo, and more recently ROS Melodic.

WARNING: The ROS wrappers are not covered by the unittests

Installations

Assuming that you installed qiBullet and ROS, first download the meshes for your robot (the meshes will for instance be used by RViz to display your robot):

# Replace distribution by melodic, kinetic or indigo, and robot by pepper or nao
sudo apt-get install ros-distribution-robot-meshes

# For Pepper with ROS kinetic:
sudo apt-get install ros-kinetic-pepper-meshes

Then install naoqi_libqi and naoqi_libqicore:

# Replace distribution by melodic, kinetic or indigo
sudo apt-get install ros-distribution-naoqi-libqi
sudo apt-get install ros-distribution-naoqi-libqicore

You can then install naoqi_driver (bridge between ROS and naoqi) and naoqi_bridge_msgs. To do so, you can either:

  • Use the official packages provided by ros-naoqi using apt-get (you can also build them from source):
# Replace distribution by melodic, kinetic or indigo
sudo apt-get install ros-distribution-naoqi-driver
sudo apt-get install ros-distribution-naoqi-bridge-msgs
  • Or use the softbankrobotics-research fork (build from source):
    • Create a catkin workspace
    • Clone naoqi_driver, the fork of the naoqi_driver repository in the workspace
    • Clone naoqi_bridge_msgs, the fork of the naoqi_bridge_msgs repository in the workspace
    • Once the repositories are cloned, compile and source your workspace.

Launching the wrapper

Create a Python script, and launch a qiBullet simulation.

import rospy
from qibullet import PepperVirtual
from qibullet import PepperRosWrapper
from qibullet import SimulationManager

if __name__ == "__main__":
    simulation_manager = SimulationManager()
    client = simulation_manager.launchSimulation(gui=True)
    pepper = simulation_manager.spawnPepper(client, spawn_ground_plane=True)

You can then instantiate a PepperRosWrapper object (respectively NaoRosWrapper and RomeoRosWrapper for Pepper and Nao), and use it to launch the ROS wrapper:

wrap = PepperRosWrapper()
wrap.launchWrapper(pepper, "/naoqi_driver")

Notice the "/naoqi_driver" passed as a second argument to the launchWrapper method: this string will be used as a namespace for some of the published and subscribed ROS topics. The topic names should be transparent whether you use qiBullet or naoqi_driver.

For the sake of the tutorial, let's assume that you want to access to the top camera data within the ROS framework:

pepper.subscribeCamera(PepperVirtual.ID_CAMERA_TOP)
rospy.spin()

(As specified in the Virtual Robot section, only one camera can be subscribed at a time, meaning that you cannot retrieve images from 2 different cameras simultaneously)

The data is published on a ROS topic, and the spin method can be called. Remember to stop the ROS wrapper before ending the program, to correctly stop the background processes:

# Your code
wrap.stopWrapper()
simulation_manager.stopSimulation(client)

You can now launch that script from a terminal where you sourced the aforementioned catkin workspace, to launch a simulation interfaced with ROS.