We can install the rosserial packages on Ubuntu using the following commands:
- Installing the rosserial package binaries using apt-get:
- In Indigo:
$ sudo apt-get install ros-indigo-rosserial ros-indigo-rosserial-arduino ros-indigo-rosserial-server
- In Jade:
$ sudo apt-get install ros-jade-rosserial ros-jade-rosserial-arduino ros-jade-rosserial-server
- For installing the rosserial_client library called ros_lib in Arduino, we have to download the latest Arduino IDE for Linux 32/64 bit. Following is the link for downloading Arduino IDE: https://www.arduino.cc/en/main/software
- Here we download the Linux 64 bit version and copy the Arduino IDE folder to the Ubuntu desktop.
- Arduino requires JAVA runtime support to run it. If it is not installed, we can install it using the following command:
$ sudo apt-get install java-common
- After installing JAVA runtime, we can switch the arduino folder using the following command:
$ cd ~/Desktop/arduino-1.6.5
- Start Arduino using the following command:
$ ./arduino
- Shown next is the Arduino IDE window:
- Go toFile | Preference for configuring the sketchbook folder of Arduino. Arduino IDE stores the sketches to this location. We created a folder called Arduino1 in the user home folder and set this folder as the sketchbook location.
- We can see a folder called libraries inside the Arduino1 folder. Switch to this folder using the following command:
$ cd ~/Arduino1/libraries/
- If there is no libraries folder, we can create a new one.
- After switching into this folder, we can generate ros_lib using a script called make_libraries.py, which is present inside the rosserial_arduino package. ros_lib is rosserial_client for Arduino, which provides the ROS client APIs inside an Arduino IDE environment.
$ rosrun rosserial_arduino make_libraries.py .
rosserial_arduino is ROS client for arduino which can communicate using UART and can publish topics, services, TF, and such others like a ROS node. The make_libraries.py script will generate a wrapper of the ROS messages and services which optimized for Arduino data types. These ROS messages and services will convert into Arduino C/C++ code equivalent, as shown next:
- Conversion of ROS messages:
ros_package_name/msg/Test.msg --> ros_package_name::Test
- Conversion of ROS services:
ros_package_name/srv/Foo.srv --> ros_package_name::Foo
For example, if we include #include <std_msgs/UInt16.h> , we can instantiate the std_msgs::UInt16 number.
If the script make_libraries.py works fine, a folder called ros_lib will generate inside the libraries folder. Restart the Arduino IDE and we will see ros_lib examples as follows:
We can take any example and make sure that it is building properly to ensure that the ros_lib APIs are working fine. The necessary APIs required for building ROS Arduino nodes are discussed next.