Example #1
0
    def launch(self):
        sent = remote.send(self.config['local_root'], self.config['remote_host'], self.config['remote_root'])
        
        if sent:
            result = remote.remote_exec(self.config['remote_host'], self.config['remote_dir'], self.config['command'])

            if result or _receive_if_failed(self.config):
                remote.receive(self.config['local_root'], self.config['remote_host'], self.config['remote_root'])
            else:
                logging.warning('Result not synced from server.')
                logging.info('To sync it manually use' + ' `' + sys.argv[0] + ' -r`')
Example #2
0
def init():
    logging.info("Starting manual control")
    print("Starting manual control")

    time.sleep(2)  # Prevent race condition as CAM sets up for run

    # This all obeys GIL so there *shouldn't* be race conditions
    buffer = collections.deque(maxlen=1)  # Buffer to hold most recent values

    # Start iterator
    it = threading.Thread(target=read_output, args=(buffer.append, ))
    it.daemon = True
    it.start()

    # Get axis info regularly
    while True:
        time.sleep(
            .1
        )  # Don't overwhelm network (lowest possible is probably ~0.005 sec)

        if not it.is_alive():  # Iterator exited
            break

        try:
            response = remote.send(map_axis(buffer[0]),
                                   port)  # Send mapped input to CAM
            # TODO timeout for response
        except:
            logging.warning("Controller input empty")
            response = "OK"

        if response != "OK":  # Not understood
            if response == "CC":
                print("Exiting manual control")
                break
            else:
                print("Error, exiting manual control")
                break

    print("Stopping CAM")
    remote.send("STOP", port)  # Stop command
Example #3
0
def houston(option):
    # Shutdown command
    if option.capitalize() == 'K':
        print("Sending shutdown command")
        print(remote.send('SD', port))
        exit(0)

    # Self test
    elif option == '0':
        print("Running test")
        print(remote.send('ST', port))

    # Manual mode
    elif option == '1':
        print(remote.send('MM', port))
        manual.init()

    # Autonomous run
    elif option == '2':
        print(remote.send('AR', port))
        autorun.init()
Example #4
0
def init():
    # Try to load file
    print("Starting autonomous run")
    run_file = input("Enter name of remote script: ")  # Get user input

    time.sleep(2)  # Prevent race condition as CAM sets up for run

    load_status = remote.send(run_file, port)
    if load_status != "OK":  # Load failed
        print("Error loading file: {}".format(load_status))
        return  # Exit to main menu

    # Autorun menu
    print("File loaded")
    # Get user input
    while True:
        opt = input("Autonomy Options:\n"
                    "\tQ - Kill script and return to menu\n"
                    "\tS - Start script\n"
                    "\t0 - Get status update\n"
                    "Enter choice: ")
        # Kill and return
        if opt.capitalize() == 'Q':
            remote.send('KP', port)
            return

        # Start run
        elif opt.capitalize() == 'S':
            if remote.send('GO', port) == "OK":
                print("Run started")
            else:
                print("Error starting run")

        # Send command, print response
        elif opt != '':
            response = remote.send(opt, port)
            print(response)
            if response == "FIN":
                print("Program finished")
Example #5
0
    def launch(self):
        sent = remote.send(self.config['local_root'],
                           self.config['remote_host'],
                           self.config['remote_root'], self.config['rsync'],
                           self.config['dry_run'])

        if sent:
            result = remote.remote_exec(self.config['remote_host'],
                                        self.config['remote_dir'],
                                        self.config['before_exec'],
                                        self.config['command'],
                                        self.config['dry_run'])

            if result or _receive_if_failed(self.config):
                remote.receive(self.config['local_root'],
                               self.config['remote_host'],
                               self.config['remote_root'],
                               self.config['rsync'], self.config['dry_run'])
            else:
                logging.warning('Result not synced from server.')
                logging.info('To sync it manually use' + ' `' + sys.argv[0] +
                             ' -r`')
Example #6
0
    # Manual mode
    elif option == '1':
        print(remote.send('MM', port))
        manual.init()

    # Autonomous run
    elif option == '2':
        print(remote.send('AR', port))
        autorun.init()


