• Ubuntu 14.04 上安装V-rep 3.4.0

  进入VREP官网下载Linux版本的V-rep(注意V-rep 3.4.0只有64位的版本,因此操作系统也要与之对应,Ubuntu 32位系统就无法运行V-rep 3.4。如果想使用以前的V-rep版本,可以进入这个网址下载)

  将下载的压缩文件解压后放到合适的位置,进入该目录下,执行sh脚本文件打开V-rep程序:

./vrep.sh

  VREP与ROS的连接主要有三种方法:

  1. The RosInterface: RosInterface是V-rep官方推荐的用来跟ROS通信的插件(We highly recommend you to first try your hands on the RosInterface, since this is the most flexible and natural approach)
  2. The ROS plugin skeleton: 可以让用户实现特定功能的ROS插件框架(This represents a skeleton project that can be used to create a new ROS plugin for V-REP / create your own specific ROS plugin for V-REP. e.g. to support ROS messages for a specific robot)
  3. ROS interfaces developed by others: 其他非V-rep官方支持的通信接口,比如V-REP ROS bridge.

RosInterface

  将VREP安装路径下的compiledRosPlugins文件夹中的libv_repExtRosInterface.so或libv_repExtRosSkeleton.so库复制到上层目录(VREP安装目录)中:

  然后在终端中运行roscore开启ROS master,接着执行vrep.sh脚本打开VREP,打开过程中会导入插件。可以看到RosInterface插件已经成功加载:

  开启一个新终端,输入rosnode list查看运行的ros节点。可以看到除了ros master以外vrep_ros_interface也成功运行:

  如果插件没能成功导入(我使用的ROS Indigo版本没遇到这种情况,但是ROS Kinetic会出错),则需要自己重新编译库文件。编译所需的几个package位于VREP安装目录的programming/ros_packages下,将其复制到自己的catkin_ws/src中,用catkin工具进行编译。具体步骤可以参照帮助文件中的ROS tutorial - Indigo页面或者文件夹中的ros_vrep_rosinterface_install_guide.txt安装说明。编译成功后将生成的.so库文件复制到V-rep安装目录中即可。

  下面看一个简单的例子。在场景中选择一个物体添加一个non-threaded脚本,这个脚本会发布仿真时间然后自己订阅它,并且还会发布坐标变换消息:

function subscriber_callback(msg)
-- This is the subscriber callback function
simAddStatusbarMessage('subscriber receiver following Float32: '..msg.data)
end function getTransformStamped(objHandle,name,relTo,relToName)
-- This function retrieves the stamped transform for a specific object
t=simGetSystemTime()
p=simGetObjectPosition(objHandle,relTo)
o=simGetObjectQuaternion(objHandle,relTo)
return {
header={
stamp=t,
frame_id=relToName
},
child_frame_id=name,
transform={
translation={x=p[],y=p[],z=p[]},
rotation={x=o[],y=o[],z=o[],w=o[]}
}
}
end if (sim_call_type==sim_childscriptcall_initialization) then
-- The child script initialization
objectHandle=simGetObjectAssociatedWithScript(sim_handle_self)
objectName=simGetObjectName(objectHandle)
-- Check if the required RosInterface is there:
moduleName=
index=
rosInterfacePresent=false
while moduleName do
moduleName=simGetModuleName(index)
if (moduleName=='RosInterface') then
rosInterfacePresent=true
end
index=index+
end -- Prepare the float32 publisher and subscriber (we subscribe to the topic we advertise):
if rosInterfacePresent then
publisher=simExtRosInterface_advertise('/simulationTime','std_msgs/Float32')
subscriber=simExtRosInterface_subscribe('/simulationTime','std_msgs/Float32','subscriber_callback')
end
end if (sim_call_type==sim_childscriptcall_actuation) then
-- Send an updated simulation time message, and send the transform of the object attached to this script:
if rosInterfacePresent then
simExtRosInterface_publish(publisher,{data=simGetSimulationTime()})
simExtRosInterface_sendTransform(getTransformStamped(objectHandle,objectName,-,'world'))
-- To send several transforms at once, use simExtRosInterface_sendTransforms instead
end
end if (sim_call_type==sim_childscriptcall_cleanup) then
-- Following not really needed in a simulation script (i.e. automatically shut down at simulation end):
if rosInterfacePresent then
simExtRosInterface_shutdownPublisher(publisher)
simExtRosInterface_shutdownSubscriber(subscriber)
end
end

  终端中输入rostopic list指令查看话题:

  为了查看消息的内容,可以输入:

