CoppeliaSim学习笔记之CoppeliaSim Edu V4.1.0 + Ubuntu 16.04 + ROS Kinetic环境搭建与基础测试

本文主要是介绍CoppeliaSim学习笔记之CoppeliaSim Edu V4.1.0 + Ubuntu 16.04 + ROS Kinetic环境搭建与基础测试,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • 1. 环境搭建
  • 2. 基础测试
  • 3. 自定义消息/服务编译使用


1. 环境搭建

  Ubuntu系统的安装在此不做介绍,网上一搜一箩筐。ROS Kinetic的安装直接参考wiki就行。CoppeliaSim 安装也比较简单,直接官网下载(以7月21日新鲜刚出炉的CoppeliaSim Edu V4.1.0 为例),具体版本根据用户而定,博主使用CoppeliaSim_Edu_V4_1_0_Ubuntu16_04,ROS Kinetic,如果嫌官网下载太慢或者想下载其他版本的话,可以使用博主分享的百度云链接:(注意区分系统)

  • CoppeliaSim_Edu_V4_2_0_Ubuntu16_04 提取码: i9c5
  • CoppeliaSim_Edu_V4_1_0_Ubuntu16_04 提取码: g9gi
  • CoppeliaSim_Edu_V4_0_0_Ubuntu16_04 提取码: afqu
  • V-REP_PRO_EDU_V3_6_2_Ubuntu16_04 提取码: x8u5
  • CoppeliaSim_Edu_V4_2_0_Ubuntu18_04 提取码:9s3o
  • CoppeliaSim_Edu_V4_1_0_Ubuntu18_04 提取码: 2g3s
  • CoppeliaSim_Edu_V4_0_0_Ubuntu18_04 提取码: 3s5f
  • V-REP_PRO_EDU_V3_6_2_Ubuntu18_04 提取码: wci8
  • CoppeliaSim_Edu_V4_2_0_Ubuntu20_04 提取码: 9wg3
  • CoppeliaSim_Edu_V4_1_0_Ubuntu20_04 提取码: qdum
  • CoppeliaSim_Edu_V4_2_0_macOS10_15 提取码: fuw4
  • CoppeliaSim_Edu_V4_1_0_Mac 提取码:pfqw
      下载完成后执行指令tar -xvf CoppeliaSim_Edu_V4_1_0_Ubuntu16_04.tar解压,进入CoppeliaSim_Edu_V4_1_0_Ubuntu16_04文件夹下,即可运行 ./coppeliaSim.sh
    在这里插入图片描述

  但此时CoppeliaSim并不能与ROS进行通信。需要搭建bridge,参考CoppeliaRobotics Github git clone --recursive https://github.com/CoppeliaRobotics/simExtROSInterface.git sim_ros_interface 下载simExtROSInterface 并重命名为 sim_ros_interface,下载位置与CoppeliaSim_Edu_V4_1_0_Ubuntu16_04放一个父文件夹下就行,相互之间也能有个照应,打架也能帮个忙。目录如下

在这里插入图片描述

# mkdir workspcace 
mkdir -p sim_ws/src
# CoppeliaSim_Edu_V4_1_0_Ubuntu16_04_path 为CoppeliaSim_Edu_V4_1_0_Ubuntu16_04的下载路径 需要根据用户路径修改
cp CoppeliaSim_Edu_V4_1_0_Ubuntu16_04_path/CoppeliaSim_Edu_V4_1_0_Ubuntu16_04.tar ~/sim_ws/src
cd ~/sim_ws/src
# unzip CoppeliaSim
tar -xvf CoppeliaSim_Edu_V4_1_0_Ubuntu16_04.tar
# download sim_ros_interface   -- bridge
git clone --recursive https://github.com/CoppeliaRobotics/simExtROSInterface.git sim_ros_interface
## 注意: 我电脑的环境大多依赖的python2,而从coppeliaSim V4.1.0的CMakeLists.txt中可知道其依赖的python3,coppeliaSim V4.0.0依赖的python2,所以在此我使用V4.0.0版本的sim_ros_interface,否则会报一堆类似于没有 rospkg的问题
cd sim_ros_interface
git checkout coppeliasim-v4.0.0
# change directory to sim_ws
cd ~/sim_ws
# compile
catkin build -j4

在这里插入图片描述

  根据Errors信息需要添加环境变量COPPELIASIM_ROOT_DIR,系统默认使用的是bash shell,在~/.bashrc末尾添加export COPPELIASIM_ROOT_DIR=/home/lyz/sim_ws/src/CoppeliaSim_Edu_V4_1_0_Ubuntu16_04/(具体路径根据自己的CoppeliaSim路径而定)。确认环境变量添加成功

