Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import rospy
00019 from airbus_ssm_core import ssm_state
00020
00021 class Input(ssm_state.ssmState):
00022 '''@SSM
00023 Description : Get a keyboard input and return an outcome accordingly.
00024 User-data :
00025 - input : the keyboard input if it's an interger.
00026 Outcome :
00027 - Test : if the input is an integer
00028 - Out : if the input is 'q'
00029 - Retry : if the input is not an integer or 'q'
00030 '''
00031
00032 def __init__(self):
00033 ssm_state.ssmState.__init__(self,outcomes=["Test","Out","Retry"],
00034 io_keys=["input"])
00035
00036
00037 def execution(self, ud):
00038 print("Prime Tester ('q' to print all prime number found) :")
00039 input = raw_input()
00040 if(input == 'q'):
00041 return 'Out'
00042 else:
00043 try:
00044 ud.input = int(input)
00045 return "Test"
00046 except:
00047 print("[Error] Couldn't convert "+str(input) +" into an int !")
00048 return "Retry"
00049
00050 class isPrime(ssm_state.ssmState):
00051 '''@SSM
00052 Description : Test if the input number is prime and add it a the prime_list if it is
00053 User-data :
00054 - input : the tested number
00055 - prime_list : the list of all the prime number_found
00056 Outcome :
00057 - Return : atfer the test even if the input number is not prime
00058 '''
00059 def __init__(self):
00060 ssm_state.ssmState.__init__(self,outcomes=["Return"],
00061 io_keys=["input","prime_list"])
00062 def is_prime(self, a):
00063 return all(a % i for i in xrange(2, a))
00064
00065 def execution(self, ud):
00066
00067 if ud.prime_list is None:
00068 ud.prime_list = []
00069
00070 if(self.is_prime(ud.input)):
00071 print(str(ud.input) + " is a prime number.")
00072 ud.prime_list.append(ud.input)
00073 else:
00074 print(str(ud.input) + " is not a prime number.")
00075
00076 return "Return"
00077
00078
00079 class Primes(ssm_state.ssmState):
00080 '''@SSM
00081 Description : Print the list of all the prime numbers found and give a list of possible actions
00082 User-data :
00083 - prime_list : the list of all the prime number found
00084 Outcome :
00085 - Continue : if the input is 'c'
00086 - Reset : if the input is 'r'
00087 - Off : if the input is 'q'
00088 '''
00089 def __init__(self):
00090 ssm_state.ssmState.__init__(self,outcomes=["Reset","Off", "Continue"],
00091 io_keys=["prime_list"])
00092
00093
00094 def execution(self, ud):
00095 ## Test if it's prime_list is not initialised
00096 if ud.prime_list is None:
00097 ud.prime_list = []
00098 print("Prime list is empty.")
00099 else:
00100 print("Prime list :")
00101 for i_prime in ud.prime_list:
00102 print(str(i_prime))
00103 while(1):
00104 print("'c' to continue")
00105 print("'r' to reset")
00106 print("'q' to quit\n")
00107 input = raw_input("input : ")
00108 if(input == 'c'):
00109 return "Continue"
00110 elif(input == 'r'):
00111 ud.prime_list = []
00112 return 'Reset'
00113 elif(input == 'q'):
00114 return 'Off'
00115 else:
00116 print("Input not recognize")
00117
00118