ROS indigo + V-REP

Typically: "How do I... ", "How can I... " questions
Post Reply
aefka
Posts: 5
Joined: 06 Dec 2017, 12:41

ROS indigo + V-REP

Post by aefka » 11 Dec 2017, 23:03

Hi

On studies I got a exercise to connect V-REP with ROS. In V-REP I have basic model Ackermann from "model browser". I want to control this model by ROS on RPi. I have got install ROS INDIGO on RPi and PC(Ubuntu 14.04). When I turn on V-REP, plugins RosInterface and RosSkeleton are loaded.

I have no idea, what I should do next. I want to control vehicle by arrows on keyboard.

Thanks for time :)

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

Re: ROS indigo + V-REP

Post by coppelia » 17 Dec 2017, 17:36

Hello,

you can get inspiration from this scene: rosInterfaceTopicPublisherAndSubscriber.ttt
and that model: Models/examples/simple Ackermann steering.ttm

Cheers

aefka
Posts: 5
Joined: 06 Dec 2017, 12:41

Re: ROS indigo + V-REP

Post by aefka » 29 Dec 2017, 15:57

First, I try to do this: https://www.youtube.com/watch?v=nLKLu4Hw_mU

When I turn on simulation appears error:

Code: Select all

Lua runtime error: [string "SCRIPT RobotBase"]:30: unsupported message type. please edit and recompile ROS plugin (simExtRosInterface_advertise @ 'RosInterface' plugin)
stack traceback:
	[C]: in function 'simExtRosInterface_advertise'
	[string "SCRIPT RobotBase"]:30: in main chunk
When I start V-REP, Plugin RosInterface is loading succesed.
I have no idea why is error about RosPlugin.

30 line of code:

Code: Select all

 sensorPub=simExtRosInterface_advertise('/frontUS','std_msg::Float32')
All code:

Code: Select all

function callback_MotorVelocity(msg)
    simSetJointTargetVelocity(hLeftMotor,msg.linear.x)
    simSetJointTargetVelocity(hRightMotor,msg.linear.y)
    simAddStatusbarMessage(string.format("Vl:%f Vr:%f", msg.linear.x, msg.linear.y))
end

if (sim_call_type==sim_childscriptcall_initialization) then

    hLeftMotor = simGetObjectHandle("LeftMotor")
    hRighrMotor = simGetObjectHandle("RightMotor")
    hFrontUS = simGetObjectHandle("FrontUS")

    local moduleName=0
    local moduleVersion=0
    local index=0
    local pluginNotFound=true
    while moduleName do
        moduleName,moduleVersion=simGetModuleName(index)
        if (moduleName=='RosInterface') then
            pluginNotFound=false
        end
        index=index+1
    end
    
    if (pluginNotFound) then
    
    simAddStatusbarMessage('The RosInterface was not found. SImulation will not run properly!')
    else
    
    sensorPub=simExtRosInterface_advertise('/frontUS','std_msg::Float32')
    simTimePub=simExtRosInterface_advertise('/simTime','std_msg::Float32')
    motorSub=simExtRosInterface_advertise('/cmd_vel','geometry_msgs::Twist','callback_MotorVelocity')
    end

    simAddStatusbarMessage('Simulation initialized')
end

if (sim_call_type==sim_childscriptcall_actuation) then 

    if not pluginNotFound then
        result,distance=simReadProximitySensor(hFrontUS)
        if(distance~=nil) then
            simExtRosInterface_publish(sensorPub,{data=distance})
            simExtRosInterface_publish(simTimePub,{data=simGetSimulationTime()})
           end
    end
end

if (sim_call_type==sim_childscriptcall_cleanup) then
    if RosInterfacePresent then
        simExtRosInterface_shutdownPublisher(sensorPub)
        simExtRosInterface_shutdownPublisher(simTimePub)
        simExtRosInterface_shutdownSubscriber(motorsSub)
    end
end

Can someone help me?

Billie1123
Posts: 62
Joined: 08 Jun 2016, 22:47

Re: ROS indigo + V-REP

Post by Billie1123 » 29 Dec 2017, 18:08

Try

Code: Select all

 sensorPub=simExtRosInterface_advertise('/frontUS','std_msg/Float32')
Regards

aefka
Posts: 5
Joined: 06 Dec 2017, 12:41

Re: ROS indigo + V-REP

Post by aefka » 29 Dec 2017, 18:36

Unfortunately, it didn't help :/

Regards

Billie1123
Posts: 62
Joined: 08 Jun 2016, 22:47

Re: ROS indigo + V-REP

Post by Billie1123 » 29 Dec 2017, 20:32

There is another misspelling I had not seen. Try

Code: Select all

 sensorPub=simExtRosInterface_advertise('/frontUS','std_msgs/Float32')
I am positive it will work (or at least, you'll get a different error :D).

Bear in mind:
- The package name is std_msgs
- Packages and message types are separated by / , not :: using the rosInterface plugin.

Regards

aefka
Posts: 5
Joined: 06 Dec 2017, 12:41

Re: ROS indigo + V-REP

Post by aefka » 29 Dec 2017, 21:05

ooo, it works, but in 32 line also error appear:

Code: Select all

Lua runtime error: [string "SCRIPT RobotBase"]:32: read in arg 3 (queueSize): expected int (simExtRosInterface_advertise @ 'RosInterface' plugin)
stack traceback:
	[C]: in function 'simExtRosInterface_advertise'
	[string "SCRIPT RobotBase"]:32: in main chunk

Line 32:

Code: Select all

motorSub=simExtRosInterface_advertise('/cmd_vel','geometry_msgs/Twist','callback_MotorVelocity')
callback_MotorVelocity is function defined at the beginning of the code

Code: Select all

function callback_MotorVelocity(msg)
    simSetJointTargetVelocity(hLeftMotor,msg.linear.x)
    simSetJointTargetVelocity(hRightMotor,msg.linear.y)
    simAddStatusbarMessage(string.format("Vl:%f Vr:%f", msg.linear.x, msg.linear.y))
end

Billie1123
Posts: 62
Joined: 08 Jun 2016, 22:47

Re: ROS indigo + V-REP

Post by Billie1123 » 29 Dec 2017, 22:46

You are using the advertise plugin constructor when you actually want a subscriber. Use simExtRosInterface_subscribe instead.

I suggest you take a better look at the aforementioned scene by coppelia (rosInterfaceTopicPublisherAndSubscriber.ttt) and to the child script of the robot rosInterfaceControlledBubbleRob from controlTypeExamples.ttt

I personally found those two scenes very handy when I first started to communicate between V-REP and ROS.

Regards

Post Reply