ros和vrep通信

ubantu 16/ros kinectic / vrep3.6.2
首先,打开一个终端,运行roscore
再打开一个终端,运行vrep

RosInterface加载成功

运行vrep自带Demo


代码

function sysCall_init()# 句柄robotHandle=sim.getObjectAssociatedWithScript(sim.handle_self)leftMotor=sim.getObjectHandle("rosInterfaceControlledBubbleRobLeftMotor") -- Handle of the left motorrightMotor=sim.getObjectHandle("rosInterfaceControlledBubbleRobRightMotor") -- Handle of the right motornoseSensor=sim.getObjectHandle("rosInterfaceControlledBubbleRobSensingNose") -- Handle of the proximity sensor-- Check if the required ROS plugin is there:# ros插件检测moduleName=0moduleVersion=0index=0pluginNotFound=truewhile moduleName domoduleName,moduleVersion=sim.getModuleName(index)if (moduleName=='RosInterface') thenpluginNotFound=falseendindex=index+1end-- Ok now launch the ROS client application:# 重要if (not pluginNotFound) thenlocal sysTime=sim.getSystemTimeInMs(-1) local leftMotorTopicName='leftMotorSpeed'..sysTime -- we add a random component so that we can have several instances of this robot runninglocal rightMotorTopicName='rightMotorSpeed'..sysTime -- we add a random component so that we can have several instances of this robot runninglocal sensorTopicName='sensorTrigger'..sysTime -- we add a random component so that we can have several instances of this robot runninglocal 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=simROS.advertise('/'..sensorTopicName,'std_msgs/Bool')simTimePub=simROS.advertise('/'..simulationTimeTopicName,'std_msgs/Float32')leftMotorSub=simROS.subscribe('/'..leftMotorTopicName,'std_msgs/Float32','setLeftMotorVelocity_cb')# 'setLeftMotorVelocity_cb'是回调函数名rightMotorSub=simROS.subscribe('/'..rightMotorTopicName,'std_msgs/Float32','setRightMotorVelocity_cb')-- Now we start the client application:result=sim.launchExecutable('rosBubbleRob2',leftMotorTopicName.." "..rightMotorTopicName.." "..sensorTopicName.." "..simulationTimeTopicName,0)elseprint("<font color='#F00'>ROS interface was not found. Cannot run.</font>@html")endend
function setLeftMotorVelocity_cb(msg)-- Left motor speed subscriber callback# msg.data是订阅的话题的消息sim.setJointTargetVelocity(leftMotor,msg.data)endfunction setRightMotorVelocity_cb(msg)-- Right motor speed subscriber callbacksim.setJointTargetVelocity(rightMotor,msg.data)end# 一个物体相对于另一个物体的坐标和四元数
function getTransformStamped(objHandle,name,relTo,relToName)t=sim.getSystemTime()p=sim.getObjectPosition(objHandle,relTo)o=sim.getObjectQuaternion(objHandle,relTo)return {header={stamp=t,frame_id=relToName},child_frame_id=name,transform={translation={x=p[1],y=p[2],z=p[3]},rotation={x=o[1],y=o[2],z=o[3],w=o[4]}}}end# 执行部分function sysCall_actuation()-- Send an updated sensor and simulation time message, and send the transform of the robot:if not pluginNotFound thenlocal result=sim.readProximitySensor(noseSensor)local detectionTrigger={}detectionTrigger['data']=result>0
# 发布消息到话题simROS.publish(sensorPub,detectionTrigger)simROS.publish(simTimePub,{data=sim.getSimulationTime()})-- Send the robot's transform:simROS.sendTransform(getTransformStamped(robotHandle,'rosInterfaceControlledBubbleRob',-1,'world'))-- To send several transforms at once, use simROS.sendTransforms insteadendendfunction sysCall_cleanup()if not pluginNotFound then-- Following not really needed in a simulation script (i.e. automatically shut down at simulation end):
# shutdown 节点simROS.shutdownPublisher(sensorPub)simROS.shutdownSubscriber(leftMotorSub)simROS.shutdownSubscriber(rightMotorSub)endend

simROS API

创建话题

往话题里发布数据

订阅话题

sim.launchExecutable

对应的执行文件在这里

leftmotor和rightmotor订阅的话题并不是在这个script里生成的,而是在rosBubbleRob2里生成的

如果使用自己定义的消息类型,需要去rosInterface中修改

function sysCall_init()robotHandle=sim.getObjectAssociatedWithScript(sim.handle_self)armJoints={-1,-1,-1,-1,-1,-1}for i=1,7,1 doarmJoints[i]=sim.getObjectHandle('j'..i)endmoduleName=0moduleVersion=0index=0pluginNotFound=truewhile moduleName domoduleName,moduleVersion=sim.getModuleName(index)if (moduleName=='RosInterface') thenpluginNotFound=falseendindex=index+1endif (not pluginNotFound) thenlocal Joint1TopicName='JointPosition_Publisher'-- JointSub=simROS.subscribe('/'..JointTopicName,'beginner_tutorials/JointTargetPosition','setJointPosition')#改成了std_msgs/Float32JointSub=simROS.subscribe('/'..Joint1TopicName,'std_msgs/Float32','setJointPosition')        -- result=sim.launchExecutable('rosBubbleRob2',leftMotorTopicName.." "..rightMotorTopicName.." "..sensorTopicName.." "..simulationTimeTopicName,0)elseprint("<font color='#F00'>ROS interface was not found. Cannot run.</font>@html")endendfunction setJointPosition(msg)    sim.setJointPosition(armJoints[1],msg.data)endfunction sysCall_actuation()-- Send an updated sensor and simulation time message, and send the transform of the robot:if not pluginNotFound then-- simROS.publish(sensorPub,detectionTrigger)endendfunction sysCall_cleanup()if not pluginNotFound thensimROS.shutdownSubscriber(JointSub)endend

