Building a Pi Camera Mini-Tankbot with a Raspberry Pi, Arduino, and ROS

Building toy robots is always fun. I had a Raspberry Pi and a Pi camera lying around, the small form factor, power and weight with a linux core was just begging to be roboticized.

This miniature tankbot takes advantage of ROS and rosbridge to get communication up quick and allow tele-operation over the internet using either a web GUI, android app, or a google glass app. The camera also has pan-tilt control using 2 servos.
Mini Robotic Tank toy
We could do everything with the raspberry pi, however I had 2 micrometal gear motors that run on 5V and comes with a Zumo kit designed for an Arduino. Arduino with the kit it is, used as the embedded real-time controller.

Architecture
The 2 motors have optical encoders soldered on. The Arduino keeps track of the encoder counts for wheel velocity as well as runs the motors. It also controls two servo motors that holds the raspberry pi camera, and 1 LED as a flashlight.

The Arduino is connected to the Raspberry pi over USB and controlled through the serial port using rosbridge. This is just a simple hack, since we could have wired over SDA/SCL pins instead (providing for 3.3V-5V interfacing between the two boards), or even had the motors and encoders controlled by the Pi through a 3.3-5V interface.

With rosbridge we can create nice little publishers for the wheel velocity data.


// Publish left and right wheel encoder ticks
void publishWheelVelocity() {
  // updateWheelPositionVelocity();
  // encoder velocities are in rev/sec, convert to m/s
  wheel_vel.data = encoder_left_velocity * METERS_PER_REV;
  lwheel_pub.publish(&wheel_vel);
  wheel_vel.data = encoder_right_velocity * METERS_PER_REV;
  rwheel_pub.publish(&wheel_vel);
}

We also publish the battery voltage level, and subscribe to commands to update our velocity.

// Command Velocity Subscriber
ros::Subscriber<geometry_msgs::Twist> cmd_vel_topic("cmd_vel", &cmd_vel_callback);

The Raspberry Pi is connected to a raspberry pi camera and the arduino. We use mjpeg-streamer to view the camera stream over the internet, we provide a javascript interface to also control the robot remotely. The pi communicates over a web socket with a main computer or laptop using ROS via rosbridge, which has a Javascript interface as well.


 
// Publishing a Topic
var setPos = new ROSLIB.Topic({
  ros : ros,
  name : '/pantilt/set_position',
  // messageType : 'pantilt/pan_tilt'
  messageType : 'rosserial_arduino/pan_tilt'
});

var setLEDs = new ROSLIB.Topic({
  ros : ros,
  name : '/set_leds',
  messageType : 'std_msgs/UInt8MultiArray'
});



Stuff used (top to bottom):
  • Raspberry Pi + Camera
  • 15000 mAh Anker Battery
  • 3D Printed Chassis
  • Arduino Uno
  • Pololu Zumobot Chassis/Motors + Encoders
  • Hot Glue/Zip-ties/Optimism

Source code on Github

Popular posts from this blog

Building a PID hover controller for Kerbal Space Program with kOS and IPython Notebook

Learning TensorFlow #1 - Using Computer Vision to turn a Chessboard image into chess tiles

Visualizing TLE Orbital Elements with Python and matplotlib