def __init__(self, navigation, task_list): """ To initilize Houston """ ################ INSTANCES ################ self.gate = Gate(self) self.path_1 = Path(self) self.dice = Dice(self) self.path_2 = Path(self) self.chip_1 = Chip(self) self.chip_2 = Chip(self) self.roulette = Roulette(self) self.slots = Slots(self) self.pinger_a = PingerA(self) self.pinger_b = PingerB(self) self.cash_in = CashIn(self) #self.buoy = Buoy(self) self.navigation = navigation self.cvcontroller = CVController() self.config = Config() self.counts = Counter() ################ THRESHOLD VARIABLES ################ self.task_timer = 300 self.break_timer = 600 ################ FLAG VARIABLES ################ self.is_killswitch_on = False ################ TIMER/COUNTER VARIABLES ################ self.last_time = time.time() ################ TASKS LIST ################ self.tasks = task_list ################ DICTIONARIES ################ """ self.tasks values listed below 'gate', 'path', 'dice', 'chip', 'path', 'chip', 'slots', 'pinger_b', 'roulette', 'pinger_a', 'cash_in' """ self.state_num = 0 self.states = [ self.gate, self.path_1, self.dice, self.chip_1, self.path_2, self.slots, self.chip_2, self.pinger_a, self.roulette, self.pinger_b, self.cash_in ] ################ AUV MOBILITY VARIABLES ################ #self.rotational_movement = {-1: } self.height = 1 self.queue_direction = [] self.rotation = 15 self.power = 120 ################ TASK THREAD ################ self.task_thread = None ################ ROS VARIABLES ################ self.r = rospy.Rate(30) #30hz self.msg = CVIn() ################ CURRENT TASK VARIABLE ################ self.current_task = None
def __init__(self, navigation, task_list): """ To initilize Houston """ ################ INSTANCES ################ self.pregate = PreGate(self) self.gate = Gate(self) self.path_1 = Path(self) self.dice = Dice(self) self.path_2 = Path(self) self.chip = Chip(self) self.roulette = Roulette(self) self.slots = Slots(self) self.pinger_a = PingerA(self) self.pinger_b = PingerB(self) self.cash_in = CashIn(self) # self.buoy = Buoy(self) self.navigation = navigation self.cvcontroller = CVController() self.counts = Counter() self.orientation = Orientation() ########################################### ########## RUN ALL TASK QUEUE ############# self.states_run_all = [ self.pregate, self.gate, self.path_1, self.dice, self.path_2, self.slots ] ################ THRESHOLD VARIABLES ################ self.task_timer = 300 self.break_timer = 600 ################ FLAG VARIABLES ################ self.is_killswitch_on = False self.is_task_running = False ################ TIMER/COUNTER VARIABLES ################ self.last_time = time.time() ################ TASKS LIST ################ """ self.tasks values listed below 'pregate', 'gate', 'path', 'dice', 'path', 'slots', 'chip', 'pinger_a', 'roulette', 'pinger_b', 'cash_in' """ self.tasks = task_list ################ DICTIONARIES ################ self.state_num = 0 self.states = [ self.pregate, self.gate, self.path_1, self.dice, self.path_2, self.slots, self.pinger_a, self.chip, self.roulette, self.pinger_b, self.cash_in ] self.gui_states = { 'pregate': self.pregate, 'gate': self.gate, 'path': self.path_1, 'dice': self.dice } self.one_or_all_tasks = { 'one': self.do_one_task, 'all': self.start_all_tasks } self.gui_task_calls = { 'pregate': 0, 'gate': 1, 'path_1': 2, 'dice': 3, 'path_2': 4, 'slots': 5, 'pinger_a': 6, 'chip': 7, 'roulette': 8, 'pinger_b': 9, 'cash_in': 10 } ################ AUV MOBILITY VARIABLES ################ #self.rotational_movement = {-1: } self.height = 1 self.queue_direction = [] self.rotation = 15 self.power = 120 self.r_power = 80 ################ TASK THREAD ################ self.task_thread = None self.all_task_loop = True ################ ROS VARIABLES ################ self.r = rospy.Rate(30) #30hz self.msg = CVIn() ################ CURRENT TASK VARIABLE ################ self.current_task = None
class Houston(): # implements(Task) def __init__(self, navigation, task_list): """ To initilize Houston """ ################ INSTANCES ################ self.gate = Gate(self) self.path_1 = Path(self) self.dice = Dice(self) self.path_2 = Path(self) self.chip_1 = Chip(self) self.chip_2 = Chip(self) self.roulette = Roulette(self) self.slots = Slots(self) self.pinger_a = PingerA(self) self.pinger_b = PingerB(self) self.cash_in = CashIn(self) #self.buoy = Buoy(self) self.navigation = navigation self.cvcontroller = CVController() self.config = Config() self.counts = Counter() ################ THRESHOLD VARIABLES ################ self.task_timer = 300 self.break_timer = 600 ################ FLAG VARIABLES ################ self.is_killswitch_on = False ################ TIMER/COUNTER VARIABLES ################ self.last_time = time.time() ################ TASKS LIST ################ self.tasks = task_list ################ DICTIONARIES ################ """ self.tasks values listed below 'gate', 'path', 'dice', 'chip', 'path', 'chip', 'slots', 'pinger_b', 'roulette', 'pinger_a', 'cash_in' """ self.state_num = 0 self.states = [ self.gate, self.path_1, self.dice, self.chip_1, self.path_2, self.slots, self.chip_2, self.pinger_a, self.roulette, self.pinger_b, self.cash_in ] ################ AUV MOBILITY VARIABLES ################ #self.rotational_movement = {-1: } self.height = 1 self.queue_direction = [] self.rotation = 15 self.power = 120 ################ TASK THREAD ################ self.task_thread = None ################ ROS VARIABLES ################ self.r = rospy.Rate(30) #30hz self.msg = CVIn() ################ CURRENT TASK VARIABLE ################ self.current_task = None # print_task ################################################################################## def print_tasks(self): counter = 0 for i in self.tasks: print '{}: {}'.format(counter, i) counter += 1 # do_task ################################################################################## def start_all_tasks(self): if self.state_num > 10: print 'no more tasks to complete' self.state = self.states[self.state_num] if not self.state.is_task_running: self.state.reset() print 'doing task: {}'.format(self.tasks[self.state_num]) self.navigation.cancel_h_nav() self.navigation.cancel_m_nav() self.navigation.cancel_r_nav() self.task_thread_start(self.state, self.tasks[self.state_num], self.navigation, self.cvcontroller, self.power, self.rotation) else: print '\nTask is currently running.' print '\nPlease wait for task to finish or cancel' if self.state.is_complete: self.state_num += 1 # do_one_task ################################################################################## def do_one_task(self, task_num): print '\nattempting to run task number: {}\ \ntask: {}'.format(task_num, self.tasks[task_num]) self.state = self.states[task_num] if not self.state.is_task_running: self.state.reset() self.navigation.cancel_h_nav() self.navigation.cancel_m_nav() self.navigation.cancel_r_nav() self.task_thread_start(self.state, self.tasks[task_num], self.navigation, self.cvcontroller, self.power, self.rotation) else: print '\nTask is currently running.' print '\nPlease wait for task to finish or cancel' # stop_task ################################################################################## def stop_task(self): # self.state = self.states[self.state_num] try: self.state.stop_task = True except: print 'no task currently running to stop' self.navigation.cancel_h_nav() self.navigation.cancel_m_nav() self.navigation.cancel_r_nav() # return_raw_frame ################################################################################## def return_raw_frame(self): if self.state.is_task_running: return self.cvcontroller.current_raw_frame() else: print 'camera is currently not running' # return_processed_frame ################################################################################## def return_processed_frame(self): if self.state.is_task_running: return self.cvcontroller.current_processed_frame() else: print 'camera is currently not running' # task_thread_start ################################################################################## def task_thread_start(self, task_call, task_name, navigation, cvcontroller, power, rotation): self.reset_thread() self.task_thread = Thread(target = task_call.start, args = (task_name, navigation, cvcontroller, power, rotation)) self.task_thread.start() # reset_thread ################################################################################## def reset_thread(self): if self.task_thread: self.task_thread = None # TODO currently unused. will remove eventually # get_task ################################################################################## def get_task(self): self.tasks = self.config.get_config('auv', 'tasks') # ['gate', 'path', 'dice', 'chip', 'path', 'chip', 'slots', 'pinger_b', # 'roulette', 'pinger_a', 'cash_in'] # start ################################################################################## def start(self): #self.get_task() # similar start to other classes, such as auv, and keyboard #self.is_killswitch_on = True self.navigation.start() # stop ################################################################################## def stop(self): # similar start to other classes, such as auv, and keyboard #self.is_killswitch_on = False self.navigation.stop()
class Houston(): # implements(Task) def __init__(self, navigation, task_list): """ To initilize Houston """ ################ INSTANCES ################ self.pregate = PreGate(self) self.gate = Gate(self) self.path_1 = Path(self) self.dice = Dice(self) self.path_2 = Path(self) self.chip = Chip(self) self.roulette = Roulette(self) self.slots = Slots(self) self.pinger_a = PingerA(self) self.pinger_b = PingerB(self) self.cash_in = CashIn(self) # self.buoy = Buoy(self) self.navigation = navigation self.cvcontroller = CVController() self.counts = Counter() self.orientation = Orientation() ########################################### ########## RUN ALL TASK QUEUE ############# self.states_run_all = [ self.pregate, self.gate, self.path_1, self.dice, self.path_2, self.slots ] ################ THRESHOLD VARIABLES ################ self.task_timer = 300 self.break_timer = 600 ################ FLAG VARIABLES ################ self.is_killswitch_on = False self.is_task_running = False ################ TIMER/COUNTER VARIABLES ################ self.last_time = time.time() ################ TASKS LIST ################ """ self.tasks values listed below 'pregate', 'gate', 'path', 'dice', 'path', 'slots', 'chip', 'pinger_a', 'roulette', 'pinger_b', 'cash_in' """ self.tasks = task_list ################ DICTIONARIES ################ self.state_num = 0 self.states = [ self.pregate, self.gate, self.path_1, self.dice, self.path_2, self.slots, self.pinger_a, self.chip, self.roulette, self.pinger_b, self.cash_in ] self.gui_states = { 'pregate': self.pregate, 'gate': self.gate, 'path': self.path_1, 'dice': self.dice } self.one_or_all_tasks = { 'one': self.do_one_task, 'all': self.start_all_tasks } self.gui_task_calls = { 'pregate': 0, 'gate': 1, 'path_1': 2, 'dice': 3, 'path_2': 4, 'slots': 5, 'pinger_a': 6, 'chip': 7, 'roulette': 8, 'pinger_b': 9, 'cash_in': 10 } ################ AUV MOBILITY VARIABLES ################ #self.rotational_movement = {-1: } self.height = 1 self.queue_direction = [] self.rotation = 15 self.power = 120 self.r_power = 80 ################ TASK THREAD ################ self.task_thread = None self.all_task_loop = True ################ ROS VARIABLES ################ self.r = rospy.Rate(30) #30hz self.msg = CVIn() ################ CURRENT TASK VARIABLE ################ self.current_task = None # reset ################################################################################## def reset(self): self.is_task_running = False self.all_task_loop = True self.orientation.reset() # print_task ################################################################################## def print_tasks(self): counter = 0 for i in self.tasks: print '{}: {}'.format(counter, i) counter += 1 # start_task ################################################################################## def start_task(self, one_or_all, task_choice): if not self.is_task_running: self.task_thread_start(one_or_all, task_choice) else: print '\nTask is currently running.' print '\nPlease wait for task to finish or cancel' # start_task_from_gui ################################################################################## def start_task_from_gui(self, one_or_all, task_name): if not self.is_task_running: self.task_thread_start(one_or_all, self.gui_task_calls[task_name]) else: print '\nTask is currently running.' print '\nPlease wait for task to finish or cancel' # start_all_tasks ################################################################################## def start_all_tasks(self, _): time.sleep(7) # self.navigation.h_nav('down', 6, 100) # time.sleep(5) self.is_task_running = True self.navigation.cancel_all_nav() self.all_task_loop = True self.state_num = 0 while self.all_task_loop: if self.state_num > len(self.states_run_all) - 1: self.all_task_loop = False print 'no more tasks to complete' # self.run_orientation() # Added to show mark we are able to set orientation before hand # print 'start_orientation {}'.format(self.orientation.start_orientation) # print 'start_angle {}'.format(self.orientation.start_angle) # self.navigation.r_nav(self.orientation.start_orientation, self.orientation.start_angle, self.r_power) # self.navigation.ros_sleep(3) # self.navigation.m_nav('power', 'forward', self.power) # self.navigation.ros_sleep(3) else: self.state = self.states_run_all[self.state_num] self.state.reset() print 'doing task: {}'.format(self.state.task_name) self.state.start(self.state.task_name, self.navigation, self.cvcontroller, self.power, self.rotation) if self.state.complete(): self.state_num += 1 self.is_task_running = False # run_orientation ################################################################################## def run_orientation(self): self.orientation.set_orientation(self.navigation, self.power, self.r_power) # do_one_task ################################################################################## def do_one_task(self, task_num): self.is_task_running = True self.navigation.cancel_h_nav() self.navigation.cancel_m_nav() self.navigation.cancel_r_nav() self.state = self.states[task_num] print '\nattempting to run task number: {}\ \ntask: {}'.format(task_num, self.state.task_name) self.state.reset() self.state.start(self.state.task_name, self.navigation, self.cvcontroller, self.power, self.rotation) self.is_task_running = False # stop_task ################################################################################## def stop_task(self): try: self.state.stop_task = True self.all_task_loop = False except: print 'no task currently running to stop' self.navigation.cancel_h_nav() self.navigation.cancel_m_nav() self.navigation.cancel_r_nav() # return_raw_frame ################################################################################## def return_raw_frame(self): if self.state.is_task_running: return self.cvcontroller.current_raw_frame() else: print 'camera is currently not running' # return_processed_frame ################################################################################## def return_processed_frame(self): if self.state.is_task_running: return self.cvcontroller.current_processed_frame() else: print 'camera is currently not running' # task_thread_start ################################################################################## # def task_thread_start(self, task_call, task_name, navigation, cvcontroller, power, rotation): # self.reset_thread() # self.task_thread = Thread(target = task_call.start, args = (task_name, navigation, cvcontroller, power, rotation)) # # self.task_thread = Thread(target = self.one_or_all_tasks.start, args = ()) # self.task_thread.start() def task_thread_start(self, one_or_all, task_choice): self.reset_thread() self.task_thread = Thread(target=self.one_or_all_tasks[one_or_all], args=(task_choice, )) self.task_thread.start() # reset_thread ################################################################################## def reset_thread(self): if self.task_thread: self.task_thread = None # TODO currently unused. will remove eventually # get_task ################################################################################## def get_task(self): self.tasks = config.get_config('auv', 'tasks') # ['gate', 'path', 'dice', 'chip', 'path', 'chip', 'slots', 'pinger_b', # 'roulette', 'pinger_a', 'cash_in'] # start ################################################################################## def start(self): #self.get_task() # similar start to other classes, such as auv, and keyboard #self.is_killswitch_on = True self.navigation.start() # stop ################################################################################## def stop(self): # similar start to other classes, such as auv, and keyboard #self.is_killswitch_on = False self.navigation.stop()