def main(switch, name, starting): if switch == "-f": findFile(name, starting) else: if switch == "-d": findDirectory(name, starting) else: sys.stop( "Input not recognized. Should have been either -f or -d: {}". format(switch))
def query_api(url): try: s = requests.get(url).json() pass except Exception: #raise e pass try: if s["reason"]: print "ERROR: " + s["reason"] sys.stop() except: return s
def main(): rospy.init_node('Saya shut_down Machine') # initiating node sm_one = smach.StateMachine(outcomes=['Stop']) with sm_one: smach.StateMachine.add('st', st.shutdown(), transitions={ 'waiting_for_command': 'st', 'shutdown_initiated': 'Stop' }) sys = smach_ros.IntrospectionServer('shut_down', sm_one, '/shut_down') sys.start() outcome = sm_one.execute() sys.stop()
def stop( self, status: int, extended_callbacks: Union[Callable, None] = None, callback_params: tuple = () ) -> None: """ Exit agent application. Execute optional supplied function parameter. :param status: exit status :type status: int :param extended_callbacks: function, called before exiting, specify a function here to be invoked, if parameter is None or not callable, callbacks is ignored, default None :type extended_callbacks: Union[Callable, None] :param callback_params: parameters for extended_callbacks, default empty tuple :type callback_params: tuple """ if extended_callbacks is not None: extended_callbacks(*callback_params) if self.network is not None: self.network.disconnect() stop(status)
def get_halfmax_x(xy, half): """Returns the interpolated x coord value corresponding to the halfmax_val in either the lower or upper half of the xy-pair Numpy array. Arguments: xy(numpy array): input array half (str): 'left' or 'lower' or 'right' or 'upper' Returns: Interpolated x coord corresponding to half_max val """ max_index = get_max_index(xy) if half in ["lower", "left"]: inc = -1 stop_ind = 0 elif half in ["upper", "right"]: inc = +1 stop_ind = len(xy) else: print "half argument must be either lower/left or upper/right" sys.stop() halfmax = 0.5 * get_max_val(xy) for i in range(max_index, stop_ind, inc): if xy[i][__Y] <= halfmax: j = i break else: #loop fell through without finding halfmax print "could not find " + half + "half max point" return float("nan") x1 = xy[j][__X] x2 = xy[j - inc][__X] y1 = xy[j][__Y] y2 = xy[j - inc][__Y] xcoor = (x1 - x2) / (y1 - y2) * (halfmax - y2) + x2 return xcoor
def SaidEx(chan, user, msg): print chan, user, msg if (user == "[1uP]MidKnight[0_0]") and (msg == "doom"): sys.stop()
def exit(self): sys.stop() self.disappear()
def main(): rospy.init_node('roba_state_machine') # initiating node mover = nt.GoalMaker( ) # Initialise object for calling navigation state nav1 mover1 = nt1.GoalMaker( ) # Initialise object for calling navigation state nav2 mover2 = nt2.GoalMaker( ) # Initialise object for calling navigation state nav3 # Create a SMACH state machine with outcomes sm_top = smach.StateMachine(outcomes=['Stop']) # creating the SMACH container with defined states with sm_top: # Add states to the container smach.StateMachine.add('Battery', bt.battery(), transitions={ 'safe': 'Face_Detection', 'unsafe': 'Stop' }) smach.StateMachine.add( 'Face_Detection', fds.Face_Detection( ), # adding FACE_Detection state from face_detection_state.py transitions={ 'face_detected': 'Detected', 'No_face_detected': 'Not_Detected' }) # mapping the outcomes of this state to other states smach.StateMachine.add( 'Detected', fds.Detected(), transitions={'Complete': 'CON'} ) # Mapping the Detected state outcome to First Arm Manipulation state smach.StateMachine.add( 'Not_Detected', fds.Not_Detected(), transitions={'Redoing': 'Battery'} ) # Mapping Redoing outcome from Not_Detected state to the Mojo Music State sm_con = smach.Concurrence( outcomes=[ 'Waiting', 'Done' ], ##### Default outcome Waiting to be checked( Whether it can be removed and the concurrent state made a default_outcome='Waiting', ##### single outcome state ##### outcome_map={ 'Done': { 'Arm_Manipulation1': 'Executed', 'Speech1': 'completed', 'ui1': 'complete' } }) with sm_con: smach.Concurrence.add('Arm_Manipulation1', ms1.Arm_Manipulation1()) smach.Concurrence.add('Speech1', ss1.Speech1()) smach.Concurrence.add('ui1', ui1.screen1()) smach.StateMachine.add('CON', sm_con, transitions={ 'Waiting': 'Stop', 'Done': 'CON1' }) sm_con1 = smach.Concurrence(outcomes=['Waiting', 'Done'], default_outcome='Waiting', outcome_map={ 'Done': { 'Arm_Manipulation2': 'Executed', 'Speech2': 'completed' } }) with sm_con1: smach.Concurrence.add('Arm_Manipulation2', ms2.Arm_Manipulation2()) smach.Concurrence.add('Speech2', ss2.Speech2()) smach.StateMachine.add('CON1', sm_con1, transitions={ 'Waiting': 'Stop', 'Done': 'map1' }) smach.StateMachine.add( 'map1', mp1.Map1( ), # Accepts button press from ui_nav and plays audio accordingly transitions={ 'complete': 'CON8', 'incomplete': 'Battery' }) sm_con4 = smach.Concurrence(outcomes=['Waiting', 'Done'], default_outcome='Waiting', outcome_map={ 'Done': { 'Speech4': 'completed', 'Arm_Manipulation5': 'Executed' } }) sm_con8 = smach.Concurrence(outcomes=['Waiting', 'Done'], default_outcome='Waiting', outcome_map={ 'Done': { 'Speech3': 'completed', 'Arm_Manipulation3': 'Executed' } }) with sm_con8: smach.Concurrence.add('Speech3', ss3.Speech3()) smach.Concurrence.add( 'Arm_Manipulation3', ms3.Arm_Manipulation3()) # Arm manipulation for rate me smach.StateMachine.add('CON8', sm_con8, transitions={ 'Waiting': 'Stop', 'Done': 'Arm_Manipulation4' }) smach.StateMachine.add( 'Arm_Manipulation4', ms4.Arm_Manipulation4(), # Arm manipulation for the Directions transitions={'Executed': 'map2'}) smach.StateMachine.add( 'map2', mp2.Map2(), transitions={ 'complete_repeat': 'map1', # Possible issue with Repeat button publishing to ui_nav and ui_options simultaneously 'complete_guide': 'CON6', 'complete_thank': 'CON4', 'incomplete': 'Battery' }) sm_con4 = smach.Concurrence(outcomes=['Waiting', 'Done'], default_outcome='Waiting', outcome_map={ 'Done': { 'Speech4': 'completed', 'Arm_Manipulation5': 'Executed' } }) with sm_con4: smach.Concurrence.add('Speech4', ss4.Speech4()) smach.Concurrence.add( 'Arm_Manipulation5', ms5.Arm_Manipulation5()) # Arm manipulation for rate me smach.StateMachine.add('CON4', sm_con4, transitions={ 'Waiting': 'Stop', 'Done': 'Speech7' }) smach.StateMachine.add('Speech7', ss7.Speech7(), transitions={'completed': 'Battery'}) sm_con6 = smach.Concurrence(outcomes=['Waiting', 'Done'], default_outcome='Waiting', outcome_map={ 'Done': { 'Speech5': 'completed', 'Speech8': 'completed', 'Arm_Manipulation7': 'Executed' } }) with sm_con6: smach.Concurrence.add('Speech5', ss5.Speech5()) smach.Concurrence.add('Speech8', ss8.Speech8()) smach.Concurrence.add('Arm_Manipulation7', ms7.Arm_Manipulation7()) smach.StateMachine.add('CON6', sm_con6, transitions={ 'Waiting': 'Stop', 'Done': 'nav' }) smach.StateMachine.add('nav', nt.nav(mover), transitions={ 'goal_reached': 'CON2', 'goal_not_reached': 'CON3' }) sm_con2 = smach.Concurrence( outcomes=['Waiting', 'Done'], default_outcome='Waiting', outcome_map={'Done': { 'ui2': 'complete', 'Speech6': 'completed' }}) with sm_con2: smach.Concurrence.add('ui2', ui2.screen2()) smach.Concurrence.add('Speech6', ss6.Speech6()) smach.StateMachine.add('CON2', sm_con2, transitions={ 'Waiting': 'Stop', 'Done': 'Arm_Manipulation6' }) smach.StateMachine.add( 'Arm_Manipulation6', ms6.Arm_Manipulation6(), # Arm manipulation for rate me 26AUG transitions={ 'Executed': 'Speech9', 'Not_Executed': 'Speech9' }) smach.StateMachine.add('Speech9', ss9.Speech9(), transitions={'completed': 'nav3'}) sm_con3 = smach.Concurrence( outcomes=['Waiting', 'Done'], default_outcome='Waiting', outcome_map={'Done': { 'ui3': 'complete', 'nav2': 'goal_reached' }}) with sm_con3: smach.Concurrence.add('ui3', ui3.screen3()) smach.Concurrence.add('nav2', nt1.nav2(mover1)) smach.StateMachine.add('CON3', sm_con3, transitions={ 'Waiting': 'Stop', 'Done': 'ui4' }) smach.StateMachine.add('nav3', nt2.nav3(mover2), transitions={'goal_reached': 'Battery'}) smach.StateMachine.add('ui4', ui4.screen4(), transitions={'complete': 'Battery'}) sys = smach_ros.IntrospectionServer('sayabot_hospitality', sm_top, '/Sayabot_Hospitality') sys.start() outcome = sm_top.execute() sys.stop()
findingAFile = False file_to_find = "" directory_to_find = "" startingDirectory = "" startingDirectory = "/Users/BigBlue/Documents/Programming/Python" startingDirectory = "/Users/BigBlue/Documents" arg1 = "" arg2 = "" arg3 = "" try: arg1 = sys.argv[1] arg2 = sys.argv[2] except: print("Error! Couldn't make sense of the input.") sys.stop("Exiting ...") if arg1 == "-f" or arg1 == "-d": if arg1 == "-f": findingAFile = True file_to_find = arg2 else: findingAFile = False directory_to_find = arg2 else: # We're going to assume a filename was passed through. findingAFile = True file_to_find = arg1 startingDirectory = arg2 try:
def Said(chan, user, msg): print chan, user, msg if (user == "smoth") or (user == "[1uP]MidKnight[0_0]") and (msg == "!end"): sys.stop()
max_rows=r1 - r0 + 1) GL = np.genfromtxt(input_prefix + '.glhood', dtype=float, skip_header=r0, max_rows=r1 - r0 + 1) if target_popname not in POP: sys.exit( "ERROR! The specified target population is not present in the ind file!" ) G = G[:, POP == target_popname] GL = GL[:, POP == target_popname] if G.shape[1] != 1: sys.stop('You did not provide a single sample specification.') nSNP_raw = G.shape[0] if maxD_cM is None: maxD_cM = D[len(D)] nSNP = G.shape[0] print('Raw nSNP: ' + str(nSNP_raw)) print( 'This script assumes that there are no missing data in your geno file...' ) bins_left_bound = np.arange(minD_cM, maxD_cM, step=stepD_cM) n_bins = len(bins_left_bound)
References: Prokka: https://github.com/tseemann/prokka GFF3 to ENA ready EMBL: https://github.com/sanger-pathogens/gff3toembl ENA Validator: https://www.ebi.ac.uk/ena/software/flat-file-validator and https://github.com/enasequence/sequencetools This script: https://github.com/peterjc/picobio/tree/master/seq_manipulation """ import sys if len(sys.argv) != 3: sys.stop("Expects two arguments: Input EMLB filename, output EMBL filename\n") input_embl = sys.argv[1] output_embl = sys.argv[2] MIN_GAP = 10 # TODO: Could be a command line option? try: from Bio import SeqIO from Bio.SeqFeature import SeqFeature, FeatureLocation from Bio._py3k import StringIO except ImportEror: sys.stop("This script requires Biopython 1.69 or later") def insert_feature(record, feature): pos = int(feature.location.start)
def main(): # ROS stuff rospy.init_node('segment_fsm_node', anonymous=True) parser = parse_args(sys.argv[1:]) right_leg_sub_topic = parser.from_right_leg left_leg_sub_topic = parser.from_left_leg right_leg_pub_topic = parser.to_right_leg left_leg_pub_topic = parser.to_left_leg trig_sub_topic = parser.from_master trig_pub_topic = parser.to_master ros_rate = parser.ros_rate # segment state instances - arguments can always be bumped up (or down) the hierarchy # Initialization seg_init = TalkWithMaster(trig_pub_topic, "Ready", trig_sub_topic, "StartLeft", "StartRight", ros_rate, 'seg_init') # Right start seg_right_start = Step(right_leg_pub_topic, left_leg_pub_topic, "StartPush", "StartLift", ros_rate, 'seg_right_start') seg_right_start_sync = Sync(right_leg_sub_topic, left_leg_sub_topic, "Done", "Done", ros_rate, 'seg_right_start_sync') # Left start seg_left_start = Step(right_leg_pub_topic, left_leg_pub_topic, "StartLift", "StartPush", ros_rate, 'seg_left_start') seg_left_start_sync = Sync(right_leg_sub_topic, left_leg_sub_topic, "Done", "Done", ros_rate, 'seg_left_start_sync') # Left cycle seg_left_step = Step(right_leg_pub_topic, left_leg_pub_topic, "Recover", "Plant", ros_rate, 'seg_left_step') seg_left_step_sync = Sync(right_leg_sub_topic, left_leg_sub_topic, "Done", "Done", ros_rate, 'seg_left_step_sync') seg_left_push = Step(right_leg_pub_topic, left_leg_pub_topic, None, "Push", ros_rate, 'seg_left_push') seg_left_push_sync = Sync(right_leg_sub_topic, left_leg_sub_topic, None, "Done", ros_rate, 'seg_left_push_sync') # Right cycle seg_right_step = Step(right_leg_pub_topic, left_leg_pub_topic, "Plant", "Recover", ros_rate, 'seg_right_step') seg_right_step_sync = Sync(right_leg_sub_topic, left_leg_sub_topic, "Done", "Done", ros_rate, 'seg_right_step_sync') seg_right_push = Step(right_leg_pub_topic, left_leg_pub_topic, "Push", None, ros_rate, 'seg_right_push') seg_right_push_sync = Sync(right_leg_sub_topic, left_leg_sub_topic, "Done", None, ros_rate, 'seg_right_push_sync') # Sync with higher-level state machine seg_left_sync_with_master = TalkWithMaster(trig_pub_topic, "Ready", trig_sub_topic, "StepRight", "StepRight", ros_rate, 'seg_left_sync_with_master') seg_right_sync_with_master = TalkWithMaster(trig_pub_topic, "Ready", trig_sub_topic, "StepLeft", "StepLeft", ros_rate, 'seg_right_sync_with_master') # Create a SMACH state machine segment_fsm_node = StateMachine(outcomes=['success']) # Open the SMACH state machine with segment_fsm_node: # Add states to the container # TODO: Maybe add conditional statements controlled by cmd line arg 'topfsm' - which can be True or False # Pub up: "Ready" --> wait --> Sub up: "StartLeft" or "StartRight" --> transition: SEG_LEFT_START or SEG_RIGHT_START StateMachine.add('SEG_INIT', seg_init, transitions={ 'success1': 'SEG_LEFT_START', 'success2': 'SEG_RIGHT_START' }) # Pub down: "StartPush" and "StartLift" --> transition: SEG_RIGHT_START_SYNC StateMachine.add('SEG_RIGHT_START', seg_right_start, transitions={'success': 'SEG_RIGHT_START_SYNC'}) # wait --> Sub down: "Done" and "Done" --> SEG_LEFT_STEP StateMachine.add('SEG_RIGHT_START_SYNC', seg_right_start_sync, transitions={'success': 'SEG_LEFT_STEP'}) StateMachine.add('SEG_LEFT_START', seg_left_start, transitions={'success': 'SEG_LEFT_START_SYNC'}) StateMachine.add('SEG_LEFT_START_SYNC', seg_left_start_sync, transitions={'success': 'SEG_RIGHT_STEP'}) StateMachine.add('SEG_LEFT_STEP', seg_left_step, transitions={'success': 'SEG_LEFT_STEP_SYNC'}) StateMachine.add('SEG_LEFT_STEP_SYNC', seg_left_step_sync, transitions={'success': 'SEG_LEFT_PUSH'}) StateMachine.add('SEG_LEFT_PUSH', seg_left_push, transitions={'success': 'SEG_LEFT_PUSH_SYNC'}) StateMachine.add('SEG_LEFT_PUSH_SYNC', seg_left_push_sync, transitions={'success': 'SEG_LEFT_SYNC_WITH_MASTER'}) StateMachine.add('SEG_RIGHT_STEP', seg_right_step, transitions={'success': 'SEG_RIGHT_STEP_SYNC'}) StateMachine.add('SEG_RIGHT_STEP_SYNC', seg_right_step_sync, transitions={'success': 'SEG_RIGHT_PUSH'}) StateMachine.add('SEG_RIGHT_PUSH', seg_right_push, transitions={'success': 'SEG_RIGHT_PUSH_SYNC'}) StateMachine.add('SEG_RIGHT_PUSH_SYNC', seg_right_push_sync, transitions={'success': 'SEG_RIGHT_SYNC_WITH_MASTER'}) StateMachine.add('SEG_LEFT_SYNC_WITH_MASTER', seg_left_sync_with_master, transitions={ 'success1': 'SEG_RIGHT_STEP', 'success2': 'SEG_RIGHT_STEP' }) StateMachine.add('SEG_RIGHT_SYNC_WITH_MASTER', seg_right_sync_with_master, transitions={ 'success1': 'SEG_LEFT_STEP', 'success2': 'SEG_LEFT_STEP' }) # Create and start the introspection server - for visualization / debugging # $ sudo apt-get install ros-kinetic-smach-viewer # $ rosrun smach_viewer smach_viewer.py sis = smach_ros.IntrospectionServer( 'segment_fsm_node' + str(rospy.get_name()), segment_fsm_node, '/SM_ROOT' + str(rospy.get_name())) sis.start() # Give Gazebo some time to start up #user_input = raw_input("Please press the 'Return/Enter' key to start executing - type: segment_fsm_node.py | node: " + str(rospy.get_name()) + "\n") # Execute SMACH state machine print("Input received. Executing - type: segment_fsm_node.py | node: " + str(rospy.get_name()) + "...\n") outcome = segment_fsm_node.execute() # spin() simply keeps python from exiting until this node is stopped rospy.spin() sys.stop() print("\nExiting " + str(rospy.get_name()))