0
$\begingroup$

Rosanswers logo

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?


Originally posted by lindzey on ROS Answers with karma: 1780 on 2015-07-17

Post score: 2

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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.


Originally posted by lindzey with karma: 1780 on 2017-05-08

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

For (1) you can set the initial state of the state machine with sm.set_initial_state(["my_inital_state"]).

For (2), in addition to rqt and the introspection server, the logs should print on each transition. You can set your own loggers if desired with smach.set_loggers

In general testing can be hard but I setup a system where my states wrap execute with a basic synchronization mechanism and the state machine is executing in a separate thread. The sequence is:

  1. States wait on a thread-safe "start" signal
  2. Test sets the "start" signal to true
  3. Test waits for a thread-safe "finished" signal from the state(s)
  4. When states finish, they set the "finished" signal to true (+ their outcome)
  5. Test wakes up and can check the outcome value(s) produced
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.