Ask Your Question
2

How to unit test smach state machines?

asked 2015-07-17 01:45:46 -0500

lindzey gravatar image

I'm struggling with how to automate tests to exercise a smach state machine. In particular:

1) Is it possible to start the state machine in a given state? I'm picturing some modification to sm.execute() that sets user data and calls the appropriate execute loop. Or maybe something that specifies the transitions required to get to the desired start state?

2) How can I check that it has transitioned as expected? Note - I'm using smach only, not ROS, but I figured that this was still probably the best place to ask. However, it means that I can't just eavesdrop on the messages that are used to update the smach viewer.

I'm using this state machine to coordinate human and autonomous control; I want to be able to test things like "from any state, joystick override quickly preempts", "from any state, loss of communications triggers preemption and transition to this state".

Has anybody done this before? Is there another way to approach this type of testing?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-05-08 01:59:40 -0500

lindzey gravatar image

For #2, rqt_smach's smach_graph.py has functionality for monitoring the current state of a smach stateMachine. It is possible to build a testing framework around that.

I never found a satisfactory answer to #1; the best approach I found is to send a series of messages designed to get the state machine to the desired state, and then assert that it is there.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2015-07-17 01:45:46 -0500

Seen: 431 times

Last updated: May 08 '17