> For the complete documentation index, see [llms.txt](https://clemson-autonomous-systems.gitbook.io/clemson-university-autonomous-systems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://clemson-autonomous-systems.gitbook.io/clemson-university-autonomous-systems/multi-agent-development/multi-agent-networking-guide/rosserial-guide.md).

# ROSSerial Connection Guide

This page will detail the procedure for establishing a ROSSerial connection with the XBEE devices.

{% hint style="warning" %}
This guide assumes that you already have some form of ROS Melodic installed on your system. If this is not the case, you should be able to substitute 'melodic' for whatever your current ROS version is, but no guarantees that will work.
{% endhint %}

## Installing ROSSerial

Installing `rosserial` is a very easy process. As long as you have already installed ROS on your system, as well as configured the `apt` repository (odds are you have already done this if you installed ROS using `apt` or `apt-get`) this is a very straightforward process.

```bash
sudo apt-get install ros-melodic-rosserial*
```

Once this is completed, congratulations you have installed `rosserial`!

### Arduino Library Installation

If you will be writing `rosserial` code for the Arduino, you will need to follow a few extra steps in order to configure the development environment on your own computer. The following steps will configure the ROS library in your Arduino workspace.

```bash
# Ensure that the rosserial-arduino package is installed onto your system
sudo apt-get install ros-melodic-rosserial-arduino

# Replace arduino_sketchbook with the actual link to the sketchbook directory
cd <arduino_sketchbook>/libraries

# Delete any existing ros_lib installation
rm -rf ros_lib

# Install the rosserial_library
# NOTE: You may need to run a ROS Master in a different terminal
rosrun rosserial_arduino make_libraries.py .
```

## Examples

These two examples are common scenarios you will find yourself in as you test the development robots. These are based off of working with the Milieu Babel robot.

### Connecting to the Arduino (Hardwired)

This guide will assume that you are connected to the Arduino device with the USB cable. Before you perform these steps, make sure that you have the communications port for the Arduino. You can find this by opening the Arduino IDE and viewing the communication port it uses for connecting to the Arduino Board.

```bash
# In Terminal A
roscore

# In Terminal B
rosrun rosserial_arduino serial_node.py _port:=/dev/ttyACM0 _baud:=9600
```

### Connecting to the Arduino (XBee)

{% hint style="warning" %}
Make sure that you have configured the XBee radios by using the information in [XBee Configuration](/clemson-university-autonomous-systems/multi-agent-development/multi-agent-networking-guide/hardware/xbee-configuration.md) before you follow the steps in this guide.
{% endhint %}

This guide will assume that you are trying to connect to the Arduino device over the XBee network. Luckily, this process is very straightforward. Simply start a ROS master and start the rosserial node, and the node should be able to establish a connection between your device and the Arduino

```bash
# In Terminal A
roscore

# In Terminal B
rosrun rosserial_python serial_node.py _port:=/dev/ttyUSB0 _baud:=9600
```
