Building a simple robot in VREP and controlling it through ROS
ฝัง
- เผยแพร่เมื่อ 8 ก.พ. 2025
- In this demostration a simple two wheel differential drive robot is made in VREP. The robot consist of two powered wheels and a castor wheel. Furthermore, the robot is equipped with an ultra-sonic sensor. The associated Lua script with the robot publishes a topic "/frontUS" on which it sends ultra-sonic range measurements. The robot subscribes to a topic "/cmd_vel" over which it recieves the left and right wheel velocity commands.
Thank you for that tutorial. It pushed me with learning LUA, ROS and V-Rep. Have a nice day :)
function cmdVel_Subscriber(msg)
-- Command velocity callback function
local V = msg.linear.x
local W = msg.angular.z
local Vl = V + L/2 * W
local Vr = V - L/2 * W
sim.setJointTargetVelocity(hLeftMotor, Vl)
sim.setJointTargetVelocity(hRightMotor, Vr)
end
function sysCall_init()
-- do some initialization here:
hLeftMotor = sim.getObjectHandle('LeftMotor')
hRightMotor = sim.getObjectHandle('RightMotor')
L = 0.06
hFrontUS = sim.getObjectHandle('FrontUS')
hRosPubFrontUS = simROS.advertise('/frontUS', 'std_msgs/Float32')
hRosSubCmdVel = simROS.subscribe('/cmd_vel', 'geometry_msgs/Twist', 'cmdVel_Subscriber')
end
function sysCall_actuation()
-- put your actuation code here
end
function sysCall_sensing()
-- put your sensing code here
local result, distance, detectedPoint = sim.readProximitySensor(hFrontUS)
local msg = {}
if (distance ~= nil) then
--print(result , distance, detectedPoint, '
')
msg['data'] = distance
simROS.publish(hRosPubFrontUS, msg)
end
end
function sysCall_cleanup()
-- do some clean-up here
simROS.shutdownPublisher(hRosPubFrontUS)
end
Hi. Can you please help me with faking gripper action in coppeliasim through MATLAB with remote API? If not possible, is there a way to call a script in coppeliasim through MATLAB that would fake the gripping. thanks in advance
After writing rostopic list in terminal, "frontUS" does not show. What could be the problem?
The following line create the topic
hRosPubRobotUS = simROS.advertise('/robotUS', 'geometry_msgs/Vector3')
and the following lines publish the message on the topic, if they found non nil values (e.g. when you place some obstacle infront of the US)
resultfront,distancefront=sim.readProximitySensor(hFrontUS)
resultleft,distanceleft=sim.readProximitySensor(hFrontUSleft)
resultright,distanceright=sim.readProximitySensor(hFrontUSright)
local msg = {}
if(distancefront~=nil or distanceleft~=nil or distanceright~=nil) then
--print(result , distance, detectedPoint, '
')
--msg['data'] = distance
simROS.publish(hRosPubRobotUS,{x=distancefront, y=distanceleft, z=distanceright})
end
Hi, Can you please share the script that you use...Thanks in advance
nice tutorial, but plz share the code
could you upload the code ?
Hi @andrew,
did you received the code?
Hello, I am new to ROS. Can you share the code that you used? thanks
You may download the accompanied code from the following URL
we.tl/xijwQS9Nyz
Hello, great demonstration!!! Please, could you upload the code again. It is not available anymore. Also, would you think VREP is a better option to work with robotic simulation than Gazebo. Thank you for your help.
Can you upload the code again? Thanks in advance
the code has been deleted..can you upload it back or send it through my email zealousanne@gmail.com..thx in advance
hello...did u get the code? could u email me? lcarvalho1972@yahoo.com.br
Watch for more V-Rep tutorials: bit.ly/2LzOuae