最近在研究用ros與V-rep配合使用,在V-rep中搭建環境與模型,在ROS中跑算法。
入坑之前聽說V-rep對ros的兼容可以達到gazebo的水平,於是歡快的入了坑。
入坑之後發現神特麼兼容,雖然V-rep中的環境和模型較gazebo豐富一些,但很不建議爲此嘗試與ros聯合使用(似乎與MATLAB聯合更人性化一些),如果非要聯合使用,請參考下文。
一、環境配置
V-rep不像gazebo一樣有ros包,所以需要在兩個程序之間搭建一座橋樑:vrep_ros_bridge,其起到了將信息在ros與V-rep只間傳遞的作用。
參考:http://wiki.ros.org/vrep_ros_bridge
然而就是這種坑爹的橋樑,阻擋了我將近一個星期,特將血淚教訓總結如下:
既然是橋樑,就需要有兩端,偏偏這座橋對兩端要求極端嚴苛:
一週內我嘗試了ROS_kinetic + v-rep 3.4.0 \ v-rep 3.3.1 \ v-rep 3.2.3 均無法正常工作(此處的正常工作是指能完成後面的一些橋接任務,而不是簡單的“Plugin 'RosBridge': load succeeded.”) ,同時我換至ros_indigo下繼續嘗試,終於在V-rep 3.3.1 EDU版上得到了成功,箇中滋味難以言表。
故關於版本問題,個人認爲ROS_Indigo + v-rep 3.3.1 EDU是比較好的選擇,其他選擇也可以實現部分功能,但感覺最完整的功能應該在我說的這個組合中。
二、安裝流程
建議按照以下流程安裝:
這裏只給出宏觀流程,具體命令官網以及其他地方已經相當詳盡了。
首先下載相應版本V-rep ,在單跑無誤的情況下git vrep_ros_bridge。
同時將環境變量中的$Vrep_root_path改爲之前的V-rep安裝地址
在工作區內catkin_make,這時候應該會有 三到四輪報錯。。。
第一輪應該是 qu..._tk_...的一個包中的錯誤,直接cd進去 touch CATKIN_IGNORE即可,但應注意這樣後未來跑控制四懸翼的demo時會無法控制
第二輪應該是找不到某個txt文件,我們進入該txt文件並將其用環境變量賦值的地址改爲絕對地址,即vrep包的所在地址即可。
第三輪依然是某個include文件夾的位置問題,解決辦法與2相類似
第四輪報錯應該是找不到幾個頭文件,這時需要把vrep.../programming/include中的所有頭文件複製至
“你的工作區”/src/vrep_ros_bridge-master/vrep_ros_plugin/include 文件夾下
至此大概可以catkin_make 過了。
接着按照官網的教程走,基本可以完成安裝。
(在kinetic下鏈接第二個.so文件時會報錯 “libv_repExtRos.so:undefined symbol: _ZN3ros4initERiPPcRKSsj”,這似乎沒有解決辦法,換ROS版本吧。。。)
三、參考資料
v-rep本身參考資料就不多,與ros配合的更少,於是常常陷入無處尋找參考資料的窘境,這裏留下一些比較好的參考資料:
各種官網在這裏就不多列舉了,其他的如下:
1/這是一個v-rep的交流網站,很多問題會在上面討論:
http://www.forum.coppeliarobotics.com/index.php?sid=665775084f94a27cc9b90cc4a5ec3441
2/這是油管上的一系列v-rep教學視頻內,雖然和ros沒多大關係,但比較適合入門
https://www.youtube.com/watch?v=xI-ZEewIzzI
3/這是一個簡短的在V-rep中搭建機器人,在ros中控制的實例,比較具有代表性:
https://www.youtube.com/watch?v=nLKLu4Hw_mU
需要特別注意的是上面視頻的一些函數是當時版本下Vrep的函數,一些版本已經不使用了,需要進行一番甄別,代碼如下:
function callback_MotorsVelocity(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")
hRightMotor = simGetObjectHandle("RightMotor")
hFrontUS = simGetObjectHandle("FrontUS")
local moduleName = 0
local moduleVersion = 0
local index = 0
local pluginNotFound = true
while moduleName do
moduleName,moduleVersion = simGetModuleName(index)
--simAddStatusbarMessage(string.format("%s",moduleName))
if(moduleName == 'Ros') then
pluginNotFound = false
end
index = index + 1
end
if(pluginNotFound) then
simAddStatusbarMessage("the RosPlugin was not found!")
else
sensorPub = simExtRosInterface_advertise('/frontUS','std_msgs/Float32')
simTimePub = simExtRosInterface_advertise('/simTime','std_msgs/Float32')
motorsSub = simExtRosInterface_subscribe('/cmd_vel','geometry_msgs/Twist','callback_MotorsVelocity')
--上面這三行會有錯誤,具體的函數請參考“4”中給出的參考資料
end
simAddStatusbarMessage("Simulation initialized")
end
if (sim_call_type == sim_childscriptcall_actuation) then
if notpluginNotFound then
retult,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 roInterfacePresent then
simExtRosInterface_shutdownPublisher(sensorPub)
simExtRosInterface_shutdownPublisher(simTimePub)
simExtRosInterface_shutdownSubscriber(motorsSub)
end
end
4/對於V-rep中謎一樣的LUA函數,實在是接受不能,好在找到了一個對這些函數、參數解釋比較詳細的地方,如下:
http://www.coppeliarobotics.com/helpFiles/en/rosPublisherTypes.htm
最後希望明天能順利搞明白更多的細節。。。。。。。。。。。。。。。。。。。。。。。。