Created
March 29, 2012 21:37
-
-
Save randvoorhies/2244068 to your computer and use it in GitHub Desktop.
ActionDemo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object searchForBuoy() | |
{ | |
double originalOrientation = currentPosition.orientation(); | |
// Look for the buoy to the right | |
ActionToken rotationRight = rotateTo(originalOrientation - pi/2); | |
while(!rotationRight.complete()) | |
{ | |
ObjectVector objects = detectedObjects(); | |
if(objects.contains("buoy")) | |
{ | |
rotationRight.cancel(); | |
return objects["buoy"]; | |
} | |
} | |
// Look for the buoy to the left | |
ActionToken rotationLeft = rotateTo(originalOrientation + pi/2); | |
while(!rotationLeft.complete()) | |
{ | |
ObjectVector objects = detectedObjects(); | |
if(objects.contains("buoy")) | |
{ | |
rotationLeft.cancel(); | |
return objects["buoy"]; | |
} | |
} | |
// Rotate to the original orientation. This returns an ActionToken, which is immediately destructed, causing it to block | |
// until the action is complete. | |
rotateTo(originalOrientation); | |
return NoObject; | |
} | |
int main() | |
{ | |
Object buoy = searchForBuoy(); | |
if(buoy != NoObject) | |
{ | |
moveTo(buoy); | |
} | |
else | |
{ | |
// Oh crap... Let's move somewhere else and try again... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment