Merge pull request #50 from emmanuelsrlok/develop

Develop
This commit is contained in:
Emmanuel HC
2026-02-05 08:11:59 -06:00
committed by GitHub
62 changed files with 3217 additions and 272 deletions

View File

@@ -9,11 +9,10 @@
[platformio]
default_envs = CRAH_PETRA_PAHHC_600_C6_TCP ; Select here the name of the configuration you want to download
default_envs = BKR_ABB_EMax2_TCP ; Select here the name of the configuration you want to download
[env]
upload_port = COM50
upload_port = COM19
[common_env_options]
framework = arduino
@@ -212,3 +211,53 @@ platform = espressif32
board = dfrobot_firebeetle2_esp32e
extends = common_env_options
build_src_filter = -<*> +<BMS/VFD/PHX3_VFD_ABB_ACH580_RTU>
[env:PHX3_CRAH_LIEBERT_80_SLAB_TCP]
platform = espressif32
board = dfrobot_firebeetle2_esp32e
extends = common_env_options
build_flags = -D USE_MODBUS_IP
build_src_filter = -<*> +<BMS/CRAH/PHX3_CRAH_LIEBERT_80_SLAB_TCP>
[env:HUM_DriSteem_RTS_RX36_TCP]
platform = espressif32
board = dfrobot_firebeetle2_esp32e
extends = common_env_options
build_flags = -D USE_MODBUS_IP
build_src_filter = -<*> +<BMS/HUM/HUM_DriSteem_RTS_RX36_TCP>
[env:CRAH_UMAS_TCP]
platform = espressif32
board = dfrobot_firebeetle2_esp32e
extends = common_env_options
build_flags = -D USE_MODBUS_IP
build_src_filter = -<*> +<BMS/CRAH/CRAH_UMAS_TCP>
[env:GEN_HSE]
platform = espressif32
board = dfrobot_firebeetle2_esp32e
extends = common_env_options
build_flags = -D USE_MODBUS_IP
build_src_filter = -<*> +<EPMS/GEN/GEN_HSE>
[env:SEL_2440_MVG]
platform = espressif32
board = dfrobot_firebeetle2_esp32e
extends = common_env_options
build_flags = -D USE_MODBUS_IP
build_src_filter = -<*> +<Base_TCP>
[env:MVG_SC_EC_M505_TCP]
platform = espressif32
board = dfrobot_firebeetle2_esp32e
extends = common_env_options
build_flags = -D USE_MODBUS_IP,
build_src_filter = -<*> +<EPMS/MVG/MVG_SC_EC_M505_TCP>
[env:GEN_CAT_GCCP_TCP]
platform = espressif32
board = dfrobot_firebeetle2_esp32e
extends = common_env_options
build_flags = -D USE_MODBUS_IP,
build_src_filter = -<*> +<EPMS/GEN/GEN_CAT_GCCP_TCP>

View File

@@ -1,16 +1,12 @@
# CHILLER YORK YVAA 0428IOK46BAVTXX TCP
## Brief Introduction
*** NOTE! ***
This code has not been verified with Chiller and Chiller Manager PLC program.
It is a best-guess based on a preliminary review of Chiller PLC program, but
has yet to be fully vetted and local tested with PLC programs.
Chiller receives Temp SP and Enable from PLC (Modscan)
Alarms are also simulated via Modscan, though those signals will be internal to Chiller
Many hard IO points are simulated using Modscan.
Assumes all Modbus points are for monitoring only and go to Ignition - not sent to PLC
Chiller receives Chiller Temp SP and Enable from PLC. The Supply Temp will ramp to Chiller Temp SP in Run Mode.
Alarms are also simulated via Modscan, though those signals will be internal to Chiller.
Hard IO points simulated with Modscan: Sys 1 Alarm, Sys 2 Alarm.
Chiller Status is sent back to PLC.
In practice, all Modbus points are for monitoring only and go to Ignition - not sent to PLC.
For the sake of simulation, some hard IO points (simulated as Modbus points) will go back to PLC for feedback or will be sent from PLC to Arduino.
## List of Equipment
This cofiguration has been used for these models:
@@ -24,20 +20,51 @@ The code is written for an ESP8266/ESP32-style microcontroller with WiFi capabil
---
## States and Strategies
Updates Alarms States. If any active alarms --> FailState
Updates Alarms States. Only the Sys 1 Fan Fault or Sys 2 Fan Fault will send unit --> FailState
Sys 1 Alarm, Sys 2 Alarm, and General Alarm will annunciate only, will not stop the unit (this is an assumption the program follows, may differ in field).
Updates Free Cooling Mode: Free Cooling Mode is activated using a coil, for simulation purposes only.
Modbus points are simulated, mostly with a SingleValue strategy for image verification in Ignition.
While in RunningState, the Supply Temp dynamically ramps to the Supply Temp SP sent from PLC (Modscan)
While in RunningState, the Supply Temp dynamically ramps to the Supply Temp SP sent from PLC (or Modscan)
The CHW In and CHW Out temperature values also dynamically ramp to match the Return and Supply Temps.
### Standby State
* **Chiller Status**: set to 0
* **Operational Code**: set to 77
* **Chiller Start Command**: set to 0
Supply Temp = 80 +/- 1
Return Temp = 80 +/- 1
System CHW Out = 80 +/- 1
System CHW In = 80 +/- 1
Ambient Temp = 1-- +/- 1
Sys 1, 2 Oil Pressure = 420 +/- 1
Sys 1, 2 Suction Pressure = 70 +/- 1
Sys 1, 2 Discharge Pressure = 70 +/- 1
Sys 1, 2 Condenser Temp = 124 +/- 1
### Running State
* **Chiller status**: set to 1
* **Supply Temperature**: **Ramp Strategy** ramps to Temp Setpoint from PLC (Modscan)
* **Operational Code**: set to 78 (running)
* **Supply Temperature**: **Ramp Strategy** ramps to Chiller Temp Setpoint from PLC (Modscan)
Supply Temp dynamically ramps to Chiller Temp Setpoint as sent from PLC (or Modscan)
Return Temp sawStrategy (79-83)
System CHW Out dynamically ramps to follow Supply Temp
System CHW In dynamically ramps to follow Return Temp
Ambient Temp = 1-- +/- 1
Sys 1, 2 Oil Pressure = 450 +/- 5
Sys 1, 2 Suction Pressure = 70 +/- 2
Sys 1, 2 Discharge Pressure = 375 +/- 4
Sys 1, 2 Compressor Pct FLA = 93 +/- 2
Sys 1, 2 Condenser Temp = 125 +/- 5
Sys 1 Fan kW = 35 +/- 2
Sys 2 Fan kW = 23 +/- 2
Sys 1 Compressor kW = 304 +/- 5
Sys 2 Compressor kW = 198 +/- 5
### Fail State
All values match that of Standby State.
The difference is in Fail State, if a Start Command is sent it will not start the Chiller.
All faults must be cleared, then unit transitions to Standby State.
* **Chiller Status**: set to 0
* **Operational Code**: set to 77
* **Chiller Start Command**: set to 0
All analog values same as in Standby State

View File

