Pilot the Brookstone Rover 2.0 and Rover Revolution from Python
This repository contains a Python API and demo program allowing you to control the Brookstone Rover 2.0 spy tank and Rover Revolution spy vehicle from your laptop or PC. To get started, you should get hold of a Rover 2.0 or Revolution (of course) and a Playstation PS3 controller or clone, and install the repository (sudo python setup.py install for Linux users), as well as PyGame and either OpenCV for Python (Rover 2.0) or ffmpeg (Rover Revolution). Join the Rover's ad-hoc wifi network from your computer. Then run either the ps3rover20.py or ps3revolution.py script from the repository. This script will allow you to drive the Rover around and watch its streaming video, as shown here. I have run this script successfully on Linux (Ubuntu), but I can't vouch for what happens on Windows or OS X, on which Python packages become much trickier. Remember, the Rover 20 is a tank, so you control it by moving the left and right sticks back and forth. If you used an inexpensive clone of the P3 controller you may have to do some adjusting of the axis and button settings at the top of the script to make it work.
Once you're up and running with the ps3rover.py or ps3revolution.py script, look at its source code (and run pydoc on rover.py) to see how RoverPylot works and how you can modify it to do other interesting things. This blog post explains how I hacked the Rover 2.0, and this blog post shows a clever application using Skype.
- The ps3rover20.py script will report a harmless error about extraneous bytes in the JPEG image.
- The ps3revolution.py script will often show a blurred/smudged image. This happens because, whereas the Rover 2.0 sends JPEG images, the Revolution sends H.264 video. I couldn't find a Python package for decoding and displaying H.264 on the fly, so I wrote little workaround that saves the video to a temporary file, which from which the script then reads. You can tweak the performance of this setup by playing with the FRAMERATE and DELAY_SEC parameters at the top of the script.
Rob Crawley has put a lot of work into getting RoverPylot to work smoothly on Windows 10. Here are his changes:
- Original:
# Create a named temporary file for video stream
tmpfile = tempfile.NamedTemporaryFile()
Changed to:
tmpfile = tempfile.NamedTemporaryFile(mode='w+b', bufsize=0 , suffix='.avi', prefix='RoverRev', dir='\Python27\RoverRev_WinPylot', delete=False) - Original:
# Wait a few seconds, then being playing the tmp video file
cmd = 'ffplay -window_title Rover_Revolution -framerate %d %s' % (FRAMERATE, tmpfile.name)
Changed to:
cmd = '/Python27/ffmpeg/bin/ffplay.exe -x 640 -y 480 -window_title Rover_Revolution -framerate %d %s' % (FRAMERATE, tmpfile.name)
Your files paths may be different than those listed below, so make your changes accordingly
Copyright and licensing information can be found in the header of each source file. Please contact me with any questions or suggestions.