$ rostopic echo /simulationTime

  脚本中主要用到下面几个函数:

  • simExtRosInterface_advertise

  • simExtRosInterface_subscribe

  • simExtRosInterface_publish

  • simExtRosInterface_sendTransform

rosInterfaceTopicPublisherAndSubscriber

  在V-rep自带的例子中还有一个场景模型"rosInterfaceTopicPublisherAndSubscriber.ttt",脚本代码中会发布视觉传感器捕获的图像信息到/image话题上,同时会自己订阅这个信息并显示出来。

-- This illustrates how to publish and subscribe to an image using the ROS Interface.
-- An alternate version using image transport can be created with following functions:
--
-- simExtRosInterface_imageTransportAdvertise
-- simExtRosInterface_imageTransportPublish
-- simExtRosInterface_imageTransportShutdownPublisher
-- simExtRosInterface_imageTransportShutdownSubscriber
-- simExtRosInterface_imageTransportSubscribe function imageMessage_callback(msg)
-- Apply the received image to the passive vision sensor that acts as an image container
simSetVisionSensorCharImage(passiveVisionSensor,msg.data)
end if (sim_call_type==sim_childscriptcall_initialization) then
-- Get some handles:
activeVisionSensor=simGetObjectHandle('Vision_sensor')
passiveVisionSensor=simGetObjectHandle('PassiveVision_sensor') -- Enable an image publisher and subscriber:
pub=simExtRosInterface_advertise('/image', 'sensor_msgs/Image')
--After calling this function, this publisher will treat uint8 arrays as string. Using strings should be in general much faster that using int arrays in Lua.
simExtRosInterface_publisherTreatUInt8ArrayAsString(pub) -- treat uint8 arrays as strings (much faster, tables/arrays are kind of slow in Lua) sub=simExtRosInterface_subscribe('/image', 'sensor_msgs/Image', 'imageMessage_callback')
simExtRosInterface_subscriberTreatUInt8ArrayAsString(sub) -- treat uint8 arrays as strings (much faster, tables/arrays are kind of slow in Lua)
end if (sim_call_type==sim_childscriptcall_sensing) then
-- Publish the image of the active vision sensor:
local data,w,h=simGetVisionSensorCharImage(activeVisionSensor)
d={}
d['header']={seq=,stamp=simExtRosInterface_getTime(), frame_id="a"}
d['height']=h
d['width']=w
d['encoding']='rgb8'
d['is_bigendian']=
d['step']=w*
d['data']=data
simExtRosInterface_publish(pub,d)
end if (sim_call_type==sim_childscriptcall_cleanup) then
-- Shut down publisher and subscriber. Not really needed from a simulation script (automatic shutdown)
simExtRosInterface_shutdownPublisher(pub)
simExtRosInterface_shutdownSubscriber(sub)
end

  可以在终端中输入下面的命令来显示/image话题的图像:

$ rosrun image_view image_view image:=/image

  在rviz中添加Image,将话题选为/image也可以查看图像信息:

 controlTypeExamples

  还有一个例子是controlTypeExamples.ttt,V-rep中的脚本负责发布接近传感器的信息以及仿真时间并订阅左右轮驱动的话题。外部的ros程序rosBubbleRob2根据接收到的传感器信息生成左右轮速度指令,并发布出去,V-rep中订阅后在回调函数里控制左右轮关节转动。

  V-rep中脚本代码如下:

function setLeftMotorVelocity_cb(msg)

    -- Left motor speed subscriber callback

    simSetJointTargetVelocity(leftMotor,msg.data)

end

function setRightMotorVelocity_cb(msg)

    -- Right motor speed subscriber callback

    simSetJointTargetVelocity(rightMotor,msg.data)

