Exemple #1
0
    def dpad_button_pressed(value, number, _joystickD_padCurrentButton):
        if (value == 0) and (number == _joystickD_padCurrentButton):
            drive.stop()
            if ps3_ControllerMode == 1:
                debug.print_to_all_devices("Stop", "SP")
        # Up button
        else:
            if number == 4:
                if value:  # value is 1 for pressed 0 for released.
                    dpad_up_button_pressed()

            # Right button
            elif number == 5:
                if value:
                    dpad_right_button_pressed()

            # Down button
            elif number == 6:
                if value:
                    dpad_down_button_pressed()

            # Left button
            elif number == 7:
                if value:
                    dpad_left_button_pressed()
Exemple #2
0
def test():
    T = time.time()
    data = read_device_1_data()
    T2 = time.time()

    debug.print_to_all_devices(data)
    debug.print_to_all_devices("time taken {}" .format(T2 - T))
Exemple #3
0
    def button_PS3(_ps3_ControllerMode):
        nonlocal current_challenge_thread, tank_drive_on

        # # change the controller Mode.
        _ps3_ControllerMode += 1

        if _ps3_ControllerMode == 1:
            tank_drive_on = True
            os.system('clear')
            debug.print_to_all_devices("You are in Drive Mode ", "-D")
            head_controller.leds_change_color(
                head_controller.leds_color['green'])
            head_controller.leds_flash(False)

        elif _ps3_ControllerMode == 2:
            stop_current_challenge()
            ui.display_selected_challenge(current_challenge)
            tank_drive_on = False

        elif _ps3_ControllerMode == 3:
            tank_drive_on = True
            _ps3_ControllerMode = 0
            os.system('clear')
            debug.print_to_all_devices("You are in Exterminate Mode", "-E")

        return _ps3_ControllerMode
Exemple #4
0
def drive_back(dalek_settings, time_to_drive):
    '''
       used when testing so you dont have to keep getting up.
    '''
    debug.print_to_all_devices("Start drive back")
    drive.backward(50)
    time.sleep(time_to_drive)
    debug.print_to_all_devices("end drive back")
Exemple #5
0
 def dpad_down_button_pressed():
     if ps3_ControllerMode == 2:  # 2 Mission Select Mode
         challenge_select(1)
     elif ps3_ControllerMode == 1:
         debug.print_to_all_devices('Backwards', "BW")
         drive.backward(dalek_settings.speed)
     else:
         head_controller.eye_move_down()
Exemple #6
0
 def dpad_up_button_pressed():
     if ps3_ControllerMode == 2:  # 2 Mission Select Mode
         challenge_select(0)
     elif ps3_ControllerMode == 1:
         debug.print_to_all_devices('Forwards', "FW")
         drive.forward(dalek_settings.speed)
     else:
         head_controller.eye_move_up()
Exemple #7
0
 def stop_current_challenge():
     nonlocal current_challenge_thread, tank_drive_on
     if current_challenge_thread.running == True:  # we are in a challenge
         debug.print_to_all_devices("Quiting Challenge.")
         current_challenge_thread.stop_running()
         current_challenge_thread.join()  # wait for thread to stop
         tank_drive_on = True
         debug.print_to_all_devices("Challenge has ended")
Exemple #8
0
 def stop_running(self):
     '''
     When this is called it ends this thread 
     This is also called if the PS3 button is pressed during a challenge,
     so add any cleanup code here.
     '''
     # drive.stop()
     self.running = False
     debug.print_to_all_devices("Done...")
Exemple #9
0
 def dpad_left_button_pressed():
     if ps3_ControllerMode == 1:
         debug.print_to_all_devices('Spin Left', "SL")
         drive.spinLeft(dalek_settings.speed)
     elif ps3_ControllerMode == 2:
         debug.print_to_all_devices('Spin Left', "SL")
         drive.spinLeft(dalek_settings.speed)
     else:
         head_controller.head_move_left()
Exemple #10
0
def get_sensor_data(_sensorNumber):

    dataToSend = [_sensorNumber, 200, 201, 255]
    try:

        receivedBytes = spi.xfer(dataToSend)
        sensorValue = (receivedBytes[2] << 8) + receivedBytes[3]
        return sensorValue
    except:
        debug.print_to_all_devices(
            "error geting data from Arduino via spi bus")
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 #12
0
 def stop_running(self):
     '''
     When this is called it ends this thread 
     This is also called if the PS3 button is pressed during a challenge,
     so add any cleanup code here.
     '''
     drive.stop()
     if self.arduino_sensor_data.is_alive():
         self.arduino_sensor_data.stop_running()
         self.arduino_sensor_data.join()  # wait for process to  finish
     self.running = False
     debug.print_to_all_devices("Done...")
    def run(self):
        self.running = True
        debug.print_to_all_devices(
            "Challenge 'slightly_deranged_golf' Started.")
        while self.running:

            ####################################################
            #                                                  #
            # Code for this challenge goes in this while loop  #
            #                                                  #
            ####################################################
            debug.print_to_all_devices("Putt! ")  # this line can be removed
            # this line can be removed
            time.sleep(2)
