Garage Door Controller State Chart v1.0 implementation

The code below implements the version 1. state chart. Below it are more advanced state charts that take into account button presses while closing and opening. The next versions could include obstacle detection and motor overload situations.

HW-dependent things are separated to HWAPI-module (see HWAPI module header)

#include "Garage1.h"
#include  "HWAPI.H"
 
/* Author: SM 2010
   Garage door controller state-machine implementation (version 1)
   Appropriate calling period for gdcTask is eg. 60 ms.
   See statechart + STT (State Transition Table) in accompanying documentation
 
   HW-Related things are encapsulated to hwapi-module.
 
*/
 
void gdcTask() {
 
   enum  tGdState {CLOSED,OPENING,OPENED,CLOSING};
   static enum tGdState state = CLOSED;
   switch (state) {
 
     case CLOSED:
      debugState(state);
       /* make sure motor is stopped */
           stop();
 
      /* Check need for transitions */
      if (isButton()) {
          state = OPENING;   
          startOpening();
       }
 
     break;
 
    case OPENING:
       debugState(state);
       /* check need for transitions*/
       if (isDoorOpened()){
         state = OPENED;
         stop();
       }
 
     break;
 
     case OPENED:
       debugState(state);
       /* check need for transitions*/
       if (isButton()) {
        state = CLOSING;
        startClosing();
      }
 
     break;
 
    case CLOSING:
       debugState(state);
       /* check need for transitions*/
       if (isDoorClosed()) {
          stop();
          state = CLOSED;
       }
     break;
 
     default:
 
     break;
    }  
}

version 1

GD_First.png

version 2

GD_Second.png

version 3a

GD_StoppedMovingWait.png

version 3b

GD_WithMovingSubstates.png
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License