示例#1
0
def evade_rev_1(drive_time, drive_burst, mode):
    print(
        "evade.evade_rev_1  > Too close!\nevade.evade_rev_1  > Performing 1st order evasive manouver\n"
    )
    drive_iterate = int(round(drive_time / drive_burst))
    ##Bring the return of the function optimal_direction in from optimal_direction.py
    opt_dir = optimal_direction.optimal_direction()
    ##Check the front distance
    front_dist = sensors.front_distance()
    if front_dist > 15 and opt_dir == 'left':
        print(
            "evade.evade_rev_1  > I will proceed forward and left with caution"
        )
        ##Repeat the steps below drive_iterate times
        for y in range(drive_iterate):
            ##Collision collision_avoidance
            check_bk_2(drive_time, drive_burst, mode)
            ##Drive left and forward for drive_burst seconds
            driveme_tank.turn_left_fwd(drive_burst, mode)

    elif front_dist > 15 and opt_dir == 'right':
        print(
            "evade.evade_rev_1  > I will proceed forward and right with caution"
        )
        ##Repeat the steps below drive_iterate times
        for y in range(drive_iterate):
            ##Collision collision_avoidance
            check_bk_2(drive_time, drive_burst, mode)
            ##Drive left and forward for drive_burst seconds
            driveme_tank.turn_right_fwd(drive_burst, mode)

    else:
        stuck_help(
            "evade.evade_rev_1  > Boxed in on 3-sides\nevade.evade_rev_1  > I don\'t know how to solve this problem"
        )
示例#2
0
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)
示例#3
0
def check_fr_2(drive_time, drive_burst, mode):
    print("evade.check_fr_2   >Second check of the front sensor:\n")
    f_dist = sensors.front_distance()
    ##Instruct action: if an object is closer than 15 cm away, check for the optimal direction and take evasive action
    if f_dist < 15:
        evade_fwd_2(drive_time, drive_burst, mode)
    else:
        print("evade.check_fr_2   > All clear in front!")
示例#4
0
def check_fr_1(drive_time, drive_burst, mode):
    print("evade.check_fr_1   > First check of the front sensor:\n")
    ##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, check for the optimal direction and take evasive action
    if f_dist < 15:
        evade_fwd_1(drive_time, drive_burst, mode)
    else:
        print("evade.check_fr_1   > All clear in front!")
示例#5
0
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:
        print('Too close,', f_dist)
##Otherwise, print 'Front okay' and continue
    else:
        print('Front okay,', f_dist)
示例#6
0
def check_fr_4(drive_time, drive_burst, mode):
    print("evade.check_fr_4   > Fourth and final check of the front sensor:\n")
    ##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, check for the optimal direction and take evasive action
    if f_dist < 15:
        stuck_help(
            'evade.check_fr_4   > Still too close at front on 4th check')
    else:
        print("evade.check_fr_4   > All clear in front!")
示例#7
0
def check_bk_2(drive_time, drive_burst, mode):
    print(
        "evade.check_bk_2   > I must find a way forward - checking the front:\n"
    )
    ##Define the variable r_dist as the distance from the rear sensor to the nearest object
    f_dist = sensors.front_distance()
    ##Instruct action: if an object is closer than 15 cm away, check for the optimal direction and take evasive action
    if f_dist < 15:
        evade_rev_2(drive_time, drive_burst, mode)
    else:
        print("evade.check_bk_2   > All clear in front!")
示例#8
0
def check_bk_3(drive_time, drive_burst, mode):
    print(
        "evade.check_bk_3   > Now check the front sensor again - is it safe?\n"
    )
    ##Define the variable r_dist as the distance from the rear sensor to the nearest object
    f_dist = sensors.front_distance()
    ##Instruct action: if an object is closer than 15 cm away, check for the optimal direction and take evasive action
    if f_dist < 15:
        stuck_help(
            "evade.check_bk_3  > Ooops!\nevade.check_bk_2  > I don\'t know how to solve this problem"
        )
    else:
        print("evade.check_bk_3   > All clear in front!")
示例#9
0
##2. Call the distance function from the sensors local library to prove it is functioning correctly.
## ---sensors.distance() --- Return the distance from the sensor to the nearest object
## ---driveme.init() --- Initialise GPIO pins to drive as output
## ---driveme.forward(tf) --- Drive Foward
## ---driveme.reverse(tf) --- Drive in Reverse
## ---driveme.turn_left_fwd(tf) --- Turn left while moving forward
## ---driveme.turn_right_fwd(tf) --- Turn right while moving forward
## ---driveme.turn_left_rev(tf) --- Turn left while moving backward
## ---driveme.turn_right_rev(tf) --- Turn right while moving backward
## ---driveme.pivot_right(tf) --- Pivot clockwise (defined as from a 'birds eye view' with 12o'clock at the front of the vehicle (Pivot right)
## ---driveme.pivot_left(tf) --- Pivot counter clockwise (Pivot left)

#Assumptions: see driveme.py

##Call the function distance from the local python script sensors.py
sensors.front_distance()


##Define the function autonomy
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