Skip to content

Instantly share code, notes, and snippets.

@randvoorhies
Created March 29, 2012 21:37
Show Gist options
  • Save randvoorhies/2244068 to your computer and use it in GitHub Desktop.
Save randvoorhies/2244068 to your computer and use it in GitHub Desktop.
ActionDemo
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