ARDUINO

 

Arduino and Arduino IDE are tools for quickly and easily programming hardware.

Using the rosserial_arduino package we can use ROS directly with the Arduino IDE.

Rosserial provides a ROS communication protocol that works over your Arduino's UART.

Arduino is fool fledged ROS node which can directly publish and subscribe to ROS messages, publish TF transforms, and get the ROS system time.

First we have to install Arduino IDE wich we can download from Arduino websites.

It is best to install the application into a folder on the application PATH, the desktop, or home folder.

When Arduino IDE is installed,we have to launch application and select a location for sketchbook,

sketchbook is a standard place to store our programs, or sketches.

ROS bindings are implemented as an Arduino library. Like all Arduino libraries, ros_lib works by putting its library implementation into the libraries folder of your sketchbook. If there is not already a libraries folder in our sketchbook, we have to make one. You can then install the library using the instructions below.

In order to use the rosserial libraries in our own code, we must first put

 

#include <ros.h>
#include <std_msgs/String.h>

without this include Arduino IDE will not be able to locate them. 



INSTALLING SOFTWARE

Installing Binaries on the ROS workstation

To install rosserial for Arduino we have to run

sudo apt-get install ros-kinetic-rosserial-arduino
sudo apt-get install ros-kinetic-rosserial

Installing from Source onto the ROS workstation

Source build instructions are different for groovy.kinect (catkin) than for earlier (rosbuild) releases.
Rather than running the library generator over each package you want to use, you run it once and generate libraries for all installed messages. 

$ cd <catkin_ws>/src
$ git clone https://github.com/ros-drivers/rosserial.git
$ cd <catkin_ws>
$ catkin_make
$ catkin_make installed
These commands clone rosserial from the github repository, generate the rosserial_msgs needed for communication, and make the ros_lib library in the <catkin_ws>/install directory. 
 We have to run catkin_make install, otherwise portions of the ros_lib directory will be missing.

Installing ros_lib into the Arduino Environment

The preceding installation steps created ros_lib, which must be copied into the Arduino build environment to enable Arduino programs to interact with ROS
<sketchbook> is the directory where the Linux Arduino environment saves your sketches.
Typically sketchbook directory is located in home directory.

Ros_lib installation instructions are different for groovy kinetic  source (catkin) than for earlier (rosbuild) or binary releases as we used  catkin for proper for our kinetic source 
Now we have to delete libraries/ros_lib in order to regenerate as its existence causes an error.

$ cd <sketchbook>/libraries
$ rm -rf ros_lib
$ rosrun rosserial_arduino make_libraries.py 
After restarting your IDE, you should see ros_lib listed under examples:

ERROR

$rosrun rosserial_arduino make_libraries.py

 

make_libraries.py generates the Arduino rosserial library files. It

requires the location of your Arduino sketchbook/libraries folder.

 

rosrun rosserial_arduino make_libraries.py <output_path>

when we put output_path the directory where you are for example

$rosrun rosserial arduino make_libraries.py ~/sketchbook/libraries

Hello World: Creating a Publisher

The code is 


/*
 * rosserial Publisher Example
 * Prints "hello world!"
 */

#include <ros.h>
#include <std_msgs/String.h>

ros::NodeHandle nh;

std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);

char hello[13] = "hello world!";

void setup()
{
  nh.initNode();
  nh.advertise(chatter);
}

void loop()
{
  str_msg.data = hello;
  chatter.publish( &str_msg );
  nh.spinOnce();
  delay(1000);
}

we have to upload the code to our Arduino,  we have to use the upload function within the Arduino IDE

Running the Code

We have to run roscore
$ roscore
and after we have to run
$ rosrun rosserial_python serial_node.py /dev/ttyACM0

Finally, watch the greetings come in from our Arduino by launching a new terminal window and entering :

$ rostopic echo chatter

 

  • No labels
You must log in to comment.