RosPlugin subscribers

While RosPlugin services in V-REP are enabled as soon as V-REP starts (given that ROSCORE was running at that time), RosPlugin topic subscription and listening to streaming data happens only on demand (i.e. subscribers need to be individually enabled). Moreover, this can only happen while a simulation is running.

V-REP offers two equivalent means of enabling and disabling RosPlugin subscribers: via the simRosEnableSubscriber and simRosDisableSubscriber services, or via custom Lua commands that can be used from within a script. In either case a topic name, a command ID and 3 enabling parameters need to be provided:

  • The topic name will be the string under which streaming data will be listened to (e.g. "robotPosition")
  • The command ID (hereafter streamCmd) specifies the type of data that we wish to set in V-REP (e.g. simros_strmcmd_set_object_pose if we wish to set an object's position and orientation using the data from the stream)
  • The 3 enabling parameters fully specify the item upon which the data should be applied (e.g. if we want to set the joint position of a joint object, then one enabling parameter will be the object handle, while the 2 other parameters will not be used. The first 2 parameters are integer values, the third parameter is a string value. Most of the time only one parameter is required for a streamCmd, sometimes none, and othertimes 2.
  • If you wish to activate/deactivate topic subscription via a Lua script, then following 2 functions will be needed:


    Description Enables a subscriber (i.e. V-REP will be listening to streaming data on a specific topic). Subscribers can only be enabled while simulation is running. Publishers can be disabled with simExtROS_disableSubscriber. At simulation end, all subscribers are automatically disabled. A subscriber can also be enabled using following ROS service: simRosEnableSubscriber. See also simExtROS_enablePublisher.
    Lua synopsis number subscriberID=simExtROS_enableSubscriber(string topicName,number queueSize,number streamCmd,number auxInt1,number auxInt2,string auxString,number callbackTag_before=-1,number callbackTag_after=-1)
    Lua parameters
    topicName: the topic name to listen to
    queueSize: the desired queue size
    streamCmd: the desired type of data to stream
    auxInt1: the first enabling parameter.
    auxInt2: the second enabling parameter
    auxString: the third enabling parameter
    callbackTag_before: specify a value>=0 if you wish to trigger a call to the general callback script everytime a message arrives. Return a value>0 from the general callback script, if you want the message to be processed, otherwise return 0. This argument can be omitted, in which case the message will be automatically processed without triggering a callback call to the general callback script.
    callbackTag_after: specify a value>=0 if you wish to trigger a call to the general callback script everytime a message has arrived and been processed. This argument can be omitted, in which case no callback call will be triggered in the general callback script once a message has been processed.
    Lua return values
    subscriberID: a subscriber ID, or -1 in case of an error. The subscriber ID is needed to disable that subscriber with simExtROS_disableSubscriber.


    Description Disables a subscriber (i.e. V-REP will stop listening to a specific topic) previously enabled with simExtROS_enableSubscriber. At simulation end, all subscribers are automatically disabled. A subscriber can also be disabled using following ROS service: simRosDisableSubscriber. See also simExtROS_disablePublisher.
    Lua synopsis boolean result=simExtROS_disableSubscriber(number subscriberID)
    Lua parameters
    subscriberID: the subscriber ID previously returned by simExtROS_enableSubscriber.
    Lua return values
    result: false if there was an error.

    As an example, imagine you wish to activate subscription of the topic "myObjectPose" that is streaming pose data, and you wish to apply that pose data to the object "myObject". Then you could write following code in a Lua script:

    local handle=simGetObjectHandle('myObject')
    local subscriberID=simExtROS_enableSubscriber('myObjectPose',1,

    The above example can also be executed directly in the console:

    $ rosservice call vrep/simRosGetObjectHandle 'myObject'
    handle: 5
    $ rosservice call vrep/simRosEnableSubscriber 'myObjectPose' 1 10243 5 -- -1 ''
    subscriberID: 0

    The first line retrieves the object handle (i.e. 5), and the second line enables listening and setting of the desired data. '10243' is the value of the variable simros_strmcmd_set_object_pose defined in the file 'programming/include/v_repConst.h'

    You can have V-REP act as publisher and subscriber at the same time. For instance, following code (to be executed just once at simulation start) will automatically match object "myObject2"'s pose with the pose of "myObject1", as long as the simulation is running:

    local object1Handle=simGetObjectHandle('myObject1')
    local effectiveTopicName=simExtROS_enablePublisher('myObjectPose',1,
    local object2Handle=simGetObjectHandle('myObject2')
    local subscriberID=simExtROS_enableSubscriber(effectiveTopicName,1

    Recommended topics

  • RosPlugin subscriber types
  • RosPlugin publishers
  • RosPlugin services