test_behavior_complex_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_INVALID import Behavior, Autonomy, OperatableStateMachine, ConcurrencyContainer, PriorityContainer, Logger
11 from flexbe_states.wait_state import WaitState
12 from flexbe_states.decision_state import DecisionState
13 from flexbe_states.log_state import LogState as flexbe_states__LogState
14 from flexbe_states.calculation_state import CalculationState
15 # Additional imports can be added inside the following tags
16 # [MANUAL_IMPORT]
17 raise ValueError("TODO: Remove!")
18 # [/MANUAL_IMPORT]
19 
20 
21 '''
22 Created on Mon Mar 30 2020
23 @author: Philipp Schillinger
24 '''
25 class TestBehaviorComplexSM(Behavior):
26  '''
27  A more complex behavior for testing the onboard engine.
28 Note: This behavior contains intentional errors that are fixed by sent modifications.
29  '''
30 
31 
32  def __init__(self):
33  super(TestBehaviorComplexSM, self).__init__()
34  self.name = 'Test Behavior Complex'
35 
36  # parameters of this behavior
37  self.add_parameter('param', 'value_1')
38 
39  # references to used behaviors
40 
41  # Additional initialization code can be added inside the following tags
42  # [MANUAL_INIT]
43 
44  # [/MANUAL_INIT]
45 
46  # Behavior comments:
47 
48 
49 
50  def create(self):
51  # x:67 y:463, x:336 y:160
52  _state_machine = OperatableStateMachine(outcomes=['finished', 'failed'], input_keys=['data'])
53  _state_machine.userdata.data = 0
54 
55  # Additional creation code can be added inside the following tags
56  # [MANUAL_CREATE]
57 
58  # [/MANUAL_CREATE]
59 
60 
61  with _state_machine:
62  # x:30 y:40
63  OperatableStateMachine.add('Wait',
64  WaitState(wait_time=0.5),
65  transitions={'done': 'Calculate'},
66  autonomy={'done': Autonomy.Off})
67 
68  # x:36 y:240
69  OperatableStateMachine.add('Log Param',
70  flexbe_states__LogState(text=self.param, severity=2),
71  transitions={'done': 'Verify Input'},
72  autonomy={'done': Autonomy.Off})
73 
74  # x:32 y:340
75  OperatableStateMachine.add('Verify Input',
76  DecisionState(outcomes=['accepted', 'rejected'], conditions=lambda x: 'accepted' if x > 3 else 'rejected'),
77  transitions={'accepted': 'finished', 'rejected': 'failed'},
78  autonomy={'accepted': Autonomy.Off, 'rejected': Autonomy.Off},
79  remapping={'input_value': 'data'})
80 
81  # x:28 y:136
82  OperatableStateMachine.add('Calculate',
83  CalculationState(calculation=self._calculate),
84  transitions={'done': 'Log Param'},
85  autonomy={'done': Autonomy.Off},
86  remapping={'input_value': 'data', 'output_value': 'data'})
87 
88 
89  return _state_machine
90 
91 
92  # Private functions can be added inside the following tags
93  # [MANUAL_FUNC]
94  def _calculate(self, data):
95  return data**2
96  # [/MANUAL_FUNC]


flexbe_onboard
Author(s): Philipp Schillinger
autogenerated on Sun Dec 13 2020 04:01:43