Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_auto not behaving as expected #74

Open
adivardi opened this issue Jun 18, 2020 · 0 comments
Open

add_auto not behaving as expected #74

adivardi opened this issue Jun 18, 2020 · 0 comments

Comments

@adivardi
Copy link

When using the add_auto function, the resulting transitions are not as expected from the documentation. I am not sure if it is a bug or I am misreading the text (if so, many of my colleagues have done the exact mistake)

Using this method, I add connector_outcomes for all the outcomes of the state. I then use transitions with the intent of overwriting some of the outcomes defined by connector_outcomes, following the documentation:

@param transitions: A dictionary mapping state outcomes to other state
        labels. If one of these transitions follows the connector outcome
        specified in the constructor, **the provided transition will override
        the automatically generated connector transition**.

However, when running this, the transition specified do not actually overwrite connector_outcomes and instead are ignored.

Example (modified from the tutorial)

class Foo(smach.State):
    def __init__(self):
        smach.State.__init__(self, outcomes=['succeeded','failed'])
        self.counter = 0

    def execute(self, userdata):
        rospy.loginfo('Executing state FOO')
        if self.counter < 3:
            self.counter += 1
            return 'succeeded'
        else:
            return 'failed'


# define state Bar
class Bar(smach.State):
    def __init__(self):
        smach.State.__init__(self, outcomes=['succeeded'])

    def execute(self, userdata):
        rospy.loginfo('Executing state BAR')
        return 'succeeded'


# main
def main():
    rospy.init_node('smach_example_state_machine')

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

    # Open the container
    with sm:
        # Add states to the container
        smach.StateMachine.add_auto('FOO', Foo(),
                                    connector_outcomes=['succeeded', 'failed'],
                                    transitions={'failed': 'failed'})

        smach.StateMachine.add('BAR', Bar(),
                               transitions={'succeeded':'succeeded'})

    # Execute SMACH plan
    outcome = sm.execute()

if __name__ == '__main__':
    main()

My expectation in this case is the Foo will have transition from succeeded to BAR and from failed to failed. However, visualizing this SM, I get:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant