Monday, July 29, 2013

Turtlebot Wanderer

The Wanderer program allows the turtlebot to move around randomly while avoiding any nearby objects.  Using the attached Xbox Kinect, the robot reads its laserscan messages and determines if there are any obstacles closer than 0.6 meters.  If there are none, it moves forward.  If it does detect any obstacles, it rotates away from them and then continues moving forward.

Turtlebot2 used with Wanderer to carry around drinks

Scan_msg class

Much of this program depends on a class called Scan_msg.  At it's initialization, a Scan_msg object creates a publisher, pub, for twist messages, variable msg to hold the twist message, variables sect_1, sect_2, and sect_3, and 3 dictionaries - ang, fwd, and dbgmsg- to hold the angular speed, linear speed, and debug message for each possible instance, respectively.
Variables sect_1, sect_2, and sect_3 each represent a specific part of the field of view of the turtlebot (see image below). 
Illustration of turtlebot field of view
 
The two main functions of this class are sort() and movement()

sort() takes in a laserscan message and goes through all the ranges read by the robot.  If any of the ranges is less than 0.6 m (an obstacle is detected), it determines which section of the field of view (sect_1, sect_2, or sect_3) the obstacle is located in and changes the value of that  section to 1.   
 

movement()  takes in the values of sect_1, sect_2, and sect_3 and uses them to determine how to move.  To do this, it creates a number with the values of these 3 variables and assigns that number to the  variable sectsect is then used with the class dictionaries to change the angular and linear velocities  of msg to the proper values and display the correct debug message.  Finally, movement() published this modified twist message (see code below).
sect = int(str(self.sect_1) + str(self.sect_2) + str(self.sect_3))
self.msg.angular.z = self.ang[sect]
self.msg.linear.x = self.fwd[sect]
rospy.loginfo(self.dbgmsg[sect])
self.pub.publish(self.msg)  
Finally, the reset_sect() function is run to reset the values of sect_1, sect_2, and sect_3 to 0.   

The function for_callback() takes in a laserscan message and runs both of the above functions. 

listener() and call_back functions
The listener() function first initializes the node navigation_sensors, and then creates a subscriber with callback function call_back()call_back() takes a Scan_msg object and passes the laserscan message to the class function for_callback(). 

Overview 
At the start of this program, a Scan_msg object called sub_obj is created.  listener() is then run, starting the subscriber, which passes a laserscan message to the call_back() function.  call_back() passes the laserscan message to sub_obj's for_callback() function.  for_callback() first runs sort(), which updates variables sect_1, sect_2, and sect_3 accordingly, then passes these updated variables to movement() which uses them to determine where to go, updates the class twist message, and publishes that message.  This process repeats for each laserscan message. 

App Chooser
Wanderer was also added as an additional feature to  App Chooser (for android).  In order to do this, I wrote files wanderer.launch, wanderer.interface, and wanderer.app and added a wanderer_icon.jpeg (for the icon) in a folder called wanderer_app.  The interface file lists any publishers and subscribers.  In the wanderer app, there were none.  The launch file defines a single node, "navigation_sensors" from the wanderer.py program (see below).
<launch>
   <node name="navigation_sensors" pkg ="navigation_sensors" type="wanderer.py" cwd="node"/></launch>  

Lastly, the app file defines a few attributes of the app and also gives the package/name of the other files and image.  In order to add this app to App Chooser, I edited the file turtlebot_apps.installed to include the wanderer app.
 Wanderer appears on the far right along with the other apps in App Chooser
All source code available at: 
https://github.com/IHeartEngineering/ihe_turtlebot_wander




1 comment:

Anonymous said...

Awesome! I'm looking forward to test-drive this app!

Btw, I was thinking about creating a similar app. However I planned to use the bumpers and cliff sensors instead of the Kinect - kind of a simple test app for Kobuki and TurtleBot. Maybe we can merge both apps ...

PS: Check GitHub - I have fresh issues for you! ;-)