tklab-tud / uscxml

SCXML interpreter and transformer/compiler written in C/C++ with bindings to Java, C#, Python and Lua
Other
106 stars 54 forks source link

How can you get a string for the current active state? #186

Closed crichardson332 closed 5 years ago

crichardson332 commented 5 years ago

I'm trying to use uSCXML to implement a "behavior executor" for a robotics application (similar to ROS). I have a basic setup using the Interpreter to parse my scxml file and process events, which seems to work fine. I want to be able to publish the active state over a pubsub mechanism so I can design a general, extensible FSM that is defined at runtime. But I can't find any way to get information on the active state. I really need something like this

std::string getActiveState()

The only api I can find that seems related to the active state is the bool isInState (const std::string &stateId), but I can't use this because it requires the state name as input. The behavior executor is not going to know the states a priori so it can't use an api that requires the state name as input. All I need is a simple string getActiveState() function, does this really not exist?

sradomski commented 5 years ago

In a state-chart, there can be multiple active states, and you can use this API

/**
 * Get all state elements that constitute the active configuration.
 * @return A list of XML elements of the active states.
 */
std::list<XERCESC_NS::DOMElement*> getConfiguration();
sradomski commented 5 years ago

You can get an attribute from a xerxes element with the ATTR macro from DOM.h:

https://github.com/tklab-tud/uscxml/blob/master/src/uscxml/util/DOM.h#L33

crichardson332 commented 5 years ago

Thanks!