Merge branch 'develop' into rdavis/UMAS_CRAH_TCP
This commit is contained in:
@@ -54,7 +54,7 @@ template<>
|
||||
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");
|
||||
Modbus_Point<ModbusRTU>* clearAlm = equipment->getModbus_Point("Clear Alm");
|
||||
Modbus_Point<ModbusRTU>* clearAlm = equipment->getModbus_Point("Clear Alarms");
|
||||
int nextStateId = clearAlm ? clearAlm->getValue() : 0;
|
||||
if (nextStateId == 1){
|
||||
return new StandbyState<ModbusRTU>();
|
||||
|
||||
@@ -38,10 +38,11 @@
|
||||
*/
|
||||
template<>
|
||||
RunningState<ModbusRTU>::RunningState() {
|
||||
addStrategy("Actual Capacity", new PIDStrategy("Active SP", 1000, "Supply Temp"));
|
||||
addStrategy("Comp1 Percent RLA", new RampStrategy(0.0f, 5.0f, 1000));
|
||||
addStrategy("Comp2 Percent RLA", new RampStrategy(0.0f, 5.0f, 1000));
|
||||
addStrategy("Return Temp", new SingleValueStrategy(85,3.0f, 1000));
|
||||
addStrategy("Actual Capacity", new PIDStrategy("Chiller Local Setpoint", 1000, "PICs Supply Temp"));
|
||||
addStrategy("C1 Comp 1 Motor Percent (RLA)", new RampStrategy(0.0f, 5.0f, 1000));
|
||||
addStrategy("C2 Comp 1 Motor Percent (RLA)", new RampStrategy(0.0f, 5.0f, 1000));
|
||||
addStrategy("C3 Comp 1 Motor Percent (RLA)", new RampStrategy(0.0f, 5.0f, 1000));
|
||||
addStrategy("PICs Return Temp", new SingleValueStrategy(85,3.0f, 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,25 +76,27 @@ State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
|
||||
// Determine the correct setpoint based on the current operating mode.
|
||||
switch(currentMode){
|
||||
case 1:
|
||||
currentSP = getPointValue(equipment, "Ice SP");
|
||||
currentSP = getPointValue(equipment, "Ice Setpoint");
|
||||
currentSP = currentSP - 20;
|
||||
break; // Added break to prevent fall-through
|
||||
case 2:
|
||||
currentSP = getPointValue(equipment, "Cool SP");
|
||||
currentSP = getPointValue(equipment, "Cooling Active Setpoint");
|
||||
currentSP = currentSP + 20;
|
||||
break; // Added break
|
||||
default:
|
||||
// The default value is already set.
|
||||
break;
|
||||
}
|
||||
Strategy_Behavior* ramp_strategy1 = getStrategy("Comp1 Percent RLA");
|
||||
Strategy_Behavior* ramp_strategy2 = getStrategy("Comp2 Percent RLA");
|
||||
Strategy_Behavior* ramp_strategy1 = getStrategy("C1 Comp 1 Motor Percent (RLA)");
|
||||
Strategy_Behavior* ramp_strategy2 = getStrategy("C2 Comp 1 Motor Percent (RLA)");
|
||||
Strategy_Behavior* ramp_strategy3 = getStrategy("C3 Comp 1 Motor Percent (RLA)");
|
||||
int actualCapacity = getPointValue(equipment, "Actual Capacity");
|
||||
if (actualCapacity < 50){
|
||||
actualCapacity = actualCapacity * 2;
|
||||
if (actualCapacity > 100) actualCapacity = 100;
|
||||
static_cast<RampStrategy*>(ramp_strategy1)->setTarget(actualCapacity);
|
||||
static_cast<RampStrategy*>(ramp_strategy2)->setTarget(0);
|
||||
static_cast<RampStrategy*>(ramp_strategy3)->setTarget(0);
|
||||
} else {
|
||||
if (actualCapacity > 100) actualCapacity = 100;
|
||||
static_cast<RampStrategy*>(ramp_strategy1)->setTarget(actualCapacity);
|
||||
@@ -110,7 +113,7 @@ State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
|
||||
static_cast<PIDStrategy*>(strategy)->setSetpoint(currentSP);
|
||||
}
|
||||
|
||||
float OutdoorTemp = getPointValue(equipment, "Outdoor Air Temp");
|
||||
float OutdoorTemp = getPointValue(equipment, "Ambient Temperature");
|
||||
Serial.printf("Outdoor Temp: %f\n", OutdoorTemp);
|
||||
if (OutdoorTemp >50.0f) {
|
||||
setPointValue(equipment, "Chiller Mode SP", 1.0f);
|
||||
@@ -120,10 +123,10 @@ State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
|
||||
setPointValue(equipment, "Chiller Mode Output", 2.0f);
|
||||
}
|
||||
|
||||
float SupplyTemp = getPointValue(equipment, "Supply Temp");
|
||||
setPointValue(equipment, "Return Temp", SupplyTemp + 14.0f);
|
||||
float SupplyTemp = getPointValue(equipment, "PICs Supply Temp");
|
||||
setPointValue(equipment, "PICs Return Temp", SupplyTemp + 14.0f);
|
||||
|
||||
setPointValue(equipment, "Active SP", currentSP);
|
||||
setPointValue(equipment, "Chiller Local Setpoint", currentSP);
|
||||
// Apply any strategies defined for the standby state
|
||||
_applyStrategies(equipment);
|
||||
return nullptr;
|
||||
@@ -139,7 +142,7 @@ void RunningState<ModbusRTU>::enterState(Equipment<ModbusRTU>* 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
|
||||
setPointValue(equipment, "Run Enabled", 1);
|
||||
setPointValue(equipment, "Run Enable", 1);
|
||||
setPointValue(equipment, "Flow Switch", 1);
|
||||
|
||||
}
|
||||
|
||||
@@ -32,9 +32,10 @@
|
||||
*/
|
||||
template<>
|
||||
StandbyState<ModbusRTU>::StandbyState() {
|
||||
addStrategy("Comp1 Percent RLA", new RampStrategy(0,5,1000));
|
||||
addStrategy("Comp2 Percent RLA", new RampStrategy(0,5,1000));
|
||||
addStrategy("Return Temp", new SingleValueStrategy(85,3.0f, 1000));
|
||||
addStrategy("C1 Comp 1 Motor Percent (RLA)", new RampStrategy(0,5,1000));
|
||||
addStrategy("C2 Comp 1 Motor Percent (RLA)", new RampStrategy(0,5,1000));
|
||||
addStrategy("C3 Comp 1 Motor Percent (RLA)", new RampStrategy(0,5,1000));
|
||||
addStrategy("PICs Return Temp", new SingleValueStrategy(85,3.0f, 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +56,7 @@ State<ModbusRTU>* StandbyState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
|
||||
if (CH_Enable_SP == 1){
|
||||
return new RunningState<ModbusRTU>();
|
||||
}
|
||||
float OutdoorTemp = getPointValue(equipment, "Outdoor Air Temp");
|
||||
float OutdoorTemp = getPointValue(equipment, "Ambient Temperature");
|
||||
Serial.printf("Outdoor Temp: %f\n", OutdoorTemp);
|
||||
if (OutdoorTemp >50.0f) {
|
||||
setPointValue(equipment, "Chiller Mode SP", 1);
|
||||
@@ -76,7 +77,7 @@ template<>
|
||||
void StandbyState<ModbusRTU>::enterState(Equipment<ModbusRTU>* equipment) {
|
||||
// Logic to run when the equipment enters this state
|
||||
Serial.println("Enter Standby State...");
|
||||
setPointValue(equipment, "Run Enabled", 0);
|
||||
setPointValue(equipment, "Run Enable", 0);
|
||||
setPointValue(equipment, "Flow Switch", 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = "QTS_CDR_Arduino"; /**< @brief The SSID of the WiFi network. */
|
||||
const char *password = "123abc456"; /**< @brief The password for the WiFi network. */
|
||||
IPAddress local_IP(172, 17, 33, 78); /**< @brief The static IP address for the device. */
|
||||
IPAddress gateway(192, 17, 33, 1); /**< @brief The gateway IP address. */
|
||||
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
|
||||
|
||||
ModbusIP mb;
|
||||
@@ -54,67 +54,51 @@
|
||||
*/
|
||||
modbusMap mb_map[] =
|
||||
{
|
||||
{HR, 100, 0, "State Control"}, //Internal to control from Modscan
|
||||
{HR, 101, 0, "Fault Code"},
|
||||
{HR_FLOAT, 102, 0, "Supply Temp"},
|
||||
{HR_FLOAT, 103, 0, "Return Temp"}, //+14
|
||||
{HR_FLOAT, 104, 0, "Flow Switch"},
|
||||
{HR, 0, 0, "Chiller Local-Network"},
|
||||
{HR, 1, 0, "Chiller Enable Output"},
|
||||
{HR, 2, 0, "Run Enabled"},
|
||||
{HR, 3, 0, "Chiller Capacity Limited"},
|
||||
{HR, 4, 0, "Alm Digital Output"},
|
||||
{HR, 6, 0, "Evap Flow Switch Sts"},
|
||||
{HR, 7, 0, "Cond Flow Switch Sts"},
|
||||
{HR, 8, 0, "Chiller On-Off"},
|
||||
{HR, 9, 0, "Chiller Enable SP"},
|
||||
{HR, 10, 0, "Clear Alm"},
|
||||
{HR, 11, 0, "Chiller Mode Output"},
|
||||
{HR_10x, 12, 0, "Active SP"},
|
||||
{HR_10x, 13, 0, "Actual Capacity"},
|
||||
{HR_10x, 14, 0, "Active Capacity Limit"},
|
||||
{HR, 15, 0, "Chiller Sts"},
|
||||
{HR_10x, 16, 0, "Evap Entering Fluid Temp"},
|
||||
{HR_10x, 17, 0, "Evap Leaving Fluid Temp"},
|
||||
{HR, 18, 0, "Evap Fluid Flow Rate"},
|
||||
{HR_10x, 19, 0, "Cond Entering Fluid Temp"},
|
||||
{HR_10x, 20, 0, "Cond Leaving Fluid Temp"},
|
||||
{HR, 21, 0, "Cond Fluid Flow Rate"},
|
||||
{HR_10x, 24, 0, "Outdoor Air Temp"},
|
||||
{HR, 25, 0, "Chiller Current"},
|
||||
{HR, 27, 0, "Total Kw"},
|
||||
{HR, 28, 0, "Warning Alm Idx"},
|
||||
{HR, 29, 0, "Problem Alm Idx"},
|
||||
{HR, 30, 0, "Fault Alm Idx"},
|
||||
{HR, 31, 0, "Warning Alm Code"},
|
||||
{HR, 32, 0, "Problem Alm Code"},
|
||||
{HR, 33, 0, "Fault Alm Code"},
|
||||
{HR, 34, 0, "Chiller Mode SP"},
|
||||
{HR_10x, 35, 0, "Cool SP"},
|
||||
{HR_10x, 36, 0, "Ice SP"},
|
||||
{HR_10x, 38, 0, "Capacity Limit SP"},
|
||||
{HR_10x, 39, 0, "Cond Refrig Pressure"},
|
||||
{HR_10x, 40, 0, "Cond Saturated Refrig Temp"},
|
||||
{HR_10x, 41, 0, "Evap Refrig Pressure"},
|
||||
{HR_10x, 42, 0, "Evap Saturated Refrig Temp"},
|
||||
{HR, 65, 0, "Comp Suction Refrig Temp"},
|
||||
{HR_10x, 68, 0, "Comp Discharge Refrig Temp"},
|
||||
{HR, 69, 0, "Comp1 Percent RLA"},
|
||||
{HR, 70, 0, "Comp1 Current"},
|
||||
{HR, 71, 0, "Comp Voltage"},
|
||||
{HR, 72, 0, "Comp Power"},
|
||||
{HR, 73, 0, "Comp Starts"},
|
||||
{HR, 74, 0, "Comp Run Hours"},
|
||||
{HR, 75, 0, "Comp Run Hours"},
|
||||
{HR, 82, 0, "Comp2 Percent RLA"},
|
||||
{HR, 303, 0, "Evap Pump Run Hours"},
|
||||
{HR, 304, 0, "Evap Pump Run Hours"},
|
||||
{HR, 305, 0, "Evap Pump Sts"},
|
||||
{HR, 316, 0, "Units"},
|
||||
{HR, 317, 0, "Chiller Model"},
|
||||
{HR, 1849, 0, "Oil Feed Pessure"},
|
||||
{HR, 1854, 0, "Wtrside Econo State"},
|
||||
{HR, 1855, 0, "Wtrside Econo En SP"},
|
||||
{HR_FLOAT, 8100, 0, "PICs Supply Temp"}, //Internal to control from Modscan
|
||||
{COIL, 8102, 0, "PICs Chiller Enable"},
|
||||
{HR_FLOAT, 8104, 0, "PICs Chiller Flow"},
|
||||
{HR_FLOAT, 8106, 0, "PICs Return Temp"},
|
||||
{HR, 3, 0, "Run Enable"},
|
||||
{HR, 9, 0, "Chiller Enable SP"},
|
||||
{HR, 10, 0, "Clear Alarms"},
|
||||
{HR, 11, 0, "Chiller Mode Output"},
|
||||
{HR_10x, 12, 0, "Chiller Local Setpoint"},
|
||||
{HR_10x, 13, 0, "Actual Capacity"},
|
||||
{HR_10x, 14, 0, "Active Capacity Limit"},
|
||||
{HR_10x, 16, 0, "System Chill Water In Temp"},
|
||||
{HR_10x, 17, 0, "System Chill Water Out Temp"},
|
||||
{HR_10x, 24, 0, "Ambient Temperature"},
|
||||
{HR, 27, 0, "Chiller Total Power"},
|
||||
{HR, 34, 0, "Chiller Mode SP"},
|
||||
{HR_10x, 35, 0, "Cooling Active Setpoint"},
|
||||
{HR_10x, 36, 0, "Ice Setpoint"},
|
||||
{HR_10x, 39, 0, "C1 Cond Refrig Pres"},
|
||||
{HR_10x, 41, 0, "C1 Evap Refrig Pres"},
|
||||
{HR_10x, 43, 0, "C2 Cond Refrig Pres"},
|
||||
{HR_10x, 45, 0, "C2 Evap Refrig Pres"},
|
||||
{HR_10x, 47, 0, "C3 Cond Refrig Pres"},
|
||||
{HR_10x, 49, 0, "C3 Evap Refrig Pres"},
|
||||
{HR_10x, 51, 0, "C4 Cond Refrig Pres"},
|
||||
{HR_10x, 53, 0, "C4 Evap Refrig Pres"},
|
||||
{HR_10x, 63, 0, "C1 Comp Suction Refrig Pres"},
|
||||
{HR_10x, 66, 0, "C1 Comp 1 Discharge Refrig Pres"},
|
||||
{HR, 69, 0, "C1 Comp 1 Motor Percent (RLA)"},
|
||||
{HR, 70, 0, "C1 Comp Current"},
|
||||
{HR, 72, 0, "C1 Comp 1 Power"},
|
||||
{HR_10x, 76, 0, "C1 Comp 2 Suction Refrig Pres"},
|
||||
{HR_10x, 79, 0, "C1 Comp 2 Discharge Refrig Pres"},
|
||||
{HR, 108, 0, "C2 Comp 1 Current"},
|
||||
{HR, 109, 0, "C2 Comp 1 Current"},
|
||||
{HR, 111, 0, "C2 Comp 1 Power"},
|
||||
{HR, 147, 0, "C3 Comp 1 Motor Percent (RLA)"},
|
||||
{HR, 148, 0, "C3 Comp 1 Current"},
|
||||
{HR, 150, 0, "C3 Comp 1 Power"},
|
||||
{HR, 592, 0, "Alarm Freeze Protection Evap 1"},
|
||||
{HR, 593, 0, "Alarm Freeze Protection Evap 2"},
|
||||
{HR_10x, 1731, 0, "C4 Comp 1 Oil Pres"},
|
||||
{HR_10x, 1770, 0, "C3 Comp 1 Oil Pres"},
|
||||
{HR_10x, 1809, 0, "C2 Comp 1 Oil Pres"},
|
||||
{HR_10x, 1849, 0, "C1 Comp 1 Oil Pres"},
|
||||
|
||||
};
|
||||
//Size of modbus map used in FOR cycles, automatically calculated.
|
||||
|
||||
43
src/BMS/CHILLER/CH_York_YVAA_RTU/README.md
Normal file
43
src/BMS/CHILLER/CH_York_YVAA_RTU/README.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# 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
|
||||
|
||||
## List of Equipment
|
||||
This cofiguration has been used for these models:
|
||||
* **YVAA**: 10-14-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
|
||||
Updates Alarms States. If any active alarms --> FailState
|
||||
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)
|
||||
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
|
||||
|
||||
### Running State
|
||||
* **Chiller status**: set to 1
|
||||
* **Supply Temperature**: **Ramp Strategy** ramps to Temp Setpoint from PLC (Modscan)
|
||||
|
||||
### Fail State
|
||||
* **Chiller Status**: set to 0
|
||||
85
src/BMS/CHILLER/CH_York_YVAA_RTU/StateUtils.cpp
Normal file
85
src/BMS/CHILLER/CH_York_YVAA_RTU/StateUtils.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* @file StateUtils.cpp
|
||||
* @brief Implementation of the StateUtils class.
|
||||
* @author Robert J. Davis
|
||||
* @date 2025-10-14
|
||||
*
|
||||
* 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 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)
|
||||
*
|
||||
* This is a function used in the update() of the Standby, Running, and Fail States.
|
||||
*
|
||||
*/
|
||||
|
||||
void updateAlarms(Equipment<ModbusRTU>* equipment){
|
||||
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");
|
||||
Modbus_Point<ModbusRTU>* Sys2FanAlarm = equipment->getModbus_Point("Sys 2 Fan Fault Alarm");
|
||||
if (Sys1FanAlarmCommand) {
|
||||
Sys1FanAlarm->setValue(Sys1FanAlarmCommand->getValue());
|
||||
if (Sys1FanAlarmCommand->getValue() == 1){
|
||||
equipment->setModbus_Point("Sys 1 Fault Code", 56);
|
||||
}
|
||||
else equipment->setModbus_Point("Sys 1 Fault Code", 0);
|
||||
}
|
||||
if (Sys2FanAlarmCommand) {
|
||||
Sys2FanAlarm->setValue(Sys2FanAlarmCommand->getValue());
|
||||
if (Sys2FanAlarmCommand->getValue() == 1){
|
||||
equipment->setModbus_Point("Sys 2 Fault Code", 56);
|
||||
}
|
||||
else equipment->setModbus_Point("Sys 2 Fault Code", 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Updates Free Cooling Mode
|
||||
*
|
||||
* This function will update the Free Cooling Mode and Valve based on Free Cooling Command
|
||||
* received from Modscan. This is for simulation purposes only - in practice, the Chiller
|
||||
* will transition to Free Cooling 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 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);
|
||||
}
|
||||
}
|
||||
43
src/BMS/CHILLER/CH_York_YVAA_RTU/StateUtils.h
Normal file
43
src/BMS/CHILLER/CH_York_YVAA_RTU/StateUtils.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @file config.h
|
||||
* @brief StateUtils class
|
||||
* @author Robert J Davis
|
||||
* @date 2025-10-06
|
||||
*
|
||||
* 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 Alarms states
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
* @return void
|
||||
*/
|
||||
void updateAlarms(Equipment<ModbusRTU>* equipment);
|
||||
|
||||
/**
|
||||
* @brief Updates Free Cooling Mode
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
* @return void
|
||||
*/
|
||||
void updateFreeCooling(Equipment<ModbusRTU>* equipment);
|
||||
107
src/BMS/CHILLER/CH_York_YVAA_RTU/State_Fail.cpp
Normal file
107
src/BMS/CHILLER/CH_York_YVAA_RTU/State_Fail.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* @file State_Fail.cpp
|
||||
* @brief Implementation of the FailState class.
|
||||
* @author Robert J. Davis
|
||||
* @date 2025-10-14
|
||||
*
|
||||
* 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"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#if defined(USE_MODBUS_IP)
|
||||
#include <ModbusIP_ESP8266.h>
|
||||
#else
|
||||
#include <ModbusRTU.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
* @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<ModbusRTU>::FailState(const std::vector<std::string>& activeAlarms) {
|
||||
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("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));
|
||||
addStrategy("Sys 2 Compressor KW", new SingleValueStrategy(0.0f, 0.0f, 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
* @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
|
||||
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",
|
||||
};
|
||||
|
||||
// If no alarms active --> send to StandbyState()
|
||||
bool alarms_active = false;
|
||||
for (const auto& desc : alarmDescriptions) {
|
||||
Modbus_Point<ModbusRTU>* point = equipment->getModbus_Point(desc);
|
||||
if (point->getValue() == 1) {
|
||||
alarms_active = true;
|
||||
}
|
||||
}
|
||||
if (!alarms_active) return new StandbyState<ModbusRTU>();
|
||||
|
||||
setPointValue(equipment, "Chiller Start Command", 0);
|
||||
|
||||
_applyStrategies(equipment);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic to execute once when entering the fail state.
|
||||
* Sets the Chiller Status to off, and updates the Operational Code for Systems to 77 (Not Running)
|
||||
* The Chiller Start Command is also set 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, "Chiller Start Command", 0);
|
||||
setPointValue(equipment, "Chiller Status", 0);
|
||||
setPointValue(equipment, "Sys 1 Operational Code", 77);
|
||||
setPointValue(equipment, "Sys 2 Operational Code", 77);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic to execute once when exiting the fail state.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void FailState<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
|
||||
// Cleanup logic to run when the equipment leaves this state
|
||||
Serial.println("Exit Fail State...");
|
||||
}
|
||||
171
src/BMS/CHILLER/CH_York_YVAA_RTU/State_Running.cpp
Normal file
171
src/BMS/CHILLER/CH_York_YVAA_RTU/State_Running.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* @file State_Running.cpp
|
||||
* @brief Implementation of the RunningState class.
|
||||
* @author Robert J Davis
|
||||
* @date 2025-10-12
|
||||
*
|
||||
* 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, number of starts for each System and totalizers
|
||||
* for the run-hours of each System.
|
||||
*/
|
||||
template<>
|
||||
RunningState<ModbusRTU>::RunningState() {
|
||||
addStrategy("Supply Temp", new RampStrategy(67.0f, 1.0f, 1000));
|
||||
addStrategy("Return Temp", new SawStrategy(79.0f, 83.0f, 1.0f, 1000));
|
||||
addStrategy("Ambient Temp", new SingleValueStrategy(100.0f, 1.0f, 1000));
|
||||
|
||||
addStrategy("System CHW Out", new RampStrategy(67.0f, 1.0f, 1000));
|
||||
addStrategy("System CHW In", new RampStrategy(81.0f, 1.0f, 1000));
|
||||
addStrategy("Sys 1 Condenser Temp", new SingleValueStrategy(125.0f, 5.0f, 1000));
|
||||
addStrategy("Sys 2 Condenser Temp", new SingleValueStrategy(125.0f, 5.0f, 1000));
|
||||
addStrategy("Sys 1 Oil Pressure", new SingleValueStrategy(450.0f, 5.0f, 1000));
|
||||
addStrategy("Sys 2 Oil Pressure", new SingleValueStrategy(450.0f, 5.0f, 1000));
|
||||
addStrategy("Sys 1 Suction Pressure", new SingleValueStrategy(70.0f, 2.0f, 1000));
|
||||
addStrategy("Sys 2 Suction Pressure", new SingleValueStrategy(70.0f, 2.0f, 1000));
|
||||
addStrategy("Sys 1 Discharge Pressure", new SingleValueStrategy(375.0f, 4.0f, 1000));
|
||||
addStrategy("Sys 2 Discharge Pressure", new SingleValueStrategy(375.0f, 4.0f, 1000));
|
||||
addStrategy("Sys 1 Compressor Pct FLA", new SingleValueStrategy(93.0f, 2.0f, 1000));
|
||||
addStrategy("Sys 2 Compressor Pct FLA", new SingleValueStrategy(93.0f, 2.0f, 1000));
|
||||
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("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));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Executes the running state's logic for one update cycle.
|
||||
*
|
||||
* This method first checks if there are any active alarms --> FailState.
|
||||
* Also checks for Free Cooling Mode (for ease of testing)
|
||||
* If no alarms are active, checks for "Chiller Start Command" = 0 (Modscan, but will be from PLC)
|
||||
* for a command to transition to the Standby state. If no transition is requested, it updates the
|
||||
* rampStrategy targetValues for the Supply Temp, CHW In, CHW Out analog values and applies the
|
||||
* strategies defined for the running 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<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
|
||||
// Update alarms states, Free Cooling mode, Freeze Protection Mode
|
||||
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",
|
||||
};
|
||||
|
||||
// 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) {
|
||||
Modbus_Point<ModbusRTU>* point = equipment->getModbus_Point(desc);
|
||||
if (point->getValue() == 1) {
|
||||
activeAlarmsDescriptions.push_back(desc);
|
||||
alarms_active = true;
|
||||
}
|
||||
}
|
||||
if (alarms_active) return new FailState<ModbusRTU>(activeAlarmsDescriptions);
|
||||
|
||||
// If no alarms 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>();
|
||||
}
|
||||
|
||||
// Set the Supply Temp ramp target value equal to the Chiller Temp Setpoint
|
||||
// Ramp CHW In Temp to Return Temp and CHW Out Temp to Supply Temp
|
||||
float BMS_Temp_Setpoint = getPointValue(equipment, "Chiller Temp Setpoint");
|
||||
float supplyTemp = getPointValue(equipment, "Supply Temp");
|
||||
float returnTemp = getPointValue(equipment, "Return Temp");
|
||||
Strategy_Behavior* Supply_Temp_strat = getStrategy("Supply Temp");
|
||||
Strategy_Behavior* CHW_Out_strat = getStrategy("System CHW Out");
|
||||
Strategy_Behavior* CHW_In_strat = getStrategy("System CHW In");
|
||||
if (Supply_Temp_strat){
|
||||
static_cast<RampStrategy*>(Supply_Temp_strat)->setTarget(BMS_Temp_Setpoint);
|
||||
static_cast<RampStrategy*>(CHW_Out_strat)->setTarget(supplyTemp);
|
||||
static_cast<RampStrategy*>(CHW_In_strat)->setTarget(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 "Chiller Status" point to indicate the unit is running.
|
||||
* Update System Operational Code to 78 (Running).
|
||||
* Increment a counter for number of starts for each System.
|
||||
* We are assuming when the Chiller is commanded to run that both Systems will activate.
|
||||
* Not enough information in Vendor SOO to add details for running systems independently,
|
||||
* switching to Free-Cooling Mode, etc.
|
||||
*
|
||||
* @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, "Chiller Status", 1);
|
||||
setPointValue(equipment, "Sys 1 Operational Code", 78);
|
||||
setPointValue(equipment, "Sys 2 Operational Code", 78);
|
||||
|
||||
// Add one to the System 1 and 2 Starts counter
|
||||
int Sys1_num_starts = getPointValue(equipment, "Sys 1 Starts");
|
||||
int Sys2_num_starts = getPointValue(equipment, "Sys 2 Starts");
|
||||
Sys1_num_starts++;
|
||||
Sys2_num_starts++;
|
||||
setPointValue(equipment, "Sys 1 Starts", Sys1_num_starts);
|
||||
setPointValue(equipment, "Sys 2 Starts", Sys2_num_starts);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic to execute once when exiting the running state.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void RunningState<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
|
||||
// Cleanup logic to run when the equipment leaves this state
|
||||
Serial.println("Exit Running State...");
|
||||
}
|
||||
136
src/BMS/CHILLER/CH_York_YVAA_RTU/State_Standby.cpp
Normal file
136
src/BMS/CHILLER/CH_York_YVAA_RTU/State_Standby.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* @file State_Standby.cpp
|
||||
* @brief Implementation of the StandbyState class.
|
||||
* @author Robert J Davis
|
||||
* @date 2025-10-13
|
||||
*
|
||||
* 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 sets a stable value for
|
||||
* the analog readings and takes Fans and Compressors to 0 kW.
|
||||
*/
|
||||
template<>
|
||||
StandbyState<ModbusRTU>::StandbyState() {
|
||||
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("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));
|
||||
addStrategy("Sys 2 Compressor KW", new SingleValueStrategy(0.0f, 0.0f, 1000));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Executes the standby state's logic for one update cycle.
|
||||
*
|
||||
* This method first checks if there are any active alarms --> FailState.
|
||||
* Also checks for Free Cooling Mode (for ease of testing)
|
||||
* If no alarms are active, checks for "Chiller Start Command" (Modscan, but will be from PLC)
|
||||
* for a command to transition to the Running state. 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.
|
||||
*/
|
||||
template<>
|
||||
State<ModbusRTU>* StandbyState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
|
||||
// Update alarms states, Free Cooling mode, Freeze Protection Mode
|
||||
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",
|
||||
};
|
||||
|
||||
// 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) {
|
||||
Modbus_Point<ModbusRTU>* point = equipment->getModbus_Point(desc);
|
||||
if (point->getValue() == 1) {
|
||||
activeAlarmsDescriptions.push_back(desc);
|
||||
alarms_active = true;
|
||||
}
|
||||
}
|
||||
if (alarms_active) return new FailState<ModbusRTU>(activeAlarmsDescriptions);
|
||||
|
||||
// If no alarms active and Start Command = 1--> send to RunningState()
|
||||
int Chiller_Enable = getPointValue(equipment, "Chiller Start Command"); // Modscan COIL 1
|
||||
if (Chiller_Enable == 1){
|
||||
return new RunningState<ModbusRTU>();
|
||||
}
|
||||
|
||||
// Apply any strategies defined for the standby state
|
||||
_applyStrategies(equipment);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic to execute once when entering the standby state.
|
||||
* Sets the "Chiller Status" point to indicate the unit is not running.
|
||||
* Updates Operational Codes for Sys 1 and Sys 2
|
||||
* Ensure Chiller Start Command is reset to 0.
|
||||
* @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, "Chiller Start Command", 0);
|
||||
setPointValue(equipment, "Chiller Status", 0);
|
||||
setPointValue(equipment, "Sys 1 Operational Code", 77);
|
||||
setPointValue(equipment, "Sys 2 Operational Code", 77);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic to execute once when exiting the standby state.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void StandbyState<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
|
||||
// Cleanup logic to run when the equipment leaves this state
|
||||
Serial.println("Exit Standby State...");
|
||||
}
|
||||
119
src/BMS/CHILLER/CH_York_YVAA_RTU/config.h
Normal file
119
src/BMS/CHILLER/CH_York_YVAA_RTU/config.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* @file config.h
|
||||
* @brief Main configuration file for the York Chiller (RTU) emulator.
|
||||
* @author Robert J Davis
|
||||
* @date 2025-10-12
|
||||
*
|
||||
* This file contains important configurations for the Modbus RTU communication
|
||||
* and the specific register map for the emulated device.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
#include <ModbusRTU.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
|
||||
|
||||
/**
|
||||
* @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, "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, 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"},
|
||||
|
||||
{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, 4, 70, "System CHW Out"},
|
||||
{HR, 5, 70, "System CHW In"},
|
||||
{HR, 7, 0, "Sys 1 Condenser Temp"},
|
||||
{HR, 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, 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, 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, 39, 0, "Local Leaving Temp Setpoint"},
|
||||
|
||||
{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"},
|
||||
|
||||
};
|
||||
//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;
|
||||
|
||||
#endif // CONFIG_H
|
||||
78
src/BMS/CHILLER/CH_York_YVAA_RTU/main.cpp
Normal file
78
src/BMS/CHILLER/CH_York_YVAA_RTU/main.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main execution program for the Daikin Chiller (RTU) Emulator.
|
||||
* @author Emmanuel Hernandez Cruz
|
||||
* @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
|
||||
* Modbus RTU protocol over a serial connection.
|
||||
*
|
||||
* The setup() function initializes the following:
|
||||
* - Serial communication for debugging.
|
||||
* - A Modbus RTU server with parameters from config.h.
|
||||
* - Modbus points (Coils, Holding Registers, etc.) based on a predefined map in config.h.
|
||||
*
|
||||
* The loop() function continuously:
|
||||
* - Services the Modbus RTU 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 Modbus RTU and register map 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 <Arduino.h>
|
||||
#include "config.h"
|
||||
#include "ModbusPoints/Modbus_PointFactory.h"
|
||||
|
||||
//=================================================================================================================================
|
||||
/**
|
||||
* @brief Initializes the application.
|
||||
* @details This function runs once at startup. It configures the serial communication
|
||||
* for debugging and the Modbus RTU server. It then creates and initializes all
|
||||
* the Modbus points based on the `mb_map` array in `config.h`.
|
||||
*/
|
||||
const int rtsPin = 4;
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Setup function started");
|
||||
|
||||
Serial2.begin(BAUDRATE, SERIAL_8N1, RX_PIN, TX_PIN);
|
||||
mb.begin(&Serial2, RST_PIN); // Start the server
|
||||
mb.slave(MODBUS_ID); // Set the slave ID
|
||||
|
||||
for(int i = 0; i < map_size; i++){
|
||||
Modbus_Point<ModbusRTU>* 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("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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user