<s> """<STR_LIT>""" <EOL> import sys <EOL> import time <EOL> import lib . lib as lib <EOL> import client . ctrl_client as ctrl_client_mod <EOL> import client . sub_client as sub_client_mod <EOL> class Pilot : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> ctrl_addr = "<STR_LIT>" , <EOL> sub_addr = "<STR_LIT>" ) : <EOL> self . config = lib . get_config ( ) <EOL> self . logger = lib . get_logger ( ) <EOL> try : <EOL> self . ctrl_client = ctrl_client_mod . CtrlClient ( ctrl_addr ) <EOL> except Exception , e : <EOL> self . logger . error ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( ctrl_addr , e ) ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> try : <EOL> self . sub_client = sub_client_mod . SubClient ( sub_addr ) <EOL> except Exception , e : <EOL> self . logger . error ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( sub_addr , e ) ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> self . ITEM_BACKUP_TIME = <NUM_LIT> <EOL> self . acts = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def call ( self , obj_name , method_name , param_dict = dict ( ) ) : <EOL> """<STR_LIT>""" <EOL> result = self . ctrl_client . call ( obj_name , method_name , param_dict ) <EOL> if result [ '<STR_LIT:type>' ] == '<STR_LIT:error>' : <EOL> self . logger . error ( "<STR_LIT>" . format ( result [ '<STR_LIT>' ] ) ) <EOL> return None <EOL> else : <EOL> return result [ '<STR_LIT>' ] <EOL> def bail ( self , msg ) : <EOL> """<STR_LIT>""" <EOL> self . logger . error ( "<STR_LIT>" . format ( msg ) ) <EOL> self . call ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def move ( self , speed , angle ) : <EOL> self . call ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : speed , '<STR_LIT>' : angle } ) <EOL> def drive ( self , speed , angle , duration ) : <EOL> return self . call ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : speed , '<STR_LIT>' : angle , <EOL> '<STR_LIT>' : duration } ) <EOL> def wait_for_start ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . call ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , "<STR_LIT>" : <NUM_LIT> } ) <EOL> def follow ( self ) : <EOL> """<STR_LIT>""" <EOL> dir_of_intersection = self . call ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return dir_of_intersection <EOL> def rotate_90 ( self , direction ) : <EOL> """<STR_LIT>""" <EOL> return self . call ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : direction } ) <EOL> def solve_activity ( self , activity ) : <EOL> """<STR_LIT>""" <EOL> return self . call ( activity , '<STR_LIT>' ) <EOL> def follow_ignoring_turns ( self ) : <EOL> return self . call ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def find_dir_of_turn ( self ) : <EOL> return self . call ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def find_dir_of_int ( self ) : <EOL> return self . call ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def rotate_to_line ( self , direction ) : <EOL> return self . call ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : direction } ) <EOL> def wait_for_ready ( self ) : <EOL> return self . call ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> time . sleep ( <NUM_LIT:10> ) <EOL> self . wait_for_ready ( ) <EOL> self . drive ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> ) <EOL> for activity in self . acts : <EOL> self . follow_ignoring_turns ( ) <EOL> act_dir = self . find_dir_of_int ( ) <EOL> self . rotate_to_line ( act_dir ) <EOL> self . follow_ignoring_turns ( ) <EOL> if activity == '<STR_LIT>' : <EOL> self . drive ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> self . drive ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> elif activity == '<STR_LIT>' : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> else : <EOL> self . solve_activity ( activity ) <EOL> self . move ( <NUM_LIT> , <NUM_LIT> ) <EOL> time . sleep ( self . ITEM_BACKUP_TIME ) <EOL> self . move ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . rotate_90 ( '<STR_LIT:right>' ) <EOL> time . sleep ( <NUM_LIT:0.5> ) <EOL> self . rotate_to_line ( '<STR_LIT:right>' ) <EOL> self . follow_ignoring_turns ( ) <EOL> if act_dir == '<STR_LIT:left>' : <EOL> self . rotate_to_line ( '<STR_LIT:right>' ) <EOL> elif act_dir == '<STR_LIT:right>' : <EOL> self . rotate_to_line ( '<STR_LIT:left>' ) <EOL> else : <EOL> self . rotate_to_line ( '<STR_LIT:right>' ) <EOL> self . follow_ignoring_turns ( ) <EOL> self . drive ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0.5> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> Pilot ( ) . run ( ) </s>
