Threaded scripts and ROS

Typically: "How do I... ", "How can I... " questions
Post Reply
atoz
Posts: 57
Joined: 18 Oct 2013, 09:02

Threaded scripts and ROS

Post by atoz » 24 Mar 2016, 18:59

Is it possible to use ROS subscribers/publishers in the initialisation stage of a threaded script? I currently have a subscriber set up and I can see from the

Code: Select all

rostopic info topic_name
command that Vrep is subscribed to the topic but not acting on the input. Although it works on a non-threaded script perfectly fine.

Thanks

[EDIT] On a similar note, where are the

Code: Select all

streamcmds e.g. simros_strmcmd_set_object_pose
values defined for the python bindings? They seem to be missing from the vrepConst.py file

coppelia
Site Admin
Posts: 7261
Joined: 14 Dec 2012, 00:25

Re: Threaded scripts and ROS

Post by coppelia » 25 Mar 2016, 12:40

Yes, you can use a threaded and non-threaded child script in a similar way. The way the current ROS interface works is somewhat semi-automatic: publishers will be automatically triggered in each simulation step, with appropriate data filled-in. The same happens with subscribers. This allows to enable streaming of a vision sensor image (for example) with a single line of code. And allows to enable subscription (and application) of a ROS image to a passive vision sensor also with a single line of code.

In next release, there will be a new (or additional ROS interface) that behaves in a very similar way as the ROS C++ API.

And yes, the stream commands constants are not defined in vrepConst.py, which is (for now) only meant to be used with the remote API. But you could add those constants to the file.

Cheers

atoz
Posts: 57
Joined: 18 Oct 2013, 09:02

Re: Threaded scripts and ROS

Post by atoz » 25 Mar 2016, 17:29

coppelia wrote:Yes, you can use a threaded and non-threaded child script in a similar way. The way the current ROS interface works is somewhat semi-automatic: publishers will be automatically triggered in each simulation step, with appropriate data filled-in. The same happens with subscribers. This allows to enable streaming of a vision sensor image (for example) with a single line of code. And allows to enable subscription (and application) of a ROS image to a passive vision sensor also with a single line of code.
I understand this. Maybe I was unclear in what I was asking. I can't get the subscriber in the threaded script functioning. It works fine in a non-threaded script and updates the value of the object I want it to. However, in a threaded script, even though I can see that V-rep is subscribed to the topic, it doesn't update the value of the object. I've set up the subscriber in the initialisation stage of the threaded script. Could it be that the thread execution in the script does not allow execution of anything outside of thread function?

Another similar issue that I've encountered is that trying to execute a declared function in a threaded script using

Code: Select all

simRosCallScriptFunction 
from Python also does not work and returns -1. However, it works fine when using a non-threaded script. I'm guessing both these issues are linked to the way threaded scripts are executed.

The reason I have all this code in a threaded script is because I would like to use the RML functions for movement and it would be nice to have all relevant code in the same script.

Thanks

coppelia
Site Admin
Posts: 7261
Joined: 14 Dec 2012, 00:25

Re: Threaded scripts and ROS

Post by coppelia » 28 Mar 2016, 09:11

Try to load the demo scene rosTopicPublisherAndSubscriber.ttt: it uses a non-threaded child script. Nor remove the attached child script, and replace it with a threaded child script with following content:

Code: Select all

-- Retrive the handle of the vision sensor we wish to stream:
visionSensorHandle=simGetObjectHandle('Vision_sensor')

-- Now enable topic publishing and streaming of the vision sensor's data:
topicName=simExtROS_enablePublisher('visionSensorData',1,simros_strmcmd_get_vision_sensor_image,visionSensorHandle,0,'')

-- Retrive the handle of the passive vision sensor. We will use the passive vision sensor
-- to visualize received data:
passiveSensorHandle=simGetObjectHandle('PassiveVision_sensor')

-- Now enable a topic subscription:
simExtROS_enableSubscriber(topicName,1,simros_strmcmd_set_vision_sensor_image,passiveSensorHandle,0,'')
It should works as with the non-threaded child script.
As for your second problem, this is a limitation of release 3.3.0, that will be relaxed in release 3.3.1. In addition to this, the new ROS interface will then also be available.

Cheers

Post Reply