《鸿蒙机器人编程》4-实践课-建造自己机器人的3D模型-实训指南_第1页
《鸿蒙机器人编程》4-实践课-建造自己机器人的3D模型-实训指南_第2页
《鸿蒙机器人编程》4-实践课-建造自己机器人的3D模型-实训指南_第3页
《鸿蒙机器人编程》4-实践课-建造自己机器人的3D模型-实训指南_第4页
《鸿蒙机器人编程》4-实践课-建造自己机器人的3D模型-实训指南_第5页
已阅读5页,还剩23页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

建造自己机器人的3D模型课程内容: 本节主要介绍机器人仿真的相关内容,结合Rviz和Gazebo进行集成使用教学目标:掌握在Rviz中显示机器人模型掌握在Gazebo中显示机器人模型掌握如何在Gazebo中控制机器人运动一.在Rviz中显示机器人模型实现流程:第一步(准备):新建功能包,导入依赖第二步(核心):编写urdf文件第三步(核心):在launch文件集成URDF与RViz第四步(结果):在RViz中显示机器人模型1.新建功能包首先进入工作空间catkin_ws的src目录下,创建名为“spark_description”的功能包,并为其导入相关依赖$cdcatkin_ws/src/$catkin_create_pkgspark_descriptionroscpprospyurdftfgeometry_msgsstd_msgs2.编写urdf文件(用urdf构建一台极简的spark机器人模型)①进入spark_description功能包,创建urdf文件夹,用于存放urdf文件。$cdspark_description$mkdirurdf②导入机器人模型素材,在项目源代码中将meshes文件夹复制到此功能包下项目源码路径:复制到创建的功能包下:③创建urdf文件(spark_description_simple.urdf)将项目源代码中的spak_description_simple.urdf文件复制到urdf文件夹下我们首先创建一个urdf文件去描述一台极简的spark机器人,用robot标签将机器人各部分包含进来。起名为sparkbase,每部分用link标签去表示,分别用joint将各部分连接。下面是详细代码:<robotname="spark_base"> <linkname="base_footprint"/> <linkname="base_link"> <visual> <origin xyz="000" rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/spark_base.DAE"/> </geometry> </visual> </link> <jointname="base_joint"type="fixed"> <origin xyz="000.01" rpy="000"/> <parentlink="base_footprint"/> <childlink="base_link"/> </joint> <linkname="left_wheel_link"> <visual> <origin xyz="000" rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/left_wheel.DAE"/> </geometry> </visual> </link> <jointname="left_wheel_joint"type="continuous"> <origin xyz="0-0.1310.024" rpy="000"/> <axisxyz="010"/> <parentlink="base_link"/> <childlink="left_wheel_link"/> </joint> <linkname="right_wheel_link"> <visual> <origin xyz="000" rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/right_wheel.DAE"/> </geometry> </visual> </link> <jointname="right_wheel_joint"type="continuous"> <origin xyz="00.1310.024"rpy="000"/> <axisxyz="010"/> <parentlink="base_link"/> <childlink="right_wheel_link"/> </joint> <linkname="spark_stack"><visual><origin xyz="000"rpy="000"/><geometry><meshfilename="package://spark_description/meshes/spark/stack/spark_stack.DAE"/></geometry></visual></link><jointname="spark_stack_joint"type="fixed"><origin xyz="000" rpy="000"/><parentlink="base_link"/><childlink="spark_stack"/></joint></robot>3.在launch文件集成URDF与RViz①创建launch文件夹,用于存放launch文件$mkdirlaunch$cdlaunch②创建launch文件将项目源代码中的spark_description_simple.launch文件复制到此launch文件夹中③导入Rviz环境,将项目源代码中的rviz文件夹复制到功能包下用urdf文件描述出机器人的基本信息后,我们就可以在rviz里面通过launch文件来启动它。launch文件中,根标签就是launch,然后定义几个在launch文件里面用到的参数。model就是机器人的模型描述文件;usegui表示是否使用gui;publishdefaultpositions表示是否发布这个位置信息。然后我们用一个param标签来将model上传到参数服务器,命名为robotdescription。launch文件的具体编写如下:<launch><argname="model"default="$(findspark_description)/urdf/teaching/spark_description_simple.urdf"/><argname="use_gui"default="false"/><argname="publish_default_positions"default="true"/><paramname="robot_description"command="$(findxacro)/xacro$(argmodel)"/><nodename="joint_state_publisher"pkg="joint_state_publisher"type="joint_state_publisher"> <paramname="use_gui"value="$(arguse_gui)"/> <paramname="publish_default_positions"value="$(argpublish_default_positions)"/> <rosparamparam="source_list">["wheel_states"]</rosparam></node><nodename="robot_state_publisher"pkg="robot_state_publisher"type="robot_state_publisher"/><nodepkg="rviz"type="rviz"name="rviz"args="-d$(findurdf_demo_rviz)/config/urdf.rviz"/></launch>4.在RViz中显示机器人模型用下列命令,启动构造好的spark机器人:$cdcatkin_ws$sourcedevel/setup.bash$roslaunchspark_descriptionspark_description_simple.launch下面是运行界面截图:二.在Gazebo中显示机器人模型实现流程:第一步(核心):编写urdf文件第二步(核心):编写launch文件第三步(结果):在Gazebo中显示机器人模型1.编写urdf文件将项目源代码中的spark_description_gazebo_simple.urdf文件复制到此urdf文件夹中如何修改上面的urdf文件使机器人在Gazebo中显示?必须步骤