end

function getTransformStamped(objHandle,name,relTo,relToName)

    t=simGetSystemTime()

    p=simGetObjectPosition(objHandle,relTo)

    o=simGetObjectQuaternion(objHandle,relTo)

    return {

        header={

            stamp=t,

            frame_id=relToName

        },

        child_frame_id=name,

        transform={

            translation={x=p[],y=p[],z=p[]},

            rotation={x=o[],y=o[],z=o[],w=o[]}

        }

    }

end

if (sim_call_type==sim_childscriptcall_initialization) then

    robotHandle=simGetObjectAssociatedWithScript(sim_handle_self)

    leftMotor=simGetObjectHandle("rosInterfaceControlledBubbleRobLeftMotor") -- Handle of the left motor

    rightMotor=simGetObjectHandle("rosInterfaceControlledBubbleRobRightMotor") -- Handle of the right motor

    noseSensor=simGetObjectHandle("rosInterfaceControlledBubbleRobSensingNose") -- Handle of the proximity sensor

    -- Check if the required ROS plugin is there:

    moduleName=

    moduleVersion=

    index=

    pluginNotFound=true

    while moduleName do

        moduleName,moduleVersion=simGetModuleName(index)

        if (moduleName=='RosInterface') then

            pluginNotFound=false

        end

        index=index+

    end

    -- Add a banner:

    if (pluginNotFound) then

        bannerText="I cannot run! (I couldn't find my RosInterface plugin)"

    else

        bannerText="I am controlled via a ROS node and the RosInterface! ('rosBubbleRob2' controlls me)"

    end

    black={,,,,,,,,,,,}

    red={,,,,,,,,,,0.2,0.2}

    simAddBanner(bannerText,,sim_banner_bitmapfont+sim_banner_overlay,nil,simGetObjectAssociatedWithScript(sim_handle_self),black,red)

    -- Ok now launch the ROS client application:

    if (not pluginNotFound) then

        local sysTime=simGetSystemTimeInMs(-) 

        local leftMotorTopicName='leftMotorSpeed'..sysTime -- we add a random component so that we can have several instances of this robot running

        local rightMotorTopicName='rightMotorSpeed'..sysTime -- we add a random component so that we can have several instances of this robot running

        local sensorTopicName='sensorTrigger'..sysTime -- we add a random component so that we can have several instances of this robot running

        local simulationTimeTopicName='simTime'..sysTime -- we add a random component so that we can have several instances of this robot running

        -- Prepare the sensor publisher and the motor speed subscribers:

        sensorPub=simExtRosInterface_advertise('/'..sensorTopicName,'std_msgs/Bool')

        simTimePub=simExtRosInterface_advertise('/'..simulationTimeTopicName,'std_msgs/Float32')

        leftMotorSub=simExtRosInterface_subscribe('/'..leftMotorTopicName,'std_msgs/Float32','setLeftMotorVelocity_cb')

        rightMotorSub=simExtRosInterface_subscribe('/'..rightMotorTopicName,'std_msgs/Float32','setRightMotorVelocity_cb')

        -- Now we start the client application:

        result=simLaunchExecutable('rosBubbleRob2',leftMotorTopicName.." "..rightMotorTopicName.." "..sensorTopicName.." "..simulationTimeTopicName,)

    end

end

if (sim_call_type==sim_childscriptcall_actuation) then

    -- Send an updated sensor and simulation time message, and send the transform of the robot:

    if not pluginNotFound then

        local result=simReadProximitySensor(noseSensor)

        local detectionTrigger={}

        detectionTrigger['data']=result>

        simExtRosInterface_publish(sensorPub,detectionTrigger)

        simExtRosInterface_publish(simTimePub,{data=simGetSimulationTime()})

        -- Send the robot's transform:

        simExtRosInterface_sendTransform(getTransformStamped(robotHandle,'rosInterfaceControlledBubbleRob',-,'world'))

        -- To send several transforms at once, use simExtRosInterface_sendTransforms instead

    end

end

