def main(dalek_settings, dalek_sounds):
    # pass
    challenge = Challenge(dalek_settings, dalek_sounds)
    challenge.start()
    time.sleep(2)
    # challenge.button_circle_pressed()
    challenge.stop_running()

    # challenge.join() # wait for thread to finish.
    debug.print_to_all_devices("\nFINISHED")
    drive.cleanup()
Exemple #2
0
def destroy():  # Shutdown GPIO and Cleanup modules

    # Allow access to sound volume
    global dalek_sounds

    debug.print_to_all_devices("\n... Shutting Down...\n", "Ext")
    dalek_sounds.play_sound("Grow_stronger")
    drive.stop()  # Make sure Bot is not moving when program exits
    drive.cleanup()  # Shutdown all motor control
    # time.sleep(2)
    #    cv2.destroyAllWindows()    # Shutdown any open windows
    # time.sleep(1.5)
    debug.destroy()  # Clear Scroll pHat
    GPIO.cleanup()  # Release GPIO resource
Exemple #3
0
def straight_line_speed_test(dalek_settings, dalek_sounds):
    arduino_sensor_data = spi.SensorData()
    arduino_sensor_data.start(
    )  # starts the new process and runs in the background
    time.sleep(0.2)
    start_button = False

    def button_start_pressed():
        print("from straighe line challenge")

    while dalek_settings.drive:
        '''
        TODO:
        The dalek_settings.drive can be turned off with the controller 
        '''

        drive.forward(dalek_settings.max_speed)

        # detects we have finished the challenge.
        if arduino_sensor_data.front_distance <= 10:
            drive.cleanup()
            debug.print_to_all_devices(
                "Center Distance:{}cm Run Finished".format(
                    arduino_sensor_data.frontPing))
            arduino_sensor_data.running = False
            break

        if arduino_sensor_data.left_ping <= 5:
            debug.print_to_all_devices("turnForwardRight", "TrR")
            drive.turnForwardRight(dalek_settings.outer_turn_speed,
                                   dalek_settings.inner_turn_speed)
            time.sleep(.1)
            drive.forward(dalek_settings.max_speed)

        if arduino_sensor_data.right_distance <= 5:
            debug.print_to_all_devices("turnForwardLeft", "TrL")
            drive.turnForwardLeft(dalek_settings.inner_turn_speed,
                                  dalek_settings.outer_turn_speed)
            time.sleep(.1)
            drive.forward(dalek_settings.max_speed)

    arduino_sensor_data.join()  # wait for process to  finish
    debug.print_to_all_devices("Done...")
Exemple #4
0
def main():
    '''
    This is only run if you run the file directly
    '''
    GPIO.setmode(
        GPIO.BOARD)  # Set the GPIO pins as numbering - Also set in drive.py
    GPIO.setwarnings(False)
    spi.init()
    dalek_settings = settings.Settings()
    dalek_settings.slow_mode()
    drive.init()
    dalek_sounds = sound_player.Mp3Player(True)  # initialize the sound player
    debug.debug_on = True
    debug.print_to_all_devices("working", "OK")
    try:
        straight_line_speed_test(dalek_settings, dalek_sounds)
        time.sleep(1)
    except:
        print("!!! error")
        drive.cleanup()
Exemple #5
0
def start(dalek_settings):
    arduino_sensor_data = spi.SensorData()
    arduino_sensor_data.start(
    )  # starts the new process and runs in the background
    time.sleep(0.2)

    while True:
        '''
           TODO:
           The dalek_settings.drive can be turned off with the controller 
           '''

        drive.forward(100)

        # detects we have finished the challenge.
        if arduino_sensor_data.front_distance <= 10:
            drive.cleanup()
            print("Center Distance:{}cm Run Finished".format(
                arduino_sensor_data.front_distance))
            arduino_sensor_data.running = False
            break

        if arduino_sensor_data.left_distance <= 5:
            print("turnForwardRight", "TrR")
            drive.turnForwardRight(dalek_settings.outer_turn_speed,
                                   dalek_settings.inner_turn_speed)
            time.sleep(.1)
            drive.forward(dalek_settings.max_speed)

        if arduino_sensor_data.right_distance <= 5:
            print("turnForwardLeft", "TrL")
            drive.turnForwardLeft(dalek_settings.inner_turn_speed,
                                  dalek_settings.outer_turn_speed)
            time.sleep(.1)
            drive.forward(dalek_settings.max_speed)

    # wait for process to  finish
        print("Done...")