Exemple #14
0
    def run(self):
        self.running = True
        debug.print_to_all_devices("Challenge 'Straight line' Started.")
        # self.arduino_sensor_data.start() #   starts the new process and runs in the background

        self.arduino_sensor_data.start()
        time.sleep(0.2)

        while self.running:
            drive.forward(self.dalek_settings.max_speed)
            time.sleep(.1)

            # # detects we have finished the challenge.
            if self.arduino_sensor_data.frontPing <= 18:
                drive.stop()
                debug.print_to_all_devices(
                    "Center Distance:{}cm Run Finished".format(
                        self.arduino_sensor_data.frontPing))
                self.stop_running()

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

            if self.arduino_sensor_data.rightPing <= 5:
                debug.print_to_all_devices("turnForwardLeft", "TrL")
                drive.turnForwardLeft(self.dalek_settings.inner_turn_speed,
                                      self.dalek_settings.outer_turn_speed)
                time.sleep(.05)
                drive.forward(self.dalek_settings.max_speed)
Exemple #15
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 #16
0
 def run(self):
     self.running = True
     debug.print_to_all_devices("Challenge 'the_duck_shoot' Started.")
     while self.running:
         drive.forward(self.dalek_settings.max_speed)
         time.sleep(1)
         ####################################################
         #                                                  #
         # Code for this challenge goes in this while loop  #
         #                                                  #
         ####################################################
         debug.print_to_all_devices("BANG!!!")  # this line can be removed
         drive.stop()
         self.stop_running()  # this line can be removed
def init():
    # you may have more than one device so add them to the list
    # It will only use the first device it finds so if two or more devices are in
    # the list, and connected, it may not find the right one
    address_list = ['00:21:4f:19:34:22', '00:21:4f:19:34:c2']
    address = "Not Connected"
    for add in address_list:
        folder = '/sys/class/power_supply/sony_controller_battery_' + add
        if os.path.exists(folder):
            debug.print_to_all_devices(
                colored("\nController Connected:{}\n".format(add), 'green'),
                "BL")
            address = add

    return address
Exemple #18
0
    def run(self):
        self.running = True
        print(
            "challenge template class is running You need to override the run(self) function"
        )
        while self.running:

            ####################################################
            #                                                  #
            # Code for this challenge goes in this while loop  #
            #                                                  #
            ####################################################
            # this line can be removed
            debug.print_to_all_devices("challenge base class !!")
            time.sleep(2)  # this line can be removed
Exemple #19
0
def init():
    head_controller.leds_change_color(head_controller.leds_color['red'])
    head_controller.leds_flash()
    fn = '/dev/input/js0'

    debug.print_to_all_devices("Testing for joystick: {}...".format(fn))

    file_exists = False
    while file_exists == False:

        file_exists = os.path.exists(fn)
        debug.print_to_all_devices('joystick paired: {} '.format(
            os.path.exists(fn)))
        time.sleep(3)

    jsdev = open(fn, 'rb')
Exemple #20
0
def change_mode_on_device_(mode):
    # mode 10: all data is read
    # mode 11: left ping only
    # mode 12: right ping only
    # mode 13: center ping only
    # mode 14: compass only
    # mode 15: all data is read and debug output
    dataToSend = [10, mode , 0, 0]
    try:

        receivedBytes = spi.xfer(dataToSend)
        # sensorValue = (receivedBytes[2] << 8) + receivedBytes[3]
        # return sensorValue
    except:
        debug.print_to_all_devices(
            "error geting data from Arduino via spi bus")
