Screenshots     Download     Pricing     Documentation     Tutorials     Resources     Contact     Forum     Search  

<<Prev 1 2 3 4 5 6 7 8 9 10 Next>>

VBScript

The point we want the robot to move towards is contained in the COG_X and COG_Y variables. These variables are created by the Center of Gravity module.

To control the motors of the SRV-1b to move towards that point we need to just use the X coordinate and steer left if the point is to the left of the screen or right if the point is towards the right of the screen. Basically we want to control the robot to keep the X COG in the middle of the screen. This will then cause the robot to move along the defined trail and also attempts to keep as much of the significant part of the image (i.e. the squares) in view.

We use the VBScript module to create two motor variables that are then fed to the Surveyor SRV-1b module.

' determine the center of the screen
midx GetVariable("IMAGE_WIDTH") / 2

' the amount of turning force or motor
' value difference that is used to 
' turn the robot.
factor 2.5

' robot speed
speed 155

' even out the motor values as one side can 
' be more powerful than the other
left_bias 5
right_bias 0

' get the COG_X that the COG module
' calculated
cogx GetVariable("COG_X")

' if we see something then change direction
' accordingly
if GetVariable("COG_BOX_SIZE") > 10 then

' how far off the center screen is the 
' robot and how forceful does that
' turn need to be
spread = CInt((midx - cogx) / factor)

' set the motor values to be used in
' the robot control module
SetVariable "left_motor", speed - spread
SetVariable 
"right_motor", speed + spread
SetVariable 
"turn_status"0

else

' if we don't see anything worth following
' we need to think about starting to turn.
' We first continue straight for a little bit 
' which ensures that the robot passes
' over the current square, we then turn
' to the right for a short bit to see if we
' missed a square outside the field of
' view and then we start doing the full
' turn. The variable turn_status keeps
' track of where we are during this
' sequence.

if GetVariable("turn_status""0" then
' have a little faith and keep going straight for a short time
  
SetVariable "right_motor", speed
  SetVariable 
"left_motor", speed
  
' in 500 ms the turn_status will jump to the
  ' next step
  
SetTimedVariable "turn_status""2"500
  
SetVariable "turn_status"1
elseif GetVariable("turn_status""2" then
' no blobs - turn one way for a little bit and then
' turn the other
  
SetVariable "right_motor", speed+15 + right_bias
  SetVariable 
"left_motor"255 - speed - 15 - left_bias
  
' in 1000 ms the turn_status will jump to the
  ' next step
  
SetTimedVariable "turn_status""4"1000
  
SetVariable "turn_status"3
elseif GetVariable("turn_status""4" then
  
SetVariable "left_motor", speed + 15 + left_bias
  SetVariable 
"right_motor"255 - speed - 15 - right_bias
end if

end if

Lets see all this in action ...

<<Prev 1 2 3 4 5 6 7 8 9 10 Next>>

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