Screenshots     Download     Purchase     Documentation     Tutorials     Resources     Contact     Forum     Search  

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

VBScripting the SRV-1

Using the variables provide by the Wall Finder module we can create the following VBScript that will map the wall variables to motor values that are then send to the SRV-1.

We would like to turn the robot away from the wall using the most efficient angle. Always turning in one direction would cause the robot to turn into the wall in many of the wall collision cases. In other words, if the robot approaches a wall like this

Turn Left

the robot should rotate to the left instead of the right. This can be accomplished by checking the sign of the WALL_SLOPE variable (-16 for the above image). If it is negative turn right, otherwise turn left.

However, there is an interesting problem using this technique when approaching a sharp angle corner (like the one at the tip of the room). The problem is that when the robot approaches the corner from one side it will use the WALL_SLOPE to turn the other direction. Once this is done the robot re-samples what it seems and determines that the WALL_SLOPE has now switched signs and therefore will move in the opposite direction to what it just did. Thus the robot is stuck in an oscillation between left and right movements.

To prevent this oscillation from happening we need to bias the rotational movement until we determine that it is safe to resample the WALL_SLOPE for a potentially new rotational direction. We do this by setting a "turn_bias" variable that once set will ensure the robot only rotates in that direction. This variable is then reset when the robot proceeds forward for a least three or more steps. This reset will only occur when the robot has decided that it is safe to move forward and can then resample the slope once again when approaching another wall.

The following VBScript is used within the VBScript module


' check if we are near a wall
if GetVariable("LOWEST_WALL_Y") < 10 then

  
' if we need to turn check the 
  ' turn bias to make sure that
  ' if we have already turned that
  ' we continue to turn in the same
  ' direction
  
turnBias GetStrVariable("turn_bias")
  
  
if turnBias "right" then
    
SetVariable "left_motor"95
    
SetVariable "right_motor"165
  
elseif turnBias "left" then
    
SetVariable "left_motor"165
    
SetVariable "right_motor"95
  
' otherwise check the wall slope to determine
  ' the best direction to turn
  
elseif GetVariable("WALL_SLOPE")  < 0.then
    
SetVariable "left_motor"95
    
SetVariable "right_motor"165
    
' don't forget to bias successive
    ' turns in the same direction
    
SetVariable "turn_bias""right"
  
else
    
SetVariable "left_motor"165
    
SetVariable "right_motor"95
    
SetVariable "turn_bias""left"
  
end if
  
else

  
' increment the forward counter
  
forwardCount GetVariable("forward_count")
  SetVariable 
"forward_count", forwardCount+1
  
' if we have moved forward for 3+ steps reset
  ' the turning bias
  
if forwardCount > then
    
SetVariable "turn_bias"""
  
end if
  
  
' move the robot forward
  
SetVariable "left_motor"150
  
SetVariable "right_motor"150
  
end if

Lets see it in action!


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

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