# gym-gazebo安装后的测试

## 目录

本节会安装以下内容

* [ ] [目录](#目录)
* [ ] [第一步：bash turtlebot\_setup.bash](#第一步bash-turtlebot_setupbash)
  * [Running an environment](#running-an-environment)
  * [Run any of the examples available in examples/. E.g.:](#run-any-of-the-examples-available-in-examples-eg)
* [ ] [第二步：source setup\_turtlebot.bash](#第二步source-setup_turtlebotbash)
  * [source](#source)
  * [进行expert操作](#进行expert操作)
* [ ] [第三步：eg export ROS\_MASTER\_URI=http://localhost:12795](#第三步eg-export-ros_master_urihttplocalhost12795)
  * [第二步和第三步操作方法的截图](#第二步和第三步操作方法的截图)
* [ ] [第四步：gzclient](#第四步gzclient)
* [ ] [五 最终效果](#五-最终效果)
  * [Display reward plot](#display-reward-plot)
  * [Killing background processes](#killing-background-processes)
* [x] Edit By Porter, 积水成渊,蛟龙生焉。&#x20;

## 第一步：bash turtlebot\_setup.bash

### Running an environment

Load the environment variables corresponding to the robot you want to launch. E.g. to load the Turtlebot:

```bash
cd gym_gazebo/envs/installation
bash turtlebot_setup.bash
```

Note: all the setup scripts are available in gym\_gazebo/envs/installation

### Run any of the examples available in examples/. E.g.:

```bash
cd examples/turtlebot
python3 circuit2_turtlebot_lidar_qlearn.py
```

![bash turtlebot\_setup.bash](https://1930597982-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LV7JLvsYnG7y7A2o-vp%2F-LeByGwsTbLwQ458tISW%2F-LeByK0NJoYshfz6aNDY%2Fgym_gazebo_test1.png?generation=1557143315576321\&alt=media)

## 第二步：source setup\_turtlebot.bash

* 我的source bash文件是setup.bash不是setup\_turtlebot.bash，所以我的是source setup.bash

### source

```bash
cd /home/porter/gym-gazebo/gym_gazebo/envs/installation/catkin_ws/devel
source setup.bash
```

### 进行expert操作

首先第一步：bash turtlebot\_setup.bash过后，终端会有如下的提示

![export GAZEBO\_MASTER\_URI=http://](https://1930597982-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LV7JLvsYnG7y7A2o-vp%2F-LeByGwsTbLwQ458tISW%2F-LeByK0Po8ZKDiR2BEJj%2Fgym_gazebo_export2.png?generation=1557143317307477\&alt=media) 得到有用的终端输出信息

```bash
porter@porter-Aspire:~/gym-gazebo/examples/turtlebot$ python3 circuit2_turtlebot_lidar_qlearn.py
ROS_MASTER_URI=http://localhost:12795

GAZEBO_MASTER_URI=http://localhost:12796

Gazebo launched!
Unable to register with master node [http://localhost:12795]: master may not be running yet. Will keep trying.
... logging to /home/porter/.ros/log/ab3f7618-6fea-11e9-a24a-f0761cd1b3e0/roslaunch-porter-Aspire-11818.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://porter-Aspire:33631/
```

## 第三步：eg export ROS\_MASTER\_URI=<http://localhost:12795>

```bash
export ROS_MASTER_URI=http://localhost:12795 # 和上面的端口号一致
export GAZEBO_MASTER_URI=http://localhost:12796 # 和上面的端口号一致
```

### 第二步和第三步操作方法的截图

![gym\_gazebo\_export1](https://1930597982-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LV7JLvsYnG7y7A2o-vp%2F-LeByGwsTbLwQ458tISW%2F-LeByK0RERrKV7NPqNOB%2Fgym_gazebo_export1.png?generation=1557143316787257\&alt=media)

## 第四步：gzclient

执行如下命令打开gazebo

```bash
gzclient
```

## 五 最终效果

![gym\_gazebo 完整运行效果](https://1930597982-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LV7JLvsYnG7y7A2o-vp%2F-LeByGwsTbLwQ458tISW%2F-LeByK0T7DQIMfW2pijx%2Fturtlebot_ros_gazebo.gif?generation=1557143319746738\&alt=media)

### Display reward plot

Display a graph showing the current reward history by running the following script:

```bash
cd /home/porter/gym-gazebo/
cd examples/utilities
python3 display_plot.py
```

HINT: use --help flag for more options.

### Killing background processes

Sometimes, after ending or killing the simulation gzserver and rosmaster stay on the background, make sure you end them before starting new tests.

We recommend creating an alias to kill those processes.

```bash
echo "alias killgazebogym='killall -9 rosout roslaunch rosmaster gzserver nodelet robot_state_publisher gzclient'" >> ~/.bashrc
```

参考来源：<https://github.com/erlerobot/gym-gazebo/tree/master#installation>