source ~/.bashrc
env | grep ROOT
>>> COPPELIASIM_ROOT_DIR=/home/lyz/sim_ws/src/CoppeliaSim_Edu_V4_1_0_Ubuntu16_04/

注意:

  a. 编译错误一:有可能报ros依赖库的错误,直接安装即可。

sudo apt-get install ros-kinetic-brics-actuator
sudo apt-get install ros-kinetic-tf2-sensor-msgs

  b. 编译错误二:有可能报compile error。 generate.py line102 runprogram('xsltproc', '-o', output('reference.html'), rel('xsl/reference.xsl'), input_xml)的问题。

sudo apt-get install xsltproc 

  c. 编译错误三:CoppeliaSim V4.1.0依赖python3,如果系统用的python2会报无rospkg等问题。

  可以使用V4.0.0的sim_ros_interface。git checkout coppeliasim-v4.0.0

  接下来重新编译catkin build -j4,编译完成后将devel/lib下的libsimExtROSInterface.so复制到CoppeliaSim_Edu_V4_1_0_Ubuntu16_04文件夹下,这样每次启动CoppeliaSim时都会自动导入*.so,导入的同时还会验证ROS master有没有启动,若没有启动日志中会包含如下错误。

[CoppeliaSim:error]   plugin 'ROSInterface': load failed (failed initialization).

  正常运行roscore,再运行CoppeliaSim,执行rosnode list会有如下显示

$ rosnode list
/rosout
/vrep_ros_interface

  除此之外,ROS与CoppeliaSim连接也可直接参考官网帮助文档或者我的翻译教程。到这里ROS与CoppeliaSim之间的bridge基本配置完成,可以打开CoppeliaSim提供的ROS相关场景进行测试。

2. 基础测试

  • 拿CoppeliaSim自带的ros场景rosInterfaceTopicPublisherAndSubscriber.ttt进行ros消息publish测试,打开scene之后直接点界面上的右三角或者用快捷键Ctrl+Space仿真运行。

在这里插入图片描述
在这里插入图片描述
  出现了topic /image,使用命令rosrun image_view image_view image:=/image查看摄像头图像

在这里插入图片描述

  测试由CoppeliaSim发布摄像头图像数据成功。

  • 拿场景controlledViaRos.ttt测试CoppeliaSim端订阅ros topic并响应。(打开场景后需要注释rosInterfaceControlledBubbleRob脚本第20行
    --result=sim.launchExecutable('rosBubbleRob2',leftMotorTopicName.." "..rightMotorTopicName.." "..sensorTopicName.." "..simulationTimeTopicName,0),否则BubbleRob会一直按照随机发布的左右轮速度运动)

在这里插入图片描述

  左轮发布速度 rostopic pub /leftMotorSpeed2497435 std_msgs/Float32 "data: 1.0",BubbleRob开始以右轮为中心转圈。
在这里插入图片描述
  至此Ubuntu上CoppeliaSim/ROS之间的topic发布和订阅均已经测试通过,接下来可以按照自己想法浪一把了。

3. 自定义消息/服务编译使用

  • CoppeliaSim

  创建自定义消息包test_msgs,消息名称为Notification.msg catkin_create_pkg test_msgs roscpp rospy std_msgs message_generation

# Notification.msg
string messages

  修改test_msgs包 CMakeLists.txt、package.xml。

