ROS学习笔记45(Using a URDF in Gazebo)

下载模型:

sudo apt-get install ros-kinetic-urdf-sim-tutorial 

1 Nonfunctional Gazebo 接口

生成模型,如下:

roslaunch urdf_sim_tutorial gazebo.launch 

这个launch文件如下所示:

  • 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:

注意:如果是直接下载的则需要进行编译。

Gazebo

然而,它没有做任何事情,是由于ROS缺少大量的关键信息这个机器人要使用的。 以前我们一直使用joint_state_publisher指定每个关节的姿态。 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.

为了让机器人是互动的,我们需要指定两两件事:插件和传输。

2 Gazebo Plugin

要使得ROS与Gazebo互动,我们必须动态链接到ROS库,它会告诉Gazebo做什么。从理论上讲,这允许机器人操作系统用一个通用的方法与Gazebo互动。在实践中,它是ROS。

连接ROS与Gazebo, 我们需要在URDF中指定插件, right before the closing </robot> tag:

<gazebo>
    <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
      <robotNamespace>/</robotNamespace>
    </plugin>
</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

然而,这不会做任何新的东西呢。为此,我们需要指定URDF之外的更多信息。

3 Spawning Controllers

现在我们已经令ROS与Gazebo链接到了一起, we need to specify some bits of ROS code that we want to run within Gazebo, 我们一般成为控制器. 这些在最初被加载进ROS parameter space. We have a yaml file joints.yaml that specifies our first controller.

type: "joint_state_controller/JointStateController"
publish_rate: 50

控制器发现在joint_state_controller 功能包,并且发布机器人关节的状态 into ROS directly from Gazebo.

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.

You can launch this, but its still not quite there.  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.

header:
  seq: 652
  stamp:
    secs: 13
    nsecs: 331000000
  frame_id: ''
name: []
position: []
velocity: []
effort: []

What else do you want Gazebo!? Well, it wants to know what joints to publish information about.

4 Transmissions

对于非固定的关节, we need to specify a transmission, 这会告诉Gazebo 对这个关节做什么. 让我们开始运行头关节。 Add the following to your URDF:

<transmission name="head_swivel_trans">
    <type>transmission_interface/SimpleTransmission</type>
    <actuator name="$head_swivel_motor">
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>
    <joint name="head_swivel">
      <hardwareInterface>PositionJointInterface</hardwareInterface>
    </joint>
  </transmission>
  • For introductory purposes, just treat most of this chunk of code as boilerplate.
  • 需要注意关节元素。名字应该匹配关节,且较早声明。
  • The hardwareInterface will be important as we explore the plugins.

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.

header:
  seq: 220
  stamp:
    secs: 4
    nsecs: 707000000
  frame_id: ''
name: ['head_swivel']
position: [-2.9051283156888985e-08]
velocity: [7.575990694887896e-06]
effort: [0.0]

我们可以继续添加传输的所有非固定关节,以使所有的关节都正确发布。但是,还有比只盯着机器人更重要的事情。我们要控制他们。所以,让我们得到另一个控制器在这里。

5 Joint Control

这是我们添加的关节控制器。

type: "position_controllers/JointPositionController"
joint: head_swivel

此指定要使用的一个JointPositionController从position_controllers包来控制head_swivel transmission.。注意控制器类型本节比赛中URDF硬件接口。

Now we can launch this with the added config as before  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"

当这个命令发布后,位置将立即更改为指定的值。这是因为我们没有指定在我们的urdf文件中对关节进行任何限制。However, if we change the joint, it will move gradually.

  <joint name="head_swivel" type="continuous">
    <parent link="base_link"/>
    <child link="head"/>
    <axis xyz="0 0 1"/>
    <origin xyz="0 0 ${bodylen/2}"/>
    <limit effort="30" velocity="1.0"/>
  </joint>

 roslaunch urdf_sim_tutorial 10-head.launch model:=urdf/11-limittransmission.urdf.xacro

6 Another Controller

我们可以更改URDF中的 Gripper 关节以相同的方式. However, i我们不想使用ROS话题单独控制gripper的每个节点, we might want to group them together. For this, we just need to specify a different controller in the ROS parameters.

type: "position_controllers/JointGroupPositionController"
joints:
  - gripper_extension
  - left_gripper_joint
  - right_gripper_joint

To launch this,  roslaunch urdf_sim_tutorial 12-gripper.launch 

With this, we can instead specify the position with an array of floats. Open and out:

rostopic pub  /r2d2_gripper_controller/command std_msgs/Float64MultiArray "layout:
  dim:
  - label: ''
    size: 3
    stride: 1
  data_offset: 0
data: [0, 0.5, 0.5]"

Closed and retracted:

rostopic pub  /r2d2_gripper_controller/command std_msgs/Float64MultiArray "layout:
  dim:
  - label: ''
    size: 3
    stride: 1
  data_offset: 0
data: [-0.4, 0, 0]"

 

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.

<transmission name="${prefix}_${suffix}_wheel_trans">
      <type>transmission_interface/SimpleTransmission</type>
      <actuator name="${prefix}_${suffix}_wheel_motor">
        <mechanicalReduction>1</mechanicalReduction>
      </actuator>
      <joint name="${prefix}_${suffix}_wheel_joint">
        <hardwareInterface>VelocityJointInterface</hardwareInterface>
      </joint>
</transmission>

This is just like the other transmissions, except

  • It uses macro parameters to specify names
  • It uses a VelocityJointInterface.

由于车轮实际去接触地面,从而与它的物理交互,我们还指定有关车轮的材料的一些附加信息。

<gazebo reference="${prefix}_${suffix}_wheel">
      <mu1 value="200.0"/>
      <mu2 value="100.0"/>
      <kp value="10000000.0" />
      <kd value="1.0" />
      <material>Gazebo/Grey</material>
</gazebo>

See http://gazebosim.org/tutorials/?tut=ros_urdf for more details.我们可以指定每个单个车轮的控制器,哪来的乐趣呢?相反,我们希望所有的车轮控制起来。为此,我们将需要更多的ROS参数。

  type: "diff_drive_controller/DiffDriveController"
  publish_rate: 50

  left_wheel: ['left_front_wheel_joint', 'left_back_wheel_joint']
  right_wheel: ['right_front_wheel_joint', 'right_back_wheel_joint']

  wheel_separation: 0.44

  # Odometry covariances for the encoder output of the robot. These values should
  # be tuned to your robot's sample odometry data, but these values are a good place
  # to start
  pose_covariance_diagonal: [0.001, 0.001, 0.001, 0.001, 0.001, 0.03]
  twist_covariance_diagonal: [0.001, 0.001, 0.001, 0.001, 0.001, 0.03]

  # Top level frame (link) of the robot description
  base_frame_id: base_link

  # Velocity and acceleration limits for the robot
  linear:
    x:
      has_velocity_limits    : true
      max_velocity           : 0.2   # m/s
      has_acceleration_limits: true
      max_acceleration       : 0.6   # m/s^2
  angular:
    z:
      has_velocity_limits    : true
      max_velocity           : 2.0   # rad/s
      has_acceleration_limits: true
      max_acceleration       : 6.0   # rad/s^2

The DiffDriveController 订阅标准的 Twist cmd_vel message and moves the robot accordingly.

 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):

Gazebo

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值