Example #1
0
    def do_navigation(self, arg):
        '\n[cv] toggle computer vision (start/1 or stop/0)\
         \n[keyboard] keyboard manual navigation'

        if arg.lower() == 'cv start' or arg.lower() == 'cv 1':
            # temp method for testing purposes
            AUV.perform_tasks()
            # print(arg)
        elif arg.lower() == 'cv stop' or arg.lower() == 'cv 0':
            AUV.stop_task()
            # print(arg)
        elif arg.lower() == 'keyboard' or arg.lower() == 'kb':
            AUV.keyboard_nav()
        else:
            print('\n[cv] toggle computer vision (start/1 or stop/0)\
                   \n[keyboard] keyboard manual navigation')
Example #2
0
    def do_task(self, arg):
        '\nto start please enter\
         \n[task] <0-10>\
         \nstop task by entering [task]\
         \n'

        print('type: [task ?] to see all options')

        if arg.lower() == 'stop' or arg.lower() == '':
            AUV.stop_task()
        elif arg.lower() == 'all':
            AUV.perform_tasks()
        elif arg.lower() == 'heading' or arg.lower() == 'h':
            AUV.save_heading()
        elif arg == '?':
            print(
                '\nto start please enter:\
                   \n[task] (0-{})\
                   \nstop task by entering [task] or [task stop]\
                   \nrun all tasks by entering [task all]\
                   \nsave current heading by entering [task heading]\
                   \n'.format(len(AUV.houston.tasks)))

            AUV.display_tasks()
        elif not arg == '':
            try:
                arg = int(arg)
            except:
                print '\nINVALID NUMBER INPUT'
                pass

            if arg >= 0 and arg <= len(AUV.houston.tasks):
                AUV.specific_task(arg)
                # AUV.display_tasks()
        else:
            print(
                '\nto start please enter:\
                   \n[task] (0-{})\
                   \nstop task by entering [task] or [task stop]\
                   \nrun all tasks by entering [task all]\
                   \nsave current heading by entering [task heading]\
                   \n'.format(len(AUV.houston.tasks)))

            AUV.display_tasks()
Example #3
0
class Controller():
    """ Controller for GUI"""
    def __init__(self):
        self.AUV = AUV()
        self.AUV.start()  # Magnet killswitch = 1

    def load_default_params(self):
        """ Change current parameters back to default parameters"""

        config.reset_option('auv', 'tasks')
        config.reset_option('auv', 'motor')

    def change_params(self):
        """ Opens the config file and updates the parameters"""

        self.AUV.open_config()

    def get_auto_mode_state(self):
        """ Get the start_auto_mode from config.ini"""

        return config.get_config('auv', 'start_auto_mode') == 1

    def set_auto_mode_state(self, value):
        """ Checkbox to determine if AUV starts in auto mode when turned on"""

        config.set_config('auv', 'start_auto_mode', value)

    def get_task_list(self):
        """ Get the list of tasks from config.ini"""

        return config.get_config('auv', 'tasks')

    def read_task_button(self, text):
        """ Read task string from button press"""

        if text == 'start tasks':
            self.AUV.perform_tasks()
        elif text == 'stop tasks':
            self.AUV.stop_task()
        else:
            self.AUV.specific_task_for_gui(text)

    def get_color_task(self):
        """ Get the task from lower_color"""

        return config.get_config('cv', 'lower_color')[0]

    def update_color(self, task_name, range0, range1, range2):
        """ Read task name and slider range values from GUI"""

        lower_color = (task_name + ', ' + str(range0[0]) + ', ' +
                       str(range1[0]) + ', ' + str(range2[0]))

        upper_color = (task_name + ', ' + str(range0[1]) + ', ' +
                       str(range1[1]) + ', ' + str(range2[1]))
        config.set_config('cv', 'lower_color', lower_color)
        config.set_config('cv', 'upper_color', upper_color)
        self.AUV.update_color()

    def manual_mode(self):
        """ Manual mode selected (Keyboard)"""

        # task.cv_controller.stop()
        pass

    def manual_move(self, direction, power, rotation, depth):
        """ Manual movement of the sub based on button press"""

        directions = {
            'brake': '`',
            'forward': 'w',
            'backward': 's',
            'strafe_l': 'q',
            'strafe_r': 'e',
            'rotate_l': 'a',
            'rotate_r': 'd',
            'up': 'r',
            'down': 'f'
        }

        if any(x in directions[direction] for x in ['w', 'q', 'e', 's']):
            self.AUV.keyboard.set_power(m_power=power)
        elif any(x in directions[direction] for x in ['a', 'd']):
            self.AUV.keyboard.set_power(r_power=power)
        elif any(x in directions[direction] for x in ['r', 'f']):
            self.AUV.keyboard.set_power(h_power=power)

        self.AUV.keyboard.navigate(directions[direction], rotation, depth)