## CMakeLists.txt 添加Notification.msg
find_package(catkin REQUIRED COMPONENTSroscpprospystd_msgsmessage_generation
)add_message_files(FILESNotification.msg
#   Message1.msg
#   Message2.msg)generate_messages(DEPENDENCIESstd_msgs)## package.xml 取消以下两行注释
<build_export_depend>message_generation</build_export_depend>
<exec_depend>message_runtime</exec_depend>

  修改sim_ros_interface包CMakeLists.txt、package.xml、meta/messages.txt。

## CMakeLists.txt
set(PKG_DEPSroscpprosconsolecv_bridgeimage_transporttfroslibactionlib_msgscontrol_msgsdiagnostic_msgsgeometry_msgsmap_msgsnav_msgspcl_msgssensor_msgsshape_msgsstd_msgstf2_geometry_msgstf2_msgstf2_sensor_msgs                                                                                                                                                                            trajectory_msgsvisualization_msgstest_msgs # 自定义消息包)
## package.xml
<package format="2"><name>sim_ros_interface</name><description>CoppeliaSim plugin for ROS interface</description><maintainer email="marc@coppeliarobotics.com">Marc</maintainer><version>3.3.0</version><author>Federico Ferri</author><license>BSD2</license><url>http://www.coppeliarobotics.com</url><buildtool_depend>catkin</buildtool_depend><depend>roscpp</depend><depend>rosmsg</depend><depend>libopencv-dev</depend><depend>cv_bridge</depend><depend>image_transport</depend><depend>tf</depend><depend>actionlib_msgs</depend><depend>control_msgs</depend><depend>diagnostic_msgs</depend><depend>geometry_msgs</depend><depend>map_msgs</depend><depend>nav_msgs</depend><depend>pcl_msgs</depend><depend>sensor_msgs</depend><depend>shape_msgs</depend><depend>std_msgs</depend><depend>tf2_geometry_msgs</depend><depend>tf2_msgs</depend><depend>tf2_sensor_msgs</depend><depend>trajectory_msgs</depend><depend>visualization_msgs</depend><depend>rosconsole</depend><depend>roslib</depend><depend>test_msgs</depend>  <!--自定义消息包-->                                         
</package>
## messages.txt 最后添加
test_msgs/Notification

  catkin build -j4 编译两个包,然后拷贝libcp ~/sim_ws/devel/lib/libsimExtROSInterface.so ~/sim_ws/src/CoppeliaSim_Edu_V4_1_0_Ubuntu16_04

  最后按正常顺序 roscore ./coppeliaSim.sh启动。以 CoppeliaSim 软件自带的 controlledViaRos.ttt为例,测试发布自定义消息类型为test_msgs/Notification的话题 /notifications。

-- 注释中带新添加字样的为测试自定义消息类型添加
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-- Launch the ROS client application:if simROS thensim.addLog(sim.verbosity_scriptinfos,"ROS interface was found.")local 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')rightMotorSub=simROS.subscribe('/'..rightMotorTopicName,'std_msgs/Float32','setRightMotorVelocity_cb')notificationPub=simROS.advertise('/notifications', 'test_msgs/Notification')   -- 新添加-- Now we start the client application:result=sim.launchExecutable('rosBubbleRob',leftMotorTopicName.." "..rightMotorTopicName.." "..sensorTopicName.." "..simulationTimeTopicName,0)elsesim.addLog(sim.verbosity_scripterrors,"ROS interface was not found. Cannot run.")endend
function setLeftMotorVelocity_cb(msg)-- Left motor speed subscriber callbacksim.setJointTargetVelocity(leftMotor,msg.data)
endfunction setRightMotorVelocity_cb(msg)-- Right motor speed subscriber callbacksim.setJointTargetVelocity(rightMotor,msg.data)
endfunction 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]}}}
endfunction sysCall_actuation()-- Send an updated sensor and simulation time message, and send the transform of the robot:if simROS thenlocal result=sim.readProximitySensor(noseSensor)local detectionTrigger={}detectionTrigger['data']=result>0simROS.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 insteadlocal robot_notification={}  -- 新添加robot_notification['messages'] = 'ok'  -- 新添加simROS.publish(notificationPub, robot_notification)  -- 新添加end
endfunction sysCall_cleanup()if simROS then-- Following not really needed in a simulation script (i.e. automatically shut down at simulation end):simROS.shutdownPublisher(sensorPub)simROS.shutdownSubscriber(leftMotorSub)simROS.shutdownSubscriber(rightMotorSub)simROS.shutdownPublisher(notificationPub) -- 新添加end
end
source ~/sim_ws/devel/setup.bash 
rostopic echo /notifications 打印话题

在这里插入图片描述

打印topic有信息证明自定义消息添加成功。

  • V-REP 3.6

  与CoppeliaSim步骤一样,不过修改的软件包不是sim_ros_interface,而是vrep_ros_interface。

  • V-REP 3.4
    • cp V-rep directory/programming/ros_packages/v_repExtRosInterface 和自定义消息包到工作空间,修改v_repExtRosInterface 文件夹package.xml、CMakeLists.txt 和meta/messages.txt;
    • messages.txt添加新消息,如 test_msgs/Notification
    • package.xml添加 <build_depend>test_msgs</build_depend> <run_depend>test_msgs</run_depend>
    • CMakeLists.txt添加
find_package(catkin REQUIRED COMPONENTSroscpp rosmsg image_transport tf cv_bridge test_msgs
)
catkin_package(CATKIN_DEPENDS test_msgs)

