Example #1
0
    def do_exit(self, arg):
        '\nExits auv'

        AUV.stop()
        print('Closing Robosub')

        return True
Example #2
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"""

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

    def change_params(self):
        """Opens the config file"""

        os.system('gedit config/config.ini')

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

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

    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)
Example #3
0
    def do_drop(self, arg):
        '\nSets state of dropper\
         \n[0] to close both gates\
         \n[1] to open both gates\
         \n[2] to drop one ball'

        # \n[state] or no argument to print current state\

        if arg == '0' or arg == '1' or arg == '2':
            AUV.dropper_state(arg)
        else:
            print('\nSets state of dropper\
                   \n[0] to close both gates\
                   \n[1] to open both gates\
                   \n[2] to drop one ball')
Example #4
0
    def do_tasks(self, arg):
        '\n[view] to view tasks\
         \n[set] to set tasks list\
         \n[reset] to reset tasks list'

        if arg.lower() == 'view':
            print(AUV.tasks)
        elif arg.lower() == 'set':
            # TODO set tasks
            # AUV.set_config('tasks', '0 1 2 3 4 5 6 7 8')
            print('test')
        elif arg.lower() == 'reset':
            AUV.set_config('tasks', '', True)
        else:
            print(AUV.tasks)
Example #5
0
    def do_navigation(self, arg):
        '\n[cv] toggle computer vision task manager\
         \n[keyboard] keyboard manual navigation'

        if arg.lower() == 'cv' or arg.lower() == 'tm':
            # TODO cv taskmanager
            print(arg)
        elif arg.lower() == 'keyboard' or arg.lower() == 'kb':
            AUV.keyboard_nav()
        # elif len(arg.split()) == 4:
        #     AUV.navigation.navigate(*parse(arg))
        else:
            print(
                '\n[cv] toggle computer vision task manager\
                 \n[keyboard] keyboard manual navigation'
            )
Example #6
0
    def do_torpedo(self, arg):
        '\nPrime or Fire torpedo\
         \n[prime] [side] Prime the torpedo with given side/s\
         \n[fire] [side] Fire the torpedo with given side/s\
         \nside -- (str) left, right'

        try:
            arg1, arg2 = parse_torpedo(arg)

            if arg1.lower() == 'prime':
                AUV.prime_torpedo(arg2)
            elif arg1.lower() == 'fire':
                AUV.fire_torpedo(arg2)
            else:
                print('\nPrime or Fire torpedo\
                       \n[prime] [side] Prime the torpedo with given side/s\
                       \n[fire] [side] Fire the torpedo with given side/s\
                       \nside -- (str) left, right')
        except ValueError:
            print('\nIncorrect number of arguments.\
                   \nTorpedo takes [prime/fire] [side]\
                   \nside -- (str) left, right')
Example #7
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 #8
0
    def do_task(self, arg):
        '\n\
         \n[task] followed by a number'

        AUV.display_tasks()

        if arg.lower() == 'stop' or arg.lower() == '':
            AUV.stop_task()
        elif not arg == '':
            try:
                arg = int(arg)
            except:
                # print '\nINVALID NUMBER INPUT'
                pass

        if arg >= 0 and arg <= 10:
            AUV.specific_task(arg)
        else:
            print '\nINVALID NUMBER INPUT'
Example #9
0
    def do_config(self, arg):
        '\nOpens the config file and updates the parameters'

        AUV.open_config()
Example #10
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) - 1))

            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 #11
0
        print('Setting up roscore.')
        os.system('killall -9 roscore')
        os.system('killall -9 rosmaster')
        os.system('killall -9 rosout')

        roscore = subprocess.Popen('roscore')
        time.sleep(1)
        return roscore

    return False


if __name__ == '__main__':
    roscore = start_roscore()

    AUV = AUV()  # initialize AUV() class

    print(
        '\n***Plug in magnet after setting up configurations to start AUV.***')
    print('\n***Set motor state to on (4) to start motors.***')

    AUV.start(
    )  # TESTING PURPOSES ONLY. REMOVE AFTER TESTING (simulates magnet killswitch = 1 ########################

    CLI().cmdloop()  # run AUV command interpreter

    # close roscore and rosmaster on exit if opened by CLI
    if (roscore):
        subprocess.Popen.kill(roscore)
        os.system('killall -9 rosmaster')
        os.system('killall -9 rosout')
Example #12
0
 def __init__(self):
     self.AUV = AUV()
     self.AUV.start()  # Magnet killswitch = 1
Example #13
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)