selftest_behavior_sm.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 ###########################################################
4 # WARNING: Generated code! #
5 # ************************** #
6 # Manual changes may get lost if file is generated again. #
7 # Only code inside the [MANUAL] tags will be kept. #
8 ###########################################################
9 
10 from flexbe_core import Behavior, Autonomy, OperatableStateMachine, ConcurrencyContainer, PriorityContainer, Logger
11 from flexbe_states.calculation_state import CalculationState
12 from flexbe_states.decision_state import DecisionState
13 # Additional imports can be added inside the following tags
14 # [MANUAL_IMPORT]
15 
16 # [/MANUAL_IMPORT]
17 
18 
19 '''
20 Created on Fri Apr 17 2020
21 @author: Philipp Schillinger
22 '''
23 class SelftestBehaviorSM(Behavior):
24  '''
25  Simple behavior for the flexbe_testing self-test of behaviors.
26  '''
27 
28 
29  def __init__(self):
30  super(SelftestBehaviorSM, self).__init__()
31  self.name = 'Selftest Behavior'
32 
33  # parameters of this behavior
34  self.add_parameter('value', 'wrong')
35 
36  # references to used behaviors
37 
38  # Additional initialization code can be added inside the following tags
39  # [MANUAL_INIT]
40 
41  # [/MANUAL_INIT]
42 
43  # Behavior comments:
44 
45 
46 
47  def create(self):
48  # x:30 y:365, x:130 y:365
49  _state_machine = OperatableStateMachine(outcomes=['finished', 'failed'], input_keys=['data'], output_keys=['result'])
50  _state_machine.userdata.data = None
51  _state_machine.userdata.result = None
52 
53  # Additional creation code can be added inside the following tags
54  # [MANUAL_CREATE]
55 
56  # [/MANUAL_CREATE]
57 
58 
59  with _state_machine:
60  # x:40 y:73
61  OperatableStateMachine.add('Modify Data',
62  CalculationState(calculation=lambda x: x * 2),
63  transitions={'done': 'Decide Param'},
64  autonomy={'done': Autonomy.Off},
65  remapping={'input_value': 'data', 'output_value': 'result'})
66 
67  # x:37 y:201
68  OperatableStateMachine.add('Decide Param',
69  DecisionState(outcomes=['finished', 'failed'], conditions=lambda x: 'finished' if self.value == 'correct' else 'failed'),
70  transitions={'finished': 'finished', 'failed': 'failed'},
71  autonomy={'finished': Autonomy.Off, 'failed': Autonomy.Off},
72  remapping={'input_value': 'data'})
73 
74 
75  return _state_machine
76 
77 
78  # Private functions can be added inside the following tags
79  # [MANUAL_FUNC]
80 
81  # [/MANUAL_FUNC]


flexbe_testing
Author(s): Philipp Schillinger
autogenerated on Sun Dec 13 2020 04:01:44