A Gentle Introduction to rosrust, and its actionlib Support

# rosrust, and actionlib


# Overview
## Introduction
My name is Salvatore and I am a Development Engineer at [株式会社Rist][Rist].

## About this article
This article is meant to be a quick and direct introduction to the actionlib support in rosrust, based on the examples of the [rosrust repository][rosrustOfficial].


# rosrust
## What is rosrust
rosrust is a [Rust][RustOfficial] implementation of a [ROS][ROSOfficial] client library.
Being rosrust a Rust [crate][cratesRepository], it assumes an existing underlying Rust environment in order to be used.

## Why it is needed
rosrust allows to interface code written in Rust to the standard ROS environment.


# Installation
## Environment

| Software | Version                            |
|:---------|:-----------------------------------|
| OS       | Ubuntu 18.04.4 LTS (Bionic Beaver) |
| Python   | Python 2.7.17                      |
|          | Python 3.6.9 (Default)             |
| ROS      | ROS 1 (Melodic)                    |
| Rust     | Rust 1.45.2 (d3fb005a3 2020-07-31) |
| rosrust  | rosrust v0.9.3                     |

For information on setting up a `ROS 1 Melodic` environment on a machine running Ubuntu, refer to the [official documentation][ROS1UbuntuInstall].

## Rust
The installation of Rust is straight forward and all the needed packages will be located into the user home directory.

- Proceed with the installation:

```bash
$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
```

- Verify the installation:

```bash
$ rustc --version
```

For more details on the installation, or alternative platforms, refer to [The Rust Programming Language][RustBookEN] book, or the [official documentation][RustInstall].

## rosrust
The rosrust crate is available at the [official github repository][rosrustOfficial].

- To proceed with the installation, clone the official repository:

```bash
$ git clone https://github.com/adnanademovic/rosrust.git
```

- Build the crate:  
  Note: in order to successfully build the rosrust crate, due to message dependencies, it is necessary to source the ROS installation path.

```bash
$ . /opt/ros/melodic/setup.bash
$ cargo build
```

At this point, the rosrust crate is available for use.


# Verify the installation
To verify the correct installation of the rosrust crate, it is possible to run the examples provided by the crate itself.

- To show a list of all available examples, run the following command from the root of the rosrust crate folder structure:

```bash
$ cargo run --example
```

- Comprehensive list of available examples in the rosrust crate:

```bash
slb@salvatorepc: rosrust (master=) $ cargo run --example
error: "--example" takes one argument.
Available examples:
    access_image_message
    camera_subscriber
    client
    client_node
    example
    fibonacci_cancelling_client
    fibonacci_client
    fibonacci_multi_call_client
    fibonacci_server
    frequency_status
    function_task
    function_task_extra
    old_client
    old_service
    parameters
    publisher
    publisher_latch_demo
    publisher_node
    pubsub_loopback
    service
    service_node
    subscriber
    subscriber_node
    subscriber_with_ids
```

Next, it will be shown the simplest publisher/subscriber example in order to determine the correct behaviour of the ROS/rosrust environment.


# Running the publisher/subscriber example
Considering the simplest example of the communication between a publisher and a subscriber on a common topic.

## Shell 1: `roscore`
- Launch roscore:

```bash
$ . /opt/ros/melodic/setup.bash
$ roscore
```

## Shell 2: `publisher`
- Launch the publisher:

```bash
$ . /opt/ros/melodic/setup.bash
$ cargo run --example publisher
```

## Shell 3: `subscriber`
- Launch the subscriber:

```bash
$ . /opt/ros/melodic/setup.bash
$ cargo run --example subscriber
```

## Shell 4: `topics`
- Show the nodes and the exchange of the messages on the specified topic:

```bash
$ . /opt/ros/melodic/setup.bash
$ rosnode list
$ rostopic list
$ rostopic info /chatter
$ rostopic echo /chatter
```

## Terminals
![Screenshot from 2020-08-18 16-51-42.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/556567/ba198368-b00c-5aff-4c70-be4f1bb8627f.png)


# Running the actionlib example
The actionlib example shows a fully functional integration with the [ROS actionlib][ROSactionlib].

### Shell 1: `roscore`
- Launch roscore:

```bash
$ . /opt/ros/melodic/setup.bash
$ roscore
```

### Shell 2: `fibonacci_server`
- Launch the publisher:

```bash
$ . /opt/ros/melodic/setup.bash
$ cargo run --example fibonacci_server
```

### Shell 3: `fibonacci_client`
- Launch the subscriber:

```bash
$ . /opt/ros/melodic/setup.bash
$ cargo run --example fibonacci_client
```

## Terminals
![Peek 2020-08-18 17-21.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/556567/329377d3-7baf-b53d-b7d4-fa2f609058b8.gif)

As shown earlier, there are a lot more examples available in the rosrust crate. Feel free to try them all!


# References

- [rosrust repository][rosrustOfficial]
- [Rust Programming Language][RustOfficial]
- [Robot Operating System][ROSOfficial]
- [Crates Repository][cratesRepository]
- [The Rust Programming Language (Book)][RustBookEN]
- [Rust Install Guide][RustInstall]
- [ROS 1 Ubuntu Install Guide][ROS1UbuntuInstall]
- [ROS actionlib][ROSactionlib]


[Rist]: https://www.rist.co.jp/
[rosrustOfficial]: https://github.com/adnanademovic/rosrust
[RustOfficial]: https://www.rust-lang.org/
[ROSOfficial]: https://www.ros.org/
[cratesRepository]: https://crates.io/
[RustBookEN]: https://doc.rust-lang.org/book/
[RustBookENInstall]: https://doc.rust-lang.org/book/ch01-01-installation.html
[RustInstall]: https://www.rust-lang.org/tools/install
[ROS1UbuntuInstall]: http://wiki.ros.org/melodic/Installation/Ubuntu
[ROSactionlib]: http://wiki.ros.org/actionlib