Skip to content

Instantly share code, notes, and snippets.

@Arvoreniad
Created August 2, 2015 09:55
Show Gist options
  • Save Arvoreniad/0a8b10d897ff0e2fcfd9 to your computer and use it in GitHub Desktop.
Save Arvoreniad/0a8b10d897ff0e2fcfd9 to your computer and use it in GitHub Desktop.
Pseudo-Ruby code for TOM.
# The application for controlling the Blu-tack device.
module BluTacker
# Function to manage the main function of the device.
def main
# A continuous loop which manages the device's operation.
loop do {
# Scan the wall for a poster and store the data in the "poster" variable.
poster = self.scanWall
# Check if the poster needs new Blu-tack.
if posterNeedsBlutack?(poster)
# Find a safe path to the poster.
navigateToPosterSafely(poster)
# Stick the poster to the wall.
stickPoster(poster)
else
# If the poster doesn't need new Blu-tack, return to the start.
next
end
}
end
# Device function to check if a poster needs blutack.
def posterNeedsBlutack?(posterLocation)
# Get the temperature of the poster's blutack and store it in the "blutackTemp" variable.
blutackTemp = self.getBluTacktemp(posterLocation);
# If the temperature is less than 20 degrees, the poster DOES need blutack (TRUE).
if blutackTemp < 20
needsBlutack? = true
# Otherwise the poster DOESN'T need blutack (FALSE).
else
needsBlutack? = false
end
# Inform the main device program if the poster needs Blu-tack.
return needsBlutack?
end
# Main device function to perform a series of movements to stick a poster to the wall.
def stickPoster(poster)
# Run in a loop to stick all of the corners.
loop do {
# Break the loop when all 4 corners have been stuck (number of completed corners equals 4).
break if poster.completedCorners == 4
# Only try to stick a corner if the device doesn't have an obstacle in its way.
if not self.hasObstacle?
# Move to the next corner of the poster.
moveToCorner()
# Put a piece of blutack in the corner where the device is now located.
placeBlutack(poster.currentCorner)
# Update the number of corners completed.
completedCorners = completedCorners + 1
# Execute this code if an obstacle is found.
else
sleep(1) # Wait for the obstacle to be removed.
next # Try again.
end
}
end
# Function to navigate the device along a safe path toward the poster.
def navigateToPosterSafely(posterLocation)
# Run in a loop while the device is not located at the poster.
while (self.location != posterLocation) {
# Move toward the poster if there is not an obstacle.
if not self.hasObstacle?
moveToPoster()
# Execute this code if an obstacle is found.
else
sleep(1) # Wait for the obstacle to be removed.
next # Try again.
end
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment