七 Gazebo学习总结之传感器的添加

本文展示的是使用者怎么直接通过Gazebo其他模型来创建复杂的模型,以及使用<include>和<joint>标签来连接一个复杂模型的不同部分。

1.增加一个激光器

a.进入先前教程的模型目录中。

cd ~/.gazebo/models/my_robot
b.打开model.sdf文件。

c.添加以下程序到文件末尾</model>标签之前。

<include>
  <uri>model://hokuyo</uri>
  <pose>0.2 0 0.2 0 0 0</pose>
</include>
<joint name="hokuyo_joint" type="revolute">
  <child>hokuyo::link</child>
  <parent>chassis</parent>
  <axis>
    <xyz>0 0 1</xyz>
    <limit>
      <upper>0</upper>
      <lower>0</lower>
    </limit>
  </axis>
</joint>

<include>块告诉Gazebo找到模型,添加到父模型给定的姿势中,<uri>块告诉Gazebo去哪儿可以找到模型。新的<joint>在模型的底座连接了插入的激光传感器,该关节有上下值的限定,是为了阻止传感器的移动。

d.开始Gzabo,增添激光器,结果如下:


2.制作一个抓手

a.为world文件创建目录

mkdir ~/simple_gripper_tutorial; cd ~/simple_gripper_tutorial
b.创建一个简单的空的world文件

gedit ~/simple_gripper_tutorial/gripper.world
复制以下的SDF到gripper.world文件中

<?xml version="1.0"?>
<sdf version="1.4">
<world name="default">

<!-- A ground plane -->
<include>
  <uri>model://ground_plane</uri>
</include>

<!-- A global light source -->
<include>
  <uri>model://sun</uri>
</include>

<include>
  <uri>model://my_gripper</uri>
</include>

</world>
</sdf>

c.在~/.gazebo下创建一个模型目录。

mkdir -p ~/.gazebo/models/my_gripper
cd ~/.gazebo/models/my_gripper
d.先布局所要创建的抓手的结构,完成创建的最容易方法是制作一个静态模型,同时添加一个links,一个静态模型意味着仿真器开始时links将不会移动,这将允许开始仿真器后,在添加关节前视觉检查link的位置。

e.创建model.config文件。

gedit ~/.gazebo/models/my_gripper/model.config
将以下内容复制到model.config文件

<?xml version="1.0"?>

<model>
  <name>My Gripper</name>
  <version>1.0</version>
  <sdf version='1.4'>simple_gripper.sdf</sdf>

  <author>
    <name>My Name</name>
    <email>me@my.email</email>
  </author>

  <description>
    My awesome robot.
  </description>
</model>

f.制作一个新的sdf模型文件。

gedit ~/.gazebo/models/my_gripper/simple_gripper.sdf

复制以下代码到simple_gripper.sdf文件

