Given a situation where one needs to implement a simple RC interface for a robot. What’s more straightforward? We could create a thick client and implement a server application for the robot but that’s too complicated. In order to have something light-weight and portable I was thinking of implementing the RC interface using some HTML and possibly some cgi.
The outcome of this tutorial will be a webpage that looks like this:
I chose a framework called pico.
Execute these steps on the BeagleBone:
git clone http://github.com/fergalwalsh/pico.git opkg install python-distutils opkg install python-compile cd pico python setup.py install
This should install pico on your BeagleBone. Now you can cd into an example directory and try it out!
cd examples/helloworld python -m pico.server
Now you can play a bit with the example and then I’ll continue.
Finished already? Let’s continue with putting something actually working behind the web interface.
If you don’t have any idea what to do for a start use this led blinker script below. I’ll create a script to send commands to my Arduino.
Since I have an Arduino behind the BeagleBone for now I’ll have to communicate with that through serial port.
Let’s get and install pySerial.
wget http://pypi.python.org/packages/source/p/pyserial/pyserial-2.6.tar.gz tar -xf pyserial-2.6.tar.gz cd pyserial-2.6 python setup.py install
Easy isn’t it?
So now that we have a Serial class we can communicate with the Arduino from the BeagleBone using Python.
I wrote the script below to control the robot. Yeah, it’s not too elegant but will do for now.
Note that I’m using string commands so I’m sending strings directly to my Arduino.
Now that we have something to call from a webpage, let’s create the page itself!
You should check out the codes in the example folder to get the hang of the framework, it shouldn’t take too long.
This is what I came up with in the end:
Note: if you are experiencing some kind of lag or blocked messages, you can help it by running the following on the BeagleBone. This “wakes up” the serial port. The above python code of mine will require a bit more massage to get this effect.
And finally here’s a video of controlling my rover using the above web page:
Like if you like my whistling and of course comments are always welcome!