---
tags: ROS2note,Gazebo,Training
---
# Gazebo: Robot Simulation
The tutorial will guide you how to run a robot in Gazebo.
# NeuronBot 2
NeuronBot Simulation supports both ROS 1 and ROS 2.
## ROS 1
Refer to https://github.com/Adlink-ROS/neuronbot2/tree/noetic-devel
## ROS 2
Refer to https://github.com/Adlink-ROS/neuronbot2/tree/foxy-devel
# OmniBot (Optional)
OmniBot Simulation is modifed from turtlebot.
Source code: https://github.com/Adlink-ROS/gazebo_demo/tree/master/robotSimulation
## Setup Environment
Build environment.
```
# Select ROS 1 melodic environment
source /opt/ros/melodic/setup.bash
mkdir ~/workspace
cd workspace
git clone https://github.com/Adlink-ROS/gazebo_demo.git
cd ~/workspace/gazebo_demo/robotSimulation
source setup.sh
```
## Run Gazebo world
We'll simulate OmniBot in Gazebo.
```
# Select ROS 1 melodic environment
source /opt/ros/melodic/setup.bash
cd ~/workspace/gazebo_demo/robotSimulation
source model.sh
roslaunch turtlebot3_gazebo turtlebot3_world.launch
```

## Run teleop
Control robot by using teleop_twist_keyboard in another terminal.
```
# Select ROS 1 melodic environment
source /opt/ros/melodic/setup.bash
cd ~/workspace/gazebo_demo/robotSimulation
source model.sh
roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
```
## SLAM and save map
* Run SLAM with gmapping in another terminal.
```
# Select ROS 1 melodic environment
source /opt/ros/melodic/setup.bash
cd ~/workspace/gazebo_demo/robotSimulation
source model.sh
roslaunch turtlebot3_slam turtlebot3_slam.launch
```
* Open new terminal to save the map.
```
# Select ROS 1 melodic environment
source /opt/ros/melodic/setup.bash
cd ~/workspace/gazebo_demo/robotSimulation/simulation_ws
mkdir maps
cd maps
rosrun map_server map_saver -f sim_map
```
## Navigation (from A to B)
* Close SLAM and run naviagation and rviz.
```
roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=$HOME/workspace/gazebo_demo/robotSimulation/simulation_ws/maps/sim_map.yaml
```
* (Optional) You can improve performance with the following command.
```
rosrun dynamic_reconfigure dynparam set gazebo max_update_rate 250
rosrun dynamic_reconfigure dynparam set gazebo time_step 0.004
# show the settings result
rosparam get /gazebo/max_update_rate
rosparam get /gazebo/time_step
```