<?xml version="1.0"?>
<sdf version="1.4">
<model name="simple_gripper">
    <link name="riser">
        <pose>-0.15 0.0 0.5 0 0 0</pose>
        <inertial>
            <pose>0 0 -0.5 0 0 0</pose>
            <inertia>
                <ixx>0.01</ixx>
                <ixy>0</ixy>
                <ixz>0</ixz>
                <iyy>0.01</iyy>
                <iyz>0</iyz>
                <izz>0.01</izz>
            </inertia>
            <mass>10.0</mass>
        </inertial>
        <collision name="collision">
            <geometry>
                <box>
                    <size>0.2 0.2 1.0</size>
                </box>
            </geometry>
        </collision>
        <visual name="visual">
            <geometry>
                <box>
                    <size>0.2 0.2 1.0</size>
                </box>
            </geometry>
            <material>
                <script>Gazebo/Purple</script>
            </material>
        </visual>
    </link>
    <link name="palm">
        <pose>0.0 0.0 0.05 0 0 0</pose>
        <inertial>
            <inertia>
                <ixx>0.01</ixx>
                <ixy>0</ixy>
                <ixz>0</ixz>
                <iyy>0.01</iyy>
                <iyz>0</iyz>
                <izz>0.01</izz>
            </inertia>
            <mass>0.5</mass>
        </inertial>
        <collision name="collision">
            <geometry>
                <box>
                    <size>0.1 0.2 0.1</size>
                </box>
            </geometry>
        </collision>
        <visual name="visual">
            <geometry>
                <box>
                    <size>0.1 0.2 0.1</size>
                </box>
            </geometry>
            <material>
                <script>Gazebo/Red</script>
            </material>
        </visual>
    </link>
    <link name="left_finger">
        <pose>0.1 0.2 0.05 0 0 -0.78539</pose>
        <inertial>
            <inertia>
                <ixx>0.01</ixx>
                <ixy>0</ixy>
                <ixz>0</ixz>
                <iyy>0.01</iyy>
                <iyz>0</iyz>
                <izz>0.01</izz>
            </inertia>
            <mass>0.1</mass>
        </inertial>
        <collision name="collision">
            <geometry>
                <box>
                    <size>0.1 0.3 0.1</size>
                </box>
            </geometry>
        </collision>
        <visual name="visual">
            <geometry>
                <box>
                    <size>0.1 0.3 0.1</size>
                </box>
            </geometry>
            <material>
                <script>Gazebo/Blue</script>
            </material>
        </visual>
    </link>
    <link name="left_finger_tip">
        <pose>0.336 0.3 0.05 0 0 1.5707</pose>
        <inertial>
            <inertia>
                <ixx>0.01</ixx>
                <ixy>0</ixy>
                <ixz>0</ixz>
                <iyy>0.01</iyy>
                <iyz>0</iyz>
                <izz>0.01</izz>
            </inertia>
            <mass>0.1</mass>
        </inertial>
        <collision name="collision">
            <geometry>
                <box>
                    <size>0.1 0.2 0.1</size>
                </box>
            </geometry>
        </collision>
        <visual name="visual">
            <geometry>
                <box>
                    <size>0.1 0.2 0.1</size>
                </box>gedit ~/.gazebo/models/my_gripper/simple_gripper.sdf
            </geometry>
            <material>
                <script>Gazebo/Blue</script>
            </material>
        </visual>
    </link>
    <link name="right_finger">
        <pose>0.1 -0.2 0.05 0 0 .78539</pose>
        <inertial>
            <inertia>
                <ixx>0.01</ixx>
                <ixy>0</ixy>
                <ixz>0</ixz>
                <iyy>0.01</iyy>
                <iyz>0</iyz>
                <izz>0.01</izz>
            </inertia>
            <mass>0.1</mass>
        </inertial>
        <collision name="collision">
            <geometry>
                <box>
                    <size>0.1 0.3 0.1</size>
                </box>
            </geometry>
        </collision>
        <visual name="visual">
            <geometry>
                <box>
                    <size>0.1 0.3 0.1</size>
                </box>
            </geometry>
            <material>
                <script>Gazebo/Green</script>
            </material>
        </visual>
    </link>
    <link name="right_finger_tip">
        <pose>0.336 -0.3 0.05 0 0 1.5707</pose>
        <inertial>
            <inertia>
                <ixx>0.01</ixx>
                <ixy>0</ixy>
                <ixz>0</ixz>
                <iyy>0.01</iyy>
                <iyz>0</iyz>
                <izz>0.01</izz>
            </inertia>
            <mass>0.1</mass>
        </inertial>
        <collision name="collision">
            <geometry>
                <box>
                    <size>0.1 0.2 0.1</size>
                </box>
            </geometry>
        </collision>
        <visual name="visual">
            <geometry>
                <box>
                    <size>0.1 0.2 0.1</size>
                </box>
            </geometry>
            <material>
                <script>Gazebo/Green</script>
            </material>
        </visual>
    </link>
    <static>true</static>
</model>
</sdf>

g.运行world文件。

gazebo ~/simple_gripper_tutorial/gripper.world
结果如下:


h.一旦满意links的布局后,我们就能增添关节,通过复制以下代码到simple_gripper.sdf文件中(在</model>行前面)。

gedit ~/.gazebo/models/my_gripper/simple_gripper.sdf
<joint name="palm_left_finger" type="revolute">
        <pose>0 -0.15 0 0 0 0</pose>
        <child>left_finger</child>
        <parent>palm</parent>
        <axis>
            <limit>
                <lower>-0.4</lower>
                <upper>0.4</upper>
            </limit>
            <xyz>0 0 1</xyz>
        </axis>
    </joint>
    <joint name="left_finger_tip" type="revolute">
        <pose>0 0.1 0 0 0 0</pose>
        <child>left_finger_tip</child>
        <parent>left_finger</parent>
        <axis>
            <limit>
                <lower>-0.4</lower>
                <upper>0.4</upper>
            </limit>
            <xyz>0 0 1</xyz>
        </axis>
    </joint>
    <joint name="palm_right_finger" type="revolute">
        <pose>0 0.15 0 0 0 0</pose>
        <child>right_finger</child>
        <parent>palm</parent>
        <axis>
            <limit>
                <lower>-0.4</lower>
                <upper>0.4</upper>
            </limit>
            <xyz>0 0 1</xyz>
        </axis>
    </joint>
    <joint name="right_finger_tip" type="revolute">
        <pose>0 0.1 0 0 0 0</pose>
        <child>right_finger_tip</child>
        <parent>right_finger</parent>
        <axis>
            <limit>
                <lower>-0.4</lower>
                <upper>0.4</upper>
            </limit>
            <xyz>0 0 1</xyz>
        </axis>
    </joint>
    <joint name="palm_riser" type="prismatic">
        <child>palm</child>
        <parent>riser</parent>
        <axis>
            <limit>
                <lower>0</lower>
                <upper>0.9</upper>
            </limit>
            <xyz>0 0 1</xyz>
        </axis>
    </joint>

且使模型处于非静止状态:

 ...
    <static>false</static>
    ...
i.再次运行Gazebo。

gazebo ~/simple_gripper_tutorial/gripper.world
结果如下:


点击模型,选择“View—>Joint”,新创建的关节点如下所示。


也能使用在GUI右边控制面板中的Joint Control widget来控制每一个关节的力量。


本文靠自己理解,翻译而来,错误之处望不吝指教!!!

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
要在Gazebo中加载激光雷达传感器,需要先在Robot URDF模型中定义传感器。在URDF文件中添加以下代码,以定义名为"my_laser"的激光雷达传感器: ```xml <sensor name='my_laser' type='ray'> <pose>0 0 0.1 0 0 0</pose> <visualize>true</visualize> <update_rate>10</update_rate> <ray> <scan> <horizontal> <samples>720</samples> <resolution>1</resolution> <min_angle>-1.5708</min_angle> <max_angle>1.5708</max_angle> </horizontal> </scan> <range> <min>0.1</min> <max>10.0</max> <resolution>0.01</resolution> </range> <noise> <type>gaussian</type> <mean>0.0</mean> <stddev>0.01</stddev> </noise> </ray> </sensor> ``` 然后,在launch文件中将该传感器添加Gazebo模拟器中: ```xml <robot name="my_robot"> <link name="base_link"> <visual> ... </visual> <collision> ... </collision> <inertial> ... </inertial> <sensor name='my_laser' type='ray'> <pose>0 0 0.1 0 0 0</pose> <visualize>true</visualize> <update_rate>10</update_rate> <ray> <scan> <horizontal> <samples>720</samples> <resolution>1</resolution> <min_angle>-1.5708</min_angle> <max_angle>1.5708</max_angle> </horizontal> </scan> <range> <min>0.1</min> <max>10.0</max> <resolution>0.01</resolution> </range> <noise> <type>gaussian</type> <mean>0.0</mean> <stddev>0.01</stddev> </noise> </ray> </sensor> </link> </robot> ``` 要在Gazebo中直接获取传感器数据,可以使用ROS消息订阅器来获取传感器的数据。首先,需要在launch文件中启动ROS节点: ```xml <node name="gazebo_ros_laser" pkg="gazebo_ros" type="gazebo_ros_laser" respawn="false" output="screen"> <remap from="/scan" to="/my_laser/scan"/> </node> ``` 然后,在ROS节点中创建一个ROS消息订阅器,以订阅激光雷达传感器的扫描数据: ```python import rospy from sensor_msgs.msg import LaserScan def callback(data): # Process laser scan data here pass rospy.init_node('laser_scan_subscriber') rospy.Subscriber('/my_laser/scan', LaserScan, callback) rospy.spin() ``` 在回调函数中,可以处理激光雷达传感器的扫描数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值