Jelle
Published © GPL3+

Make Controls with MEGA 2560 - Part 4: The Heater Control

Part 4 is about the theoretical model and the way it is implemented in the AFSM.

IntermediateProtip4 hours993
Make Controls with MEGA 2560 - Part 4: The Heater Control

Things used in this project

Story

Read more

Code

User Finite State Machine

C/C++
Heater control
// UserFiniteStateMachine.h

//*========================================================================================
//*  Application code
//*
//*  Name: UserFSM()
//*  Version:
//*  Date:
//*  Author:
//*
//*  Short description:
//*
//*
//*========================================================================================
//*========================================================================================
//*============ START USER APPLICATION ======= START USER APPLICATION =====================
//*========================================================================================
//*========================================================================================
//
// State machine
//
// Each phase exists of 2 parts, e.g. the phase actions and transition conditions.
// In the phase actions, all activated tags are mentioned. Deactivation is not needed, deactivation is
// done at the end of the main loop. In the conditions section, all conditions for the transitions to another
// phase are mentioned. When all condition are true, the new phase can be set. It is possible to programm
// more then 1 transition. In such a case it is necassery to keep the priority in mind.
//
//*========================================================================================


void UserFSM()
{
	//
	// Machine state "START" is the default state at 
	// startup of the board!
	//
	if (MachineState == FiniteState("START"))
	{
		//Enter state action
		if (EnterState()) Serial.println("START state is entered");

		// The state function
		// No actions to perform is this state.
		
		// Transaction conditions
		TransitionToState("COLD");	

		//Exit state action
		if (ExitState()) Serial.println("START state is exit");

	};


	if (MachineState == FiniteState("COLD"))
	{
		//Enter state action
		if (EnterState()) Serial.println("COLD state is entered");

		// The state function
		Activate("HEATER");

		// Transaction conditions
		if (TempValue("TTWATER") > 35.0) TransitionToState("ON-TEMP");
		
		//Exit state action
		if (ExitState()) Serial.println("COLD state is exit");
	};


	if (MachineState == FiniteState("ON-TEMP"))
	{
		//Enter state action
		if (EnterState()) Serial.println("ON-TEMP state is entered");

		// The state function
		// No action required in the state

		// Transaction conditions
		if (TempValue("TTWATER") < 34.0) TransitionToState("COLD");

		//Exit state action
		if (ExitState()) Serial.println("ON-TEMP state is exit");
	};



	//*========================================================================================
	//*========================================================================================
	//*============  END USER APPLICATION ========= END USER APPLICATION =====================
	//*========================================================================================
	//*========================================================================================
}

Credits

Jelle

Jelle

8 projects • 19 followers
I'am developing software only during rainy days.

Comments