skills.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2015 Airbus
00004 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00005 #
00006 # Licensed under the Apache License, Version 2.0 (the "License");
00007 # you may not use this file except in compliance with the License.
00008 # You may obtain a copy of the License at
00009 #
00010 #   http://www.apache.org/licenses/LICENSE-2.0
00011 #
00012 # Unless required by applicable law or agreed to in writing, software
00013 # distributed under the License is distributed on an "AS IS" BASIS,
00014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 # See the License for the specific language governing permissions and
00016 # limitations under the License.
00017 
00018 
00019 import rospy
00020 import random
00021 from airbus_ssm_core import ssm_state
00022 
00023 class Test1(ssm_state.ssmState):
00024     '''@SSM
00025         Description :  Test skill that add +1 to a user data test and return sucess.
00026         User-data :
00027         - test : an int (if not created in the datamodel will be init to 0)
00028         Outcome :
00029         - success : sucessfully add +1 or created the data test
00030         '''
00031     def __init__(self):
00032         ssm_state.ssmState.__init__(self,outcomes=["success"], io_keys=["test"])
00033         
00034     def execution(self, ud):
00035         rospy.sleep(2)
00036         if("test" in ud):
00037             ud.test = int(ud.test) + 1
00038         else:
00039             ud.test = 0
00040         print("Test : " + str(ud.test))
00041         return "success"
00042     
00043 class Test2(ssm_state.ssmState):
00044     '''@SSM
00045         Description :  A test state with a random outcomes using an inside counter
00046         User-data : None
00047         Outcome :
00048         - success : test if the counter inside the state is above 10
00049         - retry   : test if the counter inside the state is above 5 and below 10
00050         - next    : test if the counter inside the state is above 0 and below 5
00051         '''
00052     def __init__(self):
00053         ssm_state.ssmState.__init__(self,outcomes=["success","retry","next"])
00054         self.cpt_ = 0
00055         
00056     def execution(self, ud):
00057         rospy.sleep(1)
00058         choice = random.randint(1,3)
00059         self.cpt_ = self.cpt_ + choice
00060         if(self.cpt_ > 10):
00061             print("Test2 : success")
00062             return "success"
00063         elif(self.cpt_ > 5):
00064             print("Test2 : Retry")
00065             return "retry"
00066         elif(self.cpt_> 0):
00067             print("Test2 : Next")
00068             return "next"
00069         else:
00070             print("Test2 : success")
00071             return "success"
00072         
00073 class Test3(ssm_state.ssmState):
00074     '''@SSM
00075         Description :  A test state with a random outcomes with a 50/50.
00076         User-data : None
00077         Outcome :
00078         - success  : if the random int is equal to 1
00079         - failed   : otherwise
00080         '''
00081     def __init__(self):
00082         ssm_state.ssmState.__init__(self,outcomes=["success","failed"])
00083         
00084     def execution(self, ud):
00085         rospy.sleep(1)
00086         choice = random.randint(1,2)
00087         if(choice == 1):
00088             print("Test3 : success")
00089             return "success"
00090         else:
00091             print("Test3 : failed")
00092             return "failed"           
00093             
00094 
00095     
00096     
00097         
00098     
00099 
00100         


airbus_ssm_tutorial
Author(s): eads
autogenerated on Thu Jun 6 2019 17:59:32