Robot programming with Arduino and ROS
The ROS robotic operating system is a fairly powerful platform for creating robotic systems, which includes everything necessary for developing your projects from the simplest software components called “nodes” and the data exchange protocol to the simulation environment of a real Gazebo robotic platform. ROS is mainly used in conjunction with microcontrollers such as RaspberryPi and Blackbone, which have great computing capabilities and their own operating system.
Arduino is a popular prototyping board, widely used in connection with the notion “smart home” that arose not so long ago 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 using 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" of ROS and Arduino and what I managed to achieve in this bundle.
To use ROS with the Arduino board, there is an official library in ROS - rosserial_arduino .
Installing the library is as simple as installing any other ROS packages:
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 the native catkin utility was created to build packages. For versions earlier than groovy, you need to run the following commands:
For ROS versions using catkin (groovy and later), the installation procedure will be as follows:
Here ws is the name of the catkin workspace folder, usually catkin_ws.
Now all that remains is to copy the ros_lib library into the Arduino environment 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 the folder, which is the default folder for storing Arduino sketches, usually a sketchbook.
The ros_lib setting is different for ROS versions using catkin (starting with groovy) and rosbuild (fuerte and earlier).
For versions with catkin, the installation will be as follows:
And for versions of fuerte and earlier it will be like this:
Now you can open examples for rosserial_arduino in the Arduino IDE. To do this, run the Arduino IDE, select File> Examples> ros_lib. Choose the HelloWorld example to get you started.
Sketch of 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 master and the rosserial client application, which will redirect the entire Arduino message to other ROS components:
The _port parameter defines the serial port on which the Arduino board is available, for example, / dev / ttyACM0 for me.
The only action that the HelloWorld sketch performs is posting messages to the chatter theme. You can see published posts using the rostopic command:
If an error occurs 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 add the line
before turning on ros libraries in a sketch.
rosserial_arduino allows you to post 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, in my experiments, I was able to create a sketch to receive data from the HC-SR07 ultrasonic distance sensor and publish it to the range topic.
Among the interesting features of ROS that 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 data from the HC-RS07 sensor in the form of a graph as follows:
You can also control the servo by subscribing to the servo topic and publish the values for the angle of rotation of the servo with the command:
rosserial_arduino offers a series of examples of using the library with various sensors, LEDs, 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 use cases for mobile robots. For example, for a wheeled robot equipped with an ultrasonic sensor like SRF08 Ultrasonic Ranger, rosserial_arduino can be used as follows: the rosserial_arduino node can include Publisher, which sends data from the sonar at a certain time interval, and Subscriber, which subscribes to the same topic and transfers data to the method that controls the movement of the robot. The rosserial_arduino package gives the developer complete freedom: it all depends on your imagination.
Good luck experimenting with ROS and Arduino!
Arduino is a popular prototyping board, widely used in connection with the notion “smart home” that arose not so long ago 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 using 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" of ROS and Arduino and what I managed to achieve in this bundle.
To use ROS with the Arduino board, there is an official library in ROS - rosserial_arduino .
Setting rosserial_arduino
Installing the library is as simple as installing any other ROS packages:
sudo apt-get install ros--rosserial-arduino
sudo apt-get install ros--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 the native catkin utility was created to build packages. For versions earlier than groovy, you need to run the following commands:
hg clone https://kforge.ros.org/rosserial/hg rosserial
rosmake rosserial_arduino
For ROS versions using catkin (groovy and later), the installation procedure will be as follows:
cd /src
git clone https://github.com/ros-drivers/rosserial.git
cd
catkin_make
catkin_make install
source /install/setup.bash
Here ws is the name of the catkin workspace folder, usually catkin_ws.
Adding rosserial_arduino to Arduino IDE
Now all that remains is to copy the ros_lib library into the Arduino environment 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 the folder, which is the default folder for storing Arduino sketches, usually a sketchbook.
The ros_lib setting is different for ROS versions using catkin (starting with groovy) and rosbuild (fuerte and earlier).
For versions with catkin, the installation will be as follows:
cd /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 /libraries/ros_lib
Running examples for rosserial_ros
Now you can open examples for rosserial_arduino in the Arduino IDE. To do this, run the Arduino IDE, select File> Examples> ros_lib. Choose the HelloWorld example to get you started.
Sketch of 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 master 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 example, / dev / ttyACM0 for me.
The only action that the HelloWorld sketch performs is posting messages to the chatter theme. You can see published posts using the rostopic command:
rostopic echo chatter
Solving Launch Issues
If an error occurs 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 add the line
#define USE_USBCON
before turning on ros libraries in a sketch.
Features rosserial_arduino
rosserial_arduino allows you to post 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, in my experiments, I was able to create a sketch to receive data from the HC-SR07 ultrasonic distance sensor and publish it to the range topic.
Among the interesting features of ROS that 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 data from the HC-RS07 sensor in the form of a graph as follows:
rqt_plot range
You can also control the servo by subscribing to the servo topic and publish the values for the angle of rotation of the servo with the command:
rostopic pub servo std_msgs/UInt16
What's next?
rosserial_arduino offers a series of examples of using the library with various sensors, LEDs, 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 use cases for mobile robots. For example, for a wheeled robot equipped with an ultrasonic sensor like SRF08 Ultrasonic Ranger, rosserial_arduino can be used as follows: the rosserial_arduino node can include Publisher, which sends data from the sonar at a certain time interval, and Subscriber, which subscribes to the same topic and transfers data to the method that controls the movement of the robot. The rosserial_arduino package gives the developer complete freedom: it all depends on your imagination.
Good luck experimenting with ROS and Arduino!