# Main menu for running the robot
if __name__ == "__main__":
    # Wait until connected to CAM
    print("Connecting to CAM")
    ping = remote.send('HI', port)
    while ping == "Connection Error":
        print("Couldn't connect, retrying...")
        time.sleep(5)
        ping = remote.send('HI', port)
    print("Connected!")

    # Check status message
    if ping != 'HI':
        if ping == 'BZ':  # Process is currently running
            ltk = input(
                "Something is currently running; kill it? (Y/n)").capitalize()
            if ltk == "Y" or ltk == "":
                remote.send('KP', port)
            else:
                exit(0)  # Bad stuff will probably happen unless we stop
Example #7
0
 def launch(self):
     return remote.send(self.config['local_root'],
                        self.config['remote_host'],
                        self.config['remote_root'], self.config['rsync'],
                        self.config['dry_run'])
Example #8
0
        opt = input("Autonomy Options:\n"
                    "\tQ - Kill script and return to menu\n"
                    "\tS - Start script\n"
                    "\t0 - Get status update\n"
                    "Enter choice: ")
        # Kill and return
        if opt.capitalize() == 'Q':
            remote.send('KP', port)
            return

        # Start run
        elif opt.capitalize() == 'S':
            if remote.send('GO', port) == "OK":
                print("Run started")
            else:
                print("Error starting run")

        # Send command, print response
        elif opt != '':
            response = remote.send(opt, port)
            print(response)
            if response == "FIN":
                print("Program finished")


# Testing
if __name__ == "__main__":
    print(remote.send("AR", 42069))
    time.sleep(2)
    print(remote.send("test_runfile", port))
Example #9
0
 def launch(self):
     return remote.send(self.config['local_root'], self.config['remote_host'], self.config['remote_root'])
Example #10
0
def read_output(append):
    # Holds last value of axis
    axis = [
        ['ABS_X', 0],  # 0 Left stick horizontal (-32768, 2604, 32767) min=left
        ['ABS_Y', 0],  # 1 Left stick vertical (-32768, 269, 32767) min=up
        ['ABS_RX', 0],  # 2 Right stick horizontal (-32768, 0, 32767) min=left
        ['ABS_RY', 0],  # 3 Right stick vertical (-32768, 1036, 32767) min=up
        ['ABS_Z', 0],  # 4 Left trigger (0, 255) min=unpressed
        ['ABS_RZ', 0],  # 5 Right trigger (0, 255) min=unpressed
        ['ABS_HAT0X', 0],  # 6 D-Pad horizontal (-1, 0, 1) min=left
        ['ABS_HAT0Y', 0]
    ]  # 7 D-Pad vertical (-1, 0, 1) min=up

    # Range to map values to [-1, 1]. Within dead spot of 0 maps to 0
    # [dead spot, abs max]
    mappings = [
        [3000, 32767],  # 0
        [3000, 32767],  # 1
        [3000, 32767],  # 2
        [3000, 32767],  # 3
        [20, 255],  # 4
        [20, 255],  # 5
        [0, 1],  # 6
        [0, 1]
    ]  # 7

    # Event handler loop
    while True:
        events = inputs.get_gamepad()  # Poll controller
        for event in events:
            logging.debug(event)

            # Axis input
            if event.ev_type == "Absolute":
                for i in range(len(axis)):
                    if axis[i][0] == event.code:
                        axis[i][1] = map_unit(event.state, mappings[i])

            # Button input
            elif event.ev_type == "Key":
                if event.state == 1:  # 1 = press, 0 = release

                    # Exit manual mode
                    if event.code == 'BTN_SELECT':
                        print("Exiting manual mode")
                        remote.send("STOP", port)  # Stop command
                        return

                    # Toggle Easy vs Advanced mode
                    elif event.code == 'BTN_START':
                        global control_map
                        if control_map == "Easy":
                            control_map = "Advanced"
                        elif control_map == "Advanced":
                            control_map = "Easy"

                        print("Control mode: {}".format(control_map))

                response = remote.send(map_btn(event.code, event.state),
                                       port)  # Send mapped input to CAM
                # TODO timeout for response

                if response != "OK":  # Not understood
                    if response == "CC":
                        print("Exiting manual control")
                        return
                    else:
                        print("Exiting manual control, error: {}".format(
                            response))
                        return

        append(axis)  # Update most recent values