## Control scene objects in VREP through ROS

Typically: "How do I... ", "How can I... " questions
cjndiaye
Posts: 6
Joined: 23 Mar 2017, 16:20

### Control scene objects in VREP through ROS

Hi every one,
I want to put in a empty scene a conveyor belt which transport packages.
So I have to put in a scene in Vrep an object "conveyor" and "package".
The problem is that I do not know how to control my conveyor thanks to ROS nodes (accelerate, slowdown or stop) in a terminal.

Please can you help me, I will really appreciate.

coppelia
Posts: 7396
Joined: 14 Dec 2012, 00:25

### Re: Control scene objects in VREP through ROS

Hello,

Have a look at the RosInterfaceand the demo scene rosInterfaceTopicPublisherAndSubscriber.ttt. So it is just a matter to select appropriate ROS messages, and write callback routines in a V-REP child script. Those callback routines will be called each time such a message arrives via ROS. On the other hand, you can also from your child script regularly send other ROS messages (publish), such as the current conveyor position, etc.

Cheers

cjndiaye
Posts: 6
Joined: 23 Mar 2017, 16:20

### Re: Control scene objects in VREP through ROS

HI, thanks a lot for these information.

I had already seen the demo but it still a little bit blurred in my head.

Because in this demo, there is not a C++ script running in ROS and allowing control those objects in the scene.
If I understand, it just use some ROS/VREP function that are already defined thanks to ROSInterface.

So, it still not clear yet.

Thanks.

coppelia
Posts: 7396
Joined: 14 Dec 2012, 00:25

### Re: Control scene objects in VREP through ROS

The demo scene that I mention will do two things:
• It will constantly publish an image to ROS
• It will subscribe to above image from ROS
In that scene, the publisher and subscriber are the same: a V-REP script. But you are free to have a C++ application be the subscriber or publisher.

Cheers

cjndiaye
Posts: 6
Joined: 23 Mar 2017, 16:20

### Re: Control scene objects in VREP through ROS

Hi, I still have problems to control conveyor and box which are on my scene.
The scene is composed of a customizable conveyor belt, a proximity sensor and a box. I want to stop the conveyor belt when the sensor detects the box.
The code from v-rep is like this:

Code: Select all

if (sim_call_type==sim_childscriptcall_initialization) then
forwarder=simGetObjectHandle('customizableConveyor_forwarder')
textureShape=simGetObjectHandle('customizableConveyor_tableTop')

ConveyorHandle=simGetScriptAssociatedWithObject(simGetObjectHandle('customizableConveyor'))
Sensor=simGetObjectHandle('Proximity_sensor')
end
I get the handle of objects but I want to know through ROS when the sensor detects something or not in order to set 'beltVelocity' in the script in vrep to zero.

Can you help me please, I have been through since months and can't solve it. I follow many tutorials to understand the link between Ros and Vrep but it still blurred; I don't really know how to get access via Ros to those objects in the scene.

coppelia
Posts: 7396
Joined: 14 Dec 2012, 00:25

### Re: Control scene objects in VREP through ROS

Your code didn't contain any reference to ROS-related commands. You are just retrieving handles.

You will have to read the proximity sensor state (e.g. simReadProximitySensor) and sent that information to ROS via a specific publisher.

Have again a look at the demo scene I referred in my previous post: it should an example how to set-up a publisher. You can enable (or advertise) a publisher with simExtRosInterface_advertise.

Then, in each simulation loop, you can send (or publish) the state of the sensor via simExtRosInterface_publish

For reading data coming from ROS, you would enable a subscriber in a very similar was as you did with the publisher.

Cheers

cjndiaye
Posts: 6
Joined: 23 Mar 2017, 16:20

### Re: Control scene objects in VREP through ROS

HI, thanks for these information.
But I tried another way using rosPlugin suscriber types.
This is the code on Ros side:

Code: Select all

#include "ros/ros.h"
#include "std_msgs/Float32.h"
#include <sstream>
int main (int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
//Create a publisher in ROS
//The suscriber will be an object in V-rep
ros::Rate loop_rate(10);

float velocity;
while (ros::ok())
{
std_msgs::Float32 d ;
velocity=0.0;
d.data=velocity;
chat_pub.publish(d);
loop_rate.sleep();
}
return 0; }
So I just create a publisher in ROS in order to publish float that I want which will represent the 'beltVelocity'

On vrep, the code is the following:

Code: Select all

function setVelocity(d)
simSetFloatSignal('conveyorBeltVelocity',d.data)
end

if (sim_call_type==sim_childscriptcall_initialization) then
forwarder=simGetObjectHandle('customizableConveyor_forwarder')
textureShape=simGetObjectHandle('customizableConveyor_tableTop')
ConveyorHandle=simGetScriptAssociatedWithObject(simGetObjectHandle('customizableConveyor'))
end

if (sim_call_type==sim_childscriptcall_actuation) then
beltVelocity=simGetFloatSignal("conveyorBeltVelocity")
sub=simExtROS_enableSubscriber('/chat',1,simros_strmcmd_set_float_signal,ConveyorHandle,-1,'setVelocity')

-- We move the texture attached to the conveyor belt to give the impression of movement:
t=simGetSimulationTime()
simSetObjectFloatParameter(textureShape,sim_shapefloatparam_texture_x,t*beltVelocity)
relativeLinearVelocity={beltVelocity,0,0}

end 
'beltVelocity' is the variable that gives velocity to the conveyor, I just want to control it but I have errors because it seems that there is no float value received by 'beltVelocity'.
Thanks for your help.

coppelia
Posts: 7396
Joined: 14 Dec 2012, 00:25

### Re: Control scene objects in VREP through ROS

You are using the old ROS plugin, which you shouldn't use anymore. Really look at the example scene I refered to, which is using the rosInterface.

At the same time you haven't understood how non-threaded child scripts are working. In your example you are enabling a new subscriber in each simulation step. This should however only be done in the initialization phase of a child script (or, in general, only once).

Cheers

cjndiaye
Posts: 6
Joined: 23 Mar 2017, 16:20

### Re: Control scene objects in VREP through ROS

Hi, I have a little problem.
I am doing pick and place simulation and want to replace pick and place actions with conveyor belts to carry them.

The principle is explained below:
Once the object is inside the workspace of a robot, I want to change its position by moving it from the product conveyor to the conveyor which replace the pick action (as if a real robot did it) with the following function : simSetObjectPosition(p1, -1 ,first_position[1])

The problem is that if it joins the desired position, it does not be carried by the conveyor, it is like it becomes static . I think that the 'relativeToObjectHandle' of this function makes the position absolute but I don't want that.
The object has to move when it lefts the product conveyor belt to the other conveyor.

How can I do this please.

Thanks you

coppelia