Exemple #1
0
def main():
    rospy.init_node('smach_example_state_machine')

    # Create the top level SMACH state machine
    sm_top = smach.StateMachine(outcomes=['outcome5'])
    
    # Open the container
    with sm_top:

        smach.StateMachine.add('BAS', Bas(),
                               transitions={'outcome3':'SUB'})

        # Create the sub SMACH state machine
        sm_sub = smach.StateMachine(outcomes=['outcome4'])

        # Open the container
        with sm_sub:

            # Add states to the container
            smach.StateMachine.add('FOO', Foo(), 
                                   transitions={'outcome1':'BAR', 
                                                'outcome2':'outcome4'})
            smach.StateMachine.add('BAR', Bar(), 
                                   transitions={'outcome1':'FOO'})

        smach.StateMachine.add('SUB', sm_sub,
                               transitions={'outcome4':'outcome5'})

    # Execute SMACH plan
    outcome = sm_top.execute()
def main():
    rospy.init_node('smach_example_state_machine')

    # Create the top level SMACH state machine
    sm_top = smach.StateMachine(outcomes=['outcome6'])
    
    # Open the container
    with sm_top:

        smach.StateMachine.add('BAS', Bas(),
                               transitions={'outcome3':'CON'})

        # Create the sub SMACH state machine
        sm_con = smach.Concurrence(outcomes=['outcome4','outcome5'],
                                   default_outcome='outcome4',
                                   outcome_map={'outcome5':
                                       { 'FOO':'outcome2',
                                         'BAR':'outcome1'}})

        # Open the container
        with sm_con:
            # Add states to the container
            smach.Concurrence.add('FOO', Foo())
            smach.Concurrence.add('BAR', Bar())

        smach.StateMachine.add('CON', sm_con,
                               transitions={'outcome4':'CON',
                                            'outcome5':'outcome6'})

    # Execute SMACH plan
    outcome = sm_top.execute()
def main():
    rospy.init_node('smach_example_state_machine_nesting')

    # Create a SMACH state machine
    sm0 = smach.StateMachine(outcomes=['succeeded'])

    # Open the container
    with sm0:
        # Add states to the container
        smach.StateMachine.add('SET', Setter(val='hello'), {'set_it':'NESTED'})

        sm1 = smach.StateMachine(outcomes=['done'], input_keys=['x'])
        smach.StateMachine.add('NESTED', sm1, {'done':'succeeded'})
        with sm1:
            smach.StateMachine.add('GET', Getter(), {'got_it':'done'})

    # Execute SMACH plan
    outcome = sm0.execute()
def main():
    rospy.init_node('smach_example_actionlib')

    # Start an action server
    server = TestServer('test_action')

    # Create a SMACH state machine
    sm0 = smach.StateMachine(outcomes=['succeeded', 'aborted', 'preempted'])

    # Open the container
    with sm0:
        # Add states to the container

        # Add a simple action sttate. This will use an emtpy, default goal
        # As seen in TestServer above, an empty goal will always return with
        # GoalStatus.SUCCEEDED, causing this simple action state to return
        # the outcome 'succeeded'
        smach.StateMachine.add(
            'GOAL_DEFAULT',
            smach_ros.SimpleActionState('test_action', TestAction),
            {'succeeded': 'GOAL_STATIC'})

        # Add another simple action state. This will give a goal
        # that should abort the action state when it is received, so we
        # map 'aborted' for this state onto 'succeeded' for the state machine.
        smach.StateMachine.add(
            'GOAL_STATIC',
            smach_ros.SimpleActionState('test_action',
                                        TestAction,
                                        goal=TestGoal(goal=1)),
            {'aborted': 'GOAL_CB'})

        # Add another simple action state. This will give a goal
        # that should abort the action state when it is received, so we
        # map 'aborted' for this state onto 'succeeded' for the state machine.
        def goal_callback(userdata, default_goal):
            goal = TestGoal()
            goal.goal = 2
            return goal

        smach.StateMachine.add(
            'GOAL_CB',
            smach_ros.SimpleActionState('test_action',
                                        TestAction,
                                        goal_cb=goal_callback),
            {'aborted': 'succeeded'})

        # For more examples on how to set goals and process results, see
        # executive_smach/smach_ros/tests/smach_actionlib.py

    # Execute SMACH plan
    outcome = sm0.execute()

    rospy.signal_shutdown('All done.')
Exemple #5
0
def main():
    rospy.init_node('smach_example_user_data')

    # Create a SMACH state machine
    sm = smach.StateMachine(outcomes=['succeeded'])

    # Open the container
    with sm:
        # Add states to the container
        smach.StateMachine.add('SET', Setter(), {'set_it': 'GET'})
        smach.StateMachine.add('GET', Getter(), {'got_it': 'succeeded'})

    # Execute SMACH plan
    outcome = sm.execute()
Exemple #6
0
def main():
    rospy.init_node('smach_example_state_machine')

    # Create a SMACH state machine
    sm = smach.StateMachine(outcomes=['succeeded', 'aborted'])

    # Open the container
    with sm:
        # Add states to the container
        smach.StateMachine.add('FOO', ExampleState(), {'done': 'BAR'})
        smach.StateMachine.add('BAR', ExampleState(), {'done': 'BAZ'})
        smach.StateMachine.add('BAZ', ExampleState(), {'done': 'succeeded'})

    # Execute SMACH plan
    outcome = smach. async .run(sm.execute_async())
def main():
    rospy.init_node('smach_example_state_machine')

    # Create a SMACH state machine
    sm = smach.StateMachine(outcomes=['outcome4', 'outcome5'])

    # Open the container
    with sm:
        # Add states to the container
        smach.StateMachine.add('FOO', Foo(), 
                               transitions={'outcome1':'BAR', 
                                            'outcome2':'outcome4'})
        smach.StateMachine.add('BAR', Bar(), 
                               transitions={'outcome2':'FOO'})

    # Execute SMACH plan
    outcome = sm.execute()
Exemple #8
0
def radio_sm(iface):
    sm = smach.StateMachine(outcomes=[], input_keys=['radio'])
    smadd = smach.StateMachine.add
    with sm:
        smadd('DOWN', Down(), transitions={'up': 'UNASSOCIATED'})
        smadd('UNASSOCIATED',
              Unassociated(),
              transitions={
                  'associate': 'ASSOCIATING',
                  'down': 'DOWN'
              })
        smadd('ASSOCIATING',
              Associating(),
              transitions={
                  'associated': 'ASSOCIATED',
                  'failed': 'DOWN'
              })
        smadd('ASSOCIATED',
              Associated(),
              transitions={
                  'reassociate': 'ASSOCIATING',
                  'activate': 'ACTIVE',
                  'unassociated': 'DOWN'
              })
        smadd('ACTIVE',
              Active(),
              transitions={
                  'disactivate': 'DISACTIVATING',
                  'unassociated': 'DOWN'
              })
        smadd('DISACTIVATING',
              Disactivating(),
              transitions={
                  'done': 'ASSOCIATED',
                  'activate': 'ACTIVE',
                  'unassociated': 'DOWN'
              })
    ud = smach.UserData()
    ud.radio = RadioSmData(iface)
    sm.register_transition_cb(_state_change_cb)
    sm.execute_async(ud)
    return ud.radio
def main():
    rospy.init_node('smach_example_state_machine')

    # Create a SMACH state machine
    sm = smach.StateMachine(outcomes=['outcome4'])
    sm.userdata.sm_counter = 0

    # Open the container
    with sm:
        # Add states to the container
        smach.StateMachine.add('FOO', Foo(), 
                               transitions={'outcome1':'BAR', 
                                            'outcome2':'outcome4'},
                               remapping={'foo_counter_in':'sm_counter', 
                                          'foo_counter_out':'sm_counter'})
        smach.StateMachine.add('BAR', Bar(), 
                               transitions={'outcome1':'FOO'},
                               remapping={'bar_counter_in':'sm_counter'})


    # Execute SMACH plan
    outcome = sm.execute()