Building a robot sumo arena with position detection from a camera

In this project I wanted to bring together different areas I'm really interested in: real-time video analysis, robot sumo, driving with omni wheels and Bluetooth communication. We ended up creating a platform where robot programming enthusiasts can submit their sumo program and see what the winning sumo strategies are using our arena. As the robots are equal, it's a showdown of robot programming skills! You can see the end result here:

How did we get there?

After many failed attempts the most stable robot tracking was done with color detection. We also tried feature detection, channel filtering and led lights. I'll post another article on all the failed attempts. Here's how to do it right. This tutorial is written for Mac OS X. If someone can port it to windows, I'll gladly link to it.

1. Download all necessary frameworks and software

We will be needing this software:
  • OpenCV - An image analysis framework
  • Jaraco.nxt - A python library for communicating with the Mindstorms NXT robots
  • Lego Mindstorms NXT-G software
  • Sourcetree (with command line tools - my favourite) or another Mercurial client
  • Our sumo arena software from our bitbucket repository

Below are all the installation steps.You can type them in a new Terminal window. I will assume you have nothing installed and start from a clean mac. I'm not sure if you need XCode for the compilers. I think you need it. It's free in the Mac App Store and has a great iOS simulator. The easiest way to install openCV is via homebrew, so we'll install that first. Next are some python libraries. If you like to work with python it's good practice to use virtualenv en virtualenvwrapper. I'll leave that out. Follow the links if you want to know more.

2. Get the hardware

You'll be needing this:
  • Two sets of mindstorms NXT. I guess EV3 will do too. ;)
  • 6 Omni Wheels. I got mine from robotshop, but others sell them too. Google some to find the cheapest in your area.
  • A decent mac
  • A decent webcam. We used a €20 Logitech c270 HD Webcam. 720p is the best resolution for this application.
  • An arena. We used a second hand living room table, of which I removed the legs.
  • A long USB extender cable to get from the ceiling to your mac

3. Build the arena and robots

I first painted the arena black, but that did weird stuff with the camera auto gain. It washed out the colors from the markers on the robot. So in the video it's covered in paper. When I have time I'll paint it white with a nice black border.

The robots are based on the great RotaBot by HiTechnic (they sell omniwheels - rotocasters too). We added bumpers to the models and some room to put the markers. While you're there you might want to download the NXT-G programs for moving omnibots. They'll save you a lot of trouble.

4. Time to play!

If all went well so far, you'll have a functional robot sumo arena. Now you can build and download your own sumo programs. If you cloned the bitbucket software repository, you'll have a folder called 'NXT-G Programs'. Inside there's a file called 'sample sumo.rbt', which is a great boilerplate for building robot programs. To get it running you'll need to import some custom blocks into the NXT-G editor. They are in a folder called 'Import blocks'

Let me know if you succeed in building another sumo arena!