Skip to content

Commit

Permalink
Merge pull request team-vigir#11 from team-vigir/develop
Browse files Browse the repository at this point in the history
sync upstream repo
  • Loading branch information
fmessmer committed Jan 18, 2021
2 parents f6e96b4 + d8004f5 commit 3dafccc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 57 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/flexbe_ci.yml
@@ -1,11 +1,7 @@
# This is a basic workflow to help you get started with Actions
name: FlexBE CI
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
on: [push, pull_request, workflow_dispatch]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand Down
1 change: 1 addition & 0 deletions flexbe_onboard/package.xml
Expand Up @@ -22,6 +22,7 @@

<exec_depend>flexbe_core</exec_depend>
<exec_depend>flexbe_msgs</exec_depend>
<exec_depend>flexbe_states</exec_depend>
<exec_depend>rospy</exec_depend>

</package>
97 changes: 45 additions & 52 deletions flexbe_testing/src/flexbe_testing/test/selftest_behavior_sm.py
@@ -1,81 +1,74 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###########################################################
# WARNING: Generated code! #
# ************************** #
# Manual changes may get lost if file is generated again. #
# Only code inside the [MANUAL] tags will be kept. #
###########################################################

from flexbe_core import Behavior, Autonomy, OperatableStateMachine, ConcurrencyContainer, PriorityContainer, Logger
from flexbe_states.calculation_state import CalculationState
from flexbe_states.decision_state import DecisionState
# Additional imports can be added inside the following tags
# [MANUAL_IMPORT]
#
# Content is only intended for the flexbe_testing self-test
#

# [/MANUAL_IMPORT]
from flexbe_core import Behavior, Autonomy, OperatableStateMachine, EventState, Logger


'''
Created on Fri Apr 17 2020
@author: Philipp Schillinger
'''
class SelftestBehaviorSM(Behavior):
'''
Simple behavior for the flexbe_testing self-test of behaviors.
'''

''' Simple behavior for the flexbe_testing self-test of behaviors. '''

def __init__(self):
super(SelftestBehaviorSM, self).__init__()
self.name = 'Selftest Behavior'

# parameters of this behavior
self.add_parameter('value', 'wrong')

# references to used behaviors

# Additional initialization code can be added inside the following tags
# [MANUAL_INIT]

# [/MANUAL_INIT]

# Behavior comments:



def create(self):
# x:30 y:365, x:130 y:365
_state_machine = OperatableStateMachine(outcomes=['finished', 'failed'], input_keys=['data'], output_keys=['result'])
_state_machine.userdata.data = None
_state_machine.userdata.result = None

# Additional creation code can be added inside the following tags
# [MANUAL_CREATE]

# [/MANUAL_CREATE]


with _state_machine:
# x:40 y:73
OperatableStateMachine.add('Modify Data',
CalculationState(calculation=lambda x: x * 2),
SelftestBehaviorSM._CalculationState(calculation=lambda x: x * 2),
transitions={'done': 'Decide Param'},
autonomy={'done': Autonomy.Off},
remapping={'input_value': 'data', 'output_value': 'result'})

# x:37 y:201
OperatableStateMachine.add('Decide Param',
DecisionState(outcomes=['finished', 'failed'], conditions=lambda x: 'finished' if self.value == 'correct' else 'failed'),
SelftestBehaviorSM._DecisionState(outcomes=['finished', 'failed'], conditions=lambda x: 'finished' if self.value == 'correct' else 'failed'),
transitions={'finished': 'finished', 'failed': 'failed'},
autonomy={'finished': Autonomy.Off, 'failed': Autonomy.Off},
remapping={'input_value': 'data'})


return _state_machine


# Private functions can be added inside the following tags
# [MANUAL_FUNC]

# [/MANUAL_FUNC]
class _CalculationState(EventState):
''' Copy of the flexbe_states.CalculationState for use in the test behavior. '''

def __init__(self, calculation):
super(SelftestBehaviorSM._CalculationState, self).__init__(outcomes=['done'], input_keys=['input_value'], output_keys=['output_value'])
self._calculation = calculation
self._calculation_result = None

def execute(self, userdata):
userdata.output_value = self._calculation_result
return 'done'

def on_enter(self, userdata):
if self._calculation is not None:
try:
self._calculation_result = self._calculation(userdata.input_value)
except Exception as e:
Logger.logwarn('Failed to execute calculation function!\n%s' % str(e))
else:
Logger.logwarn('Passed no calculation!')

class _DecisionState(EventState):
''' Copy of the flexbe_states.DecisionState for use in the test behavior. '''

def __init__(self, outcomes, conditions):
super(SelftestBehaviorSM._DecisionState, self).__init__(outcomes=outcomes, input_keys=['input_value'])
self._conditions = conditions

def execute(self, userdata):
if self._conditions is not None:
outcome = None
try:
outcome = str(self._conditions(userdata.input_value))
except Exception as e:
Logger.logwarn('Passed no function as predicate!\n%s' % str(e))
outcome = None
if outcome is not None and outcome in self._outcomes:
return outcome

0 comments on commit 3dafccc

Please sign in to comment.