I have the following state diagram. I know how to make a simple state machine that transitions between non-nested states; however, I don't know how to transition between nested states. Could someone explain how to do this at an appropriately high level (i.e., you don't need to write the code for me--unless you're feeling particularly generous :P).
What I want to model [Modified, based on suggestions]
What I know how to implement (code below)
public class MyState : State // State enumeration
{
public static MyState A = new MyState("State A");
public static MyState B = new MyState("State B");
public static MyState C = new MyState("State C");
public static MyState D = new MyState("State D");
public static MyState E = new MyState("State E");
public static MyState F = new MyState("State F");
public static MyState NEUT = new MyState("Neutral");
public static MyState P = new MyState("P");
protected MyState(string name) : base(name) { }
}
public class MyEvent : Event // Event enumeration
{
public static MyEvent X_POS = new MyEvent("X+");
public static MyEvent X_NEG = new MyEvent("X-");
public static MyEvent Y_POS = new MyEvent("Y+");
public static MyEvent Y_NEG = new MyEvent("Y-");
protected MyEvent(string name) : base(name) { }
}
// State Machine implementation
public class MyStateMachine : StateMachine<MyState, MyEvent>
{
public MyStateMachine() : base(MyState.P) // MyState.P = initial state
{ // Set up the transition table
// P
this.addTransition(MYState.P, MyState.NEUT, MyEvent.Y_NEG);
// NEUTRAL
this.addTransition(MyState.NEUT, MyState.P, MyEvent.Y_POS);
this.addTransition(MyState.NEUT, MyState.A, MyEvent.Y_NEG);
this.addTransition(MyState.NEUT, MyState.B, MyEvent.Y_POS);
this.addTransition(MyState.NEUT, MyState.C, MyEvent.Y_NEG);
this.addTransition(MyState.NEUT, MyState.D, MyEvent.Y_POS);
this.addTransition(MyState.NEUT, MyState.E, MyEvent.Y_NEG);
this.addTransition(MyState.NEUT, MyState.F, MyEvent.Y_POS);
// A
this.addTransition(MyState.A, MyState.NEUT, MyEvent.Y_POS);
// B
this.addTransition(MyState.B, MyState.NEUT, MyEvent.Y_NEG);
// C
this.addTransition(MyState.C, MyState.NEUT, MyEvent.Y_POS);
// D
this.addTransition(MyState.D, MyState.NEUT, MyEvent.Y_NEG);
// E
this.addTransition(MyState.E, MyState.NEUT, MyEvent.Y_POS);
// F
this.addTransition(MyState.F, MyState.NEUT, MyEvent.Y_NEG);
}
public void move(MyEvent eevent)
{
try
{
this.moveNext(eevent);
}
catch (Exception e) { }
}
}
Edit: I think the crux of the issue is how to illustrate/implement transitions from a substate of a given superstate to a substate of a different superstate when the transition depends on the current substate in the original superstate. To use my example, if the current state is "P" inside superstate "Neutral", how can I illustrate/implement my state machine to show that event Y+ will transition out of the Neutral superstate altogether, into the "Not Neutral" superstate, and specifically into the "P" substate.