The ROS robotic operating system is a fairly powerful platform for creating robotic systems, which includes everything you need to develop your projects from the simplest software components called “nodes” and the data exchange protocol to the simulation environment of the real Gazebo robotic platform. ROS is mainly used in conjunction with microcontrollers such as RaspberryPi and Blackbone, which have great computational capabilities and their own operating system.
Arduino is a popular prototyping board that is widely used in connection with the new concept of “smart home” and which is an ideal starting point for beginners in the field of microelectronics and robotics.
At the moment there is not much information about the use of the ROS robotic operating system in conjunction with the Arduino microcontroller. These are mainly foreign online resources and books.
')
In this article I want to tell how to "make friends" ROS and Arduino and what I was able to achieve in this bundle.
To use ROS with the Arduino board, there is an official library at ROS -
rosserial_arduino .
Install rosserial_arduino
Installing the library is as easy as installing any other ROS packages:
sudo apt-get install ros-<distribution_name>-rosserial-arduino sudo apt-get install ros-<distribution_name>-rosserial
After that, you need to install the rosserial_arduino package from binary files. The installation is slightly different for ROS versions starting with groovy, where a custom catkin utility was created for building packages. For earlier versions of groovy, you need to run the following commands:
hg clone https://kforge.ros.org/rosserial/hg rosserial rosmake rosserial_arduino
For versions of ROS using catkin (groovy and later) the installation procedure will be as follows:
cd <ws>/src git clone https://github.com/ros-drivers/rosserial.git cd <ws> catkin_make catkin_make install source <ws>/install/setup.bash
Here ws stands for the folder name catkin workspace, usually catkin_ws.
Adding rosserial_arduino to the Arduino IDE
Now you just have to copy the ros_lib library to Arduino to allow Arduino programs to interact with ROS. The ros_lib library was generated in the previous installation steps.
The library will be copied to a folder, which is the default folder for storing Arduino sketches, usually a sketchbook.
The ros_lib setting is different for the ROS versions using catkin (starting with the groovy version) and rosbuild (fuerte and earlier).
For versions with catkin, the installation will be as follows:
cd <sketchbook>/libraries rm -rf ros_lib rosrun rosserial_arduino make_libraries.py .
And for versions of fuerte and earlier it will be like this:
roscd rosserial_arduino/src cp -r ros_lib <sketchbook>/libraries/ros_lib
Running examples for rosserial_ros
You can now open the examples for rosserial_arduino in the Arduino IDE. To do this, launch the Arduino IDE, select File> Examples> ros_lib. Select the HelloWorld example to get you started.
Sketch from the examples can be immediately downloaded to the board. Downloading is no different than downloading any other Arduino sketch.
It remains only to run the ROS wizard and the rosserial client application, which will redirect the entire Arduino message to other ROS components:
roscore rosrun rosserial_python serial_node.py _port:=/dev/ttyUSB0
The _port parameter defines the serial port on which the Arduino board is available; for me, for example, / dev / ttyACM0.
The only action that the HelloWorld sketch performs is posting messages to the chatter topic. You can see the posts posted using the rostopic command:
rostopic echo chatter
Solving startup problems
If the error appeared when starting the rosserial client application: “Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino, then you need to add a line
#define USE_USBCON
before including ros libraries in the sketch.
Rosserial_arduino features
rosserial_arduino allows you to post messages to topics and subscribe to messages from specific topics. It also allows you to use ros :: Time and TF and publish tf transformation data.
For example, during experiments, I was able to create a sketch for receiving data from the ultrasonic distance sensor
HC-SR07 and publishing to the topic range.
Among the interesting features of ROS, which can be used in rosserial_arduino is the visualization of numerical data (for example, from a sensor) with rqt_plot. For example, you can visualize the data from the HC-RS07 sensor as a graph like this:
rqt_plot range

You can also control the servo by subscribing to the servo theme and publish the values ​​for the servo angle with the command:
rostopic pub servo std_msgs/UInt16 <angle>
What's next?
rosserial_arduino offers a series of examples on the use of the library with various sensors, LED, servo and buttons. All usage examples can be found on the official ROS page:
wiki.ros.org/rosserial_arduino/Tutorials .
In my opinion, rosserial_arduino can have many usage scenarios for mobile robots. For example, for a wheeled robot equipped with an ultrasonic sensor such as the SRF08 Ultrasonic Ranger rosserial_arduino can be used as follows: the rosserial_arduino node may include a Publisher, which after a certain time interval sends data from the sonar, and Subscriber, which subscribes to the same topic and sends data to the method controls the movement of the robot. The rosserial_arduino package gives complete freedom to the developer: it all depends on your imagination.
Good luck with your ROS and Arduino experiments!