Pages: [1]   Go Down
Author Topic: Help with application of Finite State Machine library  (Read 492 times)
0 Members and 1 Guest are viewing this topic.
Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
//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:
void Exit()
{
  switch (SolarTracking.getCurrentState())
  {
 case  (_Starting):
        Serial.println('Starting');
        break;
 case  _Eval_EWsensor:
        Serial.println('Eval_EWsensor');
        break;
 case  _Eval_NSsensor:
        Serial.println('Eval_NSsensor');
        break;
 case  _Running_East:
        Serial.println('Running_East');
        break;
 case  _Running_West:
        Serial.println('Running_West');
        break;
 case  _Running_North:
        Serial.println('Running_North');
        break;
 case  _Running_South:
        Serial.println('Running_South');
        break;
 case  _Cloud_Chasing:
        Serial.println('Cloud_Chasing');
        break;
 case  _Darkness:
        Serial.println('Darkness');
        break;
 case  _Waiting_for_Sunrise:
        Serial.println('Waiting_for_Sunrise');
        break;
 case  _Error:
        Serial.println('Error');
        break;
 }      
}

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.
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1257
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Should the arguments in the println() statements be in double quotes as they are strings?
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: