Monday, September 22, 2014

A Hackers Guide To Pawly

Pried Open



Pawly is being marketed as a way to play with your pet while you're not at home. However it is much more than that. The possibilities are only limited by your imagination.
Opening up the Pawly platform is straightforward. First find the IP address of the Pawly. One way to do this is to connect to your router and see what is online. For example on my home router I point my browser to http://192.168.0.1, then go to IP & MAC Bindings. Once you have the IP you can ssh into the Raspberry Pi inside your Pawly.
Now that you are in, have a look around. You can see that Robot Operation System is installed at /opt/ros/groovy. Suddenly the possibilities expand quickly because ROS has a large and active community, as well as an advanced ecosystem to go with it.

Electric Bloodstream
ROS simplifies process communication in the robot. ROS main concepts are called topics and nodes. Topics know how to make the robot do stuff, such as turn motors on and off. A node can either publish (send messages to) or subscribe (read messages from) a topic.
In addition ROS has a code generation tool that converts your message definitions into C or Python code. This makes for tight code integration with ROS.

Nudge your Robot

A ROS topic is installed that knows how to make the Pawly drive around. The message it takes is a standard twist message. The topic knows how to convert the twist message into a power level on the left and right wheel motors so that it drives in the desired direction. The power level goes from -100 (full reverse) to 0 (stop) to +100 (full forward). A PawlyMove message is also provided that can take these values directly.
For example to spin around in a clockwise circle for 5 seconds you can publish to a topic in Python:
import roslib; roslib.load_manifest('pawly')
import rospy
from pawly.msg import PawlyMove

pub = rospy.Publisher('pawly', PawlyMove)
hertz = 10
rate = rospy.Rate(hertz)
= 0
while not rospy.is_shutdown() and i < 5*hertz:
    move = PawlyMove();
    move.right_throttle = -100
    move.left_throttle = 100
    pub.publish(move)
    rate.sleep()
    += 1
You may be wondering what the PawlyMove import is referencing. Remember I told you that ROS does code generation? All I had to do was create a msg file that looked like this and ROS did the rest:
  
  int16 left_throttle
  int16 right_throttle

This just scratches the surface of what is possible. In the next article I show you how to get images from the camera.

No comments:

Post a Comment