Simulation plays a crucial role in robotics development by allowing developers to assess their algorithms and designs without physical prototypes. In this tutorial, we will demonstrate how to simulate a robotic arm with physics-based simulator [Gazebo](https://gazebosim.org/) and visualize it with Foxglove.

## Setting up

Before getting started, install [ROS 1 Noetic](/content/blog/installing-ros1-noetic-on-ubuntu/index.html) and [Gazebo](https://gazebosim.org/).

This tutorial assumes basic knowledge of ROS – the tutorials on the [ROS Wiki](http://wiki.ros.org/ROS/Tutorials) and [the Foxglove blog](/content/tutorials/index.html) are a good place to brush up on your ROS basics.

## Running the simulation demo

Before running the simulation demo, we must first build the simulation package in the [`foxglove/tutorials` GitHub repo](https://github.com/foxglove/tutorials/blob/main/integrations/ros1/gazebo/README.md). See the `README.md` file for detailed instructions.

Once the package has been built and the workspace sourced, run the simulation:

```bash
$ roslaunch fg_gazebo_example simulation.launch
```

This will start Gazebo and spawn a Universal Robot UR5e with a mounted depth camera, a fixed RGB camera, and a box-shaped object in the Gazebo world. To spawn a robot and camera models, you can provide URDF files that contain [`<gazebo>`](https://gazebosim.org/) tags. These tags instruct Gazebo to create [depth](https://github.com/foxglove/tutorials/blob/main/integrations/ros1/gazebo/urdf/kinect.urdf.xacro#L65-L98) and [RGB](https://github.com/foxglove/tutorials/blob/main/integrations/ros1/gazebo/urdf/static_camera.urdf.xacro#L61-L94) camera sensors and expose them on ROS topics using [`gazebo_ros_pkgs`](http://wiki.ros.org/gazebo_ros_pkgs) [plugins](https://classic.gazebosim.org/tutorials?tut=ros_gzplugins).

Besides the Gazebo simulation, `simulation.launch` also launches [MoveIt](https://moveit.ros.org/) to plan and execute robot motions. The simulation also launches [`foxglove_bridge`](https://index.ros.org/p/foxglove_bridge/#noetic) to visualize the robot model and camera images in [Foxglove](/content/product/index.html).

## Moving the robot

Run the Python script in the simulation demo package to execute robot motions using MoveIt’s Python API:

```bash
$ rosrun fg_gazebo_example move_viewpoints.py
```

This will cause the robot to move through several positions to inspect the box with its mounted depth camera.

Use [`rqt_joint_trajectory_controller`](http://wiki.ros.org/rqt_joint_trajectory_controller) or MoveIt’s motion planning RViz plugin to move the robot to other arbitrary positions.

## Visualizing with Foxglove

To visualize this data, download the latest version of the [Foxglove desktop app](/content/download/index.html).

Make sure that the [`ROS_PACKAGE_PATH` setting](https://docs.foxglove.dev/docs/visualization/introduction#general) includes your workspace, so that Foxglove can locate the mesh files referenced in the robot’s URDF file.

Next, open a live Foxglove Websocket connection – specify `ws://localhost:8765` as the connection URL.

Add a [3D panel](https://docs.foxglove.dev/docs/visualization/panels/3d) to visualize the robot model and all transforms. Then, add a few [Image panels](https://docs.foxglove.dev/docs/visualization/panels/image) to view the RGB and depth image topics.

You should now see both the robot model and camera images visualized in your Foxglove layout:

## Stay in touch

To reference all code covered in this post, check out our [`foxglove/tutorials` GitHub repo](https://github.com/foxglove/tutorials/blob/main/integrations/ros1/gazebo/README.md).

As always, feel free to reach out to us directly in our [Discord community](/content/chat/index.html) to ask questions or request a topic for the next tutorial.