@@ -32,13 +32,15 @@
* @brief Updates Alarms states
*
* This function will update the Alarm status DI bits according to the Alarm Commands from Coils (Modscan)
* The appropriate Fault Code will also be set to 56 (Condenser Fan VSD Warning)
* The appropriate Fault Code will also be set to 56 (Condenser Fan VSD Warning).
* Also updates the General Alarm bit. If any alarms are active, General Alarm --> 1, else 0.
*
* This is a function used in the update() of the Standby, Running, and Fail States.
*
*/
void updateAlarms(Equipment<ModbusRTU>* equipment){
// Updates Sys 1, 2 Fan Fault Alarms with associated Fault Code
Modbus_Point<ModbusRTU>* Sys1FanAlarmCommand = equipment->getModbus_Point("Sys 1 Fan Fault ON");
Modbus_Point<ModbusRTU>* Sys2FanAlarmCommand = equipment->getModbus_Point("Sys 2 Fan Fault ON");
Modbus_Point<ModbusRTU>* Sys1FanAlarm = equipment->getModbus_Point("Sys 1 Fan Fault Alarm");
@@ -57,6 +59,20 @@ void updateAlarms(Equipment<ModbusRTU>* equipment){
}
else equipment->setModbus_Point("Sys 2 Fault Code", 0);
}
// Update General Alarm (if any Alarm is active, make general alarm active)
const std::vector<std::string> alarmDescriptions = {
"Sys 1 Alarm", "Sys 2 Alarm", "Sys 1 Fan Fault Alarm", "Sys 2 Fan Fault Alarm"
};
int numAlarms = 0;
for (int i =0; i < alarmDescriptions.size(); ++i) {
Modbus_Point<ModbusRTU>* alarmPoint = equipment->getModbus_Point(alarmDescriptions[i]);
if (alarmPoint) {
if (alarmPoint->getValue() == 1) numAlarms++;
}
}
if (numAlarms >= 1) equipment->setModbus_Point("General Alarm", 1);
else equipment->setModbus_Point("General Alarm", 0);
}
/**
@@ -74,12 +90,6 @@ void updateFreeCooling(Equipment<ModbusRTU>* equipment){
Modbus_Point<ModbusRTU>* FreeCoolingCommand = equipment->getModbus_Point("Free Cooling Mode ON");
Modbus_Point<ModbusRTU>* FreeCoolingMode = equipment->getModbus_Point("Free Cooling Mode");
Modbus_Point<ModbusRTU>* FreeCoolingValve = equipment->getModbus_Point("Free Cooling Valve");
if (FreeCoolingCommand->getValue() == 1) {
FreeCoolingMode->setValue(1);
FreeCoolingValve->setValue(1);
}
else {
FreeCoolingMode->setValue(0);
FreeCoolingValve->setValue(0);
}
FreeCoolingMode->setValue(FreeCoolingCommand->getValue());
FreeCoolingValve->setValue(FreeCoolingCommand->getValue());
}

View File

@@ -6,6 +6,7 @@
*
* This file contains the implementation for the FailState, which defines
* the behavior of the equipment when it has entered a fault condition.
* The unit enters Fail State if Sys 1 Fan Fault Alarm or Sys 2 Fan Fault Alarm is active.
*/
#include "ModbusPoints/Modbus_Point.h"
#include "Equipment/Equipment.h"
@@ -29,15 +30,31 @@
* @brief Constructs a new FailState object.
*
* This constructor receives a list of alarm descriptions and creates strategies
* to set the Compressor and Fan kW to 0.
* to set the unit back into an idle, de-energized state.
*
* @param activeAlarms A vector of strings, where each string is the
* description of a Modbus point to be set as an active alarm.
* @param activeFaults A vector of strings, where each string is the
* description of the currently active faults.
*/
template<>
FailState<ModbusRTU>::FailState(const std::vector<std::string>& activeAlarms) {
FailState<ModbusRTU>::FailState(const std::vector<std::string>& activeFaults) {
addStrategy("Supply Temp", new SingleValueStrategy(80.0f, 1.0f, 1000));
addStrategy("Return Temp", new SingleValueStrategy(80.0f, 1.0f, 1000));
addStrategy("Ambient Temp", new SingleValueStrategy(100.0f, 1.0f, 1000));
addStrategy("System CHW Out", new SingleValueStrategy(80.0f, 1.0f, 1000));
addStrategy("System CHW In", new SingleValueStrategy(80.0f, 1.0f, 1000));
addStrategy("Sys 1 Condenser Temp", new SingleValueStrategy(124.0f, 1.0f, 1000));
addStrategy("Sys 2 Condenser Temp", new SingleValueStrategy(124.0f, 1.0f, 1000));
addStrategy("Sys 1 Oil Pressure", new SingleValueStrategy(420.0f, 1.0f, 1000));
addStrategy("Sys 2 Oil Pressure", new SingleValueStrategy(420.0f, 1.0f, 1000));
addStrategy("Sys 1 Suction Pressure", new SingleValueStrategy(70.0f, 1.0f, 1000));
addStrategy("Sys 2 Suction Pressure", new SingleValueStrategy(70.0f, 1.0f, 1000));
addStrategy("Sys 1 Discharge Pressure", new SingleValueStrategy(70.0f, 1.0f, 1000));
addStrategy("Sys 2 Discharge Pressure", new SingleValueStrategy(70.0f, 1.0f, 1000));
addStrategy("Sys 1 Compressor Pct FLA", new SingleValueStrategy(0.0f, 0.0f, 1000));
addStrategy("Sys 2 Compressor Pct FLA", new SingleValueStrategy(0.0f, 0.0f, 1000));
addStrategy("Local Leaving Temp Setpoint", new SingleValueStrategy(70.0f, 0.0f, 1000));
addStrategy("VSD Output Frequency", new SingleValueStrategy(0.0f, 0.0f, 1000));
addStrategy("Sys 1 Fan KW", new SingleValueStrategy(0.0f, 0.0f, 1000));
addStrategy("Sys 2 Fan KW", new SingleValueStrategy(0.0f, 0.0f, 1000));
addStrategy("Sys 1 Compressor KW", new SingleValueStrategy(0.0f, 0.0f, 1000));
@@ -48,34 +65,45 @@ FailState<ModbusRTU>::FailState(const std::vector<std::string>& activeAlarms) {
* @brief Executes the fail state's logic for one update cycle.
*
* This method first updates all alarms states and Free Cooling Mode (for ease of testing).
* If all alarms have been cleared --> StandbyState.
* If alarms are still active, ensures the Chiller Start Command remains at 0.
* If all faults have been cleared --> StandbyState.
* If faults are still active, ensures the Chiller Start Command remains at 0.
*
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusRTU>* FailState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
// Update alarms states, Free Cooling mode, Freeze Protection Mode
// Update alarms states, Free Cooling mode
updateAlarms(equipment);
updateFreeCooling(equipment);
const std::vector<std::string> alarmDescriptions = {
"Sys 1 Alarm", "Sys 2 Alarm", "Sys 1 Fan Fault Alarm", "Sys 2 Fan Fault Alarm",
const std::vector<std::string> FaultDescriptions = {
"Sys 1 Fan Fault Alarm", "Sys 2 Fan Fault Alarm",
};
// If no alarms active --> send to StandbyState()
bool alarms_active = false;
for (const auto& desc : alarmDescriptions) {
// If no faults active --> send to StandbyState()
bool faults_active = false;
for (const auto& desc : FaultDescriptions) {
Modbus_Point<ModbusRTU>* point = equipment->getModbus_Point(desc);
if (point->getValue() == 1) {
alarms_active = true;
faults_active = true;
}
}
if (!alarms_active) return new StandbyState<ModbusRTU>();
if (!faults_active) return new StandbyState<ModbusRTU>();
setPointValue(equipment, "Chiller Start Command", 0);
// Update Operational Code depending on Free Cooling Mode
int freeCoolingState = getPointValue(equipment, "Free Cooling Mode ON");
if (freeCoolingState == 1){
setPointValue(equipment, "Sys 1 Operational Code", 82);
setPointValue(equipment, "Sys 2 Operational Code", 82);
}
else{
setPointValue(equipment, "Sys 1 Operational Code", 77);
setPointValue(equipment, "Sys 2 Operational Code", 77);
}
_applyStrategies(equipment);
return nullptr;
}

View File

@@ -60,11 +60,11 @@ RunningState<ModbusRTU>::RunningState() {
addStrategy("Sys 1 Run Hours", new TotalizerStrategy(1000));
addStrategy("Sys 2 Run Hours", new TotalizerStrategy(1000));
addStrategy("Local Leaving Temp Setpoint", new SingleValueStrategy(70.0f, 0.0f, 1000));
addStrategy("VSD Output Frequency", new SingleValueStrategy(59.0f, 1.0f, 1000));
addStrategy("Sys 1 Fan KW", new SingleValueStrategy(35.0f, 2.0f, 1000));
addStrategy("Sys 2 Fan KW", new SingleValueStrategy(23.0f, 2.0f, 1000));
addStrategy("Sys 1 Compressor KW", new SingleValueStrategy(304.0f, 5.0f, 1000));
addStrategy("Sys 2 Compressor KW", new SingleValueStrategy(198.0f, 5.0f, 1000));
}
/**
@@ -88,23 +88,23 @@ State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
updateAlarms(equipment);
updateFreeCooling(equipment);
std::vector<std::string> activeAlarmsDescriptions = {};
const std::vector<std::string> alarmDescriptions = {
"Sys 1 Alarm", "Sys 2 Alarm", "Sys 1 Fan Fault Alarm", "Sys 2 Fan Fault Alarm",
std::vector<std::string> activeFaultDescriptions = {};
const std::vector<std::string> FaultDescriptions = {
"Sys 1 Fan Fault Alarm", "Sys 2 Fan Fault Alarm"
};
// Loop through alarms, create array of active alarms and send to FailState if any alarms are active
bool alarms_active = false;
for (const auto& desc : alarmDescriptions) {
// Loop through faults, create array of active faults and send to FailState if any faults are active
bool faults_active = false;
for (const auto& desc : FaultDescriptions) {
Modbus_Point<ModbusRTU>* point = equipment->getModbus_Point(desc);
if (point->getValue() == 1) {
activeAlarmsDescriptions.push_back(desc);
alarms_active = true;
activeFaultDescriptions.push_back(desc);
faults_active = true;
}
}
if (alarms_active) return new FailState<ModbusRTU>(activeAlarmsDescriptions);
if (faults_active) return new FailState<ModbusRTU>(activeFaultDescriptions);
// If no alarms active and Start Command = 0--> send to StandbyState()
// If no faults active and Start Command = 0--> send to StandbyState()
int Chiller_Enable = getPointValue(equipment, "Chiller Start Command"); // Modscan COIL 1
if (Chiller_Enable == 0){
return new StandbyState<ModbusRTU>();
@@ -124,6 +124,17 @@ State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
static_cast<RampStrategy*>(CHW_In_strat)->setTarget(returnTemp);
}
// Update Operational Code depending on Free Cooling Mode
int freeCoolingState = getPointValue(equipment, "Free Cooling Mode ON");
if (freeCoolingState == 1){
setPointValue(equipment, "Sys 1 Operational Code", 82);
setPointValue(equipment, "Sys 2 Operational Code", 82);
}
else{
setPointValue(equipment, "Sys 1 Operational Code", 78);
setPointValue(equipment, "Sys 2 Operational Code", 78);
}
// Apply any strategies defined for the standby state
_applyStrategies(equipment);
return nullptr;

View File

@@ -55,6 +55,7 @@ StandbyState<ModbusRTU>::StandbyState() {
addStrategy("Sys 1 Compressor Pct FLA", new SingleValueStrategy(0.0f, 0.0f, 1000));
addStrategy("Sys 2 Compressor Pct FLA", new SingleValueStrategy(0.0f, 0.0f, 1000));
addStrategy("Local Leaving Temp Setpoint", new SingleValueStrategy(70.0f, 0.0f, 1000));
addStrategy("VSD Output Frequency", new SingleValueStrategy(0.0f, 0.0f, 1000));
addStrategy("Sys 1 Fan KW", new SingleValueStrategy(0.0f, 0.0f, 1000));
addStrategy("Sys 2 Fan KW", new SingleValueStrategy(0.0f, 0.0f, 1000));
addStrategy("Sys 1 Compressor KW", new SingleValueStrategy(0.0f, 0.0f, 1000));
@@ -82,7 +83,7 @@ State<ModbusRTU>* StandbyState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
std::vector<std::string> activeAlarmsDescriptions = {};
const std::vector<std::string> alarmDescriptions = {
"Sys 1 Alarm", "Sys 2 Alarm", "Sys 1 Fan Fault Alarm", "Sys 2 Fan Fault Alarm",
"Sys 1 Fan Fault Alarm", "Sys 2 Fan Fault Alarm"
};
// Loop through alarms, create array of active alarms and send to FailState if any alarms are active
@@ -102,6 +103,17 @@ State<ModbusRTU>* StandbyState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
return new RunningState<ModbusRTU>();
}
// Update Operational Code depending on Free Cooling Mode
int freeCoolingState = getPointValue(equipment, "Free Cooling Mode ON");
if (freeCoolingState == 1){
setPointValue(equipment, "Sys 1 Operational Code", 82);
setPointValue(equipment, "Sys 2 Operational Code", 82);
}
else{
setPointValue(equipment, "Sys 1 Operational Code", 77);
setPointValue(equipment, "Sys 2 Operational Code", 77);
}
// Apply any strategies defined for the standby state
_applyStrategies(equipment);
return nullptr;

View File

@@ -22,10 +22,10 @@
* @{
*/
#include <ModbusIP_ESP8266.h>
const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */
const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */
IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */
const char *ssid = "ArduinoWifiB"; /**< @brief The SSID of the WiFi network. */
const char *password = "123abc456"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(172, 17, 32, 35); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 32, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;
@@ -54,54 +54,58 @@
*/
modbusMap mb_map[] =
{
{COIL, 0, 0, "Chiller Start Command"}, // Use in Modscan - Hard IO in SCP, Used for Arduino simulation only
{COIL, 1, 0, "Sys 1 Alarm"}, // Use in Modscan - Hard IO in SCP, Used for Arduino simulation only
{COIL, 2, 0, "Sys 2 Alarm"}, // Use in Modscan - Hard IO in SCP, Used for Arduino simulation only
{COIL, 3, 0, "Sys 1 Fan Fault ON"}, // Use in Modscan - Used for Arduino simulation only
{COIL, 4, 0, "Sys 2 Fan Fault ON"}, // Use in Modscan - Used for Arduino simulation only
{COIL, 0, 1, "Chiller Start Command"}, // Use in Modscan - Hard IO in SCP, Used for Arduino simulation only. Signal should come from PLC.
{COIL, 1, 0, "Sys 1 Alarm"}, // Use in Modscan - Hard IO in SCP, Used for Arduino simulation only --> INDICATION ONLY (assumption)
{COIL, 2, 0, "Sys 2 Alarm"}, // Use in Modscan - Hard IO in SCP, Used for Arduino simulation only --> INDICATION ONLY (assumption)
{COIL, 3, 0, "Sys 1 Fan Fault ON"}, // Use in Modscan - Used for Arduino simulation only --> FAILSTATE (assumption)
{COIL, 4, 0, "Sys 2 Fan Fault ON"}, // Use in Modscan - Used for Arduino simulation only --> FAILSTATE (assumption)
{COIL, 5, 0, "Free Cooling Mode ON"}, // Use in Modscan - Used for Arduino simulation only
{DI, 0, 0, "Sys 1 Fan Fault Alarm"},
{DI, 1, 0, "Sys 2 Fan Fault Alarm"},
{DI, 65, 0, "General Alarm"}, // if any alarm is active, General Alarm = 1 --> used for INDICATION ONLY (assumption)
{DI, 174, 0, "Sys 1 Fan Fault Alarm"},
{DI, 175, 0, "Sys 2 Fan Fault Alarm"},
{IR, 130, 0, "Free Cooling Mode"},
{IR, 165, 0, "Free Cooling Valve"},
{HR, 0, 0, "Chiller Status"}, // Use in Modscan - Hard IO in SCP, Used for Arduino simulation only
{HR, 1, 0, "Chiller Temp Setpoint"}, // Use in Modscan - Hard IO in SCP, Used for Arduino simulation only
{HR, 2, 0, "Supply Temp"}, // Use in Modscan - Hard IO in SCP (PICS?), Used for Arduino simulation only
{HR, 3, 0, "Return Temp"}, // Use in Modscan - Hard IO in SCP (PICS?), Used for Arduino simulation only
{HR, 2, 0, "Supply Temp"}, // Use in Modscan - Hard IO in SCP, Used for Arduino simulation only
{HR, 3, 0, "Return Temp"}, // Use in Modscan - Hard IO in SCP, Used for Arduino simulation only
{HR, 4, 70, "System CHW Out"},
{HR, 5, 70, "System CHW In"},
{HR, 7, 0, "Sys 1 Condenser Temp"},
{HR, 9, 0, "Ambient Temp"},
{HR_10x, 7, 0, "Sys 1 Condenser Temp"},
{HR_10x, 9, 0, "Ambient Temp"},
{HR, 11, 0, "Sys 1 Oil Pressure"},
{HR, 12, 0, "Sys 1 Suction Pressure"},
{HR, 13, 0, "Sys 1 Discharge Pressure"},
{HR, 14, 0, "Sys 1 Compressor Pct FLA"},
{HR_10x, 11, 0, "Sys 1 Oil Pressure"},
{HR_10x, 12, 0, "Sys 1 Suction Pressure"},
{HR_10x, 13, 0, "Sys 1 Discharge Pressure"},
{HR_10x, 14, 0, "Sys 1 Compressor Pct FLA"},
{HR, 15, 0, "Sys 1 Run Hours"},
{HR, 16, 0, "Sys 1 Starts"},
{HR, 20, 0, "Sys 2 Oil Pressure"},
{HR, 21, 0, "Sys 2 Suction Pressure"},
{HR, 22, 0, "Sys 2 Discharge Pressure"},
{HR, 23, 0, "Sys 2 Compressor Pct FLA"},
{HR_10x, 20, 0, "Sys 2 Oil Pressure"},
{HR_10x, 21, 0, "Sys 2 Suction Pressure"},
{HR_10x, 22, 0, "Sys 2 Discharge Pressure"},
{HR_10x, 23, 0, "Sys 2 Compressor Pct FLA"},
{HR, 24, 0, "Sys 2 Run Hours"},
{HR, 25, 0, "Sys 2 Starts"},
{HR, 29, 77, "Sys 1 Operational Code"},
{HR, 30, 0, "Sys 1 Fault Code"},
{HR, 31, 77, "Sys 2 Operational Code"},
{HR, 32, 0, "Sys 2 Fault Code"},
{HR_10x, 26, 0, "VSD Output Frequency"},
{HR, 39, 0, "Local Leaving Temp Setpoint"},
{HR, 29, 77, "Sys 1 Operational Code"}, // 77:not running, 78:running, 82:free cooling
{HR, 30, 0, "Sys 1 Fault Code"}, // 56:condenser fan VSD warning
{HR, 31, 77, "Sys 2 Operational Code"}, // 77:not running, 78:running, 82:free cooling
{HR, 32, 0, "Sys 2 Fault Code"}, // 56:condenser fan VSD warning
{HR, 40, 0, "Sys 1 Fan KW"},
{HR, 41, 0, "Sys 1 Compressor KW"},
{HR, 42, 0, "Sys 2 Fan KW"},
{HR, 43, 0, "Sys 2 Compressor KW"},
{HR, 49, 0, "Sys 2 Condenser Temp"},
{HR, 50, 0, "Free Cooling Mode"},
{HR, 51, 0, "Free Cooling Valve"},
{HR, 39, 72, "Local Leaving Temp Setpoint"},
{HR_10x, 49, 0, "Sys 2 Condenser Temp"},
{HR_10x, 140, 0, "Sys 1 Fan KW"},
{HR_10x, 141, 0, "Sys 1 Compressor KW"},
{HR_10x, 142, 0, "Sys 2 Fan KW"},
{HR_10x, 143, 0, "Sys 2 Compressor KW"},
};
//Size of modbus map used in FOR cycles, automatically calculated.

View File

@@ -1,11 +1,11 @@
/**
* @file main.cpp
* @brief Main execution program for the Daikin Chiller (RTU) Emulator.
* @author Emmanuel Hernandez Cruz
* @brief Main execution program for the York YVAA Chiller (RTU) Emulator.
* @author Emmanuel Hernandez Cruz, Robert J. Davis
* @date 2025-09-02
*
* @details This file contains the main execution program for an Arduino-based
* emulator of a Daikin Chiller unit. The program communicates via the
* emulator of a York YVAA Chiller unit. The program communicates via the
* Modbus RTU protocol over a serial connection.
*
* The setup() function initializes the following:

View File

@@ -112,7 +112,6 @@ void updateAnalogs(Equipment<ModbusIP>* equipment){
else if (equipment->getModbus_Point("RA Temp High Alarm ON")->getValue()==1){
equipment->setModbus_Point("Return Air Temp", 104.0f);
}
else equipment->setModbus_Point("Return Air Temp", 74.0f);
if (equipment->getModbus_Point("RA Humidity Low Alarm ON")->getValue()==1){
equipment->setModbus_Point("Return Air Humidity", 15.0f);
@@ -120,5 +119,4 @@ void updateAnalogs(Equipment<ModbusIP>* equipment){
else if (equipment->getModbus_Point("RA Humidity High Alarm ON")->getValue()==1){
equipment->setModbus_Point("Return Air Humidity", 65.0f);
}
else equipment->setModbus_Point("Return Air Humidity", 35.0f);
}

View File

@@ -16,6 +16,7 @@
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_PID.h"
#include "Strategies/Strategy_Saw.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
@@ -39,6 +40,9 @@ FailState<ModbusIP>::FailState(const std::vector<std::string>& activeAlarms) {
// Fan speed --> 0, Run Status --> 0, Amps --> 0
addStrategy("CW Valve Position", new RampStrategy(0.0f, 5.0f, 1000));
addStrategy("Supply Air Temp", new SingleValueStrategy(74.0f, 1.0f, 1000));
addStrategy("Return Air Temp", new SingleValueStrategy(86.0f, 1.0f, 1000));
addStrategy("Return Air Humidity", new SingleValueStrategy(35.0f, 2.0f, 1000));
addStrategy("Speed Fan 1", new RampStrategy(0.0f, 10.0f, 1000));
addStrategy("Speed Fan 2", new RampStrategy(0.0f, 10.0f, 1000));
addStrategy("Speed Fan 3", new RampStrategy(0.0f, 10.0f, 1000));
@@ -57,7 +61,7 @@ FailState<ModbusIP>::FailState(const std::vector<std::string>& activeAlarms) {
addStrategy("Amps Fan 7", new RampStrategy(0.0f, 4.5f, 1000));
addStrategy("Amps Fan 8", new RampStrategy(0.0f, 4.5f, 1000));
addStrategy("Amps Fan 9", new RampStrategy(0.0f, 4.5f, 1000));
addStrategy("CRAH Heartbeat", new SawStrategy(0.0f, 60.0f, 1.0f, 1000));
}
/**
@@ -112,7 +116,7 @@ void FailState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
for (const auto& desc : motorStatusDescriptions) {
Modbus_Point<ModbusIP>* point = equipment->getModbus_Point(desc);
if (point) {
point->setValue(1);
point->setValue(0);
}
};

View File

@@ -71,11 +71,13 @@ RunningState<ModbusIP>::RunningState() {
addStrategy("Operating Hours Fan 7", new TotalizerStrategy(1000));
addStrategy("Operating Hours Fan 8", new TotalizerStrategy(1000));
addStrategy("Operating Hours Fan 9", new TotalizerStrategy(1000));
addStrategy("Supply Air Temp", new SawStrategy(60.0f, 100.0f, 2.0f, 1000)); // Won't initialize at lower bound; always initializes at 0 b/c FLOAT; initialize manually via Modscan
addStrategy("Return Air Temp", new SawStrategy(70.0f, 80.0f, 1.0f, 1000));
addStrategy("Supply Air Temp", new SawStrategy(60.0f, 100.0f, 2.2f, 1000)); // Won't initialize at lower bound; always initializes at 0 b/c FLOAT; initialize manually via Modscan
addStrategy("Return Air Humidity", new SawStrategy(25.0f, 40.0f, 1.1f, 1000));
addStrategy("Return Air Temp", new SawStrategy(70.0f, 80.0f, 0.8f, 1000));
addStrategy("Filter Differential Pressure", new SawStrategy(0.0f, 5.0f, 0.2f, 1000));
addStrategy("CW Valve Position", new PIDStrategy("Supply Air Temp Setpoint", 1000, "Supply Air Temp")); // SAT must be greater than SAT Setpoint for this PID to work.
addStrategy("CRAH Heartbeat", new SawStrategy(0.0f, 60.0f, 1.0f, 1000));
addStrategy("Fan Speed Feedback", new RampStrategy(0.0f, 1.0f, 200));
}
/**
@@ -141,6 +143,12 @@ State<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment)
}
}
// Fan Speed Feedback dynamically ramp to Fan Speed Setpoint sent to Arduino
Strategy_Behavior* speedFeedback = getStrategy("Fan Speed Feedback");
if (speedFeedback){
static_cast<RampStrategy*>(speedFeedback)->setTarget(BMS_Speed_Setpoint);
}
// Apply any strategies defined for the standby state
_applyStrategies(equipment);
return nullptr;
@@ -168,7 +176,7 @@ void RunningState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
for (const auto& desc : motorStatusDescriptions) {
Modbus_Point<ModbusIP>* point = equipment->getModbus_Point(desc);
if (point) {
point->setValue(0);
point->setValue(1);
}
}
}
@@ -193,7 +201,7 @@ void RunningState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
for (const auto& desc : motorStatusDescriptions) {
Modbus_Point<ModbusIP>* point = equipment->getModbus_Point(desc);
if (point) {
point->setValue(1);
point->setValue(0);
}
}
}

View File

@@ -41,8 +41,9 @@ StandbyState<ModbusIP>::StandbyState() {
// You can add initialization code here if needed.
// These strategies are applied at the end of the update function.
addStrategy("CW Valve Position", new RampStrategy(0.0f, 5.0f, 1000));
addStrategy("Supply Air Temp", new RampStrategy(74.0f, 1.0f, 1000));
addStrategy("Return Air Temp", new RampStrategy(86.0f, 1.0f, 1000));
addStrategy("Supply Air Temp", new SingleValueStrategy(74.0f, 1.0f, 1000));
addStrategy("Return Air Temp", new SingleValueStrategy(86.0f, 1.0f, 1000));
addStrategy("Return Air Humidity", new SingleValueStrategy(35.0f, 2.0f, 1000));
addStrategy("Speed Fan 1", new RampStrategy(0.0f, 10.0f, 1000));
addStrategy("Speed Fan 2", new RampStrategy(0.0f, 10.0f, 1000));
addStrategy("Speed Fan 3", new RampStrategy(0.0f, 10.0f, 1000));
@@ -61,7 +62,7 @@ StandbyState<ModbusIP>::StandbyState() {
addStrategy("Amps Fan 7", new RampStrategy(0.0f, 4.5f, 1000));
addStrategy("Amps Fan 8", new RampStrategy(0.0f, 4.5f, 1000));
addStrategy("Amps Fan 9", new RampStrategy(0.0f, 4.5f, 1000));
addStrategy("CRAH Heartbeat", new SawStrategy(0.0f, 60.0f, 1.0f, 1000));
}
/**
@@ -125,7 +126,7 @@ void StandbyState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
for (const auto& desc : motorStatusDescriptions) {
Modbus_Point<ModbusIP>* point = equipment->getModbus_Point(desc);
if (point) {
point->setValue(1);
point->setValue(0);
}
};

View File

@@ -21,10 +21,10 @@
* @{
*/
#include <ModbusIP_ESP8266.h>
const char *ssid = "TP-Link_D91A"; /**< @brief The SSID of the WiFi network. */
const char *password = "52761492"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */
IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */
const char *ssid = "ArduinoWifiB"; /**< @brief The SSID of the WiFi network. */
const char *password = "123abc456"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(172, 17, 32, 62); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 32, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;
@@ -99,15 +99,15 @@ modbusMap mb_map[] =
{IR, 50, 0, "Alarm Fan 7"},
{IR, 54, 0, "Alarm Fan 8"},
{IR, 58, 0, "Alarm Fan 9"},
{IR, 27, 1, "Run Status Fan 1"}, // Send to PLC
{IR, 31, 1, "Run Status Fan 2"}, // Send to PLC
{IR, 35, 1, "Run Status Fan 3"}, // Send to PLC
{IR, 39, 1, "Run Status Fan 4"}, // Send to PLC
{IR, 43, 1, "Run Status Fan 5"}, // Send to PLC
{IR, 47, 1, "Run Status Fan 6"}, // Send to PLC
{IR, 51, 1, "Run Status Fan 7"}, // Send to PLC
{IR, 55, 1, "Run Status Fan 8"}, // Send to PLC
{IR, 59, 1, "Run Status Fan 9"}, // Send to PLC
{IR, 27, 0, "Run Status Fan 1"}, // Send to PLC
{IR, 31, 0, "Run Status Fan 2"}, // Send to PLC
{IR, 35, 0, "Run Status Fan 3"}, // Send to PLC
{IR, 39, 0, "Run Status Fan 4"}, // Send to PLC
{IR, 43, 0, "Run Status Fan 5"}, // Send to PLC
{IR, 47, 0, "Run Status Fan 6"}, // Send to PLC
{IR, 51, 0, "Run Status Fan 7"}, // Send to PLC
{IR, 55, 0, "Run Status Fan 8"}, // Send to PLC
{IR, 59, 0, "Run Status Fan 9"}, // Send to PLC
{IR, 25, 0, "Speed Fan 1"},
{IR, 29, 0, "Speed Fan 2"},
{IR, 33, 0, "Speed Fan 3"},
@@ -136,6 +136,7 @@ modbusMap mb_map[] =
{IR_FLOAT, 75, 0, "Amps Fan 7"},
{IR_FLOAT, 77, 0, "Amps Fan 8"},
{IR_FLOAT, 79, 0, "Amps Fan 9"},
{IR_FLOAT, 99, 0, "CRAH Heartbeat"},
{HR_FLOAT, 13, 0, "Fan Speed Setpoint"}, // Receive signal from PLC
{HR_FLOAT, 17, 0, "Supply Air Temp Setpoint"}, // Receive signal from PLC
@@ -143,7 +144,8 @@ modbusMap mb_map[] =
{HR_FLOAT, 23, 0, "Fan Max Speed"}, // Send to PLC
{HR, 25, 0, "BMS Control Source"}, // Receive signal from PLC 0:Speed, 1:Room Temp
{HR, 26, 2, "BMS Enable Source"}, // Receive signal from PLC 0:Keypad, 1:DI, 2:BMS
{HR, 99, 0, "CRAH Heartbeat"} // Placeholder - we don't have this from UMAS yet. Not used in logic yet.
{HR_FLOAT, 28, 0, "Fan Speed Feedback"},
{HR_FLOAT, 99, 0, "PLC Heartbeat"}, // This will be seconds from PLC - if doesn't change for 15 seconds set BMS Enable Source to Local (0)
};
//Size of modbus map used in FOR cycles, automatically calculated.

View File

@@ -0,0 +1,58 @@
# CRAH Liebert 80 125 SLAB TCP
## Brief Introduction
This version of the LIEBERT 80 SLAB Electrical Gallery CRAH has different registers from the existing
"CRAH_LIEBERT_80_125_SLAB_TCP" code, hence a new instance was created. The logic in this code is also
unique from the existing LIEBERT_80_125 CRAH unit.
This implementation assumes that on/off control and supply, return air temp setpoints are sent to CRAH unit
from Ignition- there is not an associated PLC program.
## List of Equipment
This configuration has been used for these models:
* **PHX3 Liebert CW084DC1A1SDM7 SLAB**: 10-27-25
## Hardware Prerequisites
The code is written for an ESP8266/ESP32-style microcontroller with WiFi capabilities.
* **Microcontroller**: [Firebeetle 2 ESP32.](https://www.dfrobot.com/product-2231.html)
---
## States and Strategies
On/Off Control by Coil 25
Supply Air Temp Setpoint used for PID control of Fluid Control Valves 1&2
Return Air Temp Setpoint used for PID control of Fan Speed
Unsure of difference between Fluid Control Valves 1 & 2, for this simulation they are assumed to operate the same
We have reached out to vendor for clarification of these two valves.
### Standby State
* **Unit Status**: set to 2 (standby)
* **Free Cool Status**: set to 1 whenever in Standby Mode - Assuming whenever in Standby Mode will operate in Free Cooling mode
* **Fan Speed**: ramp to 0
* **Return Humidity**: saw 0 to 80, increments of 5
* **Return Air Temp**: single value 80 +/- 1
* **Supply Air Temp**: single value 80 +/- 1
* **Supply Air Flow**: ramp to 0
* **Fluid Control Valve Position 1**: ramp to 0
* **Fluid Control Valve Position 2**: ramp to 0
### Running State
* **Unit Status, Supply Fan Status, Cooling Status**: set to 1
* **Return Humidity**: saw 0 to 80, increments of 5 (same as Standby Mode)
* **Return Air Temp**: saw 62 to 110, increments of 2
* **Supply Air Temp**: saw 64 to 86, increments of 1
* **Supply Air Flow**: saw 7 to 10, increments of 1
* **Fan Speed**: PID control (Return Air Temp Setpoint, Return Air Temp)
* **Fluid Control Valve Position 1**: PID control (Supply Air Temp Setpoint, Supply Air Temp)
* **Fluid Control Valve Position 2**: PID control (Supply Air Temp Setpoint, Supply Air Temp)
### Fail State
* **Unit Status**: set to 0 (off)
* **Free Cool Status**: set to 0
* **Fan Speed**: ramp to 0
* **Return Humidity**: saw 0 to 80, increments of 5
* **Return Air Temp**: single value 80 +/- 1
* **Supply Air Temp**: single value 80 +/- 1
* **Supply Air Flow**: ramp to 0
* **Fluid Control Valve Position 1**: ramp to 0
* **Fluid Control Valve Position 2**: ramp to 0

View File

@@ -0,0 +1,99 @@
/**
* @file StateUtils.cpp
* @brief Implementation of the StateUtils class.
* @author Robert J. Davis
* @date 2025-10-24
*
* This file contains implementation of utility functions that are used in multiple States.
*/
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_Random.h"
#include "Strategies/Strategy_Saw.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_Square.h"
#include "Strategies/Strategy_PID.h"
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include "Equipment/Equipment.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "States/State.h"
#include "StateUtils.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief This function will update the Alarm status DI bits according to the Alarm Commands from Coils (Modscan)
* It will also update the Common Alarm: if any alarm is active, the Common alarm will also be active.
*
* This is a function used in the update() of the Standby, Running, and Fail States.
*
*/
void updateAlarms(Equipment<ModbusIP>* equipment){
const std::vector<std::string> alarmDescriptions = {
"Alarm Fan Overload", "Alarm Loss of Air", "Alarm Compressor 1A Overload", "Alarm Compressor 2A Overload",
"Alarm Smoke Detected", "Alarm Water Detected", "Alarm Standby Unit On", "Alarm CP High Water",
"Alarm Room Sensor Failure", "Alarm Power Loss", "Alarm High Return Air Temp", "Alarm Low Return Air Temp",
"Alarm High Return Humidity", "Alarm Low Return Humidity", "Alarm Clogged Filter", "Alarm Supply Sensor Failure",
"Alarm Unit Network Failure", "Alarm High Supply Temp", "Alarm Low Supply Temp", "Alarm Compressor 1 Short Cycle",
"Alarm Compressor 2 Short Cycle", "Alarm Fan Failure", "Alarm Circuit 1 Low Pressure", "Alarm Circuit 2 Low Pressure",
"Alarm Circuit 1 High Pressure", "Alarm Circuit 2 High Pressure", "Alarm High Return Air Dew Point",
"Alarm Low Return Air Dew Point", "Alarm Compressor 1 Over Temp", "Alarm Compressor 2 Over Temp",
"Common Alarm", "Alarm Pump Failure", "Alarm Comm Loss Condenser 1", "Alarm Comm Loss Condenser 2",
"Alarm Compressor 1B Overload", "Alarm Compressor 2B Overload"
};
const std::vector<std::string> alarmCommands = {
"Alarm Fan Overload ON", "Alarm Loss of Air ON", "Alarm Compressor 1A Overload ON", "Alarm Compressor 2A Overload ON",
"Alarm Smoke Detected ON", "Alarm Water Detected ON", "Alarm Standby Unit On ON", "Alarm High Water ON",
"Alarm Room Sensor Failure ON", "Alarm Power Loss ON", "Alarm High Return Air Temp ON", "Alarm Low Return Air Temp ON",
"Alarm High Return Humidity ON", "Alarm Low Return Humidity ON", "Alarm Clogged Filter ON", "Alarm Supply Sensor Failure ON",
"Alarm Unit Network Failure ON", "Alarm High Supply Temp ON", "Alarm Low Supply Temp ON", "Alarm Compressor 1 Short Cycle ON",
"Alarm Compressor 2 Short Cycle ON", "Alarm Fan Failure ON", "Alarm Circuit 1 Low Pressure ON", "Alarm Circuit 2 Low Pressure ON",
"Alarm Circuit 1 High Pressure ON", "Alarm Circuit 2 High Pressure ON", "Alarm High Return Air Dew Point ON",
"Alarm Low Return Air Dew Point ON", "Alarm Compressor 1 Over Temp ON", "Alarm Compressor 2 Over Temp ON",
"Common Alarm ON", "Alarm Pump Failure ON", "Alarm Comm Loss Condenser 1 ON", "Alarm Comm Loss Condenser 2 ON",
"Alarm Compressor 1B Overload ON", "Alarm Compressor 2B Overload ON"
};
int numAlarms = 0;
for (int i =0; i< alarmCommands.size() && i < alarmDescriptions.size(); ++i) {
Modbus_Point<ModbusIP>* commandPoint = equipment->getModbus_Point(alarmCommands[i]);
Modbus_Point<ModbusIP>* alarmPoint = equipment->getModbus_Point(alarmDescriptions[i]);
if (commandPoint) {
alarmPoint->setValue(commandPoint->getValue());
if (alarmPoint->getValue() == 1) numAlarms++;
}
}
if (numAlarms >= 1) equipment->setModbus_Point("Common Alarm", 1);
else equipment->setModbus_Point("Common Alarm", 0);
}
/**
* @brief Updates Dehumidifier Mode
*
* This function will update the Dehumidifier Mode based on Dehumidifier Mode Command (Coil 1)
* received from Modscan. This is for simulation purposes only - in practice, the Chiller
* will transition to Dehumidifier mode based on its own internal logic.
*
* For ease of testing, this is a function used in the update() of the Standby, Running, and Fail States.
*
*/
void updateDehumidifier(Equipment<ModbusIP>* equipment){
Modbus_Point<ModbusIP>* DehumidifierCommand = equipment->getModbus_Point("Dehumidifier Mode ON");
Modbus_Point<ModbusIP>* DehumidifierStatus = equipment->getModbus_Point("Dehumidifier Status");
if (DehumidifierCommand->getValue() == 1) {
DehumidifierStatus->setValue(1);
}
else {
DehumidifierStatus->setValue(0);
}
}

View File

@@ -0,0 +1,43 @@
/**
* @file config.h
* @brief StateUtils class
* @author Robert J Davis
* @date 2025-10-24
*
* Defines the StateUtils class, which contains utility functions used in multiple States.
*/
#pragma once
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include "Equipment/Equipment.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "States/State.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
template <typename T>
class State;
/**
* @brief Checks common alarms (non-fail alarms) and updates the Common Alarm Modbus point.
* @param equipment Pointer to the Equipment instance.
* @return void
*/
void updateAlarms(Equipment<ModbusIP>* equipment);
/**
* @brief Checks Dehumidifier Mode ON from Modscan (Coil 1) and updates the Dehumidifier Status point.
* @param equipment Pointer to the Equipment instance.
* @return void
*/
void updateDehumidifier(Equipment<ModbusIP>* equipment);

View File

@@ -0,0 +1,99 @@
/**
* @file State_Fail.cpp
* @brief Implementation of the FailState class.
* @author Robert J Davis
* @date 2025-10-24
*
* This file contains the implementation for the FailState, which defines
* the behavior of the equipment when it has entered a fault condition.
*/
#include "ModbusPoints/Modbus_Point.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_Saw.h"
#include "Strategies/Strategy_PID.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "StateUtils.h"
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief Constructs a new FailState object with a list of active alarms.
*
* This constructor ramps Fan Speed, Supply Air Flow, and Fluid Control Valves to 0.
* Return Humidity continues to saw between 0-80 (for sake of Ignition display verification)
* Return and Supply Air Temp is 80 +/- 1
*
*/
template<>
FailState<ModbusIP>::FailState(const std::vector<std::string>& activeAlarms) {
addStrategy("Fan Speed", new RampStrategy(0.0f, 10.0f, 1000));
addStrategy("Return Humidity", new SawStrategy(0.0f, 80.0f, 5.0f, 1000));
addStrategy("Return Air Temp", new SingleValueStrategy(80.0f, 1.0f, 1000));
addStrategy("Supply Air Temp", new SingleValueStrategy(80.0f, 1.0f, 1000));
addStrategy("Supply Air Flow", new RampStrategy(0.0f, 1.0f, 1000));
addStrategy("Fluid Control Valve Position 1", new RampStrategy(0.0f, 5.0f, 1000));
addStrategy("Fluid Control Valve Position 2", new RampStrategy(0.0f, 5.0f, 1000));
}
/**
* @brief Executes the fail state's logic for one update cycle.
*
* My programming logic: ensure System On/Off Control is always set to 0. This will ensure
* that after the fault is cleared, the unit will enter StandbyMode and will then be commanded
* by Operator to starts, rather than automatically restarting. This is my assumption for the sake
* of testing, actual implementation may be different.
*
* The only way to exit FailState is for the Smoke Detect and High Water alarms to be cleared.
* Upon exiting FailState, the unit will enter StandbyState.
*
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusIP>* FailState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Fail update function");
setPointValue(equipment, "System On/Off Control", 0); // my programming logic: when clear fault, should be sent to Standby Mode
updateAlarms(equipment);
updateDehumidifier(equipment); // Dehumidifier mode can be toggled while in FailState (for ease of Ignition HMI verification)
bool smokeDetectState = getPointValue(equipment, "Alarm Smoke Detected");
bool highWaterState = getPointValue(equipment, "Alarm CP High Water");
if (smokeDetectState == false && highWaterState == false){
return new StandbyState<ModbusIP>();
}
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the fail state.
* Sets the Unit Status, Supply Fan Status, Cooling Status, and Free Cooling Status to 0 (off).
* @param equipment Pointer to the Equipment instance.
*/
template<>
void FailState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
setPointValue(equipment, "Unit Status", 0);
setPointValue(equipment, "Supply Fan Status", 0);
setPointValue(equipment, "Cooling Status", 0);
setPointValue(equipment, "Free Cooling Status", 0);
}
/**
* @brief Logic to execute once when exiting the fail state.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void FailState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
// Cleanup logic to run when the equipment leaves this state
Serial.println("Exit Fail State...");
}

View File

@@ -0,0 +1,134 @@
/**
* @file State_Running.cpp
* @brief Implementation of the RunningState class.
* @author Robert J Davis
* @date 2025-10-24
*
* This file contains the implementation for the RunningState, which defines
* the behavior of the equipment when it is actively running.
*/
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_Random.h"
#include "Strategies/Strategy_Saw.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_Square.h"
#include "Strategies/Strategy_PID.h"
#include "Strategies/Strategy_Totalizer.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "States/State.h"
#include "StateUtils.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief Constructs a new RunningState object.
*
* This constructor initializes behavior strategies active during the running state.
* Return Air Temp saws between 66 and 110 to cover both low alarm and high alarm states (72 and 100).
* Supply Air Temp saws between 68 and 86 to cover both low alarm and high alarm states (72 and 78).
* Supply Air Flow saws between 7 to 10 (for Ignition HMI verification, no correlation to expected values).
* Fan Speed adjusts via PID on Return Air Temp Setpoint (note: PID parameters are set in base code, can't be adjusted)
* Fluid Control Valve Positions adjust via PID on Supply Air Temp Setpoint.
* Unsure of the difference between FCV 1 and 2, therefore they just match for the sake of testing.
*
*/
template<>
RunningState<ModbusIP>::RunningState() {
addStrategy("Return Humidity", new SawStrategy(0.0f, 80.0f, 5.0f, 1000));
addStrategy("Return Air Temp", new SawStrategy(66.0f, 110.0f, 2.0f, 1000));
addStrategy("Supply Air Temp", new SawStrategy(68.0f, 86.0f, 1.0f, 1000));
addStrategy("Supply Air Flow", new SawStrategy(7.0f, 10.0f, 1.0f, 1000));
addStrategy("Fan Speed", new PIDStrategy("Return Air Temp Setpoint", 1000, "Return Air Temp"));
addStrategy("Fluid Control Valve Position 1", new PIDStrategy("Supply Air Temp Setpoint", 1000, "Supply Air Temp"));
addStrategy("Fluid Control Valve Position 2", new PIDStrategy("Supply Air Temp Setpoint", 1000, "Supply Air Temp"));
}
/**
* @brief Executes the running state's logic for one update cycle.
*
* This method first checks for state transition commands:
* 1. Updates Alarm states
* 2. Updates Dehumidifier mode (for ease of Ignition verification)
* If the Smoke Detected or High Water alarms annunciate, send to FailState.
*
* 3. Check if On/Off Command = 0, then send to Standby State.
*
* If no transition occurs, it applies the strategies defined for the running state.
*
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
Serial.println("Running update function");
updateAlarms(equipment);
updateDehumidifier(equipment);
bool smokeDetect = getPointValue(equipment, "Alarm Smoke Detected");
bool highWater = getPointValue(equipment, "Alarm CP High Water");
std::vector<std::string> activeFailAlarms;
if (smokeDetect) activeFailAlarms.push_back("Alarm Smoke Detected");
if (highWater) activeFailAlarms.push_back("Alarm CP High Water");
if (!activeFailAlarms.empty()){
return new FailState<ModbusIP>(activeFailAlarms);
}
int On_Off_Command = getPointValue(equipment, "System On/Off Control");
if (On_Off_Command == 0){
return new StandbyState<ModbusIP>();
}
// Due to 10x scaling of Supply and Return Air Temps, need to adjust for PID strategies
float returnTemp = getPointValue(equipment, "Return Air Temp")/10;
float supplyTemp = getPointValue(equipment, "Supply Air Temp")/10;
float returnTempSP = getPointValue(equipment, "Return Air Temp Setpoint");
float supplyTempSP = getPointValue(equipment, "Supply Air Temp Setpoint");
Strategy_Behavior* FluidControlValve1_strat = getStrategy("Fluid Control Valve Position 1");
Strategy_Behavior* FluidControlValve2_strat = getStrategy("Fluid Control Valve Position 2");
Strategy_Behavior* FanSpeed_strat = getStrategy("Fan Speed");
static_cast<PIDStrategy*>(FluidControlValve1_strat)->setLimits(supplyTempSP, supplyTemp);
static_cast<PIDStrategy*>(FluidControlValve2_strat)->setLimits(supplyTempSP, supplyTemp);
static_cast<PIDStrategy*>(FanSpeed_strat)->setLimits(returnTempSP, returnTemp);
// Apply any strategies defined for the standby state
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the running state.
* Sets the Unit Status, Supply Fan Status, Cooling Status, and Free Cooling Status to 1 to indicate they are active.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void RunningState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
// Logic to run when the equipment enters this state
setPointValue(equipment, "Unit Status", 1);
setPointValue(equipment, "Supply Fan Status", 1);
setPointValue(equipment, "Cooling Status", 1);
setPointValue(equipment, "Free Cooling Status", 0);
}
/**
* @brief Logic to execute once when exiting the running state.
* All State transitions are executed on enterState function, therefore
* this exitState function is not used.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void RunningState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
// Cleanup logic to run when the equipment leaves this state
}

View File

@@ -0,0 +1,117 @@
/**
* @file State_Standby.cpp
* @brief Implementation of the StandbyState class.
* @author Robert J Davis
* @date 2025-10-24
*
* This file contains the implementation for the StandbyState, which defines
* the behavior of the equipment when it is in an idle or standby mode.
*/
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_Random.h"
#include "Strategies/Strategy_Saw.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_Square.h"
#include "Strategies/Strategy_PID.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "States/State.h"
#include "StateUtils.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief Constructs a new StandbyState object.
*
* In this state, the equipment is idle. This constructor initializes strategies
* to bring the system to a safe, idle condition.
* It ramps Fan Speed, Supply Air Flow, and Fluid Control Valves to 0.
* Return Humidity continues to saw between 0-80 (for sake of Ignition display verification)
* Return and Supply Air Temp is 80 +/- 1.
*/
template<>
StandbyState<ModbusIP>::StandbyState() {
addStrategy("Fan Speed", new RampStrategy(0.0f, 10.0f, 1000));
addStrategy("Return Humidity", new SawStrategy(0.0f, 80.0f, 5.0f, 1000));
addStrategy("Return Air Temp", new SingleValueStrategy(80.0f, 1.0f, 1000));
addStrategy("Supply Air Temp", new SingleValueStrategy(80.0f, 1.0f, 1000));
addStrategy("Supply Air Flow", new RampStrategy(0.0f, 1.0f, 1000));
addStrategy("Fluid Control Valve Position 1", new RampStrategy(0.0f, 5.0f, 1000));
addStrategy("Fluid Control Valve Position 2", new RampStrategy(0.0f, 5.0f, 1000));
}
/**
* @brief Executes the standby state's logic for one update cycle.
*
* This method first checks for state transition commands:
* 1. Updates Alarm states
* 2. Updates Dehumidifier mode (for ease of Ignition verification)
* If the Smoke Detected or High Water alarms annunciate, send to FailState.
*
* 3. Check if On/Off Command = 1, then send to Running State.
*
* If no transition occurs, it applies the strategies defined for the standby state.
*
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusIP>* StandbyState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Standby update function");
updateAlarms(equipment);
updateDehumidifier(equipment);
bool smokeDetect = getPointValue(equipment, "Alarm Smoke Detected");
bool highWater = getPointValue(equipment, "Alarm CP High Water");
std::vector<std::string> activeFailAlarms;
if (smokeDetect == true) activeFailAlarms.push_back("Alarm Smoke Detected");
if (highWater == true) activeFailAlarms.push_back("Alarm CP High Water");
if (!activeFailAlarms.empty()){
return new FailState<ModbusIP>(activeFailAlarms);
}
int On_Off_Command = getPointValue(equipment, "System On/Off Control");
if (On_Off_Command == 1){
return new RunningState<ModbusIP>();
}
// Apply any strategies defined for the standby state
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the standby state.
* Sets the Unit Status = 2 (standby) and Free Cooling Status to 1 (assume whenever in Standby Mode, runs in Free Cooling)
* Supply Fan Status, Cooling Status, Dehumidifier Status, and On/Off Command set to 0.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void StandbyState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
// Set all Unit Status to 2 (standby), ensure On Off Command also set to 0.
setPointValue(equipment, "Unit Status", 2);
setPointValue(equipment, "Supply Fan Status", 0);
setPointValue(equipment, "Cooling Status", 0);
setPointValue(equipment, "Free Cooling Status", 1);
setPointValue(equipment, "Dehumidifier Status", 0);
setPointValue(equipment, "System OnOff Control", 0);
}
/**
* @brief Logic to execute once when exiting the standby state.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void StandbyState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
// Cleanup logic to run when the equipment leaves this state
Serial.println("Exit Standby State...");
}

View File

@@ -0,0 +1,161 @@
/**
* @file config.h
* @brief Main configuration file for the Electrical Gallery CRAH Unit (TCP) emulator - Vertiv Liebert 80 Slab TCP PHX3 DC1
* @author Robert J Davis
* @date 2025-10-24
*
* This file contains two important configurations: WiFi network parameters
* and the Modbus register map for the device.
*/
#ifndef CONFIG_H
#define CONFIG_H
#include "core.h"
#include "Equipment/Equipment.h"
#if defined(USE_MODBUS_IP)
/**
* @defgroup ModbusTCPConfig Modbus IP Configuration
* @brief Parameters for Modbus TCP communication.
* @{
*/
const char *ssid = "ArduinoWifiB"; /**< @brief The SSID of the WiFi network. */
const char *password = "123abc456"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(172, 17, 32, 66); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 32, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;
#else
/**
* @defgroup ModbusRTUConfig Modbus RTU Configuration
* @brief Parameters for serial Modbus RTU communication.
* @{
*/
#include <ModbusRTU.h>
const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */
const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */
const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */
const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */
const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */
/** @} */
/** @brief Global instance of the Modbus RTU server. */
ModbusRTU mb;
#endif
/**
* @defgroup ModbusMapConfig Modbus Map Configuration
* @brief Defines the Modbus register map and related parameters for the emulator.
* @{
*/
/**
* @brief The Modbus map for the Equipment device.
* This array defines all the Modbus points available on the emulated device.
* The `description` field is crucial as it's used to look up points within the application logic.
*/
modbusMap mb_map[] =
{
{COIL, 0, 0, "Dehumidifier Mode ON"}, // For Arduino testing only
{COIL, 1, 0, "Alarm Smoke Detected ON"}, // For Arduino testing only - will send to FailState
{COIL, 2, 0, "Alarm High Water ON"}, // For Arduino testing only - will send to FailState
{COIL, 3, 0, "Alarm Fan Overload ON"}, // For Arduino testing only
{COIL, 4, 0, "Alarm Loss of Air ON"}, // For Arduino testing only
{COIL, 5, 0, "Alarm Compressor 1A Overload ON"}, // For Arduino testing only
{COIL, 6, 0, "Alarm Compressor 2A Overload ON"}, // For Arduino testing only
{COIL, 7, 0, "Alarm Water Detected ON"}, // For Arduino testing only
{COIL, 8, 0, "Alarm Standby Unit On ON"}, // For Arduino testing only
{COIL, 9, 0, "Alarm Room Sensor Failure ON"}, // For Arduino testing only
{COIL, 10, 0, "Alarm Power Loss ON"}, // For Arduino testing only
{COIL, 11, 0, "Alarm Clogged Filter ON"}, // For Arduino testing only
{COIL, 12, 0, "Alarm Supply Sensor Failure ON"}, // For Arduino testing only
{COIL, 13, 0, "Alarm Unit Network Failure ON"}, // For Arduino testing only
{COIL, 14, 0, "Alarm Compressor 1 Short Cycle ON"}, // For Arduino testing only
{COIL, 15, 0, "Alarm Compressor 2 Short Cycle ON"}, // For Arduino testing only
{COIL, 16, 0, "Alarm Fan Failure ON"}, // For Arduino testing only
{COIL, 17, 0, "Alarm Circuit 1 Low Pressure ON"}, // For Arduino testing only
{COIL, 18, 0, "Alarm Circuit 2 Low Pressure ON"}, // For Arduino testing only
{COIL, 19, 0, "Alarm Circuit 1 High Pressure ON"}, // For Arduino testing only
{COIL, 20, 0, "Alarm Circuit 2 High Pressure ON"}, // For Arduino testing only
{COIL, 21, 0, "Alarm High Return Air Dew Point ON"}, // For Arduino testing only
{COIL, 22, 0, "Alarm Low Return Air Dew Point ON"}, // For Arduino testing only
{COIL, 23, 0, "Common Alarm ON"}, // For Arduino testing only
{COIL, 24, 0, "System On/Off Control"},
{COIL, 25, 0, "Alarm Compressor 1 Over Temp ON"}, // For Arduino testing only
{COIL, 26, 0, "Alarm Compressor 2 Over Temp ON"}, // For Arduino testing only
{COIL, 27, 0, "Alarm Pump Failure ON"}, // For Arduino testing only
{COIL, 28, 0, "Alarm Comm Loss Condenser 1 ON"}, // For Arduino testing only
{COIL, 29, 0, "Alarm Comm Loss Condenser 2 ON"}, // For Arduino testing only
{COIL, 30, 0, "Alarm Compressor 1B Overload ON"}, // For Arduino testing only
{COIL, 31, 0, "Alarm Compressor 2B Overload ON"}, // For Arduino testing only
{DI, 24, 0, "Supply Fan Status"},
{DI, 25, 0, "Cooling Status"},
{DI, 26, 0, "Free Cooling Status"},
{DI, 30, 0, "Dehumidifier Status"},
{DI, 33, 0, "Alarm Fan Overload"},
{DI, 34, 0, "Alarm Loss of Air"},
{DI, 38, 0, "Alarm Compressor 1A Overload"},
{DI, 42, 0, "Alarm Compressor 2A Overload"},
{DI, 46, 0, "Alarm Smoke Detected"},
{DI, 47, 0, "Alarm Water Detected"},
{DI, 50, 0, "Alarm Standby Unit On"},
{DI, 51, 0, "Alarm CP High Water"},
{DI, 52, 0, "Alarm Room Sensor Failure"},
{DI, 60, 0, "Alarm Power Loss"},
{DI, 66, 0, "Alarm High Return Air Temp"}, // 100 set in Ignition
{DI, 67, 0, "Alarm Low Return Air Temp"}, // 72 set in Ignition
{DI, 68, 0, "Alarm High Return Humidity"}, // 60 set in Ignition
{DI, 69, 0, "Alarm Low Return Humidity"}, // 20 set in Ignition
{DI, 75, 0, "Alarm Clogged Filter"},
{DI, 76, 0, "Alarm Supply Sensor Failure"},
{DI, 91, 0, "Alarm Unit Network Failure"},
{DI, 208, 0, "Alarm High Supply Temp"}, // 78 set in Ignition
{DI, 209, 0, "Alarm Low Supply Temp"}, // 72 set in Ignition
{DI, 211, 0, "Alarm Compressor 1 Short Cycle"},
{DI, 212, 0, "Alarm Compressor 2 Short Cycle"},
{DI, 217, 0, "Alarm Fan Failure"},
{DI, 239, 0, "Alarm Circuit 1 Low Pressure"},
{DI, 240, 0, "Alarm Circuit 2 Low Pressure"},
{DI, 241, 0, "Alarm Circuit 1 High Pressure"},
{DI, 242, 0, "Alarm Circuit 2 High Pressure"},
{DI, 344, 0, "Alarm High Return Air Dew Point"},
{DI, 345, 0, "Alarm Low Return Air Dew Point"},
{DI, 348, 0, "Alarm Compressor 1 Over Temp"},
{DI, 349, 0, "Alarm Compressor 2 Over Temp"},
{DI, 350, 0, "Common Alarm"},
{DI, 491, 0, "Alarm Pump Failure"},
{DI, 682, 0, "Alarm Comm Loss Condenser 1"},
{DI, 683, 0, "Alarm Comm Loss Condenser 2"},
{DI, 740, 0, "Alarm Compressor 1B Overload"},
{DI, 741, 0, "Alarm Compressor 2B Overload"},
{IR, 99, 0, "Unit Status"}, // 0:off, 1:on, 2:standby
{IR, 102, 0, "Fan Speed"},
{IR_10x, 129, 0, "Return Humidity"},
{IR_10x, 742, 0, "Return Air Temp"},
{IR_10x, 743, 0, "Supply Air Temp"},
{IR, 1465, 0, "Supply Air Flow"},
{IR, 2050, 0, "Fluid Control Valve Position 1"},
{IR, 2051, 0, "Fluid Control Valve Position 2"},
{HR, 732, 73, "Supply Air Temp Setpoint"},
{HR, 753, 80, "Return Air Temp Setpoint"},
};
//Size of modbus map used in FOR cycles, automatically calculated.
/**
* @brief The total number of entries in the `mb_map` array.
* This is calculated at compile time and used for iterating over the map.
*/
const int map_size = sizeof(mb_map) / sizeof(mb_map[0]);
/** @brief The main loop update interval in milliseconds. */
int interval = 250;
/** @} */ // End of ModbusMapConfig group
#endif // CONFIG_H

View File

@@ -0,0 +1,51 @@
# Humidifier Dri-Steem RTS RX-36-1 TCP
## Brief Introduction
This humidifier receives on/off commands and RH Setpoint from the PLC.
The Space RH register is not used, since there will not be a Space RH sensor wired to the HUM unit.
The RH Setpoint will be determined based on dewpoints in the datahall. See QTS SOO for details.
## List of Equipment
This configuration has been used for these models:
* **RTS RX-36-1**: 10-28-2025
## Hardware Prerequisites
The code is written for an ESP8266/ESP32-style microcontroller with WiFi capabilities.
* **Microcontroller**: [Firebeetle 2 ESP32.](https://www.dfrobot.com/product-2231.html)
---
## States and Strategies
Provide a brief description of what variables and strategies were used in this configuraiton
### Standby State
Run Mode = 3 (system standby)
Duct RH = 35 +/- 5
Fill Valve, Drain Valve = 0
Steam Demand Mass/Pct = 0
Steam Output Mass/Pct = 0
If any alarms active or safety interlock = 0 --> FailState
Checks for Run Mode = 1 AND Air Proving Switch = 1 --> RunningState
### Running State
Run Mode = 1 (auto)
If any alarms active or safety interlock = 0 --> FailState
If Run Mode = 3 or loss of airflow --> StandbyState
Reads RH Setpoint from PLC
DuctRH will dynamically ramp to RH Setpoint
Fill Valve and Drain Valve switch between 0 and 1 (squareStrategy)
Steam Demand Mass between 3-6 (sawStrategy)
Steam Demand Percent between 50-80% (sawStrategy)
Tank Temp = 80 +/- 3
Steam Output Mass = 4 +/- 1
Steam Output Percent = 65 +/- 10
Water Until ADS/Service will ramp down to 0 (initializes at 1500 and 10000)
### Fail State
Run Mode = 3 (system standby)
Duct RH = 35 +/- 5
Fill Valve, Drain Valve = 0
Steam Demand Mass/Pct = 0
Steam Output Mass/Pct = 0
When all alarms are cleared and safety interlock = 1 --> StandbyState

View File

@@ -0,0 +1,91 @@
/**
* @file StateUtils.cpp
* @brief Implementation of the StateUtils class.
* @author Robert J. Davis
* @date 2025-10-28
*
* This file contains implementation of utility functions that are used in multiple States.
*/
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_Random.h"
#include "Strategies/Strategy_Saw.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_Square.h"
#include "Strategies/Strategy_PID.h"
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include "Equipment/Equipment.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "States/State.h"
#include "StateUtils.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief This function will update the Alarm bits and Safety Interlock state (based on Safety Interlock ON coil - for testing only)
* If the "Clear All Active Alarms" coil is activate, all alarms will be cleared, the Safety Interlock will be set to 1 (ready to operate),
* and the "Manual Clear Alarm Exists" bit will be set to 1.
* The "Alarms Present" (DI 10) will be set to 1 if any alarm is active (or Safety Interlock = 0). This is a register used for
* testing only, and will be used in Standby and Running States to send to FailState.
*
* This function is used in the update() of the Standby, Running, and Fail States.
*
*/
void updateAlarms(Equipment<ModbusIP>* equipment){
const std::vector<std::string> alarmDescriptions = {
"Tank Temp Sensor Fail", "Tank Overtemp", "Input RH Out of Range", "Duct RH Out of Range",
"Water Probe Check", "Water Probe Faulty", "Fill Time Excessive", "Refill Time Excessive",
"Tank Not Draining", "Boil Time Excessive"
};
// update Safety Interlock state (note: Safety Interlock = 0 means the equipment cannot run- fail safe)
if (equipment->getModbus_Point("Safety Interlock ON")->getValue() == 1){
equipment->setModbus_Point("Safety Interlock", 0);
}
else equipment->setModbus_Point("Safety Interlock", 1);
// if "Clear All Active Alarms" bit is 1 --> clear all alarms as well as safety interlock
// if "Clear All Active Alarms" bit is 0 --> if any alarms present set "Alarms Present" register to 1
if (equipment->getModbus_Point("Clear All Active Alarms")->getValue() == 1){
for (int i =0; i < alarmDescriptions.size(); ++i) {
equipment->setModbus_Point(alarmDescriptions[i], 0);
}
equipment->setModbus_Point("Safety Interlock ON", 0);
equipment->setModbus_Point("Safety Interlock", 1);
equipment->setModbus_Point("Alarms Present", 0);
equipment->setModbus_Point("Manual Clear Alarm Exists", 1); // the only way to set this back to 0 is manually via Modscan
}
else {
int numAlarms = 0;
for (int i =0; i < alarmDescriptions.size(); ++i) {
Modbus_Point<ModbusIP>* alarmPoint = equipment->getModbus_Point(alarmDescriptions[i]);
if (alarmPoint->getValue() == 1) numAlarms++;
}
if (equipment->getModbus_Point("Safety Interlock")->getValue() == 0) numAlarms++;
if (numAlarms >= 1) equipment->setModbus_Point("Alarms Present", 1);
else equipment->setModbus_Point("Alarms Present", 0);
}
}
/**
* @brief This function is used to update the Airflow Proving Switch state (DI 1)
* based on the Safety Interlock ON coil (Coil 2) - this is used for testing purposes only.
*
* This function is used in the update() of the Standby, Running, and Fail States.
*
*/
void updateAirflow(Equipment<ModbusIP>* equipment){
if (equipment->getModbus_Point("Airflow ON")->getValue() == 1){
equipment->setModbus_Point("Airflow Proving Switch", 1);
}
else equipment->setModbus_Point("Airflow Proving Switch", 0);
}

View File

@@ -0,0 +1,43 @@
/**
* @file config.h
* @brief StateUtils class
* @author Robert J Davis
* @date 2025-10-28
*
* Defines the StateUtils class, which contains utility functions used in multiple States.
*/
#pragma once
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include "Equipment/Equipment.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "States/State.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
template <typename T>
class State;
/**
* @brief Updates all alarms, safety interlock, alarms present register.
* @param equipment Pointer to the Equipment instance.
* @return void
*/
void updateAlarms(Equipment<ModbusIP>* equipment);
/**
* @brief Updates the Airflow Proving Switch state based on Airflow ON state.
* @param equipment Pointer to the Equipment instance.
* @return void
*/
void updateAirflow(Equipment<ModbusIP>* equipment);

View File

@@ -0,0 +1,91 @@
/**
* @file State_Fail.cpp
* @brief Implementation of the FailState class.
* @author Robert J Davis
* @date 2025-10-28
*
* This file contains the implementation for the FailState, which defines
* the behavior of the equipment when it has entered a fault condition.
*/
#include "ModbusPoints/Modbus_Point.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_PID.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "StateUtils.h"
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief Constructs a new FailState object with a list of active alarms.
*
* This constructor will have the Duct RH fluctuate around 35% (for visualization purposes).
*
* @param activeAlarms A vector of strings, where each string is the
* description of a Modbus point to be set as an active alarm.
* This parameter is not used in this implementation of the Fail State.
*/
template<>
FailState<ModbusIP>::FailState(const std::vector<std::string>& activeAlarms) {
addStrategy("Duct RH", new SingleValueStrategy(35.0f, 5.0f, 1000));
addStrategy("Tank Temp", new SingleValueStrategy(80.0f, 1.0f, 3000));
}
/**
* @brief Executes the fail state's logic for one update cycle.
*
* Update Alarms states. Stays in FailState until all alarms are cleared --> Standby State.
*
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusIP>* FailState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Fail update function");
updateAlarms(equipment);
bool alarmsPresent = getPointValue(equipment, "Alarms Present");
if (!alarmsPresent){
return new StandbyState<ModbusIP>();
}
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the fail state.
* Sets the Run Mode to 3 (system standby), and appropriate analogs to 0.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void FailState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Fail State...");
// Ensure Run Mode set to 3 (standby)
setPointValue(equipment, "Run Mode", 3);
setPointValue(equipment, "Fill Valve", 0);
setPointValue(equipment, "Drain Valve", 0);
setPointValue(equipment, "Steam Demand Mass", 0);
setPointValue(equipment, "Steam Demand Percent", 0);
setPointValue(equipment, "Steam Output Mass", 0);
setPointValue(equipment, "Steam Output Percent", 0);
}
/**
* @brief Logic to execute once when exiting the fail state.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void FailState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
// Cleanup logic to run when the equipment leaves this state
Serial.println("Exit Fail State...");
}

View File

@@ -0,0 +1,123 @@
/**
* @file State_Running.cpp
* @brief Implementation of the RunningState class.
* @author Robert J Davis
* @date 2025-10-28
*
* This file contains the implementation for the RunningState, which defines
* the behavior of the equipment when it is actively running.
*/
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_Random.h"
#include "Strategies/Strategy_Saw.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_Square.h"
#include "Strategies/Strategy_PID.h"
#include "Strategies/Strategy_Totalizer.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "States/State.h"
#include "StateUtils.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief Constructs a new RunningState object.
*
* This constructor initializes behavior strategies active during the running
* state including various analog values. Fill and Drain Valves switch between 0 and 1.
* Water Until ADS/Service will ramp down to 0, initialized at 1500 and 10000, respectively.
*/
template<>
RunningState<ModbusIP>::RunningState() {
addStrategy("Duct RH", new RampStrategy(40.0f, 1.0f, 2000));
addStrategy("Fill Valve", new SquareStrategy(1.0f, 0.0f, 5000));
addStrategy("Drain Valve", new SquareStrategy(0.0f, 1.0f, 4500));
addStrategy("Steam Demand Mass", new SawStrategy(3.0f, 6.0f, 1.0f, 2000)); // these values are semi-random for visualization
addStrategy("Steam Demand Percent", new SawStrategy(50.0f, 80.0f, 5.0f, 1000)); // these values are semi-random for visualization
addStrategy("Tank Temp", new SingleValueStrategy(80.0f, 3.0f, 1000)); // these values are semi-random for visualization
addStrategy("Steam Output Mass", new SingleValueStrategy(4.0f, 1.0f, 1000)); // these values are semi-random for visualization
addStrategy("Steam Output Percent", new SingleValueStrategy(65.0f, 10.0f, 1000)); // these values are semi-random for visualization
addStrategy("Water Until ADS", new RampStrategy(0.0f, 1.0f, 2000)); // ramping down to 0 from 1500
addStrategy("Water Until Service", new RampStrategy(0.0f, 1.0f, 2000)); // ramping down to 0 from 10000
}
/**
* @brief Executes the running state's logic for one update cycle.
*
* This method first checks if there are any active alarms --> FailState.
* Also updates Airflow state according to Airflow ON (Coil 1- for testing use only).
* If no alarms are active, checks for loss of airflow or "Run Mode" = 3 (Modscan, but will be from PLC)
* to transition to the Standby state. If no transition is triggered, it updates the
* rampStrategy targetValue of the Duct RH to dynamically ramp up to the Space RH Setpoint (sent from PLC).
*
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// Update alarms states and airflow switch state
updateAlarms(equipment);
updateAirflow(equipment);
// if Alarms are present (as updated in updateAlarms function) --> FailState
bool alarmsPresent = getPointValue(equipment, "Alarms Present");
if (alarmsPresent){
std::vector<std::string> activeAlarmsDesc = {}; // sending a blank string to FailState, b/c that parameter not used in FailState implementation.
return new FailState<ModbusIP>(activeAlarmsDesc);
}
// Check for Run Mode and Airflow. If Run Mode = 3 OR Airflow stopped --> StandbyState
int runMode_Command = getPointValue(equipment, "Run Mode"); // Set by PLC
int airflow = getPointValue(equipment, "Airflow Proving Switch");
if (runMode_Command == 3 || airflow == 0) {
return new StandbyState<ModbusIP>();
}
// Set the Duct RH ramp target value equal to the Space RH Setpoint
float Space_RH_Setpoint = getPointValue(equipment, "Space RH Setpoint");
float ductRH = getPointValue(equipment, "Duct RH");
Strategy_Behavior* DuctRH_strat = getStrategy("Duct RH");
if (DuctRH_strat){
static_cast<RampStrategy*>(DuctRH_strat)->setTarget(Space_RH_Setpoint);
}
// Apply any strategies defined for the standby state
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the running state.
*
* Note: do not need to set Run Mode = 1 (auto) since that is required to
* send the unit to Run Mode in the first place. Run Mode will already = 1.
*
* @param equipment Pointer to the Equipment instance.
*/
template<>
void RunningState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Running State...");
}
/**
* @brief Logic to execute once when exiting the running state.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void RunningState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
// Cleanup logic to run when the equipment leaves this state
Serial.println("Exit Running State...");
}

View File

@@ -0,0 +1,110 @@
/**
* @file State_Standby.cpp
* @brief Implementation of the StandbyState class.
* @author Robert J Davis
* @date 2025-10-28
*
* This file contains the implementation for the StandbyState, which defines
* the behavior of the equipment when it is in an idle or standby mode.
*/
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_Random.h"
#include "Strategies/Strategy_Saw.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_Square.h"
#include "Strategies/Strategy_PID.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "States/State.h"
#include "StateUtils.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief Constructs a new StandbyState object.
*
* In this state, the equipment is idle. This constructor will have
* Duct RH fluctuate around 35% for visualization purposes only.
*
*/
template<>
StandbyState<ModbusIP>::StandbyState() {
addStrategy("Duct RH", new SingleValueStrategy(35.0f, 5.0f, 1000));
addStrategy("Tank Temp", new SingleValueStrategy(80.0f, 1.0f, 3000));
}
/**
* @brief Executes the standby state's logic for one update cycle.
*
* This method first checks for state transition commands:
* 1. Updates Alarm states
* 2. Updates Airflow Switch state (based on Airflow ON command - used just for simulation purposes)
* If any Alarms are active or Safety Interlock = 0, send to FailState.
*
* 3. Check if Run Mode = 1 and Airflow Switch = 1, then send to Running State.
*
* If no transition occurs, it applies the strategies defined for the standby state.
*
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusIP>* StandbyState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Standby update function");
updateAlarms(equipment);
updateAirflow(equipment);
// if Alarms are present (as updated in updateAlarms function) --> FailState
bool alarmsPresent = getPointValue(equipment, "Alarms Present");
if (alarmsPresent){
std::vector<std::string> activeAlarmsDesc = {}; // sending a blank string to FailState, b/c that parameter not used in FailState implementation.
return new FailState<ModbusIP>(activeAlarmsDesc);
}
// Check for Run Mode and Airflow Proving Switch. If Run Mode = 1 and there is Airflow --> RunningState
int runMode_Command = getPointValue(equipment, "Run Mode"); // Set by PLC
int airflow = getPointValue(equipment, "Airflow Proving Switch");
if (airflow == 1 && runMode_Command == 1) {
return new RunningState<ModbusIP>();
}
// Apply any strategies defined for the standby state
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the standby state.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void StandbyState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
Serial.println("Enter Standby State...");
// Set Run Mode to 3 (standby), just in case entered Standby on loss of airflow
setPointValue(equipment, "Run Mode", 3);
setPointValue(equipment, "Fill Valve", 0);
setPointValue(equipment, "Drain Valve", 0);
setPointValue(equipment, "Steam Demand Mass", 0);
setPointValue(equipment, "Steam Demand Percent", 0);
setPointValue(equipment, "Steam Output Mass", 0);
setPointValue(equipment, "Steam Output Percent", 0);
}
/**
* @brief Logic to execute once when exiting the standby state.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void StandbyState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
// Cleanup logic to run when the equipment leaves this state
Serial.println("Exit Standby State...");
}

View File

@@ -0,0 +1,108 @@
/**
* @file config.h
* @brief Main configuration file for the DriSteem Humidifier (TCP) emulator.
* @author Robert J Davis
* @date 2025-10-27
*
* This file contains two important configurations: WiFi network parameters
* and the Modbus register map for the device.
*/
#ifndef CONFIG_H
#define CONFIG_H
#include "core.h"
#include "Equipment/Equipment.h"
#if defined(USE_MODBUS_IP)
/**
* @defgroup ModbusTCPConfig Modbus IP Configuration
* @brief Parameters for Modbus TCP communication.
* @{
*/
#include <ModbusIP_ESP8266.h>
const char *ssid = "ArduinoWifiB"; /**< @brief The SSID of the WiFi network. */
const char *password = "123abc456"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(172, 17, 32, 68); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 32, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;
#else
/**
* @defgroup ModbusRTUConfig Modbus RTU Configuration
* @brief Parameters for serial Modbus RTU communication.
* @{
*/
#include <ModbusRTU.h>
const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */
const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */
const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */
const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */
const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */
/** @} */
/** @brief Global instance of the Modbus RTU server. */
ModbusRTU mb;
#endif
/**
* @defgroup ModbusMapConfig Modbus Map Configuration
* @brief Defines the Modbus register map and related parameters for the emulator.
* @{
*/
/**
* @brief The Modbus map for the Equipment device.
* This array defines all the Modbus points available on the emulated device.
* The `description` field is crucial as it's used to look up points within the application logic.
*/
modbusMap mb_map[] =
{
{COIL, 0, 0, "Airflow ON"}, // Used for Modscan testing only to set Airflow Proving Switch
{COIL, 1, 0, "Safety Interlock ON"}, // Used for Modscan testing only to trip Safety Interlock
{COIL, 2, 0, "Manual Clear Alarm Exists"},
{COIL, 3, 0, "Clear All Active Alarms"}, // OCmd_Reset
{COIL, 4, 0, "Tank Temp Sensor Fail"},
{COIL, 5, 0, "Tank Overtemp"},
{COIL, 6, 0, "Input RH Out of Range"},
{COIL, 7, 0, "Duct RH Out of Range"},
{COIL, 9, 0, "Water Probe Check"},
{COIL, 10, 0, "Water Probe Faulty"},
{COIL, 11, 0, "Fill Time Excessive"},
{COIL, 12, 0, "Refill Time Excessive"},
{COIL, 13, 0, "Tank Not Draining"},
{COIL, 14, 0, "Boil Time Excessive"},
{DI, 0, 0, "Airflow Proving Switch"}, // 0:open, 1:closed
{DI, 2, 1, "Safety Interlock"}, // 0:open, 1:closed
{DI, 7, 0, "Fill Valve"}, // 0:closed, 1:open
{DI, 8, 0, "Drain Valve"}, // 0:not draining, 1:draining
{DI, 9, 0, "Alarms Present"}, // Used for Modscan testing only - not part of vendor Modbus table
{IR, 0, 0, "Space RH"}, // Relative_Humidity --> NOT USED, sensor not connected to HUM
{IR, 2, 0, "Duct RH"}, // OSet_CV
{IR, 3, 0, "Steam Demand Mass"},
{IR, 4, 0, "Steam Demand Percent"},
{IR, 6, 0, "Tank Temp"},
{IR, 7, 0, "Steam Output Mass"},
{IR, 8, 0, "Steam Output Percent"},
{IR_10x, 9, 1500, "Water Until ADS"}, // 1 = 100 lbs (I know this is 10x function only)
{IR_10x, 10, 10000, "Water Until Service"}, // 1 = 100 lbs (I know this is 10x function only)
{HR, 0, 3, "Run Mode"}, // Operation_Mode, 1:auto, 2:local standby, 3:system standby, 4:manual drain
{HR, 1, 0, "Space RH Setpoint"}, // Relative_Humidity_SP
{HR, 3, 85, "Duct High Limit Setpoint"},
};
//Size of modbus map used in FOR cycles, automatically calculated.
/**
* @brief The total number of entries in the `mb_map` array.
* This is calculated at compile time and used for iterating over the map.
*/
const int map_size = sizeof(mb_map) / sizeof(mb_map[0]);
/** @brief The main loop update interval in milliseconds. */
int interval = 250;
/** @} */ // End of ModbusMapConfig group
#endif // CONFIG_H

View File

@@ -0,0 +1,86 @@
/**
* @file main.cpp
* @brief Main execution program for the DriSteem Humidifier (TCP) Emulator.
* @author Emmanuel Hernandez Cruz, Robert J Davis
* @date 2025-09-02
*
* @details This file contains the main execution program for an Arduino-based emulator of the DriSteem Humidifier unit.
* The program uses a Wi-Fi connection to communicate via the Modbus IP protocol.
*
* The setup() function initializes the following:
* - Serial communication for debugging.
* - Wi-Fi connection using credentials from config.h.
* - A Modbus TCP server.
* - Modbus points (Coils, Holding Registers, etc.) based on a predefined map in config.h.
*
* The loop() function continuously:
* - Services the Modbus TCP server to handle incoming requests.
* - Periodically calls the main update loop for the emulated equipment, which
* manages state transitions and behavior strategies.
*
* @see config.h for Wi-Fi and Modbus configuration.
* @see Equipment.h for the main equipment logic.
* @see State.h for different equipment states.
* @see Strategies/Strategy_Behavior.h for value generation strategies.
* @see Modbus_Point.h for the base class for all Modbus points.
*/
//=================================================================================================================================
//Libraries and declaration of variables.
#include <WiFi.h>
#include "config.h"
#include "ModbusPoints/Modbus_PointFactory.h"
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
//=================================================================================================================================
/**
* @brief Initializes the application.
* @details This function runs once at startup. It configures the serial communication,
* Wi-Fi, and the Modbus server. It also creates and initializes all the Modbus points
* based on the `mb_map` array in `config.h`.
*/
void setup() {
Serial.begin(115200); //Serial comm start
WiFi.config(local_IP, gateway, subnet); // Wifi service start
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Connected!!");
mb.server(); //Modbus server start
Serial.println("Server Created");
Serial.println(map_size);
for(int i = 0; i < map_size; i++){
Modbus_Point<ModbusIP>* point = createModbus_Point(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
if (point) {
point->addToModbusServer();
EquipmentInstance.addModbus_Point(mb_map[i].description, point);
}
}
Serial.println("All modbus Points created");
Serial.println("Setup function ended");
}
//=================================================================================================================================
/**
* @brief The main application loop.
* @details This function runs repeatedly after setup() has completed. It performs two main actions:
* 1. It continuously services the Modbus server by calling `mb.task()` to handle
* incoming requests from a Modbus master.
* 2. At a fixed interval (defined in `config.h`), it calls `EquipmentInstance.update()`
* to run the emulator's internal state machine and behavior logic.
*/
void loop() {
mb.task();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
unsigned long startTime = millis();
EquipmentInstance.update();
unsigned long endTime = millis();
unsigned long elapsedTime = endTime - startTime;
Serial.printf("Control Execution time: %d ms\n", elapsedTime);
}
}

View File

@@ -1,13 +1,12 @@
# VFD ABB ACH580 RTU
## Brief Introduction
This is based on a 50hp motor, 480V, 65 FLA, 60Hz, 1800 rpm (PHX3 DC1/2)
This is based on a 50hp motor, 480V, 65 FLA, 60Hz, 1800 rpm (PHX3 DC1/2).
Modbus addresses are based on 32-bit registers.
## List of Equipment
This configuration has been used for these models:
* **ACH580**: 10-23-2025
* **Model**: 09-15-23
* **Model**: 09-15-25
* **ACH580**: 10-23-2025 (PHX3)
## Hardware Prerequisites
@@ -19,12 +18,11 @@ The code is written for an ESP8266/ESP32-style microcontroller with WiFi capabil
---
## States and Strategies
The hardwire IO signals to/from VFD/PLC are Start Cmd, Stop Cmd, Speed Command, Speed Feedback, VFD Run Status, VFD Fault.
The hardwire IO signals to/from VFD/PLC are Start Cmd, Stop Cmd, Speed Command, Speed Feedback, Run Status, Fault Status.
User needs to set the speed command (HR 150) in RPM from the PLC
User needs to set the Start command (HR 151) from the PLC
It appears these registers were arbitrarily chosen for the purpose of this Arduino simulation.
The registers selected are based on FS Config file from CDR project.
Currently there is no connection on Speed Feedback, Run Status, or Fault from Arduino to PICS
It appears these hard IO registers were arbitrarily chosen for the purpose of this Arduino simulation.
The registers selected are based on FS Config file from CDR project. Run Status and Fault Status registers were added for simulation.
### Standby State
* **Equipment**: Equipment parameters go back to 0
@@ -37,4 +35,6 @@ Currently there is no connection on Speed Feedback, Run Status, or Fault from Ar
* **Totalizers Strategy**: Inverter kWh cnt, Hours Run
### Fail State
* Not used
* Enters Fail State if Fault Status is set to 0.
While in Fail State, the Start/Stop command is reset to 0.
The only way to exit Fail State is if Fault Status = 1 --> Standby State.

View File

@@ -1,16 +1,18 @@
/**
* @file State_Fail.cpp
* @brief Implementation of the FailState class.
* @author Emmanuel Hernandez Cruz
* @date 2025-09-05
* @author Robert J Davis
* @date 2025-10-30
*
* This file contains the implementation for the FailState, which defines
* the behavior of the equipment when it has entered a fault condition.
*
*/
#include "States/State_Standby.h"
#include "States/State_Fail.h"
#include "ModbusPoints/Modbus_Point.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_PID.h"
@@ -26,21 +28,26 @@
/**
* @brief Constructs a new FailState object.
*
* This constructor receives a list of alarm descriptions and creates strategies
* to set the corresponding Modbus points to a value of 1, indicating an
* active alarm. It also initializes a PID strategy for the valve position.
* This constructor sets the associated analog signals to the same values as Standby.
*/
template<>
FailState<ModbusRTU>::FailState(const std::vector<std::string>& activeAlarms) {
// Simulate a failure: set common alarm and a specific fan alarm.
addStrategy("Speed Feedback", new RampStrategy(0.0f, 200.0f, 1000 ));
addStrategy("Motor Current", new RampStrategy(0.0f, 20.0f, 1000 ));
addStrategy("Motor Torque", new RampStrategy(0.0f, 20.0f, 1000 ));
addStrategy("Inverter Temperature", new RampStrategy(0.0f, 1.0f, 1000 ));
addStrategy("Output Frequency", new SingleValueStrategy(0.1f, 0.2f, 1000 ));
addStrategy("Output Voltage", new SingleValueStrategy(0.1f, 0.1f, 1000 ));
addStrategy("DC Voltage", new SingleValueStrategy(0.1f, 0.1f, 1000 ));
addStrategy("Motor Shaft Power", new SingleValueStrategy(0.1f, 0.1f, 1000 ));
}
/**
* @brief Executes the fail state's logic for one update cycle.
*
* This method checks the "Clear Alm" Modbus point for a command to transition
* back to Standby, which would typically happen after a fault is cleared by a
* user. If no transition is requested, it continues to apply the failure strategies.
* While in FailState, the Unit cannot be started and the Start/Stop command is reset to 0.
* When the fault is cleared --> Standby State.
*
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
@@ -50,23 +57,36 @@ State<ModbusRTU>* FailState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment)
// STATE control, add conditions if change to a different state is needed
Serial.println("Fail update function");
int faultNotPresent = getPointValue(equipment, "Fault Status");
if(faultNotPresent == 1){
return new StandbyState<ModbusRTU>();
}
setPointValue(equipment, "Start/Stop", 0);
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the fail state. Sets the main alarm bit.
* @brief Logic to execute once when entering the fail state. Sets the Run Status to 0.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void FailState<ModbusRTU>::enterState(Equipment<ModbusRTU>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Fail State...");
setPointValue(equipment, "Speed Scaling", 1800);
setPointValue(equipment, "Frequency Scaling", 60);
setPointValue(equipment, "Nominal Current", 65);
setPointValue(equipment, "Nominal Voltage", 480);
setPointValue(equipment, "Nominal Frequency", 60);
setPointValue(equipment, "Nominal Speed", 1800);
setPointValue(equipment, "Nominal Power", 50);
setPointValue(equipment, "Run Status", 0);
}
/**
* @brief Logic to execute once when exiting the fail state. Clears the main alarm bit.
* @brief Logic to execute once when exiting the fail state.
* @param equipment Pointer to the Equipment instance.
*/
template<>

View File

@@ -1,7 +1,7 @@
/**
* @file State_Running.cpp
* @brief Implementation of the RunningState class.
* @author Emmanuel Hernandez Cruz, Robert J Davis
* @author Robert J Davis
* @date 2025-10-22
*
* This file contains the implementation for the RunningState, which defines
@@ -36,13 +36,12 @@
* @brief Constructs a new RunningState object.
*
* This constructor initializes behavior strategies active during the running
* state, such as a PID controller for the 'CW Valve Position' and totalizers
* for the run-hours of each EC fan.
* state, such as speed feedback, current, torque, hours run, etc.
* These values are based on a 50hp motor, 480V, 65 FLA, 60Hz, 1800 rpm (PHX3 DC1/2)
*/
template<>
RunningState<ModbusRTU>::RunningState() {
addStrategy("Motor Speed Used", new RampStrategy(1800.0f, 100.0f, 1000));
addStrategy("Motor Speed estimated", new RampStrategy(1800.0f, 100.0f, 1000));
addStrategy("Speed Feedback", new RampStrategy(1800.0f, 100.0f, 1000));
addStrategy("Motor Current", new RampStrategy(65.0f, 7.0f, 1000));
addStrategy("Motor Torque", new RampStrategy(90.0f, 10.0f, 1000));
addStrategy("Inverter Temperature", new SquareStrategy(40.0f, 80.0f, 1000));
@@ -50,21 +49,19 @@ RunningState<ModbusRTU>::RunningState() {
addStrategy("Output Frequency", new RampStrategy(60.0f, 3.0f, 1000 ));
addStrategy("Output Voltage", new RampStrategy(480.0f, 15.0f, 1000 ));
addStrategy("DC Voltage", new RampStrategy(678.0f, 20.0f, 1000 ));
addStrategy("Output Power", new RampStrategy(36.7f, 2.0f, 1000 ));
addStrategy("Inverter kWh cnt", new TotalizerStrategy(1000));
addStrategy("Hours Run", new TotalizerStrategy(1000));
addStrategy("Motor Shaft Power", new RampStrategy(36.7f, 2.0f, 1000 ));
addStrategy("Inverter MWh counter", new TotalizerStrategy(1000));
addStrategy("Inverter kWh counter", new TotalizerStrategy(1000));
}
/**
* @brief Executes the running state's logic for one update cycle.
*
* This method first checks for state transition commands:
* 1. It reads the "ON/OFF Command By BMS" point. If it's 0, it transitions to StandbyState.
* 2. It reads the "Fault Code" point. If it's non-zero, it transitions to FailState,
* passing the corresponding alarm description.
* 1. If Fault is 0 (there is a fault present) --> FailState
* 2. It reads the "Stop/Start" command point (from PLC). If it's 0, it transitions to StandbyState.
*
* If no transition occurs, it applies the strategies defined for the running state.
* If no transition occurs, it updates values according to speed setpoint sent from PLC.
*
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
@@ -74,6 +71,17 @@ State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
// STATE control, add conditions if change to a different state is needed
Serial.println("Running update function");
// If Fault Status = 0, there is a fault --> FailState
int faultNotPresent = getPointValue(equipment, "Fault Status");
if(faultNotPresent == 0){
return new FailState<ModbusRTU>({"Fault Status"});
}
int VFD_Start_Stop = getPointValue(equipment, "Start/Stop");
if (VFD_Start_Stop == 0){
return new StandbyState<ModbusRTU>();
}
float speed_pct = getPointValue(equipment, "Speed Cmd") / 1800.0f;
// Based on Affinity Laws. Motor: 65 FLA, 480V, 60Hz, 1800 rpm, 50hp
float voltage_update = speed_pct * 480;
@@ -83,24 +91,11 @@ State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
float freq_update = speed_pct * 60;
float power_update = speed_pct * speed_pct * speed_pct * 36.77f; // 50 hp ~ 36.77kW
int VFD_Start_Stop = getPointValue(equipment, "Start/Stop");
if (VFD_Start_Stop == 0){
return new StandbyState<ModbusRTU>();
}
float currentSP = getPointValue(equipment, "Speed Cmd");
Strategy_Behavior* motorSpeedUsed = getStrategy("Motor Speed Used");
// 2. Check if the strategy exists
if (motorSpeedUsed) {
// 3. Cast it to a RampStrategy pointer and call setSetpoint.
static_cast<RampStrategy*>(motorSpeedUsed)->setTarget(currentSP);
}
// To have Motor Speed estimated slightly different - for purposes of differentiating in Ignition
float rpm_est = currentSP * 0.98f;
Strategy_Behavior* motorSpeedEst = getStrategy("Motor Speed estimated");
if (motorSpeedEst) {
static_cast<RampStrategy*>(motorSpeedEst)->setTarget(rpm_est);
Strategy_Behavior* speedFeedback = getStrategy("Speed Feedback");
if (speedFeedback) {
static_cast<RampStrategy*>(speedFeedback)->setTarget(currentSP);
}
Strategy_Behavior* frequencystrategy = getStrategy("Output Frequency");
@@ -128,7 +123,7 @@ State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
static_cast<RampStrategy*>(voltagestrategy)->setTarget(voltage_update);
}
Strategy_Behavior* powerstrategy = getStrategy("Output Power");
Strategy_Behavior* powerstrategy = getStrategy("Motor Shaft Power");
if (powerstrategy) {
static_cast<RampStrategy*>(powerstrategy)->setTarget(power_update);
}
@@ -140,19 +135,26 @@ State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
/**
* @brief Logic to execute once when entering the running state.
* Sets the "Chiller Sts" point to indicate the unit is running.
* Sets the Run Status" point to indicate the unit is running.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void RunningState<ModbusRTU>::enterState(Equipment<ModbusRTU>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Running State...");
setPointValue(equipment, "Speed Scaling", 1800);
setPointValue(equipment, "Frequency Scaling", 60);
setPointValue(equipment, "Nominal Current", 65);
setPointValue(equipment, "Nominal Voltage", 480);
setPointValue(equipment, "Nominal Frequency", 60);
setPointValue(equipment, "Nominal Speed", 1800);
setPointValue(equipment, "Nominal Power", 50);
setPointValue(equipment, "Run Status", 1);
}
/**
* @brief Logic to execute once when exiting the running state.
* Sets the "Chiller Sts" point to indicate the unit is no longer running.
* Sets the "Output Frequency" to 0.
* @param equipment Pointer to the Equipment instance.
*/
template<>

View File

@@ -1,7 +1,7 @@
/**
* @file State_Standby.cpp
* @brief Implementation of the StandbyState class.
* @author Emmanuel Hernandez Cruz, Robert J Davis
* @author Robert J Davis
* @date 2025-10-23
*
* This file contains the implementation for the StandbyState, which defines
@@ -26,30 +26,29 @@
* @brief Constructs a new StandbyState object.
*
* In this state, the equipment is idle. This constructor initializes several
* strategies to generate random values for various status points, simulating
* a live but non-operational unit.
* strategies to simulate a live but non-operational unit. Most values are ramped down to 0.
*/
template<>
StandbyState<ModbusRTU>::StandbyState() {
addStrategy("Output Frequency", new SingleValueStrategy(0.1f, 0.2f, 1000 ));
addStrategy("Output Voltage", new SingleValueStrategy(0.1f, 0.1f, 1000 ));
addStrategy("DC Voltage", new SingleValueStrategy(0.1f, 0.1f, 1000 ));
addStrategy("Output Power", new SingleValueStrategy(0.1f, 0.1f, 1000 ));
addStrategy("Motor Speed Used", new RampStrategy(0.0f, 200.0f, 1000 ));
addStrategy("Motor Speed estimated", new RampStrategy(0.0f, 200.0f, 1000 ));
addStrategy("Speed Feedback", new RampStrategy(0.0f, 200.0f, 1000 ));
addStrategy("Motor Current", new RampStrategy(0.0f, 20.0f, 1000 ));
addStrategy("Motor Torque", new RampStrategy(0.0f, 20.0f, 1000 ));
addStrategy("Inverter Temperature", new RampStrategy(0.0f, 1.0f, 1000 ));
addStrategy("Output Frequency", new SingleValueStrategy(0.1f, 0.2f, 1000 ));
addStrategy("Output Voltage", new SingleValueStrategy(0.1f, 0.1f, 1000 ));
addStrategy("DC Voltage", new SingleValueStrategy(0.1f, 0.1f, 1000 ));
addStrategy("Motor Shaft Power", new SingleValueStrategy(0.1f, 0.1f, 1000 ));
}
/**
* @brief Executes the standby state's logic for one update cycle.
*
* This method checks the "Chiller On-Off" Modbus point for a command to
* transition to the Running state. If no transition is requested, it applies
* the strategies defined for the standby state.
* This method first checks for state transition commands:
* 1. If Fault is 0 (there is a fault present) --> FailState
* 2. It reads the "Start/Stop" point (from PLC). If it's 1 --> RunningState
*
* If no transition is requested, it applies the strategies defined for the standby state.
*
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
@@ -58,6 +57,13 @@ template<>
State<ModbusRTU>* StandbyState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Standby update function");
// If Fault Status = 0, there is a fault --> FailState
int faultNotPresent = getPointValue(equipment, "Fault Status");
if(faultNotPresent == 0){
return new FailState<ModbusRTU>({"Fault Status"});
}
int VFD_Start_Stop = getPointValue(equipment, "Start/Stop");
if (VFD_Start_Stop == 1){
return new RunningState<ModbusRTU>();
@@ -69,14 +75,21 @@ State<ModbusRTU>* StandbyState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
/**
* @brief Logic to execute once when entering the standby state.
* Sets the "Chiller Sts" point to indicate the unit is not running.
* Sets the "Run Status" point to indicate the unit is not running.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void StandbyState<ModbusRTU>::enterState(Equipment<ModbusRTU>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Standby State...");
setPointValue(equipment, "Speed Scaling", 1800);
setPointValue(equipment, "Frequency Scaling", 60);
setPointValue(equipment, "Nominal Current", 65);
setPointValue(equipment, "Nominal Voltage", 480);
setPointValue(equipment, "Nominal Frequency", 60);
setPointValue(equipment, "Nominal Speed", 1800);
setPointValue(equipment, "Nominal Power", 50);
setPointValue(equipment, "Run Status", 0);
}
/**

View File

@@ -1,11 +1,13 @@
/**
* @file config.h
* @brief Main configuration file for the ABB ACH580 (VFD) emulator.
* @author Emmanuel Hernandez Cruz, Robert J Davis
* @brief Main configuration file for the ABB ACH580 VFD (RTU) emulator.
* @author Robert J Davis
* @date 2025-10-22
*
* This file contains important configurations for the Modbus RTU communication
* and the specific register map for the emulated device.
* These are 32-bit modbus registers.
* Added "Run Status" and "Fault Status" to simulated hard IO points and send feedback to PLC during simulation.
*/
#ifndef CONFIG_H
@@ -54,36 +56,38 @@
*/
modbusMap mb_map[] =
{
{HR, 149, 0, "Speed Cmd"}, // expecting rpm (1800 rpm max)
{HR, 151, 0, "Start/Stop"},
{HR, 152, 0, "HOA Command"},
{HR, 100, 0, "Motor Speed Used"}, // RJD: 1800 rpm max
{HR, 101, 0, "Motor Speed estimated"}, // RJD: 1800 rpm max
{HR_10x, 105, 0, "Output Frequency"}, // 60 Hz @100% speed
{HR, 106, 0, "Motor Current"}, // RJD: Changed from HR_10x to HR, 65 FLA
{HR, 149, 1650, "Speed Cmd"}, // arbitrary register number - receive signal from PLC (hardwire IO in field); expecting rpm (1800 rpm max)
{HR, 151, 1, "Start/Stop"}, // arbitrary register number - receive signal from PLC (hardwire IO in practice)
{HR, 152, 0, "HOA Command"}, // arbitrary register number - not used in program
{HR, 154, 0, "Run Status"}, // arbitrary register number - 0:off, 1:on (simulated hardwire IO) sending feedback to PLC during simulation.
{HR, 155, 1, "Fault Status"}, // arbitrary register number - 0:faulted, 1:not faulted (simulated hardwire IO). When = 0, will turn off VFD.
// {HR, 156, 0, "Speed Feedback"}, // arbitrary register number - send signal to PLC (simulated hardwire IO). Will be equal to Motor Speed Used register
{HR, 100, 0, "Speed Feedback"}, // 1800 rpm max
{HR, 105, 0, "Output Frequency"}, // 60 Hz @100% speed
{HR, 106, 0, "Motor Current"}, // 65 FLA
{HR_10x, 109, 0, "Motor Torque"}, // % of nominal torque
{HR_10x, 110, 0, "DC Voltage"}, // approx 678 VDC @100% speed
{HR, 112, 0, "Output Voltage"}, // RJD: 480 VAC
{HR, 113, 0, "Output Power"}, //max 372580 // RJD: Changed from HR_10x to HR, 50 hp ~ 36.77 kW
{HR_10x, 119, 0, "Inverter kWh cnt"},
{HR, 502, 0, "Hours Run"},
{HR, 112, 0, "Output Voltage"}, // 480 VAC
{HR_10x, 116, 0, "Motor Shaft Power"}, // 50 hp ~ 36.77 kW
{HR, 118, 0, "Inverter MWh counter"},
{HR_10x, 119, 0, "Inverter kWh counter"},
{HR, 510, 0, "Inverter Temperature"}, // RJD: Changed from HR_10x to HR, % of fault limit
{HR, 521, 0, "HOA Status Word"},
{HR, 519, 0, "Diagnostic Word"}, // not used in program. Bit 9:Drive Over-Temp Alarm
{HR, 410, 0, "Last Fault"},
{HR, 411, 0, "2nd to last Fault"},
{HR, 412, 0, "3rd to last Fault"},
{HR, 439, 0, "Event Word Param"},
{HR, 1000, 0, "DI Status"}, // not used in program.
{HR, 1211, 0, "AI1 Scaled"}, // not used in program.
{HR, 1221, 0, "AI2 Scaled"}, // not used in program.
{HR, 1310, 0, "AO1 Actual"}, // not used in program.
{HR, 1910, 0, "External Control Location"}, // not used in program.
{HR, 4600, 0, "Speed Scaling"}, // ADD: 1800 rpm
{HR, 4601, 0, "Frequency Scaling"}, // ADD: 60 Hz
{HR, 9905, 0, "Nominal Current"}, // ADD: 65 A
{HR_10x, 9906, 0, "Nominal Voltage"}, // ADD: 480 V
{HR_10x, 9907, 0, "Nominal Frequency"}, // ADD: 60 Hz
{HR, 9908, 0, "Nominal Speed"}, // ADD: 1800 rpm
{HR_10x, 9909, 0, "Nominal Power"}, // ADD: 50 hp
{HR, 610, 0, "Status Word 1"},
{HR, 615, 0, "Status Word 2"},
{HR, 616, 0, "Status Word 3"},
{HR, 617, 0, "Status Word 4"},
{HR, 618, 0, "Status Word 5"},
{HR, 619, 0, "Status Word 6"},
{HR, 620, 0, "Status Word 7"},
{HR, 621, 0, "Status Word 8"},
};
//Size of modbus map used in FOR cycles, automatically calculated.
/**

View File

@@ -1,11 +1,11 @@
/**
* @file main.cpp
* @brief Main execution program for the Daikin Chiller (RTU) Emulator.
* @author Emmanuel Hernandez Cruz
* @brief Main execution program for the ABB ACH580 VFD (RTU) Emulator.
* @author Emmanuel Hernandez Cruz, Robert J Davis
* @date 2025-09-02
*
* @details This file contains the main execution program for an Arduino-based
* emulator of a Daikin Chiller unit. The program communicates via the
* emulator of a ABB ACH580 VFD unit. The program communicates via the
* Modbus RTU protocol over a serial connection.
*
* The setup() function initializes the following:

View File

@@ -21,10 +21,10 @@
* @{
*/
#include <ModbusIP_ESP8266.h>
const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */
const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */
IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */
const char *ssid = "QTS_ATL_Arduino"; /**< @brief The SSID of the WiFi network. */
const char *password = "Fayetteville123"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(172, 17, 25, 115); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 25, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;

View File

@@ -21,10 +21,10 @@
* @{
*/
#include <ModbusIP_ESP8266.h>
const char *ssid = "QTS_CDR_Arduino"; /**< @brief The SSID of the WiFi network. */
const char *ssid = "ArduinoWifiB"; /**< @brief The SSID of the WiFi network. */
const char *password = "123abc456"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(172, 17, 33, 173); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 33, 1); /**< @brief The gateway IP address. */
IPAddress local_IP(172, 17, 32, 82); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 32, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;

View File

@@ -38,6 +38,13 @@
*/
template<>
RunningState<ModbusIP>::RunningState() {
addStrategy("V_AB", new SingleValueStrategy(4800.0F, 5.0f, 1000));
addStrategy("V_BC", new SingleValueStrategy(4800.0F, 5.0f, 1000));
addStrategy("V_CA", new SingleValueStrategy(4800.0F, 5.0f, 1000));
addStrategy("Amps A", new SingleValueStrategy(1.0f, 10.0f, 1000));
addStrategy("Amps B", new SingleValueStrategy(1.0f, 10.0f, 1000));
addStrategy("Amps C", new SingleValueStrategy(1.0f, 10.0f, 1000));
}
/**
@@ -57,7 +64,48 @@ template<>
State<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Running update function");
float State_Ctrl = getPointValue(equipment, "PxControl");
if (State_Ctrl == 0.0f){
return new StandbyState<ModbusIP>();
}
if (State_Ctrl == 1.0f){
setBitValue(equipment, "CB_Position", 0, true);
setBitValue(equipment, "CB_Position", 12, false);
}
if (State_Ctrl == 2.0f){
return new StandbyState<ModbusIP>();
}
float volts_AB = getPointValue(equipment, "V_AB");
float volts_BC = getPointValue(equipment, "V_BC");
float volts_AC = getPointValue(equipment, "V_CA");
setPointValue(equipment, "V_AN", volts_AB/1.732f);
setPointValue(equipment, "V_BN", volts_BC/1.732f);
setPointValue(equipment, "V_CN", volts_AC/1.732f);
int I_load = getPointValue(equipment, "PxLoad");
int I_rating = getPointValue(equipment, "PxRating");
float load = static_cast<float>(I_load);
float rating = static_cast<float>(I_rating);
float real_load = rating * (load/100.0f);
setPointValue(equipment, "Amps A", real_load * 10.0f);
setPointValue(equipment, "Amps B", real_load * 10.0f);
setPointValue(equipment, "Amps C", real_load * 10.0f);
setPointValue(equipment, "Amps G", volts_AB * 0.037f);
setPointValue(equipment, "Amps N", volts_BC * 0.034f);
float kva = (1.732f * ((volts_AB + volts_BC + volts_AC)/4.0f) * real_load * (0.92f))/100000.0f;
float kw = (1.732f * ((volts_AB + volts_BC + volts_AC)/4.0f) * real_load )/10000.0f;
setPointValue(equipment, "kW", kw);
setPointValue(equipment, "kVA", kva);
setPointValue(equipment, "kVA2", kva);
setPointValue(equipment, "kWh", 1724.0f);
// Apply any strategies defined for the standby state
_applyStrategies(equipment);
return nullptr;

View File

@@ -56,7 +56,18 @@ template<>
State<ModbusIP>* StandbyState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Standby update function");
float State_Ctrl = getPointValue(equipment, "PxControl");
if (State_Ctrl == 1.0f){
return new RunningState<ModbusIP>();
}
if (State_Ctrl == 0.0f){
setBitValue(equipment, "CB_Position", 0, false);
setBitValue(equipment, "CB_Position", 12, false);
}
if (State_Ctrl == 2.0f){
setBitValue(equipment, "CB_Position", 0, false);
setBitValue(equipment, "CB_Position", 12, true);
}
// Apply any strategies defined for the standby state
_applyStrategies(equipment);
return nullptr;
@@ -72,6 +83,21 @@ template<>
void StandbyState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Standby State...");
setPointValue(equipment, "V_AB", 0.0f);
setPointValue(equipment, "V_BC", 0.0f);
setPointValue(equipment, "V_CA", 0.0f);
setPointValue(equipment, "V_AN", 0.0f);
setPointValue(equipment, "V_BN", 0.0f);
setPointValue(equipment, "V_CN", 0.0f);
setPointValue(equipment, "Amps A", 0.0f);
setPointValue(equipment, "Amps B", 0.0f);
setPointValue(equipment, "Amps C", 0.0f);
setPointValue(equipment, "Amps G", 0.0f);
setPointValue(equipment, "Amps N", 0.0f);
setPointValue(equipment, "kW", 0.0f);
setPointValue(equipment, "k_VA", 0.0f);
setPointValue(equipment, "k_VA2", 0.0f);
setPointValue(equipment, "kWh", 0.0f);
}
/**

View File

@@ -21,10 +21,10 @@
* @{
*/
#include <ModbusIP_ESP8266.h>
const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */
const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(172, 17, 22, 152); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 22, 254); /**< @brief The gateway IP address. */
const char *ssid = "wifi"; /**< @brief The SSID of the WiFi network. */
const char *password = "password"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(192, 168, 1, 170); /**< @brief The static IP address for the device. */
IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;
@@ -63,23 +63,25 @@ modbusMap mb_map[] = {
// Convert from ESP8266 to traditional Modbus addressing: subtract 30001/40001.
// Input Registers (3x) - Floating Point (MSB & LSB)
{IR, 40, 0, "CB_Position" }, // 300041.0 - Circuit Breaker Position
{IR, 40, 0, "CB_Trip" }, // 300041.12 - Circuit Breaker Tripped
{IR_LONG, 100, 0, "Amps_A" }, //DWORD
{IR_LONG, 102, 0, "Amps_B" }, //DWORD
{IR_LONG, 104, 0, "Amps_C" }, //DWORD
{IR_LONG, 106, 0, "Amps_N" }, //DWORD
{IR_LONG, 108, 0, "Amps_G" }, //DWORD
{IR, 150, 0, "V_AN" }, //WORD
{IR, 151, 0, "V_BN" }, //WORD
{IR, 152, 0, "V_CN" }, //WORD
{IR, 154, 0, "V_AB" }, //WORD
{IR, 155, 0, "V_BC" }, //WORD
{IR, 156, 0, "V_CA" }, //WORD
{IR_LONG, 222, 0, "k_VA" }, //LONG
{IR_LONG, 206, 0, "kW" }, //LONG
{IR_LONG, 304, 0, "kWh" }, //LONG
{IR, 253, 0, "k_VA" }, //SHORT
{HR, 9, 0, "PxControl"}, //Open-Close Cmd
{HR, 10, 0, "PxLoad"}, //Adjustble Load
{HR, 11, 0, "PxRating"}, //Max amp to calculate kw, kVA, etc
{IR, 39, 0, "CB_Position" }, // 300041.0 - Circuit Breaker Position || 300041.12 - Circuit Breaker Tripped
{IR_LONG, 99, 0, "Amps A" }, //DWORD
{IR_LONG, 101, 0, "Amps B" }, //DWORD
{IR_LONG, 103, 0, "Amps C" }, //DWORD
{IR_LONG, 105, 0, "Amps N" }, //DWORD
{IR_LONG, 107, 0, "Amps G" }, //DWORD
{IR, 149, 0, "V_AN" }, //WORD
{IR, 150, 0, "V_BN" }, //WORD
{IR, 151, 0, "V_CN" }, //WORD
{IR, 153, 0, "V_AB" }, //WORD
{IR, 154, 0, "V_BC" }, //WORD
{IR, 155, 0, "V_CA" }, //WORD
{IR_LONG, 221, 0, "k_VA" }, //LONG
{IR_LONG, 205, 0, "kW" }, //LONG
{IR_LONG, 303, 0, "kWh" }, //LONG
{IR, 252, 0, "k_VA2" }, //SHORT
};
//Size of modbus map used in FOR cycles, automatically calculated.

View File

@@ -98,6 +98,7 @@ void StandbyState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
setPointValue(equipment, "kW", 0.0f);
setPointValue(equipment, "kVA", 0.0f);
setPointValue(equipment, "kWh", 0.0f);
setBitValue(equipment, "Alarm General", 0, false);
}
/**

View File

@@ -21,10 +21,10 @@
* @{
*/
#include <ModbusIP_ESP8266.h>
const char *ssid = "QTS_CDR_Arduino"; /**< @brief The SSID of the WiFi network. */
const char *ssid = "ArduinoWifiB"; /**< @brief The SSID of the WiFi network. */
const char *password = "123abc456"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(172, 17, 33, 154); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 33, 1); /**< @brief The gateway IP address. */
IPAddress local_IP(172, 17, 32, 102); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 32, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;

View File

@@ -60,6 +60,7 @@
*/
modbusMap mb_map[] = {
// ESP8266 Modbus server uses 0-based addressing, while Modbus Poll uses 1-based addressing.
{HR, 48899, 0, "Alm01" }, // 448900
{HR, 48898, 0, "Alm02" }, // 448899
{HR, 48905, 0, "Alm03" }, // 448906

View File

@@ -0,0 +1,33 @@
# EQUIPMENT_TYPE MANUFACTURER MODEL TCP
## Brief Introduction
Equipment specifc details that make it different from other devices
## List of Equipmentt
This cofiguration has been used for these models:
* **Model**: 09-15-22
* **Model**: 09-15-23
* **Model**: 09-15-25
## Hardware Prerequisites
The code is written for an ESP8266/ESP32-style microcontroller with WiFi capabilities.
* **Microcontroller**: [Firebeetle 2 ESP32.](https://www.dfrobot.com/product-2231.html)
---
## States and Strategies
Provide a brief description of what variables and strategies were used in this configuraiton
### Standby State
* **Equipment running**: set to 0
* **Common Alarm**: set to 0
* **SAT temperature**: set to 85
### Running State
* **Equipment running**: set to 1
* **SAT temperature**: **Ramp Strategy** set to 65 deg setpoint
### Fail State
* **Commong Alarm**: set to 1
* **SAT temperature**: **Ramp Strategy** set to 105 deg setpointset

View File

@@ -0,0 +1,92 @@
/**
* @file State_Running.cpp
* @brief Implementation of the RunningState class.
* @author Emmanuel Hernandez Cruz
* @date 2025-09-05
*
* This file contains the implementation for the RunningState, which defines
* the behavior of the equipment when it is actively running.
*/
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_Random.h"
#include "Strategies/Strategy_Saw.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_Square.h"
#include "Strategies/Strategy_PID.h"
#include "Strategies/Strategy_Totalizer.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "States/State.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief Constructs a new RunningState object.
*
* This constructor initializes behavior strategies active during the running
* state, such as a PID controller for the 'CW Valve Position' and totalizers
* for the run-hours of each EC fan.
*/
template<>
RunningState<ModbusIP>::RunningState() {
}
/**
* @brief Executes the running state's logic for one update cycle.
*
* This method first checks for state transition commands:
* 1. It reads the "ON/OFF Command By BMS" point. If it's 0, it transitions to StandbyState.
* 2. It reads the "Fault Code" point. If it's non-zero, it transitions to FailState,
* passing the corresponding alarm description.
*
* If no transition occurs, it applies the strategies defined for the running state.
*
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Running update function");
float Mode = getPointValue(equipment, "PxMode");
if (static_cast<int>(Mode) == 2 ){
return new StandbyState<ModbusIP>();
}
// Apply any strategies defined for the standby state
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the running state.
* Sets the "Run Status" for all EC fans to 1 to indicate they are active.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void RunningState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Running State...");
// You could also update a Modbus register to show the "standby" state
}
/**
* @brief Logic to execute once when exiting the running state.
* Sets the "Run Status" for all EC fans to 0 before transitioning to the next state.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void RunningState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
// Cleanup logic to run when the equipment leaves this state
Serial.println("Exit Running State...");
}

View File

@@ -0,0 +1,89 @@
/**
* @file State_Standby.cpp
* @brief Implementation of the StandbyState class.
* @author Emmanuel Hernandez Cruz
* @date 2025-09-05
*
* This file contains the implementation for the StandbyState, which defines
* the behavior of the equipment when it is in an idle or standby mode.
*/
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_Random.h"
#include "Strategies/Strategy_Saw.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_Square.h"
#include "Strategies/Strategy_PID.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "States/State.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief Constructs a new StandbyState object.
*
* In this state, the equipment is idle. This constructor initializes strategies
* to bring the system to a safe, idle condition. It sets a stable value for
* the SAT reading and creates ramp strategies to bring the CW valve and all
* EC fan speeds down to zero.
*/
template<>
StandbyState<ModbusIP>::StandbyState() {
// You can add initialization code here if needed
}
/**
* @brief Executes the standby state's logic for one update cycle.
*
* This method applies the strategies defined for the standby state (e.g.,
* ramping values to zero).
*
* @warning This method currently does not check for a command to transition to the
* Running state. This logic needs to be added to allow the unit to start.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusIP>* StandbyState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Standby update function");
float Mode = getPointValue(equipment, "PxMode");
if (static_cast<int>(Mode) == 2 ){
return new RunningState<ModbusIP>();
}
// Apply any strategies defined for the standby state
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the standby state.
* This method performs cleanup by setting all alarm points and all EC fan
* run status points to 0.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void StandbyState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Standby State...");
}
/**
* @brief Logic to execute once when exiting the standby state.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void StandbyState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
// Cleanup logic to run when the equipment leaves this state
Serial.println("Exit Standby State...");
}

View File

@@ -0,0 +1,133 @@
/**
* @file config.h
* @brief Main configuration file for the GEN CAT EMCP4
* @author Zach Gutierrez
* @date 2025-09-02
*
* This file contains two important configurations: WiFi network parameters
* and the Modbus register map for the device.
*/
#ifndef CONFIG_H
#define CONFIG_H
#include "core.h"
#include "Equipment/Equipment.h"
#if defined(USE_MODBUS_IP)
/**
* @defgroup ModbusTCPConfig Modbus IP Configuration
* @brief Parameters for Modbus TCP communication.
* @{
*/
#include <ModbusIP_ESP8266.h>
const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */
const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */
IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;
#else
/**
* @defgroup ModbusRTUConfig Modbus RTU Configuration
* @brief Parameters for serial Modbus RTU communication.
* @{
*/
#include <ModbusRTU.h>
const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */
const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */
const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */
const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */
const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */
/** @} */
/** @brief Global instance of the Modbus RTU server. */
ModbusRTU mb;
#endif
/**
* @defgroup ModbusMapConfig Modbus Map Configuration
* @brief Defines the Modbus register map and related parameters for the emulator.
* @{
*/
/**
* @brief The Modbus map for the Equipment device.
* This array defines all the Modbus points available on the emulated device.
* The `description` field is crucial as it's used to look up points within the application logic.
*/
modbusMap mb_map[] = {
// ESP8266 Modbus server uses 0-based addressing, while Modbus Poll uses 1-based addressing.
{HR, 9, 0, "PxMode" }, // 448900 High_Coolant_Temp_Warning
{HR, 10, 0, "Px01" }, // 448899 Low_Coolant_Temp
{HR, 11, 0, "Px02" }, // 448906 Unexpected_Engine_Shutdown
{HR, 48900, 0, "Alm01" }, // 448900 High_Coolant_Temp_Warning
{HR, 48899, 0, "Alm02" }, // 448899 Low_Coolant_Temp
{HR, 48906, 0, "Alm03" }, // 448906 Unexpected_Engine_Shutdown
{HR, 48897, 0, "Alm04" }, // 448897 Emergency_Stop
{HR, 48901, 0, "Alm05" }, // 448901 High_Coolant_Temp_Alarm
{HR, 48904, 0, "Alm06" }, // 448904 Engine_Overspeed
{HR, 48902, 0, "Alm07" }, // 448902 Low_Oil_Pressure_Warning
{HR, 48903, 0, "Alm08" }, // 448903 Low_Oil_Pressure_Alarm
{HR, 48908, 0, "Fuel_LoLo" }, // 448908 Fuel_LoLo
{HR, 48913, 0, "Alm10" }, // 448913 Low_Battery_Voltage
{HR, 48898, 0, "Alm11" }, // 448898 Engine_Overcrank
{HR, 48915, 0, "Fuel_Hi" }, // 448915 Fuel_Hi
{HR, 48907, 0, "Fuel_Lo" }, // 448907 Fuel_Lo
{HR, 48912, 0, "Alm14" }, // 448912 High_Battery_Voltage
{HR, 48905, 0, "Common_Alarm" }, // 448905 Common_Alarm
{HR, 48914, 0, "Batt_Charge_Fail" }, // 448914 Battery_Charger_Failure
{HR, 48916, 0, "EPS_Supp_Load" }, // 448916 EPS_Supplying_Load
{HR, 8655, 0, "Bkr_State" }, // 48655 Gen_Breaker_State
{HR, 1025, 0, "Oil Pressure" }, // 41025 Engine_Oil_Pressure
{HR, 1026, 0, "Coolant Temp" }, // 41026 Coolant_Temperature_degC
{HR, 1027, 0, "Oil_Temp_degC" }, // 41027 Oil_Temperature_degC
{HR, 1030, 0, "Battery_Voltage" }, // 41030 Battery_Voltage
{HR, 1031, 0, "Engine_Speed" }, // 41031 Engine_Speed
{HR, 1032, 0, "Freq" }, // 41032 Freq
{HR, 1033, 0, "Volts_AN" }, // 41033 Volts_AN
{HR, 1035, 0, "Volts_BN" }, // 41035 Volts_BN
{HR, 1037, 0, "Volts_CN" }, // 41037 Volts_CN
{HR, 1039, 0, "Volts_AB" }, // 41039 Volts_AB
{HR, 1041, 0, "Volts_BC" }, // 41041 Volts_BC
{HR, 1043, 0, "Volts_CA" }, // 41043 Volts_CA
{HR, 1045, 0, "Amps_A" }, // 41045 Amps_A
{HR, 1047, 0, "Amps_B" }, // 41047 Amps_B
{HR, 1049, 0, "Amps_C" }, // 41049 Amps_C
{HR, 1053, 0, "kW_A" }, // 41053 kW_A
{HR, 1055, 0, "kW_B" }, // 41055 kW_B
{HR, 1057, 0, "kW_C" }, // 41057 kW_C
{HR, 1289, 0, "L_Exhaust_degC" }, // 41289 Left_Exhaust_Temp_degC
{HR, 1290, 0, "R_Exhaust_degC" }, // 41290 Right_Exhaust_Temp_degC
{HR, 1355, 0, "Percent_Load" }, // 41355 Percent_Load
{HR, 1537, 0, "kW_Tot" }, // 41537 kW
{HR, 1539, 0, "kVA_A" }, // 41539 kVA_A
{HR, 1541, 0, "kVA_B" }, // 41541 kVA_B
{HR, 1543, 0, "kVA_C" }, // 41543 kVA_C
{HR, 1545, 0, "kVA_Tot" }, // 41545 kVA
{HR, 1553, 0, "kVAR_Tot" }, // 41553 kVAR
{HR, 1558, 0, "PF_Tot" }, // 41558 PF
{HR, 1799, 0, "TTL_Run_Hours" }, // 41799 TTL_Run_Hours
{HR, 1801, 0, "kWh_Tot" }, // 41801 kWh
{HR, 1809, 0, "TTL_Starts" }, // 41809 TTL_Engine_Starts
{HR, 48909, 0, "Auto_Mode" }, // 448909 Auto_Mode
{HR, 48910, 0, "Stop_Mode" }, // 448910 Stop_Mode
{HR, 48911, 0, "Manual_Mode" }, // 448911 Manual_Mode
{HR, 772, 0, "Gen_Sts" } // 400772 Generator Status
};
//Size of modbus map used in FOR cycles, automatically calculated.
/**
* @brief The total number of entries in the `mb_map` array.
* This is calculated at compile time and used for iterating over the map.
*/
const int map_size = sizeof(mb_map) / sizeof(mb_map[0]);
/** @brief The main loop update interval in milliseconds. */
int interval = 250;
/** @} */ // End of ModbusMapConfig group
#endif // CONFIG_H

View File

@@ -0,0 +1,86 @@
/**
* @file main.cpp
* @brief Main execution program for the CRAH Unit (TCP) Emulator.
* @author Emmanuel Hernandez Cruz
* @date 2025-09-02
*
* @details This file contains the main execution program for an Arduino-based emulator of a CRAH unit.
* The program uses a Wi-Fi connection to communicate via the Modbus IP protocol.
*
* The setup() function initializes the following:
* - Serial communication for debugging.
* - Wi-Fi connection using credentials from config.h.
* - A Modbus TCP server.
* - Modbus points (Coils, Holding Registers, etc.) based on a predefined map in config.h.
*
* The loop() function continuously:
* - Services the Modbus TCP server to handle incoming requests.
* - Periodically calls the main update loop for the emulated equipment, which
* manages state transitions and behavior strategies.
*
* @see config.h for Wi-Fi and Modbus configuration.
* @see Equipment.h for the main equipment logic.
* @see State.h for different equipment states.
* @see Strategies/Strategy_Behavior.h for value generation strategies.
* @see Modbus_Point.h for the base class for all Modbus points.
*/
//=================================================================================================================================
//Libraries and declaration of variables.
#include <WiFi.h>
#include "config.h"
#include "ModbusPoints/Modbus_PointFactory.h"
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
//=================================================================================================================================
/**
* @brief Initializes the application.
* @details This function runs once at startup. It configures the serial communication,
* Wi-Fi, and the Modbus server. It also creates and initializes all the Modbus points
* based on the `mb_map` array in `config.h`.
*/
void setup() {
Serial.begin(115200); //Serial comm start
WiFi.config(local_IP, gateway, subnet); // Wifi service start
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Connected!!");
mb.server(); //Modbus server start
Serial.println("Server Created");
Serial.println(map_size);
for(int i = 0; i < map_size; i++){
Modbus_Point<ModbusIP>* point = createModbus_Point(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
if (point) {
point->addToModbusServer();
EquipmentInstance.addModbus_Point(mb_map[i].description, point);
}
}
Serial.println("All modbus Points created");
Serial.println("Setup function ended");
}
//=================================================================================================================================
/**
* @brief The main application loop.
* @details This function runs repeatedly after setup() has completed. It performs two main actions:
* 1. It continuously services the Modbus server by calling `mb.task()` to handle
* incoming requests from a Modbus master.
* 2. At a fixed interval (defined in `config.h`), it calls `EquipmentInstance.update()`
* to run the emulator's internal state machine and behavior logic.
*/
void loop() {
mb.task();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
unsigned long startTime = millis();
EquipmentInstance.update();
unsigned long endTime = millis();
unsigned long elapsedTime = endTime - startTime;
Serial.printf("Control Execution time: %d ms\n", elapsedTime);
}
}

View File

@@ -21,10 +21,10 @@
* @{
*/
#include <ModbusIP_ESP8266.h>
const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */
const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */
IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */
const char *ssid = "ArduinoWifiB"; /**< @brief The SSID of the WiFi network. */
const char *password = "123abc456"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(172, 17, 32, 81); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 32, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;

View File

@@ -0,0 +1,81 @@
/**
* @file State_Fail.cpp
* @brief Implementation of the FailState class.
* @author Emmanuel Hernandez Cruz
* @date 2025-09-05
*
* This file contains the implementation for the FailState, which defines
* the behavior of the equipment when it has entered a fault condition.
*/
#include "ModbusPoints/Modbus_Point.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_PID.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief Constructs a new FailState object with a list of active alarms.
*
* This constructor receives a list of alarm descriptions and creates strategies
* to set the corresponding Modbus points to a value of 1, indicating an
* active alarm. It also initializes a PID strategy for the 'CW Valve Position'
* to maintain its state during the fault.
* @param activeAlarms A vector of strings, where each string is the
* description of a Modbus point to be set as an active alarm.
*/
template<>
FailState<ModbusIP>::FailState(const std::vector<std::string>& activeAlarms) {
// Simulate a failure: set common alarm and a specific fan alarm.
}
/**
* @brief Executes the fail state's logic for one update cycle.
*
* This method checks the "Alarm Reset" Modbus point for a command to
* transition back to Standby, which would typically happen after a fault
* is cleared by a user. If no transition is requested, it continues to apply
* the failure strategies (e.g., keeping alarm bits active).
*
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusIP>* FailState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Fail update function");
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the fail state.
* Sets the "Alarm Common" point to 1 to indicate a general fault condition.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void FailState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Fail State...");
}
/**
* @brief Logic to execute once when exiting the fail state.
* Clears the "Alarm Common" point to 0 before transitioning to the next state.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void FailState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
// Cleanup logic to run when the equipment leaves this state
Serial.println("Exit Fail State...");
}

View File

@@ -0,0 +1,271 @@
/**
* @file State_Running.cpp
* @brief Implementation of the RunningState class.
* @author Emmanuel Hernandez Cruz
* @date 2025-09-05
*
* This file contains the implementation for the RunningState, which defines
* the behavior of the equipment when it is actively running.
*/
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_Random.h"
#include "Strategies/Strategy_Saw.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_Square.h"
#include "Strategies/Strategy_PID.h"
#include "Strategies/Strategy_Totalizer.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "States/State.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief Constructs a new RunningState object.
*
* This constructor initializes behavior strategies active during the running
* state, such as a PID controller for the 'CW Valve Position' and totalizers
* for the run-hours of each EC fan.
*/
template<>
RunningState<ModbusIP>::RunningState() {
}
/**
* @brief Executes the running state's logic for one update cycle.
*
* This method first checks for state transition commands:
* 1. It reads the "ON/OFF Command By BMS" point. If it's 0, it transitions to StandbyState.
* 2. It reads the "Fault Code" point. If it's non-zero, it transitions to FailState,
* passing the corresponding alarm description.
*
* If no transition occurs, it applies the strategies defined for the running state.
*
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Running update function");
float StateCtrl = getPointValue(equipment, "Px_Mode");
if (StateCtrl == 1.0f) {
return new StandbyState<ModbusIP>();
}
float W1 = getPointValue(equipment, "Px_W1");
float W2 = getPointValue(equipment, "Px_W2");
float W3 = getPointValue(equipment, "Px_W3");
float W4 = getPointValue(equipment, "Px_W4");
float W5 = getPointValue(equipment, "Px_W5");
float W6 = getPointValue(equipment, "Px_W6");
// Apply any strategies defined for the standby state
switch (static_cast<int>(W1)){
case 0:
setBitValue(equipment, "MVG_STS_01", 0, false);
setBitValue(equipment, "MVG_STS_01", 1, false);
setBitValue(equipment, "MVG_STS_01", 2, false);
break;
case 1:
setBitValue(equipment, "MVG_STS_01", 0, true);
setBitValue(equipment, "MVG_STS_01", 1, false);
setBitValue(equipment, "MVG_STS_01", 2, false);
break;
case 2:
setBitValue(equipment, "MVG_STS_01", 0, false);
setBitValue(equipment, "MVG_STS_01", 1, true);
setBitValue(equipment, "MVG_STS_01", 2, false);
break;
case 3:
setBitValue(equipment, "MVG_STS_01", 0, true);
setBitValue(equipment, "MVG_STS_01", 1, false);
setBitValue(equipment, "MVG_STS_01", 2, true);
break;
default:
setBitValue(equipment, "MVG_STS_01", 0, false);
setBitValue(equipment, "MVG_STS_01", 1, false);
setBitValue(equipment, "MVG_STS_01", 2, false);
break;
}
switch (static_cast<int>(W2)){
case 0:
setBitValue(equipment, "MVG_STS_01", 3, false);
setBitValue(equipment, "MVG_STS_01", 4, false);
setBitValue(equipment, "MVG_STS_01", 5, false);
break;
case 1:
setBitValue(equipment, "MVG_STS_01", 3, true);
setBitValue(equipment, "MVG_STS_01", 4, false);
setBitValue(equipment, "MVG_STS_01", 5, false);
break;
case 2:
setBitValue(equipment, "MVG_STS_01", 3, false);
setBitValue(equipment, "MVG_STS_01", 4, true);
setBitValue(equipment, "MVG_STS_01", 5, false);
break;
case 3:
setBitValue(equipment, "MVG_STS_01", 3, true);
setBitValue(equipment, "MVG_STS_01", 4, false);
setBitValue(equipment, "MVG_STS_01", 5, true);
break;
default:
setBitValue(equipment, "MVG_STS_01", 3, false);
setBitValue(equipment, "MVG_STS_01", 4, false);
setBitValue(equipment, "MVG_STS_01", 5, false);
break;
}
switch (static_cast<int>(W3)){
case 0:
setBitValue(equipment, "MVG_STS_01", 6, false);
setBitValue(equipment, "MVG_STS_01", 7, false);
setBitValue(equipment, "MVG_STS_02", 0, false);
break;
case 1:
setBitValue(equipment, "MVG_STS_01", 6, true);
setBitValue(equipment, "MVG_STS_01", 7, false);
setBitValue(equipment, "MVG_STS_02", 0, false);
break;
case 2:
setBitValue(equipment, "MVG_STS_01", 6, false);
setBitValue(equipment, "MVG_STS_01", 7, true);
setBitValue(equipment, "MVG_STS_02", 0, false);
break;
case 3:
setBitValue(equipment, "MVG_STS_01", 6, true);
setBitValue(equipment, "MVG_STS_01", 7, false);
setBitValue(equipment, "MVG_STS_02", 0, true);
break;
default:
setBitValue(equipment, "MVG_STS_01", 6, false);
setBitValue(equipment, "MVG_STS_01", 7, false);
setBitValue(equipment, "MVG_STS_02", 0, false);
break;
}
switch (static_cast<int>(W4)){
case 0:
setBitValue(equipment, "MVG_STS_02", 1, false);
setBitValue(equipment, "MVG_STS_02", 2, false);
setBitValue(equipment, "MVG_STS_02", 3, false);
break;
case 1:
setBitValue(equipment, "MVG_STS_02", 1, true);
setBitValue(equipment, "MVG_STS_02", 2, false);
setBitValue(equipment, "MVG_STS_02", 3, false);
break;
case 2:
setBitValue(equipment, "MVG_STS_02", 1, false);
setBitValue(equipment, "MVG_STS_02", 2, true);
setBitValue(equipment, "MVG_STS_02", 3, false);
break;
case 3:
setBitValue(equipment, "MVG_STS_02", 1, true);
setBitValue(equipment, "MVG_STS_02", 2, false);
setBitValue(equipment, "MVG_STS_02", 3, true);
break;
default:
setBitValue(equipment, "MVG_STS_02", 1, false);
setBitValue(equipment, "MVG_STS_02", 2, false);
setBitValue(equipment, "MVG_STS_02", 3, false);
break;
}
switch (static_cast<int>(W5)){
case 0:
setBitValue(equipment, "MVG_STS_02", 4, false);
setBitValue(equipment, "MVG_STS_02", 5, false);
setBitValue(equipment, "MVG_STS_02", 6, false);
break;
case 1:
setBitValue(equipment, "MVG_STS_02", 4, true);
setBitValue(equipment, "MVG_STS_02", 5, false);
setBitValue(equipment, "MVG_STS_02", 6, false);
break;
case 2:
setBitValue(equipment, "MVG_STS_02", 4, false);
setBitValue(equipment, "MVG_STS_02", 5, true);
setBitValue(equipment, "MVG_STS_02", 6, false);
break;
case 3:
setBitValue(equipment, "MVG_STS_02", 4, true);
setBitValue(equipment, "MVG_STS_02", 5, false);
setBitValue(equipment, "MVG_STS_02", 6, true);
break;
default:
setBitValue(equipment, "MVG_STS_02", 4, false);
setBitValue(equipment, "MVG_STS_02", 5, false);
setBitValue(equipment, "MVG_STS_02", 6, false);
break;
}
switch (static_cast<int>(W6)){
case 0:
setBitValue(equipment, "MVG_STS_02", 7, false);
setBitValue(equipment, "MVG_STS_03", 0, false);
setBitValue(equipment, "MVG_STS_03", 1, false);
break;
case 1:
setBitValue(equipment, "MVG_STS_02", 7, true);
setBitValue(equipment, "MVG_STS_03", 0, false);
setBitValue(equipment, "MVG_STS_03", 1, false);
break;
case 2:
setBitValue(equipment, "MVG_STS_02", 7, false);
setBitValue(equipment, "MVG_STS_03", 0, true);
setBitValue(equipment, "MVG_STS_03", 1, false);
break;
case 3:
setBitValue(equipment, "MVG_STS_02", 7, true);
setBitValue(equipment, "MVG_STS_03", 0, false);
setBitValue(equipment, "MVG_STS_03", 1, true);
break;
default:
setBitValue(equipment, "MVG_STS_02", 7, false);
setBitValue(equipment, "MVG_STS_03", 0, false);
setBitValue(equipment, "MVG_STS_03", 1, false);
break;
}
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the running state.
* Sets the "Run Status" for all EC fans to 1 to indicate they are active.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void RunningState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Running State...");
// You could also update a Modbus register to show the "standby" state
}
/**
* @brief Logic to execute once when exiting the running state.
* Sets the "Run Status" for all EC fans to 0 before transitioning to the next state.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void RunningState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
// Cleanup logic to run when the equipment leaves this state
Serial.println("Exit Running State...");
setPointValue(equipment, "MVG_STS_01", 0);
setPointValue(equipment, "MVG_STS_02", 0);
setPointValue(equipment, "MVG_STS_03", 0);
}

View File

@@ -0,0 +1,88 @@
/**
* @file State_Standby.cpp
* @brief Implementation of the StandbyState class.
* @author Emmanuel Hernandez Cruz
* @date 2025-09-05
*
* This file contains the implementation for the StandbyState, which defines
* the behavior of the equipment when it is in an idle or standby mode.
*/
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_Random.h"
#include "Strategies/Strategy_Saw.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_Square.h"
#include "Strategies/Strategy_PID.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "States/State.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief Constructs a new StandbyState object.
*
* In this state, the equipment is idle. This constructor initializes strategies
* to bring the system to a safe, idle condition. It sets a stable value for
* the SAT reading and creates ramp strategies to bring the CW valve and all
* EC fan speeds down to zero.
*/
template<>
StandbyState<ModbusIP>::StandbyState() {
// You can add initialization code here if needed
}
/**
* @brief Executes the standby state's logic for one update cycle.
*
* This method applies the strategies defined for the standby state (e.g.,
* ramping values to zero).
*
* @warning This method currently does not check for a command to transition to the
* Running state. This logic needs to be added to allow the unit to start.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusIP>* StandbyState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Standby update function");
float StateCtrl = getPointValue(equipment, "Px_Mode");
if (StateCtrl == 2.0f) {
return new RunningState<ModbusIP>();
}
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the standby state.
* This method performs cleanup by setting all alarm points and all EC fan
* run status points to 0.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void StandbyState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Standby State...");
}
/**
* @brief Logic to execute once when exiting the standby state.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void StandbyState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
// Cleanup logic to run when the equipment leaves this state
Serial.println("Exit Standby State...");
}

View File

@@ -0,0 +1,86 @@
/**
* @file config.h
* @brief Main configuration file for the CRAH Unit (TCP) emulator.
* @author Emmanuel Hernandez Cruz
* @date 2025-09-02
*
* This file contains two important configurations: WiFi network parameters
* and the Modbus register map for the device.
*/
#ifndef CONFIG_H
#define CONFIG_H
#include "core.h"
#include "Equipment/Equipment.h"
#if defined(USE_MODBUS_IP)
/**
* @defgroup ModbusTCPConfig Modbus IP Configuration
* @brief Parameters for Modbus TCP communication.
* @{
*/
#include <ModbusIP_ESP8266.h>
const char *ssid = "ArduinoWifiB"; /**< @brief The SSID of the WiFi network. */
const char *password = "123abc456"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(172, 17, 32, 82); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 32, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;
#else
/**
* @defgroup ModbusRTUConfig Modbus RTU Configuration
* @brief Parameters for serial Modbus RTU communication.
* @{
*/
#include <ModbusRTU.h>
const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */
const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */
const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */
const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */
const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */
/** @} */
/** @brief Global instance of the Modbus RTU server. */
ModbusRTU mb;
#endif
/**
* @defgroup ModbusMapConfig Modbus Map Configuration
* @brief Defines the Modbus register map and related parameters for the emulator.
* @{
*/
/**
* @brief The Modbus map for the Equipment device.
* This array defines all the Modbus points available on the emulated device.
* The `description` field is crucial as it's used to look up points within the application logic.
*/
modbusMap mb_map[] =
{
{HR, 9, 0, "Px_Mode"},
{HR, 10, 0, "Px_W1"},
{HR, 11, 0, "Px_W2"},
{HR, 12, 0, "Px_W3"},
{HR, 13, 0, "Px_W4"},
{HR, 14, 0, "Px_W5"},
{HR, 15, 0, "Px_W6"},
{HR, 1049, 0, "MVG_STS_01"},
{HR, 1050, 0, "MVG_STS_02"},
{HR, 1051, 0, "MVG_STS_03"},
};
//Size of modbus map used in FOR cycles, automatically calculated.
/**
* @brief The total number of entries in the `mb_map` array.
* This is calculated at compile time and used for iterating over the map.
*/
const int map_size = sizeof(mb_map) / sizeof(mb_map[0]);
/** @brief The main loop update interval in milliseconds. */
int interval = 250;
/** @} */ // End of ModbusMapConfig group
#endif // CONFIG_H

View File

@@ -0,0 +1,86 @@
/**
* @file main.cpp
* @brief Main execution program for the CRAH Unit (TCP) Emulator.
* @author Emmanuel Hernandez Cruz
* @date 2025-09-02
*
* @details This file contains the main execution program for an Arduino-based emulator of a CRAH unit.
* The program uses a Wi-Fi connection to communicate via the Modbus IP protocol.
*
* The setup() function initializes the following:
* - Serial communication for debugging.
* - Wi-Fi connection using credentials from config.h.
* - A Modbus TCP server.
* - Modbus points (Coils, Holding Registers, etc.) based on a predefined map in config.h.
*
* The loop() function continuously:
* - Services the Modbus TCP server to handle incoming requests.
* - Periodically calls the main update loop for the emulated equipment, which
* manages state transitions and behavior strategies.
*
* @see config.h for Wi-Fi and Modbus configuration.
* @see Equipment.h for the main equipment logic.
* @see State.h for different equipment states.
* @see Strategies/Strategy_Behavior.h for value generation strategies.
* @see Modbus_Point.h for the base class for all Modbus points.
*/
//=================================================================================================================================
//Libraries and declaration of variables.
#include <WiFi.h>
#include "config.h"
#include "ModbusPoints/Modbus_PointFactory.h"
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
//=================================================================================================================================
/**
* @brief Initializes the application.
* @details This function runs once at startup. It configures the serial communication,
* Wi-Fi, and the Modbus server. It also creates and initializes all the Modbus points
* based on the `mb_map` array in `config.h`.
*/
void setup() {
Serial.begin(115200); //Serial comm start
WiFi.config(local_IP, gateway, subnet); // Wifi service start
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Connected!!");
mb.server(); //Modbus server start
Serial.println("Server Created");
Serial.println(map_size);
for(int i = 0; i < map_size; i++){
Modbus_Point<ModbusIP>* point = createModbus_Point(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
if (point) {
point->addToModbusServer();
EquipmentInstance.addModbus_Point(mb_map[i].description, point);
}
}
Serial.println("All modbus Points created");
Serial.println("Setup function ended");
}
//=================================================================================================================================
/**
* @brief The main application loop.
* @details This function runs repeatedly after setup() has completed. It performs two main actions:
* 1. It continuously services the Modbus server by calling `mb.task()` to handle
* incoming requests from a Modbus master.
* 2. At a fixed interval (defined in `config.h`), it calls `EquipmentInstance.update()`
* to run the emulator's internal state machine and behavior logic.
*/
void loop() {
mb.task();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
unsigned long startTime = millis();
EquipmentInstance.update();
unsigned long endTime = millis();
unsigned long elapsedTime = endTime - startTime;
Serial.printf("Control Execution time: %d ms\n", elapsedTime);
}
}

View File

@@ -0,0 +1,48 @@
# Daikin Chiller (RTU) Emulator
This project is an Arduino-based emulator for a Daikin Chiller unit, communicating over Modbus RTU. It is designed to be a flexible template that can be adapted to simulate different types of chillers by modifying the configuration and state logic.
The emulator operates on a state machine with three core states:
* **Standby**: The chiller is idle but ready.
* **Running**: The chiller is active and operational.
* **Fail**: The chiller has encountered a fault condition.
## Features
* **Modbus RTU Communication**: Emulates a Modbus slave device.
* **State Machine Logic**: Simulates different operational states (Standby, Running, Fail).
* **Dynamic Value Simulation**: Uses "Strategies" (e.g., PID, Ramp) to generate realistic, changing values for Modbus points.
* **Configurable Modbus Map**: The entire Modbus register map is defined in a single, easy-to-modify file (`config.h`).
* **Extensible Design**: The structure allows for the addition of new states and behaviors.
## Hardware Prerequisites
The code is written for an ESP8266/ESP32-style microcontroller with WiFi capabilities and at least one hardware serial port for RS485 communication.
* **Microcontroller**: ESP8266, ESP32, or similar.
* **RS485 Transceiver**: A module like the MAX485 to interface with the Modbus RTU bus.
## Software Dependencies
This project relies on a Modbus library. Ensure you have the correct library installed in your Arduino IDE.
* **Modbus Library**: The code uses a library that provides `ModbusRTU.h` and optionally `ModbusIP_ESP8266.h`.
---
## How to Customize for a New Chiller
To adapt this template for a new chiller, follow these steps.
### 1. Configure Device-Specific Parameters (`config.h`)
Open `CH_Daikin_AWV026B_RTU/config.h`. This is the main file for device-specific settings.
#### Modbus RTU Settings
Update the following constants for your device's serial communication setup.
```c++
const int BAUDRATE = 19200; // The serial communication speed
const int RX_PIN = 17; // The GPIO pin for receiving data (RX)
const int TX_PIN = 16; // The GPIO pin for transmitting data (TX)
const int RST_PIN = 4; // The GPIO pin for RS485 direction control
const int MODBUS_ID = 1; // The unique slave ID for this device

View File

@@ -0,0 +1,81 @@
/**
* @file State_Fail.cpp
* @brief Implementation of the FailState class.
* @author Emmanuel Hernandez Cruz
* @date 2025-09-05
*
* This file contains the implementation for the FailState, which defines
* the behavior of the equipment when it has entered a fault condition.
*/
#include "ModbusPoints/Modbus_Point.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_SingleValue.h"
#include "Strategies/Strategy_PID.h"
#include "States/State_Standby.h"
#include "States/State_Running.h"
#include "States/State_Fail.h"
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief Constructs a new FailState object with a list of active alarms.
*
* This constructor receives a list of alarm descriptions and creates strategies
* to set the corresponding Modbus points to a value of 1, indicating an
* active alarm. It also initializes a PID strategy for the 'CW Valve Position'
* to maintain its state during the fault.
* @param activeAlarms A vector of strings, where each string is the
* description of a Modbus point to be set as an active alarm.
*/
template<>
FailState<ModbusIP>::FailState(const std::vector<std::string>& activeAlarms) {
// Simulate a failure: set common alarm and a specific fan alarm.
}
/**
* @brief Executes the fail state's logic for one update cycle.
*
* This method checks the "Alarm Reset" Modbus point for a command to
* transition back to Standby, which would typically happen after a fault
* is cleared by a user. If no transition is requested, it continues to apply
* the failure strategies (e.g., keeping alarm bits active).
*
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusIP>* FailState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Fail update function");
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the fail state.
* Sets the "Alarm Common" point to 1 to indicate a general fault condition.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void FailState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Fail State...");
}
/**
* @brief Logic to execute once when exiting the fail state.
* Clears the "Alarm Common" point to 0 before transitioning to the next state.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void FailState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
// Cleanup logic to run when the equipment leaves this state
Serial.println("Exit Fail State...");
}

View File

@@ -21,10 +21,10 @@
* @{
*/
#include <ModbusIP_ESP8266.h>
const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */
const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */
IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */
const char *ssid = "ArduinoWifiB"; /**< @brief The SSID of the WiFi network. */
const char *password = "123abc456"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(172, 17, 32, 88); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 32, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;

View File

@@ -0,0 +1,86 @@
/**
* @file main.cpp
* @brief Main execution program for the CRAH Unit (TCP) Emulator.
* @author Emmanuel Hernandez Cruz
* @date 2025-09-02
*
* @details This file contains the main execution program for an Arduino-based emulator of a CRAH unit.
* The program uses a Wi-Fi connection to communicate via the Modbus IP protocol.
*
* The setup() function initializes the following:
* - Serial communication for debugging.
* - Wi-Fi connection using credentials from config.h.
* - A Modbus TCP server.
* - Modbus points (Coils, Holding Registers, etc.) based on a predefined map in config.h.
*
* The loop() function continuously:
* - Services the Modbus TCP server to handle incoming requests.
* - Periodically calls the main update loop for the emulated equipment, which
* manages state transitions and behavior strategies.
*
* @see config.h for Wi-Fi and Modbus configuration.
* @see Equipment.h for the main equipment logic.
* @see State.h for different equipment states.
* @see Strategies/Strategy_Behavior.h for value generation strategies.
* @see Modbus_Point.h for the base class for all Modbus points.
*/
//=================================================================================================================================
//Libraries and declaration of variables.
#include <WiFi.h>
#include "config.h"
#include "ModbusPoints/Modbus_PointFactory.h"
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
//=================================================================================================================================
/**
* @brief Initializes the application.
* @details This function runs once at startup. It configures the serial communication,
* Wi-Fi, and the Modbus server. It also creates and initializes all the Modbus points
* based on the `mb_map` array in `config.h`.
*/
void setup() {
Serial.begin(115200); //Serial comm start
WiFi.config(local_IP, gateway, subnet); // Wifi service start
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Connected!!");
mb.server(); //Modbus server start
Serial.println("Server Created");
Serial.println(map_size);
for(int i = 0; i < map_size; i++){
Modbus_Point<ModbusIP>* point = createModbus_Point(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
if (point) {
point->addToModbusServer();
EquipmentInstance.addModbus_Point(mb_map[i].description, point);
}
}
Serial.println("All modbus Points created");
Serial.println("Setup function ended");
}
//=================================================================================================================================
/**
* @brief The main application loop.
* @details This function runs repeatedly after setup() has completed. It performs two main actions:
* 1. It continuously services the Modbus server by calling `mb.task()` to handle
* incoming requests from a Modbus master.
* 2. At a fixed interval (defined in `config.h`), it calls `EquipmentInstance.update()`
* to run the emulator's internal state machine and behavior logic.
*/
void loop() {
mb.task();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
unsigned long startTime = millis();
EquipmentInstance.update();
unsigned long endTime = millis();
unsigned long elapsedTime = endTime - startTime;
Serial.printf("Control Execution time: %d ms\n", elapsedTime);
}
}