This tutorial shows the basics of using RoboRealm to control the HexEngine via a bluetooth link, along with the use of a wireless CMOS camera attached to the pan/tilt head to track colour BLOB's. This tutorial will also work with a pan only head, and a wired camera if a wireless type is not available. The camera will need to be colour. I have used a 2.4Ghz type which runs from a 9V PP3 battery installed in the PP3 battery holder. The BLOB colour that is track can be changed according to the background environment, This is why I have used a four colour juggling ball for the test.
This project was initially started by Erik Lely. The code is a combination of Erik's initial test and my own version of the BLOB tracking code taken from RoboRealm's website.
Please take time to understand RoboRealm using their on-line help and tutorials, this tutorial assumes a base knowledge of RoboRealm.
Downloaded and install RoboRealm, download the Hexapod_BLOB_Tracking.zip file below and extract the files into a project folder. Start RoboRealm and load the Hexapod_BLOB_track_V1.robo file from your project directory.
RoboRealm Interface - (This is a brief description of RoboRealm, for more information and tutorials, please visit the RoboRealm website.) One Roborealm is running, and you have loaded the Hexapod_BLOB_track.robo file, you will need to select the video source you intend to use, to do this, click on the options button at the top of the display area, and select the video source from the pop-up menu. You need to make sure the "Camera" button at the bottom of the display area is clicked to start the video feed. Below the display are is the sequence of commands to tell Roborelam how to process the image. You can select each step of the sequence to see what effect it has on the image, at the end of the last three parts of the sequence are the "Keyboard Read", "VB Script" and the "Serial" output modules, these have no effect on the image processing. Take some time to familiarize your self with the sequence and try to understand each step. To run a sequence you need to click the "RUN" button at the top of the display area.
Loading the VB Script - The VB script file is the engine that tells the hexapod how to move according the the information supplied, e.g. the COG position and size. You will need to double click on the "VB Script Programme" sequence to bring up the VB Script Source window, from here you need to select the "Hexapod_BLOB_Track_V1.vbs" file from the project directory you installed the file. Once selected, click "Reload & Run" and close the window. It is best to edit the VB Script in an external editor, save changes and "Reload & Run" using the method described above.
Serial Setup - First make sure the settings of the serial module are correct. Choose the appropriate comport and baud settings. The other setting should be left unchanged.
RGB Filter setup - Now we need to tune the RGB filter in a way that only the object you want to follow is seen. Double click on the "RGBFilter Red" sequence to bring up the settings window. From here you can tweak "Min Intensity" and "Min Hue" to tune the effectiveness of your RGB filter. Make sure your image background contains as little of the co lour you are trying to isolate. You can use either the "Color Scale" or "Color Mask" option.
Play around with the different settings until you get picture like the one shown here.
Center of gravity (COG) - If the RGB filter is setup correctly then the picture shown in Roborealm should look a lot like the picture shown here (Note, select the "Display_Variables" sequence to see this view). Notice that a blue box is surrounding the red ball, showing that Roborealm is detecting it correctly. You can also see some of the internal script variables overlayed on the image, such as COG x,y COG size FPS and current HexEngine power state.
Useful Keys - A couple of useful keys within RoboRealm:
CTRL + k Will switch between the sequence window and a dedicated sequence run window.
F11 will show the video in full screen, press ESC to return to normal size.
CTRL F9 will wake the Hexapod and enable tracking.
CTRL F10 will disable tracking and sleep the Hexapod.
CTRL F11 will enable walk tracking, as well as pop the video to full screen.
CTRL F12 will disable walk tracking.
VB Script - I have commented the VB Script, so you can take a look through and see the various parameters that can be tweaked/modified to change the hexapod behavior. If you are using a pan/tilt head, depending on the way the head is built, you may need to invert the tilt and/or the pan axis.
Note: The method for reversing Pan/Tilt described in V1 of the script does not work. If you need to reverse the pan and/or tilt servos, find the following lines and remove the relevant minus sign in front of the pan/tilt variable:
VariableH1 = (256 + int(-gPan)) and 255
VariableH2 = (256 + int(-gTilt)) and 255
e.g. to reverse Tilt:
VariableH1 = (256 + int(-gPan)) and 255
VariableH2 = (256 + int(gTilt)) and 255
There are many improvements that could be made to this tutorial, in particular a plug-in could be written to directly talk to the HexEngine instead of using the generic serial output routine. Also there the tracking system itself could be greatly improved, however, I think this gives a good starting point for hexapod based vision projects, If you change the code and wish to share, please get in touch or post your results in the forum.
Thanks to Erik Lely for getting this project started.