#!/usr/bin/env pythonimport rospyimport mathfrom std_msgs.msg import Float32rospy.init_node('joint1targetpositionpublisher', anonymous=True)pub=rospy.Publisher('Joint1Position_Publisher', Float32, queue_size=10)rate = rospy.Rate(2)count = 0while not rospy.is_shutdown():msg = Float32()msg.data = count * math.pi/180rospy.loginfo(msg)pub.publish(msg)count = count + 1rate.sleep()

vrep教程(十一)通过rosInterface控制vrep中的机械臂相关推荐

  1. 对于STM32F103控制的三轴机械臂基本功能测试-关节转动控制

    ➤01 机械臂调试 1.简介 对于 基于STM32对于三轴机械臂控制器设计 的设计已经进行了如下的调试: 对于STM32F103三轴机械臂控制器进行基本功能测试-关节角度读取 对于STM32F103三 ...

  2. 使用 MoveIt 控制自己的真实机械臂【2】——编写 action server 端代码

    上一篇文章中, 使用 MoveIt 控制自己的真实机械臂[1]--配置 action client 端,已经完成了 MoveIt 这边 action client 的基本配置,MoveIt 理论上可以 ...

  3. 使用 MoveIt 控制自己的真实机械臂【3】——优化轨迹发给真实机械臂执行

    上一篇文章中,使用 MoveIt 控制自己的真实机械臂[2]--编写 action server 端代码,已经实现了 action server 端代码,并且拿到了 MoveIt 规划的轨迹数据.当然 ...

  4. 使用ROS MoveIt!控制真实五自由度机械臂

    文章目录 使用ROS MoveIt!控制diy五自由度机械臂 写在前面 修改功能包中相关文件 编写myrobot_controllers.yaml文件 修改launch文件 myrobot_drive ...

  5. MATLAB 中的机械臂算法——运动学

    MATLAB 中的机械臂算法--运动学 机械臂算法 MATLAB 在 2016 年就推出了 Robotics System Toolbox(RST),其中有很多关于机械臂方面的算法.而且随着客户需求的 ...

  6. 【机器人操作系统(ROS)中的机械臂仿真】

    [机器人操作系统(ROS)中的机械臂仿真] 1. 前言 2. 什么是机械臂? 3. 设计机械臂 4. 模型设计 5. 了解启动文件 6. 了解自定义节点 7. 运行机械臂模拟 8. 结果和结论 1. ...

  7. 基于stm32的视觉和蓝牙控制F407芯片智能机械臂控制小车

    1.项目概述: 本实验是通过手机APP通过蓝牙连接HC-05模块,向HC-05发送数据,HC-05蓝牙模块通过蓝牙接收到来自APP的数据并通过UART串口传输给STM32核心板,然后STM32通过PW ...

  8. 使用 MoveIt 控制自己的真实机械臂【4】——了解 MoveIt 的轨迹规划实现机制

    上一节中我们提到了一个planning request adapters 的概念,在这一节中我们将对其展开详细了解. planning request adapters 是运动规划中 Motion P ...

  9. 实验室中的机械臂-资料汇总

    本文不断完善和化学实验室分析机器人机械臂相关的资料和报道. ■ 相关网页报道 化学实验室中的可灵活移动的机器人 ▲ 登上Nature杂志封面的化学实验室的灵活机器人

  10. MoveIT和KDL中进行机械臂位置和姿态插值

    机械臂轨迹规划中,可以使用直线和圆弧规划,不同规划方式对应不同的计算方法.在MoveIT中,moveit_planners/pilz_industrial_motion_planner/src/下保存 ...

最新文章

  1. Ubuntu14.04上编译指定版本的protobuf源码操作步骤
  2. .NET面向上下文、AOP架构模式(实现)
  3. Linux学习笔记之文件管理和目录管理类命令
  4. BetaBot 木马分析
  5. 梦心日记本V2.0完工
  6. Update of SharePoint Me
  7. C++拷贝构造函数、深拷贝、浅拷贝
  8. LeetCode Guess Number Higher or Lower II(动态规划)
  9. Java并发编程:AbstractQueuedSynchronizer的内部结构
  10. 一图理解JavaWeb项目
  11. Exercise: Linear Regression
  12. SpringBoot非官方教程 | 第二篇:Spring Boot配置文件详解
  13. 安装程序无法继续 因为你的计算机安装了更新的,xp安装不了ie提示“安装了更新的Internet Explorer版本”怎么办...
  14. centos7上systemd详解
  15. Android蓝牙设备名显示修改
  16. vscode找不到config_vscode中的 jsconfig.json
  17. 数据机房温湿度检测物联网以太网传感器解决方案
  18. java日期格式_java日期和时间的格式化
  19. factorial函数
  20. CentOS7安装CA根证书

热门文章

  1. 解决vscode c++ 无法跳转代码(区别于大部分网上的解决方案)
  2. 电脑如何长截屏截图_您的意见很重要-截屏技术调查
  3. bcb dll返回字符_⑩的游戏修改小课堂4——HOOK、DLL注入与游戏乱码修正
  4. 正点原子stm32F407学习笔记3——蜂鸣器实验
  5. 支付路由技术概述以及简单的建设说明
  6. 中国证监会计算机专业考试试题,中国证监会计算机专业考试大纲
  7. 车厘子“爱马仕”之名不保?中国网红水果能否打开海外市场?
  8. Check It Again:论文整理
  9. Linux工具篇 | Ubuntu利用deepin-wine安装企业微信
  10. 智能对话机器人实战开发(1)- 体系结构和分类