Go Down

Topic: Help with application of Finite State Machine library (Read 943 times) previous topic - next topic


For my solar tracker I decided to make use of the available Finite State Machine Library which is a nice tiny library but coded in a way which I do not yet fully comprehend yet. The FSM states are coded as follows and this compiles ok:

Code: [Select]
//setup SolarTracking states
State _Starting             = State (NULL,                Starting,                  Exit);
State _Eval_EWsensor        = State (Entry_Eval_EWsensor, Eval_EWsensor,             Exit);
State _Running_East         = State (NULL,                Running_East,              Exit);
State _Running_West         = State (NULL,                Running_West,              Exit);
State _Eval_NSsensor        = State (Entry_Eval_NSsensor, Eval_NSsensor,             Exit);
State _Running_North        = State (NULL,                Running_North,             Exit);
State _Running_South        = State (NULL,                Running_South,             Exit);
State _Cloud_Chasing        = State (Entry_Cloud_Chasing, Cloud_Chasing,             Exit);
State _Darkness             = State (Enter_Darkness,      Darkness,                  Exit);
State _Waiting_for_Sunrise  = State (Entry_Waiting_for_Sunrise, Waiting_for_Sunrise, Exit);
State _Error                = State (NULL,                Error,                     Exit);

FSM SolarTracking = FSM (_Starting);  

For debugging reasons I want to print the current state the FSM is in through the Exit method of each state in the following way:
Code: [Select]
void Exit()
 switch (SolarTracking.getCurrentState())
case  (_Starting):
case  _Eval_EWsensor:
case  _Eval_NSsensor:
case  _Running_East:
case  _Running_West:
case  _Running_North:
case  _Running_South:
case  _Cloud_Chasing:
case  _Darkness:
case  _Waiting_for_Sunrise:
case  _Error:

Now the compiler complains about the switch statement and reports: 'switch quantity not an integer'. I can't figure out how to solve this. Your help is much appreciated.


Should the arguments in the println() statements be in double quotes as they are strings?
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com


getCurrentState returns a state object, not the integer switch expects, so you can't use it. It looks like there was once an id field you could have used for this purpose, but it's commented out in the library. One way to achieve the same thing appears to be through use of a bunch of if tests calling the isInState method on the FSM.

Go Up