Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Hardware
The hardware setup is pretty straightforward, mount the camera to the 2 motors where 1 allows it to tilt up and down while the other allows it to pan left and right. Initially i did not use the worm-gears, but decided to do so to slow the motor down since its a bit of a problem controlling the speed through Roborealm.
Step 2: Software
The software used is Roborealm you can get a free trial version at their page here http://www.roborealm.com
There are 4 main steps to setting up the software
Examples ->motion detection
Add that as your first filter/module
You will want the background image to be set to Previous frame.
For the technique used and difference threshold, you really need to play around with that as it depends on your environment, lighting and what you are trying to track.
Also remember to check "set still to black" its important for the next step
2)Center of Gravity
Add that as your second filter/module
For this part, you also need to play around with the filter settings.
The display settings do not affect the performance, just what is shows
3)Lego_NXT (if you are using some other hardware select that instead)
For this part you would want to check "Enable Motors"
Then define 2 variables by typing into the boxes, here I used "Aa" and "Cc", you will be using these variables in your VBscript
You will need to load your VBScript (We will get there in the next step) and run it
Step 3: VBscript and Endword
Personally I have never done anything in Visual Basic but it worked out fine since I am familiar with some other languages
The script was modified off the script that I got from the video on youtube (link at intro step) so credits to him.
For the script, remember to make sure the variables you use matches the ones you defined at the Lego_NXT module, there I used "Aa" and "Bb" so I use the same thing here. For the NXT motors, 0 means full power in one direction and 255 is full power in the other direction while 128 is stop
And I am only using a resolution of 352x288 since thats the maximum resolution i could select while getting 30fps, it might be different for your setup. This means the pixel at which you want your robot to start turning left, right, up or down depends on your resolution.
you can check and change your resolution at Options->Camera->Video Format
Here is the code i used, excluding the dashed lines
' initialize all values
Aa = 128
Bb = 128
Cc = 128
' get the size (width or height) of the current bounding box
size = GetVariable("COG_BOX_SIZE")
' if it is equal to "" then no object was detected
if size <> 0 and size < 150 then
' get the horizontal center of gravity
cogX = GetVariable("COG_X")
' pan left
if cogX < 150 then
StartTime = Timer
Aa = 40
Elapsed = Timer - StartTime
' pan right
if cogX > 200 then
' stop x
if cogX = 0 then
Aa = 128
' get the vertical center of gravity
cogY = GetVariable("COG_Y")
' tilt down
if cogY < 134 then
Cc = 40
' tilt up
if cogY > 154 then
Cc = 220
' stop y
if cogY = 0 then
Cc = 128
SetVariable "Aa", Aa
SetVariable "Cc", Cc
Thank you for reading, feel free to leave you comments, opinions and feedback. Questions are also welcome
and if you like it please vote