【urdf_tutorials】Using a URDF in Gazebo 在Gazebo中使用URDF
Using a URDF in Gazebo 在Gazebo中使用URDF
原文链接: https://wiki.ros.org/urdf/Tutorials/Using a URDF in Gazebo
Description: Preliminary tutorial on how to spawn and control your robot in Gazebo.
描述:关于如何在Gazebo中繁殖和控制机器人的初步教程。
Keywords: URDF, Gazebo
关键词:URDF、Gazebo
Tutorial Level: INTERMEDIATE
教程级别:中级
Please download the URDF simulation tutorial from github or using aptitude, i.e. for ROS melodic:
请从github下载URDF模拟教程或使用apt,以ROS melodic为例:
1 | sudo apt-get install ros-melodic-urdf-sim-tutorial |
1 Nonfunctional Gazebo Interface
We can spawn the model we already created into Gazebo using gazebo.launch
我们可以使用Gazebo.launch将我们已经创建的模型派生到Gazebo中
1 | roslaunch urdf_sim_tutorial gazebo.launch |
This launch file
此启动文件
-
Loads the urdf from the macro tutorial into the parameter description (as before)
-
Launches an empty gazebo world
-
Runs the script to read the urdf from the parameter and spawn it in gazebo.
-
By default, the gazebo gui will also be displayed, and look like this:
-
将urdf从宏教程加载到参数描述中(如前所述)
-
启动一个空的露台世界
-
运行脚本从参数中读取urdf并在gazebo中生成它。
-
默认情况下,还将显示gazebo gui,如下所示:
Note: If you download the package directly from git, then please create a workspace and put the two folders under $yourworkspacefolder/src and compile with command catkin_make.
注意:如果您直接从git下载包,请创建一个工作区,并将这两个文件夹放在$yourworkspacefolder/src下,然后使用命令catkin_make进行编译。
However, it doesn’t do anything, and is missing lots of key information that ROS would need to use this robot. Previously we had been using joint_state_publisher to specify the pose of each joint. However, the robot itself should provide that information in the real world or in gazebo. Yet without specifying that, Gazebo doesn’t know to publish that information.
然而,它什么都不做,并且丢失了ROS使用该机器人所需的许多关键信息。之前我们一直使用joint_state_publisher来指定每个关节的姿势。然而,机器人本身应该在现实世界或瞪眼中提供这些信息。然而,在没有具体说明的情况下,Gazebo不知道要发布这些信息。
To get the robot to be interactive (with you and ROS), we need to specify two things: Plugins and Transmissions.
为了让机器人与你和ROS互动,我们需要指定两件事:插件和传输。
2 Gazebo Plugin
To get ROS to interact with Gazebo, we have to dynamically link to the ROS library that will tell Gazebo what to do. Theoretically, this allows for other Robot Operating Systems to interact with Gazebo in a generic way. In practice, its just ROS.
为了让ROS与Gazebo交互,我们必须动态链接到ROS库,该库将告诉Gazebo该做什么。理论上,这允许其他机器人操作系统以通用方式与Gazebo交互。实际上,这只是ROS。
To link Gazebo and ROS, we specify the plugin in the URDF, right before the closing tag:
要链接Gazebo和ROS,我们在URDF中指定插件,就在关闭标签之前:
1 | <gazebo> |
You can see this in https://github.com/ros/urdf_sim_tutorial/blob/master/urdf/09-publishjoints.urdf.xacro and by running roslaunch urdf_sim_tutorial gazebo.launch model:=urdf/09-publishjoints.urdf.xacro
你可以在https://github.com/ros/urdf_sim_tutorial/blob/master/urdf/09-publishjoints.urdf.xacro并通过运行`roslaunch urdf_sim_tutorial gazebo.launch model:=urdf/09-publishjoints.urdf.xacro`
However, this won’t do anything new yet. For that we need to specify more information outside the URDF.
然而,这还没有什么新的作用。为此,我们需要在URDF之外指定更多信息。
3 Spawning Controllers
Now that we’ve linked ROS and Gazebo, we need to specify some bits of ROS code that we want to run within Gazebo, which we generically call controllers. These are initially loaded into the ROS parameter space. We have a yaml file joints.yaml that specifies our first controller.
现在我们已经链接了ROS和Gazebo,我们需要指定一些要在Gazebo中运行的ROS代码,我们通常称之为控制器。这些初始加载到ROS参数空间。我们有一个指定第一个控制器的yaml文件joints.yaml。
1 | type: "joint_state_controller/JointStateController" |
This controller is found in the joint_state_controller package and publishes the state of the robot’s joints into ROS directly from Gazebo.
该控制器位于joint_state_controller包中,并将机器人关节的状态直接从Gazebo发布到ROS中。
In 09-joints.launch you can see how we should load this yaml file into the r2d2_joint_state_controller namespace. Then we call the [[controller_manager]]/spawner script with that namespace which loads it into Gazebo.
在09-joints.launch中,您可以看到如何将这个yaml文件加载到r2d2_joint_state_controller命名空间中。然后,我们使用该名称空间调用[[controller_manager]]/spowner脚本,将其加载到Gazebo中。
You can launch this, but its still not quite there. roslaunch urdf_sim_tutorial 09-joints.launch
你可以启动这个,但它仍然不太到位。roslaunch urdf_sim_tutorial 09-joints.launch
This will run the controller and in fact publish on the /joint_states topic…but with nothing in them.
这将运行控制器,并实际上在/joint_states主题上发布。。。。但里面什么都没有。
1 | header: |
What else do you want Gazebo!? Well, it wants to know what joints to publish information about.
你还想要什么Gazebo!?嗯,它想知道要发布关于哪些关节的信息。
4 Transmissions
For every non-fixed joint, we need to specify a transmission, which tells Gazebo what to do with the joint. Let’s start with the head joint. Add the following to your URDF:
对于每个非固定接头,我们需要指定一个变速器,它告诉Gazebo如何处理接头。让我们从头部关节开始。将以下内容添加到URDF中:
1 | <transmission name="head_swivel_trans"> |
-
For introductory purposes, just treat most of this chunk of code as boilerplate.
-
The first thing to note is the joint element. The name should match the joint declared earlier.
-
The hardwareInterface will be important as we explore the plugins.
-
出于介绍目的,只需将这段代码的大部分作为样板。
-
首先要注意的是关节元素。名称应与前面声明的关节匹配。
-
在我们探索插件时,hardwareInterface将非常重要。
You can run this URDF with our previous launch configuration. roslaunch urdf_sim_tutorial 09-joints.launch model:=urdf/10-firsttransmission.urdf.xacro
Now, the head is displayed properly in RViz because the head joint is listed in the joint_states messages.
您可以使用我们以前的启动配置运行此URDF。roslaunch urdf_sim_tutorial 09-joints.launch model:=urdf/10-firsttransmission.urdf.xacro
现在,头部在RViz中正确显示,因为头部关节列在joint_states消息中。
5 Joint Control
Here’s the next controller config we’re adding.
这是我们要添加的下一个控制器配置。
1 | type: "position_controllers/JointPositionController" |
This specifies to use the a JointPositionController from the position_controllers package to control the head_swivel transmission. Note that hardware interface in the URDF for this joint matches the controller type.
这指定使用position_controllers包中的JointPositionController来控制head_swivel传输。注意,此接头的URDF中的硬件接口与控制器类型匹配。
Now we can launch this with the added config as before roslaunch urdf_sim_tutorial 10-head.launch
现在,我们可以像之前一样使用添加的配置来启动它,如roslaunch urdf_sim_tutorial 10-head.launch
Now Gazebo is subscribed to a new topic, and you can then control the position of the head by publishing a value in ROS. rostopic pub /r2d2_head_controller/command std_msgs/Float64 "data: -0.707"
现在Gazebo订阅了一个新主题,然后您可以通过在ROS中发布值来控制负责人的位置。rostopic pub /r2d2_head_controller/command std_msgs/Float64 "data: -0.707"
When this command is published, the position will immediately change to the specified value. This is because we did not specify any limits for the joint in our urdf. However, if we change the joint, it will move gradually.
发布此命令后,位置将立即更改为指定值。这是因为我们在urdf中没有为关节指定任何限制。然而,如果我们改变关节,它会逐渐移动。
1 | <joint name="head_swivel" type="continuous"> |
1 | roslaunch urdf_sim_tutorial 10-head.launch model:=urdf/11-limittransmission.urdf.xacro |
6 Another Controller
We can change the URDF for the Gripper joints in a similar way. However, instead of individually controlling each joint of the gripper with its own ROS topic, we might want to group them together. For this, we just need to specify a different controller in the ROS parameters.
我们可以以类似的方式更改夹持器关节的URDF。然而,我们可能希望将它们分组在一起,而不是用自己的ROS主题单独控制夹持器的每个关节。为此,我们只需要在ROS参数中指定一个不同的控制器。
1 | type: "position_controllers/JointGroupPositionController" |
To launch this, roslaunch urdf_sim_tutorial 12-gripper.launch
要启动此功能,请执行roslaunch urdf_sim_tutorial 12-gripper.launch
With this, we can instead specify the position with an array of floats. Open and out:
使用此选项,我们可以使用浮点数组指定位置。打开和输出:
1 | rostopic pub /r2d2_gripper_controller/command std_msgs/Float64MultiArray "layout: |
Closed and retracted:
关闭和缩回:
1 | rostopic pub /r2d2_gripper_controller/command std_msgs/Float64MultiArray "layout: |
7 The Wheels on the Droid Go Round and Round
To drive the robot around, we specify yet another transmission for each of the wheels from within the wheel macro.
为了驱动机器人,我们在轮子宏中为每个轮子指定了另一个传动装置。
1 | <transmission name="${prefix}_${suffix}_wheel_trans"> |
This is just like the other transmissions, except
- It uses macro parameters to specify names
- It uses a VelocityJointInterface.
这和其他变速器一样,除了
- 它使用宏参数指定名称
- 它使用VelocityJointInterface。
Since the wheels are actually going to touch the ground and thus interact with it physically, we also specify some additional information about the material of the wheels.
由于车轮实际上会接触地面,从而与地面物理交互,因此我们还指定了有关车轮材料的一些附加信息。
1 | <gazebo reference="${prefix}_${suffix}_wheel"> |
See http://gazebosim.org/tutorials/?tut=ros_urdf for more details.
http://gazebosim.org/tutorials/?tut=ros_urdf 了解更多详情。
We could specify controllers for each of the individual wheels, but where’s the fun in that? Instead we want to control all the wheels together. For that, we’re going to need a lot more ROS parameters.
我们可以为每个单独的轮子指定控制器,但这其中的乐趣何在?相反,我们希望一起控制所有车轮。为此,我们需要更多的ROS参数。
1 | type: "diff_drive_controller/DiffDriveController" |
The DiffDriveController subscribes to a standard Twist cmd_vel message and moves the robot accordingly.
DiffDriveController订阅标准Twist cmd_vel消息,并相应地移动机器人。
1 | roslaunch urdf_sim_tutorial 13-diffdrive.launch |
In addition to loading the above configuration, this also opens the RobotSteering panel, allowing you to drive the R2D2 robot around, while also observing its actual behavior (in Gazebo) and it’s visualized behavior (in RViz):
除了加载上述配置,这还将打开RobotSteering面板,允许您驾驶R2D2机器人四处走动,同时观察其实际行为(在Gazebo中)和可视化行为(在RViz中):
Congrats! Now you’re simulating robots with URDF.
恭喜!现在您正在使用URDF模拟机器人。