理解gym-gazebo系列(二)

这篇博客详细介绍了如何利用gym-gazebo为turtlebot创建一个新的物理环境。作者通过3个步骤,包括用gazebo建立ROOM场景、添加环境变量以及编写launch文件,来实现turtlebot在自定义场景中的运行。在过程中,作者对比并调整了circuit2.world模型的参数,以解决turtlebot几乎不动的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本博文系列将记录本人理解gym-gazebo的过程。最终目标是添加自己建的环境,并使用gym来在此环境中进行强化学习的研究。

本章将研究怎么新建一个物理环境,并在此环境中加载gym-gazebo中定义好的turtlebot机器人。

我们知道,运行ros需要roslaunch一个launch文件,举一个例子,我们想要运行turtlebot在circuit2.world这个环境中,那么需要到assets中的launch文件夹中,运行

roslaunch ~/gym-gazebo/gym_gazebo/envs/assets/launch/GazeboCircuit2cTurtlebotLidar_v0.launch

因此,想要创建一个新的环境,在使用当机器人tuetlebot不变的情况下,只需要修改turtlebot所在的.world文件以及launch文件。

本章的过程共分为3步

1 使用gazebo建立ROOM场景
2 将该场景文件地址添加到环境变量
3 编写launch该场景的launch文件

  • 使用gazebo建立ROOM场景

    world文件代码以及场景图如下所示

