Controlling a Turtlebot Arm with an Arduino RFID

From COINS Research Group
Jump to: navigation, search

Tutorial Overview

Title

Simple program for Turtlebot Arm PhantomX Pincher with ROS and Arduino (UNO) board

Author

Abdelrahman Mahmoud

Note

This tutorial was developed for ROS Hydro and Indigo versions. For any suggestions/comments about this tutorial, please send an email to akoubaa@coins-lab.org / a.mahmoud1994@gmail.com Make sure that you complete the previous tutorial and download the Turtlebot Arm Robot package.

Make sure you download:

  1. Arduino 1.0.6 version
  2. Rosserial_arduino setup package
  3. Make sure to complete this tutorial to have a background about the Listener.cpp file and how it functions.
  4. Download the ArbotiX package for Arduino for the d2xx package.
  5. Download the drivers for the RFID and the guide in this page

After downloading the d2xx package follow the readme file to install

Components

  • RFIDuino v1.2 shield and external antenna

rfid connection with 2 different tags

Description

In this tutorial, I will present an integration and the steps to sync a Turtlebot Arm PhantomX Pincher with a RFID using UNO arduino board with a C++ (listener) file for the turtlebot arm robot and an arduino file (publisher) for the UNO board with ROS. First step, you need to define any tag in the arduino code. When the antenna reads this tag you will hear a sound/tone if the tag was not equal to the predefined one you will see a red light from the led on the RFID. Then the program publishes a topic of type char array containing the tag value/number. Second step, the C++ code will receive this message/topic and compare it to a defined tag. If the two tags were the same the gripper will open and if not it will close.

Main Steps

Let's divide this tutorial into two parts:

1-The Publisher: an arduino program with ros library that will allow us to publish a certain topic carrying a value that you can define according to the type of message/data you want (Boolean, String, char...etc). This program reads the data from the antenna and send it in a message/topic. Every topic can have a single value of a single type as mentioned before.

2-The Listener: a C++ program that can receive the topic that was published from the arduino program and give the command to the Gripper either to open or to close so it controls the turtlebot arm robot.

The Arduino Program:

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

//Create the node handler and the message type
ros::NodeHandle nh;
std_msgs::String str_msg;

//Create a publisher for the message
ros::Publisher pub_tag("/tagRead", &str_msg);

//initialize an RFIDuino object for hardware version 1.1
RFIDuino myRFIDuino(1.1);    //you can use RFIDuino myRFIDuino(1.2) for the other version

char tagWord[8];
String tagStr;

//enter your ID numbers below as a 'key' tag
byte keyTag[5] ={37,0,0,161,253};  //an array that will hold all of our 'key tags'. Key tags are treated differently from 
other tags read
byte tagData[5];                   //Holds the ID numbers from the tag
boolean verifyKey = false;

void setup()
{

 nh.initNode();
 nh.advertise(pub_tag);    

}

void loop()
{   

 if(myRFIDuino.scanForTag(tagData) == true)
 {

   verifyKey = myRFIDuino.compareTagData(tagData, keyTag);//run the comparetagData to check the tag just read against the 
   'key' tag we defined.
   
if(verifyKey == true)//if a 'true' is returned by comparetagData, the current read is a key tag
   {                       
   
     digitalWrite(myRFIDuino.led2,HIGH);         //turn green LED on
     myRFIDuino.successSound();                  //Play a 'success' sound from the buzzer, 3 notes acsending 
     delay(250);                                 //wait for a period before turning off the LED
     digitalWrite(myRFIDuino.led2,LOW);       //turn the green LED off       
  
   }
 else//otherwise the tag is not a key tag
   {        
  
     digitalWrite(myRFIDuino.led1,HIGH);         //turn red LED on
     delay(250);                                 //wait for a period before turning off the LED
     digitalWrite(myRFIDuino.led1,LOW);          //turn the red LED off        
  
   }
  
 //convert the byte array into String
     tagStr = String(tagData[0]);
     tagStr = tagStr + String(tagData[1]);
     tagStr = tagStr + String(tagData[2]);
     tagStr = tagStr + String(tagData[3]);
     tagStr = tagStr + String(tagData[4]);

 //convert the String into char array
     tagStr.toCharArray(tagWord,11);
    
 //store the data in the str_msg message
     str_msg.data = tagWord;
    
 //publish the message 
     pub_tag.publish(&str_msg);
 
 //reset the String to be equal to an empty String BUT you can remove this line 
     tagStr="";
 
  }
     nh.spinOnce(); }

Note: I tried to change the byte array into a char array right away but nothing worked except the naive way.

The Turtlebot Arm robot program:

Designed not only for this tutorial and it is a bit advanced for this one but we will describe the parts that is used in this tutorial.file link

The part we are using is the readTagCallback() Function , openGripper() and closeGripper()

Note: Make sure that you put the file in the right place and changed your CMakeLists.txt file

Executing step

1. Upload the ros program in the (ArbotiX Sketches) to the turtlebot arm robot and make sure you picked the right Board and the right Serial Port.

2. Run this command : sudo chmod 777 /dev/ttyUSB0

To give the permission to the port you are using. Note: make sure you give the permission to the right port.

3. roslaunch turtlebot_arm_bringup arm.launch

To launch the arm.launch file and load the drivers for the robot. =Note:= make sure that the arm robot is connected to the same port in the arm.yaml file.

4. rosrun beginner_tutorials armcontrol

Where beginner_tutorials is the package containing the listener file and the armcontrol in the listener file.

Note Make sure that you compile the work space before loading anything to avoid errors. Follow the link to know how.

5. Upload the Arduino program to your board. Make sure that you choose the right Board and Serial Port.

6. rosrun rosserial_python serial_node.py /dev/ttyACM0

where the ttyACM0 is the port for the Arduino board.

Note If it fails uploading in step 5 or fails running in step 6 repeat step 2 but for the arduino board's port.

7. Try putting the tag you define in front of the RFID.

Note: do not give a close gripper command if the gripper is closed or the program might stop!!!

Video