def check_front(): ##Define the variable f_dist as the distance from the front sensor to the nearest object f_dist = sensors.front_distance() ##Instruct action: if an object is closer than 15 cm away, print "Too close, and the distance", and continue if f_dist < 15: driveme.init() driveme.reverse(2)
def autonomy(): tf = 0.3 x = random.randrange(0, 4) if x == 0: for y in range(30): check_front() driveme.init() driveme.forward(tf) elif x == 1: for y in range(30): check_front() driveme.init() driveme.pivot_left(tf) elif x == 2: for y in range(30): check_front() driveme.init() driveme.turn_right_fwd(tf) elif x == 3: for y in range(30): check_front() driveme.init() driveme.turn_left_fwd(tf)
def autonomy(): ##Set the time to run (for actions other than forward) tf = 0.1 ##Introduce a variable, x, that will take on a sudorandom value to drive the vechicle in explore mode. x will take on values from 1-7 x = random.randrange(0, 1) ##Set actions for the vechicle based on the value of x ##Drive forward for 5 seconds if x = 0 if x == 0: ##Repeat the steps below 30 times for y in range(10): check_front() ##Initialise GPIO pins (based on instructions defined in driveme.py) driveme.init() ##Drive forward for 0.03 seconds driveme.forward(tf)
def check_front(): driveme.init() dist = sensors.distance() if dist < 15: print('Too close,', dist) driveme.init() driveme.reverse(2) dist = sensors.distance() if dist < 15: print('Too close,', dist) driveme.init() driveme.pivot_left(3) driveme.init() driveme.reverse(2) dist = sensors.distance() if dist < 15: print('Too close, giving up', dist) sys.exit()
def autonomy(): ##Set the time to run (for actions other than forward) tf = 1 ##Introduce a variable, x, that will take on a sudorandom value to drive the vechicle in explore mode. x will take on values from 1-7 x = random.randrange(0, 8) ##Set actions for the vechicle based on the value of x ##Drive forward for 5 seconds if x = 0 if x == 0: ##Initialise GPIO pins (based on instructions defined in driveme.py) driveme.init() ##Drive forward for 5 seconds driveme.forward(5) ##Pivot left for tf seconds if x = 1 elif x == 1: driveme.init() driveme.pivot_left(tf) ##Pivot right for tf seconds if x = 2 elif x == 2: driveme.init() driveme.pivot_right(tf) ##Drive forward and to the left for tf seconds if x = 3 elif x == 3: driveme.init() driveme.turn_left_fwd(tf) ##Drive forward and to the right for tf seconds if x = 4 elif x == 4: driveme.init() driveme.turn_right_fwd(tf) ##Drive left and reverse for tf seconds if x = 5 elif x == 5: driveme.init() driveme.turn_left_rev(tf) ##Drive right and reverse for tf seconds if x = 6 elif x == 6: driveme.init() driveme.turn_right_rev(tf) ##Reverse for tf seconds if x = 7 elif x == 7: driveme.init() driveme.reverse(tf)