ROS Interfaces

There are several ROS interfaces available for CoppeliaSim. Each one offers a specific behaviour, feature, or a way to operate:

  • The ROS Interface: the ROS Interface duplicates the C++ ROS API with a good fidelity. This makes it the ideal choice for very flexible communication via ROS, but might require a little bit more insight on the various messages and the way ROS operates.
  • The ROS 2 Interface: the ROS 2 Interface duplicates the C++ ROS 2 API with a good fidelity. This makes it the ideal choice for very flexible communication via ROS 2, but might require a little bit more insight on the various messages and the way ROS 2 operates.
  • ROS interfaces developed by others: those are not directly supported by us. For instance, the CoppeliaSim ROS bridge.
  • All ROS interfaces can normally operate side-by-side, but we highly recommend you to first try your hands on the ROS Interface, since this is the most flexible and natural approach. The packages to the first two above listed ROS interfaces are located here and here. Use the catkin tools to build those packages, otherwise you might run into difficulties.

    As an example, a vision sensor ROS2 publisher could look like:

    function sysCall_init() visionSensor=sim.getObject('/Vision_sensor') -- Enable an image publisher: pub=simROS2.createPublisher('/image', 'sensor_msgs/msg/Image') simROS2.publisherTreatUInt8ArrayAsString(pub) end function sysCall_sensing() -- Publish the image of the vision sensor: local img,resolution=sim.getVisionSensorImg(visionSensor) data={} data.header={stamp=simROS2.getTime(), frame_id='a'} data.height=resolution[2] data.width=resolution[1] data.encoding='rgb8' data.is_bigendian=1 data.step=resolution[1]*3 data.data=img simROS2.publish(pub,data) end function sysCall_cleanup() simROS2.shutdownPublisher(pub) end

    The subscriber on the other hand could look like:

    function sysCall_init() -- Enable an image subscriber: sub=simROS2.createSubscription('/image', 'sensor_msgs/msg/Image', 'image_callback') simROS2.subscriptionTreatUInt8ArrayAsString(sub) end function image_callback(msg) -- Here we have received an image end function sysCall_cleanup() simROS2.shutdownSubscription(sub) end

    Also have a look at the ROS tutorial and the external controller tutorial.