Exemple #21
0
    def tank_drive(_leftPaddle, _rightPaddle):
        debug.print_to_all_devices("left: {}  Right: {}".format(
            _leftPaddle, _rightPaddle))

        if (_leftPaddle == 0) and (_rightPaddle == 0):
            drive.stop()
            debug.clear()
        elif (_leftPaddle < 0) and (_rightPaddle < 0):
            drive.paddleForward(-_leftPaddle, -_rightPaddle)
            # debug.print_to_all_devices("forwards","Fw")
        elif (_leftPaddle > 0) and (_rightPaddle > 0):
            drive.paddleBackward(_leftPaddle, _rightPaddle)
            # debug.print_to_all_devices("Backwards", "Bw")
        elif (_leftPaddle <= 0) and (_rightPaddle >= 0):
            drive.turnForwardRight(-_leftPaddle, _rightPaddle)
            # debug.print_to_all_devices("Spin Right", "SR")
        elif (_leftPaddle >= 0) and (_rightPaddle <= 0):
            drive.turnForwardLeft(_leftPaddle, -_rightPaddle)
    def run(self):
        self.running = True
        debug.print_to_all_devices("Challenge 'somewhere over the rainbow")

        if video_capture._check_camera_open(
        ) == False:  # check if VideoCapture object was associated to webcam successfully
            print("error: capWebcam not accessed successfully\n\n"
                  )  # if not, print error message to std out
            os.system(
                "pause"
            )  # pause until user presses a key so user can see error message
            self.running = False  # ruturns

        intXFrameCenter = int(float(hRes) / 2.0)
        intYFrameCenter = int(float(vRes) / 2.0)

        if intXFrameCenter == 0.0:
            # scrollphat.clear()         # Shutdown Scroll pHat
            # scrollphat.write_string('Err')
            time.sleep(2)
            self.running = False  # ruturns

        panServoPosition = intXFrameCenter

        # print ('\nPress "A" to Chase the Rainbow')
        # print ('Press "Hm" to return to main menu\n')

        # scrollphat.clear()         # Shutdown Scroll pHat
        # scrollphat.write_string('"A"')

        time.sleep(.25)

        ####################################################
        #                                                  #
        # Code for this challenge goes in this while loop  #
        #    call    self.running= False to exit challenge #
        ####################################################
        while self.running:

            debug.print_to_all_devices(
                "rainbow start ")  # this line can be removed
            # this line can be removed
            time.sleep(2)
    def run(self):
        self.running = True
        self.address = init()
        while self.address == "Not Connected":
            self.address = init()
            debug.print_to_all_devices(
                colored("NO Controller Connected", 'red'), "BL")
            time.sleep(1)

        while self.running:
            self.battery_capacity, self.battery_status = get_battery_status(
                self.address)

            if self.battery_status == "Not Connected":
                debug.print_to_all_devices(
                    colored("NO Controller Connected", 'red'), "BL")
            else:

                if int(self.battery_capacity) < 25:
                    debug.print_to_all_devices(
                        colored(
                            "Controller Battery LOW --- RECHARGE IT \n---capacity:{}---status:{}"
                            .format(self.battery_capacity,
                                    self.battery_status), 'red'), "BL")

                elif int(self.battery_capacity) <= 51:
                    debug.print_to_all_devices(
                        colored(
                            "Controller Battery -- LESS THAN HALF FULL \n---capacity:{}---status:{}"
                            .format(self.battery_capacity,
                                    self.battery_status), 'yellow'), "BM")
                else:
                    debug.print_to_all_devices(
                        colored(
                            "Controller Battery -- GOOD \n---capacity:{}---status:{}"
                            .format(self.battery_capacity,
                                    self.battery_status), 'green'), "BG")
            # create a timer that can be stopped immediately
            for x in range(self.frequency):
                time.sleep(1)
                if self.running == False:
                    break
Exemple #24
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 #25
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 #26
0
    def button_select_pressed(ps3_controller_mode):
        nonlocal current_challenge_thread, button_select_status, tank_drive_on

        # uses for shuting down the program safely
        button_select_status = True
        check_for_finished_using_controller()

        if ps3_controller_mode == 2:  # Challenge Select Mode
            ui.you_selected_challenge(current_challenge)

            if current_challenge == 1:  # output for onboard device
                debug.print_to_all_devices("TODO: Obstacle Course")

            elif current_challenge == 2:
                os.system('clear')  # clear the stout
                tank_drive_on = False
                current_challenge_thread = straight_line.Challenge(
                    dalek_settings, dalek_sounds)
                current_challenge_thread.start()

            elif current_challenge == 3:
                debug.print_to_all_devices("TODO: Minimal Maze")

            elif current_challenge == 4:  # somewhere_over_the_rainbow
                os.system('clear')  # clear the stout
                tank_drive_on = False
                current_challenge_thread = somewhere_over_the_rainbow.Challenge(
                    dalek_settings, dalek_sounds)
                current_challenge_thread.start()

            elif current_challenge == 5:
                debug.print_to_all_devices("TODO: PiNoon")

            elif current_challenge == 6:
                os.system('clear')  # clear the stout
                current_challenge_thread = the_duck_shoot.Challenge(
                    dalek_settings, dalek_sounds)
                current_challenge_thread.start()
                # current_challenge_thread.join()

            elif current_challenge == 7:
                tank_drive_on = True
                os.system('clear')
                current_challenge_thread = slightly_deranged_golf.Challenge(
                    dalek_settings, dalek_sounds)
                current_challenge_thread.start()
Exemple #27
0
 def button_L1_released(self):
     debug.print_to_all_devices(
         "L1_released() in challenges/ChallengeBase class")
Exemple #28
0
 def button_square_pressed(self):
     debug.print_to_all_devices(
         "square_button_pressed() in challenges/ChallengeBase class")
Exemple #29
0
 def button_triangle_released(self):
     debug.print_to_all_devices(
         "triangle_button_released() in challenges/ChallengeBase class")
Exemple #30
0
 def button_cross_pressed(self):
     debug.print_to_all_devices(
         "x_button_pressed() in challenges/ChallengeBase class")