
V-Rep:RosInterface
发布日期:2021-05-07 01:18:22
浏览次数:18
分类:原创文章
本文共 3139 字,大约阅读时间需要 10 分钟。
启用RosInterface
http://www.coppeliarobotics.com/helpFiles/en/rosTutorialIndigo.htm
- 打开终端执行
roscore
- 启动
vrep
当在终端看到下列代码即表示成功加载RosInterface插件
Plugin 'RosInterface': loading...Plugin 'RosInterface': load succeeded.
并且在终端输入以下命令应看到可用节点如下:
$ rosnode list/rosout/vrep_ros_interface
若没有成功加载,执行以下步骤:
- 在vrep安装目录下搜索l
ibv_repExtRosInterface.so
文件 - 将
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
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2025年03月28日 13时27分34秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Unity之PlayerPrefs
2019-03-05
简单的xml读取存储方法(未优化)
2019-03-05
Flower
2019-03-05
Nginx---惊群
2019-03-05
Redis未授权漏洞
2019-03-05
供应ASTM D3475认证丨ASTM D3475防儿童包装测试费用
2019-03-05
2种解法 - 获取一条直线上最多的点数
2019-03-05
项目中常用的审计类型概述
2019-03-05
新生儿不建议吃鱼肝油,这些你知道吗
2019-03-05
新生儿哭是因为什么
2019-03-05
基础知识
2019-03-05
nodeName与tagName的区别
2019-03-05
(九)实现页面底部购物车的样式
2019-03-05
在vue中给对象扩展属性的方法
2019-03-05
Neo4j : 通过节点的 id属性 对节点进行查,改,删操作
2019-03-05
Linux标准错误和标准输出重定向到同一个文件
2019-03-05
HTTP Status 404 – Not Found
2019-03-05