:在每一个<link>内添加<inertia>标签。可选步骤

:在每一个<link>内添加<gazebo>标签。将外观颜色转换成Gazebo格式;将stl文件转换成dae文件,获得更好的渲染效果;添加传感器插件。在<robot>标签内添加<gazebo>。为了防止机器人陷入障碍物,我们增加了碰撞模型标签。此标签设置了碰撞模型的位置、姿态以及碰撞几何体,以便机器人能够进行碰撞检测。具体代码如下:<robotname="spark"> <linkname="base_footprint"/> <linkname="base_link"> <inertial> <origin xyz="000"rpy="000"/> <mass value="0.916261377"/> <inertiaixx="0.001"ixy="0.0"ixz="0.0" iyy="0.001"iyz="0.0" izz="0.001"/> </inertial> <visual> <origin xyz="000" rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/spark_base.DAE"/> </geometry> </visual> <collision> <origin xyz="000"rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/spark_base.DAE"/> </geometry> </collision> </link> <jointname="base_joint"type="fixed"> <origin xyz="000.01" rpy="000"/> <parentlink="base_footprint"/> <childlink="base_link"/> </joint> <linkname="left_wheel_link"> <inertial> <massvalue="0.01"/> <originxyz="000"/> <inertiaixx="0.001"ixy="0.0"ixz="0.0" iyy="0.001"iyz="0.0" izz="0.001"/> </inertial> <visual> <origin xyz="000"rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/left_wheel.DAE"/> </geometry> </visual> <collision> <origin xyz="000" rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/left_wheel.DAE"/> </geometry> </collision> </link> <jointname="left_wheel_joint"type="continuous"> <origin xyz="0-0.1310.024"rpy="000"/> <axisxyz="010"/> <parentlink="base_link"/> <childlink="left_wheel_link"/> </joint> <linkname="right_wheel_link"> <inertial> <massvalue="0.01"/> <originxyz="000"/> <inertiaixx="0.001"ixy="0.0"ixz="0.0" iyy="0.001"iyz="0.0" izz="0.001"/> </inertial> <visual> <origin xyz="000" rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/right_wheel.DAE"/> </geometry> </visual> <collision> <origin xyz="000"rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/right_wheel.DAE"/> </geometry> </collision> </link> <jointname="right_wheel_joint"type="continuous"> <origin xyz="00.1310.024"rpy="000"/> <axisxyz="010"/> <parentlink="base_link"/> <childlink="right_wheel_link"/> </joint><linkname="spark_stack"><inertial><origin xyz="000" rpy="000"/><massvalue="0.224592038"/><inertiaixx="0.052467491"ixy="-0.000000000"ixz="0.001956704"iyy="0.055610919"iyz="0.000000000"izz="0.012118046"/></inertial><visual><origin xyz="000" rpy="000"/><geometry><meshfilename="package://spark_description/meshes/spark/stack/spark_stack.DAE"/></geometry></visual><collision><originxyz="000"rpy="000"/><geometry><meshfilename="package://spark_description/meshes/spark/stack/spark_stack.DAE"/></geometry></collision></link><jointname="spark_stack_joint"type="fixed"><origin xyz="000" rpy="000"/><parentlink="base_link"/><childlink="spark_stack"/></joint><transmissionname="tran1"><type>transmission_interface/SimpleTransmission</type><jointname="left_wheel_joint"><hardwareInterface>VelocityJointInterface</hardwareInterface></joint><actuatorname="motor1"><hardwareInterface>VelocityJointInterface</hardwareInterface><mechanicalReduction>1</mechanicalReduction></actuator></transmission><transmissionname="tran2"><type>transmission_interface/SimpleTransmission</type><jointname="right_wheel_joint"><hardwareInterface>VelocityJointInterface</hardwareInterface></joint><actuatorname="motor2"><hardwareInterface>VelocityJointInterface</hardwareInterface><mechanicalReduction>-1</mechanicalReduction></actuator></transmission><gazebo><pluginname="gazebo_ros_control"filename="libgazebo_ros_control.so"><robotNamespace>/</robotNamespace><robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType></plugin></gazebo> </robot>2.编写launch文件将项目源代码中的spark_gazebo_simple.launch文件复制到此launch文件夹中具体代码如下:<launch><!--thesearetheargumentsyoucanpassthislaunchfile,forexamplepaused:=true--><argname="paused"default="false"/><argname="use_sim_time"default="true"/><argname="gui"default="true"/><argname="headless"default="false"/><argname="debug"default="false"/><!--Weresumethelogicinempty_world.launch--><includefile="$(findgazebo_ros)/launch/empty_world.launch"><argname="debug"value="$(argdebug)"/><argname="gui"value="$(arggui)"/><argname="paused"value="$(argpaused)"/><argname="use_sim_time"value="$(arguse_sim_time)"/><argname="headless"value="$(argheadless)"/></include><!--urdfxmlrobotdescriptionloadedontheParameterServer--><paramname="robot_description"command="$(findxacro)/xacro'$(findspark_description)/urdf/teaching/spark_description_gazebo_simple.urdf'"/><nodename="joint_state_publisher"pkg="joint_state_publisher"type="joint_state_publisher"></node><!--Startingrobotstatepublishwhichwillpublishtf--><nodename="robot_state_publisher"pkg="robot_state_publisher"type="robot_state_publisher"output="screen"><paramname="publish_frequency"type="double"value="50.0"/></node><!--Runapythonscripttothesendaservicecalltogazebo_rostospawnaURDFrobot--><nodename="urdf_spawner"pkg="gazebo_ros"type="spawn_model"respawn="false"output="screen" args="-urdf-modelspark-paramrobot_description"/></launch>3.在Gazebo中显示机器人模型用下列命令,将spark机器人模型加载到gazebo:$cdcatkin_ws$sourcedevel/setup.bash$roslaunchspark_descriptionspark_gazebo_simple.launch下面是运行界面截图:三.在gazebo中实现spark机器人的运动仿真实现流程:第一步(核心):编写urdf文件第二步(核心):创建控制器配置文件第三步(核心):编写launch文件第四步(结果):启动Gazebo并发布spark_controller/cmd_vel消息控制机器人运动1.编写urdf文件将项目源代码中的spark_description_gazebo.urdf文件复制到此urdf文件夹中如何修改上面的urdf文件使机器人在Gazebo中实现运动控制?必须步骤

