Esempio n. 1
0
    def create_statemachine(self, state_machine_model):
        NestedState.separator = ':'

        states = [{
            'name':
            'base',
            'children': ['not_ready', 'ready', 'active', 'fail', 'processing']
        }]

        transitions = [['start', 'base', 'base:not_ready'],
                       ['unavailable', 'base', 'base:not_ready'],
                       ['deactivate', 'base', 'base:not_ready'],
                       ['activate', 'base:not_ready', 'base:active'],
                       ['idle', 'base:not_ready', 'base:ready'],
                       ['ready', 'base:ready', 'base:active'],
                       ['activate', 'base:ready', 'base:active'],
                       ['idle', 'base:active', 'base:ready'],
                       ['not_ready', 'base:active', 'base:ready'],
                       ['failure', 'base:active', 'base:fail'],
                       ['active', 'base:active', 'base:processing'],
                       ['idle', 'base:processing', 'base:fail'],
                       ['ready', 'base:processing', 'base:fail'],
                       ['not_ready', 'base:processing', 'base:fail'],
                       ['active', 'base:processing', 'base:fail'],
                       ['activate', 'base:processing', 'base:fail'],
                       ['fail', 'base:processing', 'base:fail'],
                       ['idle', 'base:fail', 'base:ready'],
                       ['ready', 'base:fail', 'base:ready'],
                       ['not_ready', 'base:fail', 'base:ready'],
                       ['active', 'base:fail', 'base:ready'],
                       ['activate', 'base:fail', 'base:ready'],
                       ['failure', 'base:fail', 'base:ready'],
                       ['complete', 'base:fail', 'base:ready'], {
                           'trigger': 'complete',
                           'source': 'base:processing',
                           'dest': 'base:not_ready',
                           'after': 'COMPLETE'
                       }, ['default', 'base:processing', 'base:fail'],
                       ['default', 'base:fail', 'base:ready'],
                       ['default', 'base:not_ready', 'base:not_ready'],
                       ['default', 'base:ready', 'base:ready'],
                       ['default', 'base:active', 'base:active'],
                       ['reset', '*', 'base:not_ready']]

        statemachine = Machine(model=state_machine_model,
                               states=states,
                               transitions=transitions,
                               initial='base',
                               ignore_invalid_triggers=True)

        statemachine.on_enter('base:ready', 'READY')
        statemachine.on_enter('base:active', 'ACTIVE')
        statemachine.on_enter('base:not_ready', 'NOT_READY')
        statemachine.on_enter('base:fail', 'FAILURE')
        statemachine.on_exit('base:fail', 'complete_failed')
        statemachine.on_enter('base:processing', 'PROCESSING')

        return statemachine
Esempio n. 2
0
    def create_statemachine(self, state_machine_model):
        NestedState.separator = ':'

        states = [{
            'name':
            'base',
            'children': [
                'activated', {
                    'name':
                    'operational',
                    'children': [
                        'loading', 'cycle_start', 'unloading', 'idle',
                        'in_transition'
                    ]
                }, {
                    'name': 'disabled',
                    'children': ['fault', 'not_ready']
                }
            ]
        }]

        transitions = [
            ['start', 'base', 'base:disabled'],
            ['cnc_controller_mode_automatic', 'base', 'base:activated'],
            ['reset_cnc', 'base', 'base:activated'],
            ['enable', 'base', 'base:activated'],
            ['disable', 'base', 'base:activated'],
            ['cnc_controller_mode_manual', 'base', 'base:activated'],
            [
                'cnc_controller_mode_manual_data_input', 'base',
                'base:activated'
            ],
            [
                'cnc_controller_mode_automatic', 'base:disabled',
                'base:activated'
            ],
            ['robot_material_load_ready', 'base:disabled', 'base:activated'],
            ['robot_material_unload_ready', 'base:disabled', 'base:activated'],
            [
                'default', 'base:operational:cycle_start',
                'base:operational:cycle_start'
            ], {
                'trigger': 'complete',
                'source': 'base:operational:loading',
                'dest': 'base:operational:cycle_start',
                'before': 'LOADED'
            },
            [
                'complete', 'base:operational:in_transition',
                'base:operational:loading'
            ], {
                'trigger': 'complete',
                'source': 'base:operational:unloading',
                'dest': 'base:operational:in_transition',
                'before': 'UNLOADED'
            }, ['fault', 'base', 'base:disabled:fault'],
            ['robot_system_fault', 'base', 'base:disabled:fault'],
            ['default', 'base:disabled:fault', 'base:disabled:fault'],
            ['faulted', 'base:activated', 'base:disabled:fault'],
            [
                'cnc_fault', 'base:operational:cycle_start',
                'base:disabled:fault'
            ], ['start', 'base:disabled', 'base:disabled:not_ready'],
            ['default', 'base:disabled:not_ready', 'base:disabled:not_ready'],
            ['default', 'base:disabled', 'base:disabled:not_ready'],
            ['still_not_ready', 'base:activated', 'base:disabled:not_ready'],
            ['loading', 'base:operational', 'base:operational:loading'],
            [
                'default', 'base:operational:loading',
                'base:operational:loading'
            ], ['unloading', 'base:operational', 'base:operational:unloading'],
            [
                'default', 'base:operational:unloading',
                'base:operational:unloading'
            ],
            [
                'cnc_execution_ready', 'base:operational:cycle_start',
                'base:operational:unloading'
            ], ['failed', 'base:operational:loading', 'base:operational:idle'],
            ['failed', 'base:operational:unloading', 'base:operational:idle'],
            ['start', 'base:operational', 'base:operational:idle'], {
                'trigger': 'robot_material_unload_ready',
                'source': 'base:operational:idle',
                'dest': 'base:operational',
                'after': 'EXITING_IDLE'
            }, {
                'trigger': 'robot_material_load_ready',
                'source': 'base:operational:idle',
                'dest': 'base:operational',
                'after': 'EXITING_IDLE'
            }, ['default', 'base:operational:idle', 'base:operational:idle'],
            ['make_operational', 'base:activated', 'base:operational']
        ]

        statemachine = Machine(model=state_machine_model,
                               states=states,
                               transitions=transitions,
                               initial='base',
                               ignore_invalid_triggers=True)

        statemachine.on_enter('base:disabled', 'CNC_NOT_READY')
        statemachine.on_enter('base:disabled:not_ready', 'CNC_NOT_READY')
        statemachine.on_enter('base:disabled:fault', 'CNC_NOT_READY')
        statemachine.on_enter('base:activated', 'ACTIVATE')
        statemachine.on_enter('base:operational', 'OPERATIONAL')
        statemachine.on_enter('base:operational:idle', 'IDLE')
        statemachine.on_enter('base:operational:cycle_start', 'CYCLING')
        statemachine.on_enter('base:operational:loading', 'LOADING')
        statemachine.on_enter('base:operational:unloading', 'UNLOADING')
        statemachine.on_enter('base:operational:in_transition',
                              'IN_TRANSITION')
        statemachine.on_exit('base:operational:in_transition',
                             'EXIT_TRANSITION')

        return statemachine
Esempio n. 3
0
    def create_statemachine(state_machine_model):
        """Create and initialize the robot state machine"""

        NestedState.separator = ':'
        states = [
            {
                'name': 'base',
                'children': [
                    'activated',
                    {
                        'name': 'operational',
                        'children': [
                            'idle',
                            'loading',
                            'unloading',
                            'in_transition'
                        ]
                    },
                    {
                        'name': 'disabled',
                        'children': [
                            'not_ready',
                            {
                                'name': 'fault',
                                'children': ['software', 'hardware', 'e_stop']
                            },
                        ]
                    },
                ]
            }
        ]

        transitions = [
            ['start', 'base', 'base:disabled:not_ready'],
            ['activate', 'base:disabled:not_ready', 'base:activated'],
            ['make_operational', 'base:activated', 'base:operational'],
            ['make_idle', 'base:operational', 'base:operational:idle'],

            ['enable', 'base', 'base:activated'],

            ['fault', 'base', 'base:disabled:fault'],
            ['safety_violation', 'base', 'base:disabled:soft'],
            ['collision', 'base', 'base:disabled:fault:soft'],
            ['hard_fault', 'base', 'base:disable:fault:hard'],
            ['e_stop', 'base', 'base:disabled:fault:e_stop'],
            ['clear_fault', 'base:disabled:fault', 'base:disabled:not_ready'],

            {
                'trigger': 'material_unload_ready',
                'source': 'base:operational:idle',
                'dest': 'base:operational:unloading',
            },
            {
                'trigger': 'material_load_ready',
                'source': 'base:operational:idle',
                'dest': 'base:operational:loading',
            },
            {
                'trigger': 'complete',
                'source': 'base:operational:unloading',
                'dest': 'base:operational:loading',
                'before': 'UNLOADING_COMPLETE'
            },

            ['complete', 'base:operational:in_transition', 'base:operational:idle'],

            {
                'trigger':'complete',
                'source':'base:operational:loading',
                'dest':'base:operational:in_transition',
                'before':'LOADING_COMPLETE'
            },


        ]

        statemachine = Machine(
            model = state_machine_model,
            states = states,
            transitions = transitions,
            initial = 'base',
            ignore_invalid_triggers=True
        )

        statemachine.on_enter('base:activated', 'ACTIVATE')
        statemachine.on_enter('base:operational', 'OPERATIONAL')
        statemachine.on_enter('base:operational:idle','IDLE')
        statemachine.on_enter('base:operational:loading', 'LOADING')
        statemachine.on_enter('base:operational:unloading', 'UNLOADING')
        statemachine.on_enter('base:disabled:fault', 'FAULT')
        statemachine.on_enter('base:operational:in_transition', 'IN_TRANSITION')
        statemachine.on_exit('base:operational:in_transition', 'EXIT_TRANSITION')

        return statemachine