理解gym-gazebo系列(二)

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

本博文系列将记录本人理解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>
          <s
  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 17
    评论
根据你提供的代码,我看到你有两个表格容器 `.centerBox_1_table_container`,第一个用于显示台风列表,第个用于显示选中台风的详细信息。 要实现表头固定而内容区域滚动的效果,可以按照以下步骤进行修改: 1. 在 CSS 中,给第一个表格容器 `.centerBox_1_table_container` 添加 `max-height` 属性,并设置合适的高度来限制内容区域的高度。例如:`max-height: 200px;`。 2. 给第一个表格容器 `.centerBox_1_table_container` 添加 `overflow-y: auto;` 属性,以实现垂直滚动。 3. 在 HTML 中,给第一个表格容器的 `<table>` 元素添加一个 `<thead>` 元素,用于存放表头。 4. 在第一个表格容器的 `<table>` 元素中,将原先的表头行 `<tr>` 移动到 `<thead>` 元素中。 5. 将第一个表格容器的 `<table>` 元素中的 `<tbody>` 元素删除,因为我们只需要固定表头而不需要滚动内容。 下面是修改后的代码示例: ```html <div class="guanbi3" @click="guanbi('centerBox_1')"></div> </div> <select v-model="selectedYear"> <option v-for="year in years" :key="year" :value="year">{{ year }}</option> </select> <div class="centerBox_1_table_contain"> <table> <thead> <tr> <th></th> <th>台风编号</th> <th>台风名</th> <th>英文名</th> </tr> </thead> </table> </div> <div class="centerBox_1_table_container"> <table> <tr v-for="typhoon in filteredTyphoons" :key="typhoon.id"> <td class="radio-cell"><input type="radio" :value="typhoon.id" v-model="selectedTyphoonId"></td> <td>{{ typhoon.number }}</td> <td>{{ typhoon.name }}</td> <td>{{ typhoon.englishName }}</td> </tr> </table> </div> <div class="centerBox_1_table_container" style="max-height: 200px; overflow-y: auto;"> <table v-if="selectedTyphoonId"> <thead> <tr> <th>事件</th> <th>风速</th> <th>移向</th> <th>强度</th> </tr> </thead> <tbody> <tr v-for="detail in selectedTyphoonDetails" :key="detail.id"> <td>{{ detail.event }}</td> <td>{{ detail.windSpeed }}</td> <td>{{ detail.direction }}</td> <td>{{ detail.intensity }}</td> </tr> </tbody> </table> </div> </div> </div> ``` 在修改后的代码中,我添加了一个新的 `<div>` 元素来包裹第一个表格容器,并给这个 `<div>` 元素添加了 `max-height` 和 `overflow-y` 属性,来限制内容区域的高度并实现垂直滚动。同时,将原先的表头行 `<tr>` 移动到新添加的 `<thead>` 元素中。 请根据实际情况对代码进行适当调整和修改。希望这次能够满足你的需求。如果还有问题,请随时提问。
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值