:向URDF文件中的joint添加<transmission>标签。向URDF文件中添加ros_control插件,并添加相应插件的controller配置文件。可选步骤:

在每一个<link>内添加<gazebo>标签。将外观颜色转换成Gazebo格式;将stl文件转换成dae文件,获得更好的渲染效果;添加传感器插件。在每一个<joint>内添加<gazebo>标签。设置适当的阻尼动力系数;添加执行器控制插件。在<robot>标签内添加<gazebo>。为了完成传动所描述的这种动力驱动,我们需要加载roscontrol这个插件。这里我们用到了gazebo里面的一个插件libgazeboroscontrol。首先要在这个gazebo标签里加上plugin插件的标签,连同设置了你的插件的名字、文件名。这里面还允许你设置机器人的命名空间,还有这个机器人的仿真的类型。具体代码如下:<robotname="spark"> <linkname="base_footprint"/> <linkname="base_link"> <inertial> <origin xyz="000"rpy="000"/> <mass value="0.916261377"/> <inertiaixx="0.001"ixy="0.0"ixz="0.0" iyy="0.001"iyz="0.0" izz="0.001"/> </inertial> <visual> <origin xyz="000" rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/spark_base.DAE"/> </geometry> </visual> <collision> <origin xyz="000"rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/spark_base.DAE"/> </geometry> </collision> </link> <jointname="base_joint"type="fixed"> <origin xyz="000.01" rpy="000"/> <parentlink="base_footprint"/> <childlink="base_link"/> </joint> <linkname="left_wheel_link"> <inertial> <massvalue="0.01"/> <originxyz="000"/> <inertiaixx="0.001"ixy="0.0"ixz="0.0" iyy="0.001"iyz="0.0" izz="0.001"/> </inertial> <visual> <origin xyz="000"rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/left_wheel.DAE"/> </geometry> </visual> <collision> <origin xyz="000" rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/left_wheel.DAE"/> </geometry> </collision> </link> <jointname="left_wheel_joint"type="continuous"> <origin xyz="0-0.1310.024"rpy="000"/> <axisxyz="010"/> <parentlink="base_link"/> <childlink="left_wheel_link"/> </joint> <linkname="right_wheel_link"> <inertial> <massvalue="0.01"/> <originxyz="000"/> <inertiaixx="0.001"ixy="0.0"ixz="0.0" iyy="0.001"iyz="0.0" izz="0.001"/> </inertial> <visual> <origin xyz="000" rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/right_wheel.DAE"/> </geometry> </visual> <collision> <origin xyz="000"rpy="000"/> <geometry> <mesh filename="package://spark_description/meshes/spark/base/right_wheel.DAE"/> </geometry> </collision> </link> <jointname="right_wheel_joint"type="continuous"> <origin xyz="00.1310.024"rpy="000"/> <axisxyz="010"/> <parentlink="base_link"/> <childlink="right_wheel_link"/> </joint><linkname="spark_stack"><inertial><origin xyz="000" rpy="000"/><massvalue="0.224592038"/><inertiaixx="0.052467491"ixy="-0.000000000"ixz="0.001956704"iyy="0.055610919"iyz="0.000000000"izz="0.012118046"/></inertial><visual><origin xyz="000" rpy="000"/><geometry><meshfilename="package://spark_description/meshes/spark/stack/spark_stack.DAE"/></geometry></visual><collision><originxyz="000"rpy="000"/><geometry><meshfilename="package://spark_description/meshes/spark/stack/spark_stack.DAE"/></geometry></collision></link><jointname="spark_stack_joint"type="fixed"><origin xyz="000" rpy="000"/><parentlink="base_link"/><childlink="spark_stack"/></joint><transmissionname="tran1"><type>transmission_interface/SimpleTransmission</type><jointname="left_wheel_joint"><hardwareInterface>VelocityJointInterface</hardwareInterface></joint><actuatorname="motor1"><hardwareInterface>VelocityJointInterface</hardwareInterface><mechanicalReduction>1</mechanicalReduction></actuator></transmission><transmissionname="tran2"><type>transmission_interface/SimpleTransmission</type><jointname="right_wheel_joint"><hardwareInterface>VelocityJointInterface</hardwareInterface></joint><actuatorname="motor2"><hardwareInterface>VelocityJointInterface</hardwareInterface><mechanicalReduction>-1</mechanicalReduction></actuator></transmission><gazebo><pluginname="gazebo_ros_control"filename="libgazebo_ros_control.so"><robotNamespace>/</robotNamespace><robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType></plugin></gazebo> </robot>2.创建控制器配置文件控制器的一些参数,我们通常把它写成一个配置文件。命名为controller.yaml①在功能包下创建config文件夹,用于存放配置文件$mkdirconfig$cdconfig②将项目源代码中的controller.yaml文件复制到此config文件夹中具体代码如下:joint_state_controller:type:joint_state_controller/JointStateControllerpublish_rate:20spark_controller:type:"diff_drive_controller/DiffDriveController"left_wheel:"left_wheel_joint"right_wheel:"right_wheel_joint"wheel_separation:0.11wheel_radius:0.04publish_rate:50.0#defaultsto50pose_covariance_diagonal:[0.001,0.001,1000000.0,1000000.0,1000000.0,1000.0]twist_covariance_diagonal:[0.001,0.001,1000000.0,1000000.0,1000000.0,1000.0]cmd_vel_timeout:20.0#wetestthisseparately,giveplentyfortheothertests我们这里面将控制器的这个参数写到controller.yaml,然后我们用rosparam来将这些配置参数加载到参数服务器上。这里面控制器包括jointstatecontroller和sparkcontroller。3.创建launch文件将项目源代码中的spark_gazebo.launch文件复制到此launch文件夹中具体代码如下:<launch><!--urdfxmlrobotdescriptionloadedontheParameterServer--><paramname="robot_description"command="$(findxacro)/xacro'$(findspark_description)/urdf/teaching/spark_description_gazebo.urdf'"/><nodename="joint_state_publisher"pkg="joint_state_publisher"type="joint_state_publisher"></node><!--Startingrobotstatepublishwhichwillpublishtf--><nodename="robot_s

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论