if (sim_call_type==sim_childscriptcall_cleanup) then

    if not pluginNotFound then

        -- Following not really needed in a simulation script (i.e. automatically shut down at simulation end):

        simExtRosInterface_shutdownPublisher(sensorPub)

        simExtRosInterface_shutdownSubscriber(leftMotorSub)

        simExtRosInterface_shutdownSubscriber(rightMotorSub)

    end

end

rosInterface helper tool

  在模型浏览器的tools文件夹中有一个RosInterface的帮助工具,将其拖入场景中可以方便实现一些控制功能。

  主要有下面一些功能:

  • startSimulation topic: can be used to start a simulation by publishing on this topic a std_msgs::Bool message.
  • pauseSimulation topic: can be used to pause a simulation by publishing on this topic a std_msgs::Bool message.
  • stopSimulation topic: can be used to stop a simulation by publishing on this topic a std_msgs::Bool message.
  • enableSyncMode topic: by publishing a std_msgs::Bool message on this topic, you can enable/disable the synchronous simulation mode.
  • triggerNextStep topic: by publishing a std_msgs::Bool message on this topic, you can trigger the next simulation step, while in the synchronous simulation mode.
  • simulationStepDone topic: a message of type std_msgs::Bool will be published at the end of each simulation pass.
  • simulationState topic: messages of type std_msgs::Int32 will be published on a regular basis. 0 indicates that the simulation is stopped, 1 that it is running and 2 that it is paused.
  • simulationTime topic: messages of type std_msgs::Float32 will be published on a regular basis, indicating the current simulation time.

  可以在终端中输入下面的一些命令进行测试:

$ rostopic pub /startSimulation std_msgs/Bool true --once
$ rostopic pub /pauseSimulation std_msgs/Bool true --once
$ rostopic pub /stopSimulation std_msgs/Bool true --once
$ rostopic pub /enableSyncMode std_msgs/Bool true --once $ rostopic pub /triggerNextStep std_msgs/Bool true --once

  比如在终端中输入:rostopic pub /startSimulation std_msgs/Bool true --once, 就可以开始仿真,跟手动点击仿真按钮效果一样。

参考:

vrep_ros_bridge

Ros与Vrep平台搭建

机器人操作系统ROS(indigo)与三维仿真软件V-Rep(3.2.1)通信接口使用笔记

从零开始的仿真之旅——在Ubuntu下配置V-Rep仿真平台下的搭载ROS系统的机器人仿真

