Screenshots     Download     Pricing     Documentation     Tutorials     Resources     Contact     Forum     Search  

<<Prev 1 2 3 4 5 6 Next>>

Scanning with the Lego Roverbot

Given that the Roverbots position within the camera's field of view is unknown we cannot use absolute pixel size to determine which orientation the Roverbot is relative to the camera. We can only determine the smallest yellow blob size by scanning all sizes of the Roverbot. This scanning technique involves using a VBScript to spin the Roverbot for at least one revolution by setting the left motor to an opposite value to the right motor. While spinning the camera continues to detect the blob size and records the minimum pixels of that blob size. The minimum area will be the side that is facing us as the Roverbot front is where the IR receiver on the Roverbot is located. Since the back of the Roverbot is all yellow the front will contain fewer yellow pixels than the back.

Once the smallest yellow blob is detected we can continue spinning the Roverbot until we once again see this smallest yellow area (within a specified error margin). Once this is detected we can stop the spinning and the Roverbot will be oriented straight towards the camera.

The following VBScript program performs this scan.

' first determine what state we're in
select case GetVariable("state")

  
case "0"

    
' if we are still sampling then get 
    ' the sample count
    
sample GetVariable("sample")

    
' set the motors to rotate
    
SetVariable "LEFT_MOTOR"3
    
SetVariable "RIGHT_MOTOR", -3

    
' get how many pixels exist in the 
    ' current bounding box    
    
size GetVariable("COG_AREA")
    min_size 
GetVariable("min_size")
    
if min_size then
      
SetVariable "min_size", size
    
else    
      
' if it is the smallest we've seen
      ' then remember that
      
if size<min_size then
        
SetVariable "min_size", size
      
end if  
    end if

    
sample sample + 1

    
' if we're done sampling
    ' change the state to the next 
    ' step
    
if sample>80 then
      
SetVariable "state""2"
      
SetVariable "sample"0
    
else
      
SetVariable "sample", sample
    
end if
    
  case 
"2"

    
' we're done sampling, now we
    ' need to keep rotating until
    ' we see the smallest side
    ' again
    
SetVariable "LEFT_MOTOR"3
    
SetVariable "RIGHT_MOTOR", -3

    
size GetVariable("COG_AREA")
    min_size 
GetVariable("min_size")

    
' if the current pixels within the
    ' bounding box is with 80% of the
    ' smallest recorded amount then
    ' assume that we have a match
    
if (min_size / size) > .then

      
' we have a match so stop
      ' the motors and jump to the 
      ' next state
      
SetVariable "LEFT_MOTOR"0
      
SetVariable "RIGHT_MOTOR"0
      
SetVariable "state""3"

    
end if
  
  case 
"3"

    
' we're done ... reset the min_size
    ' in case we run this again.
    
SetVariable "min_size"10000

end select

Now that we have the script we need to map the left_motor and right_motor values to the Lego Mindstorm's RCX brick through the IR tower.

<<Prev 1 2 3 4 5 6 Next>>

© 2005 - 2012 RoboRealm. All Rights Reserved. | Contact | Glossary | Privacy | Disclaimer | Link to Us | Resources | Site Map