V-Rep:RosInterface
发布日期:2021-05-07 01:18:22 浏览次数:18 分类:原创文章

本文共 3139 字,大约阅读时间需要 10 分钟。

启用RosInterface

http://www.coppeliarobotics.com/helpFiles/en/rosTutorialIndigo.htm

  1. 打开终端执行roscore
  2. 启动vrep

当在终端看到下列代码即表示成功加载RosInterface插件

Plugin 'RosInterface': loading...Plugin 'RosInterface': load succeeded.

并且在终端输入以下命令应看到可用节点如下:

$ rosnode list/rosout/vrep_ros_interface

若没有成功加载,执行以下步骤:

  1. 在vrep安装目录下搜索libv_repExtRosInterface.so文件
  2. ibv_repExtRosInterface.so文件放到安装目录的根目录即可

官方例程

可自行参阅
http://www.coppeliarobotics.com/helpFiles/en/rosTutorialIndigo.htm
应注意,在需要发布topic或者trasform等等有时间栈的东西时,应在前添加判断ROSInterface是否在该时间点运行
if simROS then
且应尽量使用sim.getSystemTime()输出时间栈,否则使用‘’‘simROS.getTime()```会使时间不一致(利用的ros::Time::now())
TODO:翻译例程步骤

API

主要使用一下API:

-- 发布器初始化pub=simROS.advertise('/image', 'sensor_msgs/Image')-- 订阅器初始化sub=simROS.subscribe('/image', 'sensor_msgs/Image', 'imageMessage_callback')-- 发布节点-- data为tables/array数据类型,亦为所需要发布的数据simROS.publish(pub,data)

类比ros

pub=n.advertise<sensor_msgs::Image>("/image",1);sub=n.subscriber("/image",1,imageMessage_callback);pub.publish(data);

可以从官方例程rosInterfaceTopicPublisherAndSubscriber.ttt里得代码,了解具体的使用方法

-- 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:---- simROS.imageTransportAdvertise-- simROS.imageTransportPublish-- simROS.imageTransportShutdownPublisher-- simROS.imageTransportShutdownSubscriber-- simROS.imageTransportSubscribefunction sysCall_init()            -- Get some handles:    -- 转臂上的摄像头    activeVisionSensor=sim.getObjectHandle('Vision_sensor')    -- 世界上的摄像头    passiveVisionSensor=sim.getObjectHandle('PassiveVision_sensor')        -- Enable an image publisher and subscriber:    -- 类似pub=n.advertise<sensor_msgs::Image>("/image",1);    pub=simROS.advertise('/image', 'sensor_msgs/Image')    -- 对发布器进行格式转换,使得数组转换为字符串,使通讯更快    simROS.publisherTreatUInt8ArrayAsString(pub) -- treat uint8 arrays as strings (much faster, tables/arrays are kind of slow in Lua)    -- 类似sub=n.subscriber("/image",1,imageMessage_callback);    sub=simROS.subscribe('/image', 'sensor_msgs/Image', 'imageMessage_callback')    -- 对发布器进行格式转换,使得数组转换为字符串,使通讯更快    simROS.subscriberTreatUInt8ArrayAsString(sub) -- treat uint8 arrays as strings (much faster, tables/arrays are kind of slow in Lua)    end-- 订阅者sub的回调函数function imageMessage_callback(msg)    -- Apply the received image to the passive vision sensor that acts as an image container    sim.setVisionSensorCharImage(passiveVisionSensor,msg.data)end-- 摄像头的回调函数function sysCall_sensing()    -- Publish the image of the active vision sensor:    local data,w,h=sim.getVisionSensorCharImage(activeVisionSensor)    -- 生成tables/arrays类型的数据类型,tables/arrays只要数据中的成员与希望的数据类型一致即可作成任何类型的数据类型。    -- 因此可以将tables/arrays类型看作数据载体    d={   }    d['header']={   seq=0,stamp=simROS.getTime(), frame_id="a"}    d['height']=h    d['width']=w    d['encoding']='rgb8'    d['is_bigendian']=1    d['step']=w*3    d['data']=data    simROS.publish(pub,d)endfunction sysCall_cleanup()    -- Shut down publisher and subscriber. Not really needed from a simulation script (automatic shutdown)    simROS.shutdownPublisher(pub)    simROS.shutdownSubscriber(sub)end
上一篇:多线程的伪共享
下一篇:R语言环境配置及首个例程

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年03月28日 13时27分34秒