V-rep学习笔记:ROSInterface的更多相关文章

  1. R语言与机器学习学习笔记

    人工神经网络(ANN),简称神经网络,是一种模仿生物神经网络的结构和功能的数学模型或计算模型.神经网络由大量的人工神经元联结进行计算.大多数情况下人工神经网络能在外界信息的基础上改变内部结构,是一种自 ...

  2. 蒟蒻的长链剖分学习笔记(例题:HOTEL加强版、重建计划)

    长链剖分学习笔记 说到树的链剖,大多数人都会首先想到重链剖分.的确,目前重链剖分在OI中有更加多样化的应用,但它大多时候是替代不了长链剖分的. 重链剖分是把size最大的儿子当成重儿子,顾名思义长链剖 ...

  3. KD-Tree 学习笔记

    这是一篇又长又烂的学习笔记,请做好及时退出的准备. KD-Tree 的复杂度大概是 \(O(n^{1-\frac{1}{k}})\) \(k\) 是维度 由于网上找不到靠谱的证明,咕了. 会证明之后再 ...

  4. 「学习笔记」FFT 快速傅里叶变换

    目录 「学习笔记」FFT 快速傅里叶变换 啥是 FFT 呀?它可以干什么? 必备芝士 点值表示 复数 傅立叶正变换 傅里叶逆变换 FFT 的代码实现 还会有的 NTT 和三模数 NTT... 「学习笔 ...

  5. CF1147F Zigzag Game & 稳定婚姻问题学习笔记

    CF1147F Zigzag Game 这题太神仙了,不得不记录一下. 我网络流做不动了,DS做不动了,DP做不动了,特别自闭.于是博弈论之神(就是随手切3500博弈的那种) \(\color{bla ...

  6. DirectX Graphics Infrastructure(DXGI):最佳范例 学习笔记

    今天要学习的这篇文章写的算是比较早的了,大概在DX11时代就写好了,当时龙书11版看得很潦草,并没有注意这篇文章,现在看12,觉得是跳不过去的一篇文章,地址如下: https://msdn.micro ...

  7. Sass学习笔记之入门篇

    Sass又名SCSS,是CSS预处理器之一,,它能用来清晰地.结构化地描述文件样式,有着比普通 CSS 更加强大的功能. Sass 能够提供更简洁.更优雅的语法,同时提供多种功能来创建可维护和管理的样 ...

  8. react-native学习笔记--史上最详细Windows版本搭建安装React Native环境配置

    参考:http://www.lcode.org/react-native/ React native中文网:http://reactnative.cn/docs/0.23/android-setup. ...

  9. swift学习笔记5——其它部分(自动引用计数、错误处理、泛型...)

    之前学习swift时的个人笔记,根据github:the-swift-programming-language-in-chinese学习.总结,将重要的内容提取,加以理解后整理为学习笔记,方便以后查询 ...

  10. Oracle学习笔记三 SQL命令

    SQL简介 SQL 支持下列类别的命令: 1.数据定义语言(DDL) 2.数据操纵语言(DML) 3.事务控制语言(TCL) 4.数据控制语言(DCL)  

随机推荐

  1. Java遍历对象所有属性

    要获取对象的所有属性可以使用getDeclaredFields()方法会返回一个Field数组遍历这个数组几个遍历所有属性注意使用这个方法会抛出4个异常然后根据属性的类型选择执行对应的内容 publi ...

  2. LaTeX技巧205:使用split输入多行公式技巧

    我们在输入多行公式的时候,split,array,multiline,align,aligned等等都是我们可以选用的环境,这里介绍split的使用方法.演示效果图: 演示代码:\documentcl ...

  3. arcsde10 postgresql8.3 服务停止问题

    ---恢复内容开始--- arcsde10 安装在windows server2008 R2 X64 上. 从.gdb文件数据库 拷贝40W多的数据到ArcSDE ,然后postgresql就停止了, ...

  4. dubbo源码解析-spi(4)

    前言 本篇是spi的第四篇,本篇讲解的是spi中增加的AOP,还是和上一篇一样,我们先从大家熟悉的spring引出AOP. AOP是老生常谈的话题了,思想都不会是一蹴而就的.比如架构设计从All in ...

  5. 数据库实例: STOREBOOK > 用户 > 编辑 用户: SYSMAN

    ylbtech-Oracle:数据库实例: STOREBOOK  >  用户  >  编辑 用户: SYSMAN 编辑 用户: SYSMAN 1. 一般信息返回顶部 1.1,   1.2, ...

  6. 第三章 消息摘要算法--MD5

    注意:本节内容主要参考自<Java加密与解密的艺术(第2版)>第6章“验证数据完整性--消息摘要算法” 3.1.消息摘要算法:防止消息在传递过程中被篡改. 原理:任何消息经过消息摘要算法后 ...

  7. WPF中使用流文档

    转载自:http://www.cnblogs.com/zlgcool/archive/2008/11/17/1335456.html WPF面向的是UI展现,而文本显示无疑是UI层中的重要功能之一.W ...

  8. iOS开发-16进制颜色转换

    项目中经常会用到颜色转换,有的是通过十六进制转成数字转颜色,想简单的点直接通过字符串转一下,简单扩展了一下分类UIColor,代码如下: +(UIColor *)colorWithHex:(NSStr ...

  9. css3 animation 学习

    css3中可以实现动画效果,主要是通过css3中新增加的属性(transform , transition,animation )来完成. 他们的详细解释可以参考 W3CSCHOOL 下面是效果图: ...

  10. Datetimepicker配置参数

    jquery的datetimepicker时间控件除了样式有点不太美观,功能性还是相当强大的. 在正常情况下input的type应该设置为"text",可点击又可输入(mask,e ...