Interfacing Arduino with ROS

Interfacing an Arduino board with ROS simply means running a ROS node on Arduino that can publish/subscribe like a normal ROS node. An Arduino ROS node can be used to acquire and publish sensor values to a ROS environment, and other nodes can process it. Also, we can control devices, for example, actuators such as DC motors, by publishing values to an Arduino node. The main communication between PC and Arduino happens over UART. There is a dedicated protocol called ROS Serial (http://wiki.ros.org/rosserial/Overview), implemented as a ROS metapackage called rosserial, which can encode and decode ROS Serial messages. Using the ROS Serial protocol, we can publish and subscribe to Arduino like a ROS node over UART.

To start with ROS interfacing of Arduino, follow these steps:

  1. First, we have to install some ROS packages on Ubuntu. The following commands can be used to install them.
  2. Installing the rosserial metapackage:
          $ sudo apt-get install ros-kinetic-rosserial
  1. The following command will install the rosserial-arduino client package on ROS. This client package helps create a client library of the Arduino IDE for ROS. Using this library, we can create Arduino ROS nodes that work like a normal ROS node.
          $ sudo apt-get install ros-kinetic-rosserial-arduino
  1. After installing these packages, you need to download and set up the Arduino IDE. We need to download this IDE to program Arduino boards. You can download the latest Arduino IDE from (https://www.arduino.cc/en/Main/Software).
  2. You can download the Arduino IDE for Linux 64/32-bit according to your OS configuration and run the arduino executable after extracting the package.
  3. To add the ROS library for the Arduino IDE, first you have to go to File | Preference and set the Sketchbook location, as shown in this screenshot:
Figure 6: Arduino board preference
  1. Go to the sketchbook location and create a folder called libraries if it is not present, and open a Terminal inside the libraries folder. We are keeping all Arduino libraries on this folder. Enter the following command to generate the ros_lib library for Arduino:
          $ rosrun rosserial_arduino make_libraries.py .
  1. You will see the following messages printing during the execution of the command. You may get an error after some time, but that's perfectly fine.
Figure 7: Building the Arduino ROS library
  1. After the execution of this command, a folder called ros_lib will be generated, which is the Arduino ROS serial client library.
  1. Now, you can open the Arduino IDE and check that the option highlighted in the following figure is available. You can take any of the ROS examples and compile and check whether it is building without any errors:
Figure 8: ros_lib on Arduino IDE

Congratulations! You have successfully set up ros_lib on Arduino. Now we can perform a few experiments using the ROS-Arduino interface.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.226.66