ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Revision history [back]

Userdata should only be accessed within states/containers which declare read (input key) or write (output key) access, although it is usually fine to initialize internal userdata keys on container construction.

Anyways, your example fails for the following reason: The key sm_data is only written by state Foo. Consequently, it only exists after the state returns with one of its outcomes (assuming the state declared foo_counter_out as output key). This won't happen before calling sm_top.execute(), which is after the print statement in your example. Before the very last line, you only construct the state machine, but do not execute it.

Yes, a userdata key can be passed to any amount of states. Consider it just as a variable to be updated during state machine execution.