<sdf version='1.4'>
  <world name='default'>
    <light name='sun' type='directional'>
      <cast_shadows>1</cast_shadows>
      <pose>0 0 10 0 -0 0</pose>
      <diffuse>0.8 0.8 0.8 1</diffuse>
      <specular>0.2 0.2 0.2 1</specular>
      <attenuation>
        <range>1000</range>
        <constant>0.9</constant>
        <linear>0.01</linear>
        <quadratic>0.001</quadratic>
      </attenuation>
      <direction>0.5 0.1 -0.9</direction>
    </light>
        <model name='ground_plane'>
      <static>1</static>
      <link name='link'>
        <collision name='collision'>
          <geometry>
            <plane>
              <normal>0 0 1</normal>
              <size>100 100</size>
            </plane>
          </geometry>
          <surface>
            <friction>
              <ode>
                <mu>100</mu>
                <mu2>50</mu2>
              </ode>
            </friction>
            <bounce/>
            <contact>
              <ode/>
            </contact>
          </surface>
          <max_contacts>10</max_contacts>
        </collision>
        <visual name='visual'>
          <cast_shadows>0</cast_shadows>
          <geometry>
            <plane>
              <normal>0 0 1</normal>
              <size>100 100</size>
            </plane>
          </geometry>
          <material>
            <script>
              <uri>file://media/materials/scripts/gazebo.material</uri>
              <name>Gazebo/Grey</name>
            </script>
          </material>
        </visual>
        <velocity_decay>
          <linear>0</linear>
          <angular>0</angular>
        </velocity_decay>
        <self_collide>0</self_collide>
        <kinematic>0</kinematic>
        <gravity>1</gravity>
      </link>
    </model>
    <gravity>0 0 -9.8</gravity>
    <magnetic_field>6e-06 2.3e-05 -4.2e-05</magnetic_field>
    <atmosphere type='adiabatic'/>
    <physics name='default_physics' default='0' type='ode'>
      <max_step_size>0.01</max_step_size>
      <real_time_factor>1</real_time_factor>
      <real_time_update_rate>0</real_time_update_rate>
    </physics>
    <scene>
      <ambient>0.4 0.4 0.4 1</ambient>
      <background>0.7 0.7 0.7 1</background>
      <shadows>1</shadows>
    </scene>
    <spherical_coordinates>
      <surface_model>EARTH_WGS84</surface_model>
      <latitude_deg>0</latitude_deg>
      <longitude_deg>0</longitude_deg>
      <elevation>0</elevation>
      <heading_deg>0</heading_deg>
    </spherical_coordinates>
    <model name='room'>
      <pose frame=''>1.2563 2.23891 0 0 -0 0</pose>
      <link name='Wall_0'>
        <collision name='Wall_0_Collision'>
          <geometry>
            <box>
              <size>6.5 0.15 2.5</size>
            </box>
          </geometry>
          <pose frame=''>0 0 1.25 0 -0 0</pose>
          <max_contacts>10</max_contacts>
          <surface>
            <contact>
              <ode/>
            </contact>
            <bounce/>
            <friction>
              <torsional>
                <ode/>
              </torsional>
              <ode/>
            </friction>
          </surface>
        </collision>
        <visual name='Wall_0_Visual'>
          <pose frame=''>0 0 1.25 0 -0 0</pose>
          <geometry>
            <box>
              <size>6.5 0.15 2.5</size>
            </box>
          </geometry>
          <material>
            <script>
              <uri>file://media/materials/scripts/gazebo.material</uri>
              <name>Gazebo/Wood</name>
            </script>
            <ambient>1 1 1 1</ambient>
          </material>
        </visual>
        <pose frame=''>0 -3.425 0 0 -0 0</pose>
        <self_collide>0</self_collide>
        <kinematic>0</kinematic>
        <gravity>1</gravity>
      </link>
      <link name='Wall_1'>
        <pose frame=''>3.175 0 0 0 -0 1.5708</pose>
        <visual name='Wall_1_Visual_0'>
          <pose frame=''>-2.56946 0 1.25 0 -0 0</pose>
          <geometry>
            <box>
              <size>1.86109 0.15 2.5</size>
            </box>
          </geometry>
          <material>
            <script>
              <uri>file://media/materials/scripts/gazebo.material</uri>
              <name>Gazebo/Wood</name>
            </script>
            <ambient>0.760784 0.662745 0.627451 1</ambient>
          </material>
        </visual>
        <collision name='Wall_1_Collision_0'>
          <geometry>
            <box>
              <size>1.86109 0.15 2.5</size>
            </box>
          </geometry>
          <pose frame=''>-2.56946 0 1.25 0 -0 0</pose>
          <max_contacts>10</max_contacts>
          <surface>
            <contact>
              <ode/>
            </contact>
            <bounce/>
            <friction>
              <torsional>
                <ode/>
              </torsional>
              <ode/>
            </friction>
          </surface>
        </collision>
        <visual name='Wall_1_Visual_1'>
          <pose frame=''>0.930543 0 0.5 0 -0 0</pose>
          <geometry>
            <box>
              <size>5.13891 0.15 1</size>
            </box>
          </geometry>
          <material>
            <script>
              <uri>file://media/materials/scripts/gazebo.material</uri>
              <name>Gazebo/Wood</name>
            </script>
            <ambient>0.760784 0.662745 0.627451 1</ambient>
          </material>
        </visual>
        <collision name='Wall_1_Collision_1'>
          <geometry>
            <box>
              <size>5.13891 0.15 1</size>
            </box>
          </geometry>
          <pose frame=''>0.930543 0 0.5 0 -0 0</pose>
          <max_contacts>10</max_contacts>
          <surface>
            <contact>
              <ode/>
            </contact>
            <bounce/>
            <friction>
              <torsional>
                <ode/>
              </torsional>
              <ode/>
            </friction>
          </surface>
        </collision>
        <visual name='Wall_1_Visual_2'>
          <pose frame=''>0.261087 0 1.75 0 -0 0</pose>
          <geometry>
            <box>
              <size>2.2 0.15 1.5</size>
            </box>
          </geometry>
          <material>
            <script>
              <uri>file://media/materials/scripts/gazebo.material</uri>
              <name>Gazebo/Wood</name>
            </script>
            <ambient>0.760784 0.662745 0.627451 1</ambient>
          </material>
        </visual>
        <collision name='Wall_1_Collision_2'>
          <geometry>
            <box>
              <size>2.2 0.15 1.5</size>
            </box>
          </geometry>
          <pose frame=''>0.261087 0 1.75 0 -0 0</pose>
          <max_contacts>10</max_contacts>
          <surface>
            <contact>
              <ode/>
            </contact>
            <bounce/>
            <friction>
              <torsional>
                <ode/>
              </torsional>
              <ode/>
            </friction>
          </surface>
        </collision>
        <visual name='Wall_1_Visual_3'>
          <pose frame=''>2.83054 0 1.75 0 -0 0</pose>
          <geometry>
            <box>
              <size>1.33891 0.15 1.5</size>
            </box>
          </geometry>
          <material>
            <script>
              <uri>file://media/materials/scripts/gazebo.material</uri>
              <name>Gazebo/Wood</name>
            </script>
            <ambient>0.760784 0.662745 0.627451 1</ambient>
          </material>
        </visual>
        <collision name='Wall_1_Collision_3'>
          <geometry>
            <box>
              <size>1.33891 0.15 1.5</size>
            </box>
          </geometry>
          <pose frame=''>2.83054 0 1.75 0 -0 0</pose>
          <max_contacts>10</max_contacts>
          <surface>
            <contact>
              <ode/>
            </contact>
            <bounce/>
            <friction>
              <torsional>
                <ode/>
              </torsional>
              <ode/>
            </friction>
          </surface>
        </collision>
        <visual name='Wall_1_Visual_4'>
          <pose frame=''>-1.23891 0 2.15 0 -0 0</pose>
          <geometry>
            <box>
              <size>0.8 0.15 0.7</size>
            </box>
          </geometry>
          <material>
            <script>
              <uri>file://media/materials/scripts/gazebo.material</uri>
              <name>Gazebo/Wood</name>
            </script>
            <ambient>0.760784 0.662745 0.627451 1</ambient>
          </material>
        </visual>
        <collision name='Wall_1_Collision_4'>
          <geometry>
            <box>
              <size>0.8 0.15 0.7</size>
            </box>
          </geometry>
          <pose frame=''>-1.23891 0 2.15 0 -0 0</pose>
          <max_contacts>10</max_contacts>
          <surface>
            <contact>
              <ode/>
            </contact>
            <bounce/>
            <friction>
              <torsional>
                <ode/>
              </torsional>
              <ode/>
            </friction>
          </surface>
        </collision>
        <visual name='Wall_1_Visual_5'>
          <pose frame=''>1.76109 0 2.15 0 -0 0</pose>
          <geometry>
            <box>
              <size>0.8 0.15 0.7</size>
            </box>
          </geometry>
          <material>
            <script>
              <uri>file://media/materials/scripts/gazebo.material</uri>
              <name>Gazebo/Wood</name>
            </script>
            <ambient>0.760784 0.662745 0.627451 1</ambient>
          </material>
        </visual>
        <collision name='Wall_1_Collision_5'>
          <geometry>
            <box>
              <size>0.8 0.15 0.7</size>
            </box>
          </geometry>
          <pose frame=''>1.76109 0 2.15 0 -0 0</pose>
          <max_contacts>10</max_contacts>
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值