def dispose():
    drive.cleanup()
def print_compass():
    print("L F R Rear {} {} {} {}".format(
        compass_positions['left'],
        compass_positions['forward'],
        compass_positions['right'],
        compass_positions['backwards']))


# def turn_left():
#     turnspeed = 50
#     while DalekSensors.compass > (145+5):
#         drive.spinLeft(turnspeed)
#         time.sleep(.2)

#     print(DalekSensors.compass)
#     drive.stop()
#     print("Stop")
#     time.sleep(1)
#     print(DalekSensors.compass)
#     DalekSensors.stop_running()


if __name__ == "__main__":

    main()
    drive.stop()
    head_controller.leds_change_color(head_controller.leds_color['off'])
    drive.cleanup()
    DalekSensors.stop_running()
Exemple #8
0
def straight_line_speed_test_1(dalek_settings, dalek_sounds):
    '''
    finds the middle of the area and drives down it.
    '''
    arduino_sensor_data = spi.SensorData()
    arduino_sensor_data.start(
    )  # starts the new process and runs in the background
    time.sleep(0.2)

    turning_left = False
    turning_right = False
    previous_center_value = arduino_sensor_data.left_ping - arduino_sensor_data.right_distance
    counter = 0

    while dalek_settings.drive:
        '''
        TODO:
        The dalek_settings.drive can be turned off with the controller 
        '''

        drive.forward(dalek_settings.max_speed)
        time.sleep(.5)

        # detects we have finished the challenge.
        if arduino_sensor_data.frontPing <= 10:
            drive.cleanup()
            debug.print_to_all_devices(
                "Center Distance:{}cm Run Finished".format(
                    arduino_sensor_data.frontPing))
            arduino_sensor_data.running = False
            break

        center_value = arduino_sensor_data.left_ping - arduino_sensor_data.right_distance
        print(center_value)

        # if  (center_value - 1) <= previous_center_value <= (center_value + 1) :
        if previous_center_value == center_value:
            # use the if between to stop hunting, a few centermeters either way
            #  should be fine.
            # we are driving parallel to walls
            # we should be able to drive forward while moving into the middle.
            print("parallel to walls {} {}".format(previous_center_value,
                                                   center_value))

        else:
            print("Not parallel to walls {} {}".format(previous_center_value,
                                                       center_value))

        counter += 1
        if counter == 10:
            previous_center_value = center_value
            counter = 0

        # print(counter)

        if (center_value < -2) and turning_right == False:
            turning_right = True
            turning_left = False
            drive.turnForwardRight(dalek_settings.outer_turn_speed,
                                   dalek_settings.inner_turn_speed)
            debug.print_to_all_devices("turnForwardRight", "TrR")
            time.sleep(.05)
            # drive.forward(dalek_settings.max_speed)
            # time.sleep(.05)

        if (center_value > 2) and turning_left == False:
            turning_left = True
            turning_right = False
            drive.turnForwardLeft(dalek_settings.inner_turn_speed,
                                  dalek_settings.outer_turn_speed)
            debug.print_to_all_devices("turnForwardLeft", "TrL")
            time.sleep(.05)
            # drive.forward(dalek_settings.max_speed)
            # time.sleep(.05)

        # if  -2 <= center_value <= 2:
        #     # if it is between these values
        #     # straiten up the bot
        #     if turning_left

    arduino_sensor_data.join()  # wait for process to  finish
    debug.print_to_all_devices("Done...")
Exemple #9
0
def main(dalek_settings, dalek_sounds):
    init()
    use(dalek_settings, dalek_sounds)
    drive.cleanup()
Exemple #10
0
def main():
    init()
    start()
    drive.cleanup()