Skip to content

Instantly share code, notes, and snippets.

@njdart
Created January 13, 2016 13:48
Show Gist options
  • Save njdart/c1db936ef16ad348466d to your computer and use it in GitHub Desktop.
Save njdart/c1db936ef16ad348466d to your computer and use it in GitHub Desktop.
Example Project Layout for Hills Road Robotics
import communications
import solution_set
import SR
"""
Hills Robot (Hobo) Class, this should be the end point for all competition code
"""
class Hobo(object):
"""
Hobo class constructor
"""
def __init__(self, config):
# set up config, camers, communications etc
pass
"""
Drive forward `distance` meters
distance: int: the distance to drive in meters
returns void
"""
def forward(self, distance):
pass
"""
Drive backward `distance` meters
distance: int: the distance to drive in meters
returns void
"""
def backward(self, distance):
pass
def turnBy(self, degrees):
pass
def turnTo(self, degrees):
pass
def findMarkers(self, degrees):
pass
def hasTimeLeft(self):
pass
def getWeightedMarkersWithSolution(self):
pass
def driveAlignWith(self, marker):
pass
def pickUpCube(self):
pass
def canSeeMarker(self, marker):
pass
def sendSolutionSetToArms(self, solution_set):
pass
def tryFacingHome(self):
pass
def canSeeHomeZone(self):
pass
def driveToHome(self):
pass
def dropCubes(self):
pass
from hillsrobot import Hobo
if __name__ == "__main__":
# Main
R = Hobo({
"res": [1024, 768],
"testing": {
"zone": 1
"zone-facing": 120 # degrees
}
})
R.forward(4) #go to center cube (assumes facing forward)
R.turnBy(-90) # point towards arena
while R.hasTimeLeft():
marker_solution_sets = R.getWeightedMarkersWithSolution();
if not marker_solution_sets:
R.turnBy(45) #degrees
else :
firstMarker = marker_solution_sets[0]
R.driveAlignWith(firstMarker)
R.pickUpCube()
R.reverse(2);
if not R.canSeeMarker(firstMarker.marker_id):
R.sendSolutionSetToArms(firstMarker)
if len(marker_solution_sets) > 1:
secondMarker = marker_solution_sets[1]
R.turnBy(secondMarker.getSimplifedAngle) # either 45 or -45
marker_solution_sets = R.getWeightedMarkersWithSolution()
# ... TBC
# Running out of time
R.tryFacingHome()
if R.canSeeHomeZone():
R.driveToHome()
else:
while not R.canSeeHomeZone():
R.drive(1)
R.dropCubes()
R.party() #!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment