(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Sequence container

Description: This tutorial teaches you how to use the Sequence container.

Tutorial Level: BEGINNER

Next Tutorial: Iterator container

The Sequence container is a StateMachine container, extended with auto-generated transitions that create a sequence of states from the order in which said states are added to the container. Only the differences are noted here.

Creating a Sequence Container

First import the sequence type:

   1 from smach import Sequence

A container Sequence has its outcomes, specified on construction, along with the 'connector_outcome' which is used for the automatic transitions. The constructor signature is:

   1 __init__(self, outcomes, connector_outcome):

Adding States

Adding states to a sequence is the same as to a container.

But, each state added will receive an additional transition from it to the state which is added after it. The transition will follow the outcome specified at construction of this container.

If one of the transitions given in the dictionary mapping parameter to 'Sequence.add()' follows the connector outcome specified in the constructor, the provided transition will override the automatically generated connector transition.


For example, when creating a sequence of action states, no transition mapping is needed. All action states have the usual outcome triple, which the sequence needs to have as its outcomes, too:

   1 sq = Sequence(
   2         outcomes = ['succeeded','aborted','preempted'],
   3         connector_outcome = 'succeeded')
   4 with sq:
   5     Sequence.add('MOVE_ARM_GRAB_PRE', MoveVerticalGripperPoseActionState())
   6     Sequence.add('MOVE_GRIPPER_OPEN', MoveGripperState(GRIPPER_MAX_WIDTH))
   7     Sequence.add('MOVE_ARM_GRAB',     MoveVerticalGripperPoseActionState())
   8     Sequence.add('MOVE_GRIPPER_CLOSE', MoveGripperState(grab_width))
   9     Sequence.add('MOVE_ARM_GRAB_POST', MoveVerticalGripperPoseActionState())

Wiki: smach/Tutorials/Sequence container (last edited 2012-07-13 09:26:11 by FelixKolbe)