编译完成之后,将devel/lib/*.so复制到V-rep,覆盖以前的*.so。

注意:

  V-rep 3.4不存在单独的vrep_ros_interface包,它是将其集成在V-rep文件夹中,主要在programming/ros_packages下,所以针对ros做的操作包括新消息类型、服务类型的添加都在此。

至此仿真环境与ROS的bridge搭建、测试基本完成,接下来进行仿真环境和小车模型的搭建。

这篇关于CoppeliaSim学习笔记之CoppeliaSim Edu V4.1.0 + Ubuntu 16.04 + ROS Kinetic环境搭建与基础测试的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/762017

相关文章

ESP32 esp-idf esp-adf环境安装及.a库创建与编译

简介 ESP32 功能丰富的 Wi-Fi & 蓝牙 MCU, 适用于多样的物联网应用。使用freertos操作系统。 ESP-IDF 官方物联网开发框架。 ESP-ADF 官方音频开发框架。 文档参照 https://espressif-docs.readthedocs-hosted.com/projects/esp-adf/zh-cn/latest/get-started/index

51单片机学习记录———定时器

文章目录 前言一、定时器介绍二、STC89C52定时器资源三、定时器框图四、定时器模式五、定时器相关寄存器六、定时器练习 前言 一个学习嵌入式的小白~ 有问题评论区或私信指出~ 提示:以下是本篇文章正文内容,下面案例可供参考 一、定时器介绍 定时器介绍:51单片机的定时器属于单片机的内部资源,其电路的连接和运转均在单片机内部完成。 定时器作用: 1.用于计数系统,可

问题:第一次世界大战的起止时间是 #其他#学习方法#微信

问题:第一次世界大战的起止时间是 A.1913 ~1918 年 B.1913 ~1918 年 C.1914 ~1918 年 D.1914 ~1919 年 参考答案如图所示

[word] word设置上标快捷键 #学习方法#其他#媒体

word设置上标快捷键 办公中,少不了使用word,这个是大家必备的软件,今天给大家分享word设置上标快捷键,希望在办公中能帮到您! 1、添加上标 在录入一些公式,或者是化学产品时,需要添加上标内容,按下快捷键Ctrl+shift++就能将需要的内容设置为上标符号。 word设置上标快捷键的方法就是以上内容了,需要的小伙伴都可以试一试呢!

Tolua使用笔记(上)

目录   1.准备工作 2.运行例子 01.HelloWorld:在C#中,创建和销毁Lua虚拟机 和 简单调用。 02.ScriptsFromFile:在C#中,对一个lua文件的执行调用 03.CallLuaFunction:在C#中,对lua函数的操作 04.AccessingLuaVariables:在C#中,对lua变量的操作 05.LuaCoroutine:在Lua中,

AssetBundle学习笔记

AssetBundle是unity自定义的资源格式,通过调用引擎的资源打包接口对资源进行打包成.assetbundle格式的资源包。本文介绍了AssetBundle的生成,使用,加载,卸载以及Unity资源更新的一个基本步骤。 目录 1.定义: 2.AssetBundle的生成: 1)设置AssetBundle包的属性——通过编辑器界面 补充:分组策略 2)调用引擎接口API

RedHat运维-Linux文本操作基础-AWK进阶

你不用整理,跟着敲一遍,有个印象,然后把它保存到本地,以后要用再去看,如果有了新东西,你自个再添加。这是我参考牛客上的shell编程专项题,只不过换成了问答的方式而已。不用背,就算是我自己亲自敲,我现在好多也记不住。 1. 输出nowcoder.txt文件第5行的内容 2. 输出nowcoder.txt文件第6行的内容 3. 输出nowcoder.txt文件第7行的内容 4. 输出nowcode

Javascript高级程序设计(第四版)--学习记录之变量、内存

原始值与引用值 原始值:简单的数据即基础数据类型,按值访问。 引用值:由多个值构成的对象即复杂数据类型,按引用访问。 动态属性 对于引用值而言,可以随时添加、修改和删除其属性和方法。 let person = new Object();person.name = 'Jason';person.age = 42;console.log(person.name,person.age);//'J

一份LLM资源清单围观技术大佬的日常;手把手教你在美国搭建「百万卡」AI数据中心;为啥大模型做不好简单的数学计算? | ShowMeAI日报

👀日报&周刊合集 | 🎡ShowMeAI官网 | 🧡 点赞关注评论拜托啦! 1. 为啥大模型做不好简单的数学计算?从大模型高考数学成绩不及格说起 司南评测体系 OpenCompass 选取 7 个大模型 (6 个开源模型+ GPT-4o),组织参与了 2024 年高考「新课标I卷」的语文、数学、英语考试,然后由经验丰富的判卷老师评判得分。 结果如上图所

大学湖北中医药大学法医学试题及答案,分享几个实用搜题和学习工具 #微信#学习方法#职场发展

今天分享拥有拍照搜题、文字搜题、语音搜题、多重搜题等搜题模式,可以快速查找问题解析,加深对题目答案的理解。 1.快练题 这是一个网站 找题的网站海量题库,在线搜题,快速刷题~为您提供百万优质题库,直接搜索题库名称,支持多种刷题模式:顺序练习、语音听题、本地搜题、顺序阅读、模拟考试、组卷考试、赶快下载吧! 2.彩虹搜题 这是个老公众号了 支持手写输入,截图搜题,详细步骤,解题必备