From 40282fca0d8ff3d107a5303a376c0a3abd65855d Mon Sep 17 00:00:00 2001 From: RobertJDavis Date: Tue, 4 Nov 2025 14:16:03 -0700 Subject: [PATCH 01/16] updates for Schertz testing --- platformio.ini | 11 ++++- src/BMS/CHILLER/CH_York_YVAA_RTU/config.h | 10 ++--- src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp | 3 +- src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp | 4 +- src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp | 2 +- src/BMS/CRAH/CRAH_UMAS_TCP/config.h | 13 +++--- .../PHX3_CRAH_LIEBERT_80_SLAB_TCP/config.h | 9 ++-- .../HUM/HUM_DriSteem_RTS_RX36_TCP/config.h | 8 ++-- .../PHX3_VFD_ABB_ACH580_RTU/State_Fail.cpp | 11 +++-- .../PHX3_VFD_ABB_ACH580_RTU/State_Running.cpp | 31 +++++--------- .../PHX3_VFD_ABB_ACH580_RTU/State_Standby.cpp | 11 +++-- src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h | 42 +++++++++++-------- 12 files changed, 85 insertions(+), 70 deletions(-) diff --git a/platformio.ini b/platformio.ini index 2bec804..ce2f5ec 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,10 +10,10 @@ [platformio] -default_envs = PHX3_CRAH_LIEBERT_80_SLAB_TCP ; Select here the name of the configuration you want to download +default_envs = PHX3_VFD_ABB_ACH580_RTU ; Select here the name of the configuration you want to download [env] -upload_port = COM9 +upload_port = COM13 [common_env_options] framework = arduino @@ -226,3 +226,10 @@ board = dfrobot_firebeetle2_esp32e extends = common_env_options build_flags = -D USE_MODBUS_IP build_src_filter = -<*> + + +[env:CRAH_UMAS_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + \ No newline at end of file diff --git a/src/BMS/CHILLER/CH_York_YVAA_RTU/config.h b/src/BMS/CHILLER/CH_York_YVAA_RTU/config.h index 79e7383..ee3284c 100644 --- a/src/BMS/CHILLER/CH_York_YVAA_RTU/config.h +++ b/src/BMS/CHILLER/CH_York_YVAA_RTU/config.h @@ -22,11 +22,11 @@ * @{ */ #include - 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. */ + 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; #else diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp index eafcf6b..c2f9171 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp @@ -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" @@ -57,7 +58,7 @@ FailState::FailState(const std::vector& 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)); } /** diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp index f85524b..00cab5f 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp @@ -71,11 +71,11 @@ RunningState::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("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 Temp", new SawStrategy(70.0f, 80.0f, 1.0f, 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)); } /** diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp index 70be6d4..a0f6b7d 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp @@ -61,7 +61,7 @@ StandbyState::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)); } /** diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/config.h b/src/BMS/CRAH/CRAH_UMAS_TCP/config.h index 9490535..fc381ad 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/config.h +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/config.h @@ -21,10 +21,10 @@ * @{ */ #include - 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, 30, 22, 100); /**< @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; @@ -135,7 +135,8 @@ modbusMap mb_map[] = {IR_FLOAT, 73, 0, "Amps Fan 6"}, {IR_FLOAT, 75, 0, "Amps Fan 7"}, {IR_FLOAT, 77, 0, "Amps Fan 8"}, - {IR_FLOAT, 79, 0, "Amps Fan 9"}, + {IR_FLOAT, 79, 0, "Amps Fan 9"}, + {IR_FLOAT, 99, 0, "CRAH Heartbeat"}, // Placeholder - we don't have this from UMAS yet. Not used in logic yet. {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,7 @@ 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. + }; //Size of modbus map used in FOR cycles, automatically calculated. diff --git a/src/BMS/CRAH/PHX3_CRAH_LIEBERT_80_SLAB_TCP/config.h b/src/BMS/CRAH/PHX3_CRAH_LIEBERT_80_SLAB_TCP/config.h index f547b18..c027708 100644 --- a/src/BMS/CRAH/PHX3_CRAH_LIEBERT_80_SLAB_TCP/config.h +++ b/src/BMS/CRAH/PHX3_CRAH_LIEBERT_80_SLAB_TCP/config.h @@ -20,11 +20,10 @@ * @brief Parameters for Modbus TCP communication. * @{ */ - #include - 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, 63); /**< @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; diff --git a/src/BMS/HUM/HUM_DriSteem_RTS_RX36_TCP/config.h b/src/BMS/HUM/HUM_DriSteem_RTS_RX36_TCP/config.h index 41b252c..a40b037 100644 --- a/src/BMS/HUM/HUM_DriSteem_RTS_RX36_TCP/config.h +++ b/src/BMS/HUM/HUM_DriSteem_RTS_RX36_TCP/config.h @@ -21,10 +21,10 @@ * @{ */ #include - 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, 67); /**< @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; diff --git a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Fail.cpp b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Fail.cpp index f7b8919..987b5fd 100644 --- a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Fail.cpp +++ b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Fail.cpp @@ -32,9 +32,7 @@ */ template<> FailState::FailState(const std::vector& activeAlarms) { - addStrategy("Motor Speed Used", new RampStrategy(0.0f, 200.0f, 1000 )); addStrategy("Speed Feedback", new RampStrategy(0.0f, 200.0f, 1000 )); - addStrategy("Motor Speed estimated", 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 )); @@ -42,7 +40,7 @@ FailState::FailState(const std::vector& activeAlarms) { 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 Shaft Power", new SingleValueStrategy(0.1f, 0.1f, 1000 )); } /** @@ -77,6 +75,13 @@ template<> void FailState::enterState(Equipment* 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); } diff --git a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Running.cpp b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Running.cpp index 36d586d..5748056 100644 --- a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Running.cpp +++ b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Running.cpp @@ -41,9 +41,7 @@ */ template<> RunningState::RunningState() { - addStrategy("Motor Speed Used", new RampStrategy(1800.0f, 100.0f, 1000)); addStrategy("Speed Feedback", new RampStrategy(1800.0f, 100.0f, 1000)); - addStrategy("Motor Speed estimated", 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)); @@ -51,9 +49,9 @@ RunningState::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)); } /** @@ -94,25 +92,11 @@ State* RunningState::update(Equipment* equipmen float power_update = speed_pct * speed_pct * speed_pct * 36.77f; // 50 hp ~ 36.77kW 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(motorSpeedUsed)->setTarget(currentSP); - } - Strategy_Behavior* speedFeedback = getStrategy("Speed Feedback"); if (speedFeedback) { static_cast(speedFeedback)->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(motorSpeedEst)->setTarget(rpm_est); - } - Strategy_Behavior* frequencystrategy = getStrategy("Output Frequency"); if (frequencystrategy) { static_cast(frequencystrategy)->setTarget(freq_update); @@ -138,7 +122,7 @@ State* RunningState::update(Equipment* equipmen static_cast(voltagestrategy)->setTarget(voltage_update); } - Strategy_Behavior* powerstrategy = getStrategy("Output Power"); + Strategy_Behavior* powerstrategy = getStrategy("Motor Shaft Power"); if (powerstrategy) { static_cast(powerstrategy)->setTarget(power_update); } @@ -157,6 +141,13 @@ template<> void RunningState::enterState(Equipment* 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); } diff --git a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Standby.cpp b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Standby.cpp index 01629e0..41b3048 100644 --- a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Standby.cpp +++ b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Standby.cpp @@ -30,9 +30,7 @@ */ template<> StandbyState::StandbyState() { - addStrategy("Motor Speed Used", new RampStrategy(0.0f, 200.0f, 1000 )); addStrategy("Speed Feedback", new RampStrategy(0.0f, 200.0f, 1000 )); - addStrategy("Motor Speed estimated", 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 )); @@ -40,7 +38,7 @@ StandbyState::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 Shaft Power", new SingleValueStrategy(0.1f, 0.1f, 1000 )); } /** @@ -84,6 +82,13 @@ template<> void StandbyState::enterState(Equipment* 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); } diff --git a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h index 1389e79..e347759 100644 --- a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h +++ b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h @@ -63,25 +63,31 @@ modbusMap mb_map[] = {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_FLOAT, 20201, 0, "Motor Speed Used"}, // RJD: 1800 rpm max - {HR_FLOAT, 20203, 0, "Motor Speed estimated"}, // RJD: 1800 rpm max - {HR_FLOAT, 20211, 0, "Output Frequency"}, // 60 Hz @100% speed - {HR_FLOAT, 20213, 0, "Motor Current"}, // RJD: Changed from HR_10x to HR, 65 FLA - {HR_FLOAT, 20219, 0, "Motor Torque"}, // % of nominal torque - {HR_FLOAT, 20221, 0, "DC Voltage"}, // approx 678 VDC @100% speed - {HR_FLOAT, 20225, 0, "Output Voltage"}, // RJD: 480 VAC - {HR_FLOAT, 20227, 0, "Output Power"}, //max 372580 // RJD: Changed from HR_10x to HR, 50 hp ~ 36.77 kW - {HR_FLOAT, 20239, 0, "Inverter kWh cnt"}, - {HR_FLOAT, 21005, 0, "Hours Run"}, - {HR_FLOAT, 21021, 0, "Inverter Temperature"}, // RJD: Changed from HR_10x to HR, % of fault limit + {HR_FLOAT, 100, 0, "Motor Speed Used"}, // 1800 rpm max + {HR_FLOAT, 105, 0, "Output Frequency"}, // 60 Hz @100% speed + {HR_FLOAT, 106, 0, "Motor Current"}, // 65 FLA + {HR_FLOAT, 109, 0, "Motor Torque"}, // % of nominal torque + {HR_FLOAT, 110, 0, "DC Voltage"}, // approx 678 VDC @100% speed + {HR_FLOAT, 112, 0, "Output Voltage"}, // 480 VAC + {HR_FLOAT, 116, 0, "Motor Shaft Power"}, // 50 hp ~ 36.77 kW + {HR_FLOAT, 118, 0, "Inverter MWh counter"}, + {HR_FLOAT, 119, 0, "Inverter kWh counter"}, + {HR_FLOAT, 510, 0, "Inverter Temperature"}, // RJD: Changed from HR_10x to HR, % of fault limit + {HR, 519, 0, "Diagnostic Word"}, // not used in program. Bit 9:Drive Over-Temp Alarm - {HR, 21243, 0, "HOA Status Word"}, // not used in program - {HR, 20801, 0, "Trip Fault"}, // not used in program - {HR, 20821, 0, "Last Fault"}, // not used in program - {HR, 20823, 0, "2nd to last Fault"}, // not used in program - {HR, 20825, 0, "3rd to last Fault"}, // not used in program - {HR, 21221, 0, "Main Status Word"}, // not used in program - {HR, 21231, 0, "Drive Status Word 1"}, // not used in program + {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_FLOAT, 4600, 0, "Speed Scaling"}, // ADD: 1800 rpm + {HR_FLOAT, 4601, 0, "Frequency Scaling"}, // ADD: 60 Hz + {HR_FLOAT, 9905, 0, "Nominal Current"}, // ADD: 65 A + {HR_FLOAT, 9906, 0, "Nominal Voltage"}, // ADD: 480 V + {HR_FLOAT, 9907, 0, "Nominal Frequency"}, // ADD: 60 Hz + {HR_FLOAT, 9908, 0, "Nominal Speed"}, // ADD: 1800 rpm + {HR_FLOAT, 9909, 0, "Nominal Power"}, // ADD: 50 hp + }; //Size of modbus map used in FOR cycles, automatically calculated. /** From f0e3a3a5e568fade229c94642f33c99e5928199d Mon Sep 17 00:00:00 2001 From: RobertJDavis Date: Tue, 4 Nov 2025 14:21:19 -0700 Subject: [PATCH 02/16] change com port during testing --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index ce2f5ec..9b4bf2c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,7 +13,7 @@ default_envs = PHX3_VFD_ABB_ACH580_RTU ; Select here the name of the configuration you want to download [env] -upload_port = COM13 +upload_port = COM6 [common_env_options] framework = arduino From dfc103f1e1719835de4e94e6b432fc75a10f9d85 Mon Sep 17 00:00:00 2001 From: RobertJDavis Date: Tue, 4 Nov 2025 15:15:45 -0700 Subject: [PATCH 03/16] updated PHX3 VFD registers per new UDT --- .../PHX3_VFD_ABB_ACH580_RTU/State_Running.cpp | 3 +- src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h | 48 +++++++++---------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Running.cpp b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Running.cpp index 5748056..9fc5ab2 100644 --- a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Running.cpp +++ b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Running.cpp @@ -90,8 +90,9 @@ State* RunningState::update(Equipment* equipmen float torque_update = speed_pct * speed_pct * 100; // This is a % of nominal motor torque float freq_update = speed_pct * 60; float power_update = speed_pct * speed_pct * speed_pct * 36.77f; // 50 hp ~ 36.77kW - + float currentSP = getPointValue(equipment, "Speed Cmd"); + Strategy_Behavior* speedFeedback = getStrategy("Speed Feedback"); if (speedFeedback) { static_cast(speedFeedback)->setTarget(currentSP); diff --git a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h index e347759..d3c2a9e 100644 --- a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h +++ b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h @@ -61,32 +61,32 @@ modbusMap mb_map[] = {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, 156, 0, "Speed Feedback"}, // arbitrary register number - send signal to PLC (simulated hardwire IO). Will be equal to Motor Speed Used register - {HR_FLOAT, 100, 0, "Motor Speed Used"}, // 1800 rpm max - {HR_FLOAT, 105, 0, "Output Frequency"}, // 60 Hz @100% speed - {HR_FLOAT, 106, 0, "Motor Current"}, // 65 FLA - {HR_FLOAT, 109, 0, "Motor Torque"}, // % of nominal torque - {HR_FLOAT, 110, 0, "DC Voltage"}, // approx 678 VDC @100% speed - {HR_FLOAT, 112, 0, "Output Voltage"}, // 480 VAC - {HR_FLOAT, 116, 0, "Motor Shaft Power"}, // 50 hp ~ 36.77 kW - {HR_FLOAT, 118, 0, "Inverter MWh counter"}, - {HR_FLOAT, 119, 0, "Inverter kWh counter"}, - {HR_FLOAT, 510, 0, "Inverter Temperature"}, // RJD: Changed from HR_10x to HR, % of fault limit - {HR, 519, 0, "Diagnostic Word"}, // not used in program. Bit 9:Drive Over-Temp Alarm + {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, 109, 0, "Motor Torque"}, // % of nominal torque + {HR, 110, 0, "DC Voltage"}, // approx 678 VDC @100% speed + {HR, 112, 0, "Output Voltage"}, // 480 VAC + {HR, 116, 0, "Motor Shaft Power"}, // 50 hp ~ 36.77 kW + {HR, 118, 0, "Inverter MWh counter"}, + {HR, 119, 0, "Inverter kWh counter"}, + {HR, 510, 0, "Inverter Temperature"}, // RJD: Changed from HR_10x to HR, % of fault limit + {HR, 519, 0, "Diagnostic Word"}, // not used in program. Bit 9:Drive Over-Temp Alarm - {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_FLOAT, 4600, 0, "Speed Scaling"}, // ADD: 1800 rpm - {HR_FLOAT, 4601, 0, "Frequency Scaling"}, // ADD: 60 Hz - {HR_FLOAT, 9905, 0, "Nominal Current"}, // ADD: 65 A - {HR_FLOAT, 9906, 0, "Nominal Voltage"}, // ADD: 480 V - {HR_FLOAT, 9907, 0, "Nominal Frequency"}, // ADD: 60 Hz - {HR_FLOAT, 9908, 0, "Nominal Speed"}, // ADD: 1800 rpm - {HR_FLOAT, 9909, 0, "Nominal Power"}, // ADD: 50 hp + {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, 9906, 0, "Nominal Voltage"}, // ADD: 480 V + {HR, 9907, 0, "Nominal Frequency"}, // ADD: 60 Hz + {HR, 9908, 0, "Nominal Speed"}, // ADD: 1800 rpm + {HR, 9909, 0, "Nominal Power"}, // ADD: 50 hp }; //Size of modbus map used in FOR cycles, automatically calculated. From e5ae233875e4e5538be1414686af04e70d2246e4 Mon Sep 17 00:00:00 2001 From: RobertJDavis Date: Wed, 5 Nov 2025 07:13:59 -0700 Subject: [PATCH 04/16] Added Fan Speed Feedback register to UMAS DH CRAH. Added Fan Speed Feedback register to UMAS DH CRAH. --- platformio.ini | 2 +- src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp | 2 ++ src/BMS/CRAH/CRAH_UMAS_TCP/config.h | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index 9b4bf2c..b7351a8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,7 +10,7 @@ [platformio] -default_envs = PHX3_VFD_ABB_ACH580_RTU ; Select here the name of the configuration you want to download +default_envs = CRAH_UMAS_TCP ; Select here the name of the configuration you want to download [env] upload_port = COM6 diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp index 00cab5f..ef8177c 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp @@ -141,6 +141,8 @@ State* RunningState::update(Equipment* equipment) } } + setPointValue(equipment, "Fan Speed Feedback", BMS_Speed_Setpoint); + // Apply any strategies defined for the standby state _applyStrategies(equipment); return nullptr; diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/config.h b/src/BMS/CRAH/CRAH_UMAS_TCP/config.h index fc381ad..196db82 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/config.h +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/config.h @@ -23,7 +23,7 @@ #include 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, 30, 22, 100); /**< @brief The static IP address for the device. */ + IPAddress local_IP(172, 17, 32, 49); /**< @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. */ @@ -144,6 +144,7 @@ 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_FLOAT, 28, 0, "Fan Speed Feedback"}, }; From b4a626b908749a75a9ab645e27b7ae1e8b6455b8 Mon Sep 17 00:00:00 2001 From: RobertJDavis Date: Thu, 6 Nov 2025 06:52:10 -0700 Subject: [PATCH 05/16] minor adjustments to CRAH UMAS TCP added Fan Speed Feedback register 40029, initialized unit to run for better image visualization while we wait for PICS-Arduino solution. --- platformio.ini | 4 +-- src/BMS/CRAH/CRAH_UMAS_TCP/StateUtils.cpp | 27 +++++++++++++++++-- src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp | 3 +++ src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp | 10 +++++-- src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp | 5 ++-- src/BMS/CRAH/CRAH_UMAS_TCP/config.h | 6 ++--- .../PHX3_CRAH_LIEBERT_80_SLAB_TCP/config.h | 2 +- .../HUM/HUM_DriSteem_RTS_RX36_TCP/config.h | 2 +- src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h | 4 +-- 9 files changed, 48 insertions(+), 15 deletions(-) diff --git a/platformio.ini b/platformio.ini index b7351a8..efbda27 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,10 +10,10 @@ [platformio] -default_envs = CRAH_UMAS_TCP ; Select here the name of the configuration you want to download +default_envs = CH_York_YVAA_RTU ; Select here the name of the configuration you want to download [env] -upload_port = COM6 +upload_port = COM16 [common_env_options] framework = arduino diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/StateUtils.cpp b/src/BMS/CRAH/CRAH_UMAS_TCP/StateUtils.cpp index 056bf7b..f980695 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/StateUtils.cpp +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/StateUtils.cpp @@ -112,7 +112,6 @@ void updateAnalogs(Equipment* 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,29 @@ void updateAnalogs(Equipment* 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); +} + +/** + * @brief This function is used to update the Control Mode (feedback), + * based on the selected BMS Control Source and BMS Enable Source. + * + * This is a function used in the update() of the Standby, Running, and Fail States. + * +*/ +void checkHB(Equipment* equipment){ + Modbus_Point* PLC_Heartbeat = equipment -> getModbus_Point ("PLC Heartbeat"); + int BMS_Control_Source = BMS_Control_Source_Pt ? BMS_Control_Source_Pt->getValue() : 0; + int BMS_Enable_Source = BMS_Enable_Source_Pt ? BMS_Enable_Source_Pt->getValue() : 0; + int Control_Mode_Selected = Control_Mode_Pt ? Control_Mode_Pt->getValue() : -1; + + if (BMS_Control_Source == 0 && BMS_Enable_Source == 2) { + Control_Mode_Selected = 0; + } else if (BMS_Control_Source == 1 && BMS_Enable_Source == 2) { + Control_Mode_Selected = 1; + } else if (BMS_Enable_Source == 0) { + Control_Mode_Selected = 2; + } + equipment->setModbus_Point("Control Mode Selected", Control_Mode_Selected); + + equipment->setModbus_Point("General Alarm", 0); } \ No newline at end of file diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp index c2f9171..eed9417 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp @@ -40,6 +40,9 @@ FailState::FailState(const std::vector& 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)); diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp index ef8177c..a7b797b 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp @@ -72,10 +72,12 @@ RunningState::RunningState() { 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.2f, 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("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,7 +143,11 @@ State* RunningState::update(Equipment* equipment) } } - setPointValue(equipment, "Fan Speed Feedback", BMS_Speed_Setpoint); + // Fan Speed Feedback dynamically ramp to Fan Speed Setpoint sent to Arduino + Strategy_Behavior* speedFeedback = getStrategy("Fan Speed Feedback"); + if (speedFeedback){ + static_cast(speedFeedback)->setTarget(BMS_Speed_Setpoint); + } // Apply any strategies defined for the standby state _applyStrategies(equipment); diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp index a0f6b7d..5c86a7a 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp @@ -41,8 +41,9 @@ StandbyState::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)); diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/config.h b/src/BMS/CRAH/CRAH_UMAS_TCP/config.h index 196db82..409f130 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/config.h +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/config.h @@ -23,7 +23,7 @@ #include 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, 49); /**< @brief The static IP address for the device. */ + 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. */ @@ -136,7 +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"}, // Placeholder - we don't have this from UMAS yet. Not used in logic yet. + {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 @@ -145,7 +145,7 @@ modbusMap mb_map[] = {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_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. diff --git a/src/BMS/CRAH/PHX3_CRAH_LIEBERT_80_SLAB_TCP/config.h b/src/BMS/CRAH/PHX3_CRAH_LIEBERT_80_SLAB_TCP/config.h index c027708..2aec506 100644 --- a/src/BMS/CRAH/PHX3_CRAH_LIEBERT_80_SLAB_TCP/config.h +++ b/src/BMS/CRAH/PHX3_CRAH_LIEBERT_80_SLAB_TCP/config.h @@ -22,7 +22,7 @@ */ 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, 63); /**< @brief The static IP address for the device. */ + 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. */ diff --git a/src/BMS/HUM/HUM_DriSteem_RTS_RX36_TCP/config.h b/src/BMS/HUM/HUM_DriSteem_RTS_RX36_TCP/config.h index a40b037..b78c910 100644 --- a/src/BMS/HUM/HUM_DriSteem_RTS_RX36_TCP/config.h +++ b/src/BMS/HUM/HUM_DriSteem_RTS_RX36_TCP/config.h @@ -23,7 +23,7 @@ #include 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, 67); /**< @brief The static IP address for the device. */ + 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. */ diff --git a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h index d3c2a9e..79b6515 100644 --- a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h +++ b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h @@ -56,8 +56,8 @@ */ modbusMap mb_map[] = { - {HR, 149, 1800, "Speed Cmd"}, // arbitrary register number - receive signal from PLC (hardwire IO in field); expecting rpm (1800 rpm max) - {HR, 151, 0, "Start/Stop"}, // arbitrary register number - receive signal from PLC (hardwire IO in practice) + {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. From aa204e615ebeb67df394ac730888d8535af11957 Mon Sep 17 00:00:00 2001 From: RobertJDavis Date: Thu, 6 Nov 2025 17:40:55 -0700 Subject: [PATCH 06/16] PHX3 uploading to EPMS devices Changed "SEL_2440 (MVG)" to "SEL_2440_MVG" so device can load onto Arduino. Uploaded existing EPMS code to PHX3 EPMS Arduinos. Changes to run status bit of UMAS CRAH. Modified a few PHX3 VFD ACH580 registers from HR to HR_10x. --- platformio.ini | 17 +++++++++++-- src/BMS/CHILLER/CH_York_YVAA_RTU/config.h | 4 +-- src/BMS/CRAH/CRAH_UMAS_TCP/StateUtils.cpp | 25 ------------------- src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp | 2 +- src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp | 4 +-- src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp | 2 +- src/BMS/CRAH/CRAH_UMAS_TCP/config.h | 18 ++++++------- src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h | 14 +++++------ .../ATS/ATS_Woodward_DTSC200A_TCP/config.h | 6 ++--- src/EPMS/Breaker/BKR_ABB_EMax2_TCP/config.h | 8 +++--- src/EPMS/Breaker/BKR_ABB_XT_TCP/config.h | 6 ++--- src/EPMS/GEN/GEN_HSE/config.h | 8 +++--- .../README.md | 0 .../State_Fail.cpp | 0 .../State_Running.cpp | 0 .../State_Standby.cpp | 0 .../{SEL_2440 (MVG) => SEL_2440_MVG}/config.h | 8 +++--- .../{SEL_2440 (MVG) => SEL_2440_MVG}/main.cpp | 0 18 files changed, 55 insertions(+), 67 deletions(-) rename src/EPMS/MVG/{SEL_2440 (MVG) => SEL_2440_MVG}/README.md (100%) rename src/EPMS/MVG/{SEL_2440 (MVG) => SEL_2440_MVG}/State_Fail.cpp (100%) rename src/EPMS/MVG/{SEL_2440 (MVG) => SEL_2440_MVG}/State_Running.cpp (100%) rename src/EPMS/MVG/{SEL_2440 (MVG) => SEL_2440_MVG}/State_Standby.cpp (100%) rename src/EPMS/MVG/{SEL_2440 (MVG) => SEL_2440_MVG}/config.h (88%) rename src/EPMS/MVG/{SEL_2440 (MVG) => SEL_2440_MVG}/main.cpp (100%) diff --git a/platformio.ini b/platformio.ini index efbda27..2ff69aa 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,6 @@ [platformio] - default_envs = CH_York_YVAA_RTU ; Select here the name of the configuration you want to download [env] @@ -232,4 +231,18 @@ platform = espressif32 board = dfrobot_firebeetle2_esp32e extends = common_env_options build_flags = -D USE_MODBUS_IP -build_src_filter = -<*> + \ No newline at end of file +build_src_filter = -<*> + + +[env:GEN_HSE] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + + +[env:SEL_2440_MVG] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + \ No newline at end of file diff --git a/src/BMS/CHILLER/CH_York_YVAA_RTU/config.h b/src/BMS/CHILLER/CH_York_YVAA_RTU/config.h index ee3284c..86dc254 100644 --- a/src/BMS/CHILLER/CH_York_YVAA_RTU/config.h +++ b/src/BMS/CHILLER/CH_York_YVAA_RTU/config.h @@ -54,7 +54,7 @@ */ modbusMap mb_map[] = { - {COIL, 0, 0, "Chiller Start Command"}, // Use in Modscan - Hard IO in SCP, Used for Arduino simulation only. Signal should come from PLC. + {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) @@ -99,7 +99,7 @@ modbusMap mb_map[] = {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, 39, 0, "Local Leaving Temp Setpoint"}, + {HR, 39, 72, "Local Leaving Temp Setpoint"}, {HR_10x, 49, 0, "Sys 2 Condenser Temp"}, {HR_10x, 140, 0, "Sys 1 Fan KW"}, diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/StateUtils.cpp b/src/BMS/CRAH/CRAH_UMAS_TCP/StateUtils.cpp index f980695..8fdfcc1 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/StateUtils.cpp +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/StateUtils.cpp @@ -119,29 +119,4 @@ void updateAnalogs(Equipment* equipment){ else if (equipment->getModbus_Point("RA Humidity High Alarm ON")->getValue()==1){ equipment->setModbus_Point("Return Air Humidity", 65.0f); } -} - -/** - * @brief This function is used to update the Control Mode (feedback), - * based on the selected BMS Control Source and BMS Enable Source. - * - * This is a function used in the update() of the Standby, Running, and Fail States. - * -*/ -void checkHB(Equipment* equipment){ - Modbus_Point* PLC_Heartbeat = equipment -> getModbus_Point ("PLC Heartbeat"); - int BMS_Control_Source = BMS_Control_Source_Pt ? BMS_Control_Source_Pt->getValue() : 0; - int BMS_Enable_Source = BMS_Enable_Source_Pt ? BMS_Enable_Source_Pt->getValue() : 0; - int Control_Mode_Selected = Control_Mode_Pt ? Control_Mode_Pt->getValue() : -1; - - if (BMS_Control_Source == 0 && BMS_Enable_Source == 2) { - Control_Mode_Selected = 0; - } else if (BMS_Control_Source == 1 && BMS_Enable_Source == 2) { - Control_Mode_Selected = 1; - } else if (BMS_Enable_Source == 0) { - Control_Mode_Selected = 2; - } - equipment->setModbus_Point("Control Mode Selected", Control_Mode_Selected); - - equipment->setModbus_Point("General Alarm", 0); } \ No newline at end of file diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp index eed9417..ceeb819 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Fail.cpp @@ -116,7 +116,7 @@ void FailState::enterState(Equipment* equipment) { for (const auto& desc : motorStatusDescriptions) { Modbus_Point* point = equipment->getModbus_Point(desc); if (point) { - point->setValue(1); + point->setValue(0); } }; diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp index a7b797b..a1c8f16 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Running.cpp @@ -176,7 +176,7 @@ void RunningState::enterState(Equipment* equipment) { for (const auto& desc : motorStatusDescriptions) { Modbus_Point* point = equipment->getModbus_Point(desc); if (point) { - point->setValue(0); + point->setValue(1); } } } @@ -201,7 +201,7 @@ void RunningState::exitState(Equipment* equipment) { for (const auto& desc : motorStatusDescriptions) { Modbus_Point* point = equipment->getModbus_Point(desc); if (point) { - point->setValue(1); + point->setValue(0); } } } \ No newline at end of file diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp index 5c86a7a..2b78791 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/State_Standby.cpp @@ -126,7 +126,7 @@ void StandbyState::enterState(Equipment* equipment) { for (const auto& desc : motorStatusDescriptions) { Modbus_Point* point = equipment->getModbus_Point(desc); if (point) { - point->setValue(1); + point->setValue(0); } }; diff --git a/src/BMS/CRAH/CRAH_UMAS_TCP/config.h b/src/BMS/CRAH/CRAH_UMAS_TCP/config.h index 409f130..186fa3b 100644 --- a/src/BMS/CRAH/CRAH_UMAS_TCP/config.h +++ b/src/BMS/CRAH/CRAH_UMAS_TCP/config.h @@ -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"}, diff --git a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h index 79b6515..78bff06 100644 --- a/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h +++ b/src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h @@ -66,12 +66,12 @@ modbusMap mb_map[] = {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, 109, 0, "Motor Torque"}, // % of nominal torque - {HR, 110, 0, "DC Voltage"}, // approx 678 VDC @100% speed + {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"}, // 480 VAC - {HR, 116, 0, "Motor Shaft Power"}, // 50 hp ~ 36.77 kW + {HR_10x, 116, 0, "Motor Shaft Power"}, // 50 hp ~ 36.77 kW {HR, 118, 0, "Inverter MWh counter"}, - {HR, 119, 0, "Inverter kWh counter"}, + {HR_10x, 119, 0, "Inverter kWh counter"}, {HR, 510, 0, "Inverter Temperature"}, // RJD: Changed from HR_10x to HR, % of fault limit {HR, 519, 0, "Diagnostic Word"}, // not used in program. Bit 9:Drive Over-Temp Alarm @@ -83,10 +83,10 @@ modbusMap mb_map[] = {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, 9906, 0, "Nominal Voltage"}, // ADD: 480 V - {HR, 9907, 0, "Nominal Frequency"}, // ADD: 60 Hz + {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, 9909, 0, "Nominal Power"}, // ADD: 50 hp + {HR_10x, 9909, 0, "Nominal Power"}, // ADD: 50 hp }; //Size of modbus map used in FOR cycles, automatically calculated. diff --git a/src/EPMS/ATS/ATS_Woodward_DTSC200A_TCP/config.h b/src/EPMS/ATS/ATS_Woodward_DTSC200A_TCP/config.h index 3f7bcf0..1223b95 100644 --- a/src/EPMS/ATS/ATS_Woodward_DTSC200A_TCP/config.h +++ b/src/EPMS/ATS/ATS_Woodward_DTSC200A_TCP/config.h @@ -21,10 +21,10 @@ * @{ */ #include - 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; diff --git a/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/config.h b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/config.h index 3887572..22baf7d 100644 --- a/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/config.h +++ b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/config.h @@ -21,10 +21,10 @@ * @{ */ #include - 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 = "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, 90); /**< @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; diff --git a/src/EPMS/Breaker/BKR_ABB_XT_TCP/config.h b/src/EPMS/Breaker/BKR_ABB_XT_TCP/config.h index b77bc05..7dd406b 100644 --- a/src/EPMS/Breaker/BKR_ABB_XT_TCP/config.h +++ b/src/EPMS/Breaker/BKR_ABB_XT_TCP/config.h @@ -21,10 +21,10 @@ * @{ */ #include - 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; diff --git a/src/EPMS/GEN/GEN_HSE/config.h b/src/EPMS/GEN/GEN_HSE/config.h index 49fa677..f5c4439 100644 --- a/src/EPMS/GEN/GEN_HSE/config.h +++ b/src/EPMS/GEN/GEN_HSE/config.h @@ -21,10 +21,10 @@ * @{ */ #include - 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; diff --git a/src/EPMS/MVG/SEL_2440 (MVG)/README.md b/src/EPMS/MVG/SEL_2440_MVG/README.md similarity index 100% rename from src/EPMS/MVG/SEL_2440 (MVG)/README.md rename to src/EPMS/MVG/SEL_2440_MVG/README.md diff --git a/src/EPMS/MVG/SEL_2440 (MVG)/State_Fail.cpp b/src/EPMS/MVG/SEL_2440_MVG/State_Fail.cpp similarity index 100% rename from src/EPMS/MVG/SEL_2440 (MVG)/State_Fail.cpp rename to src/EPMS/MVG/SEL_2440_MVG/State_Fail.cpp diff --git a/src/EPMS/MVG/SEL_2440 (MVG)/State_Running.cpp b/src/EPMS/MVG/SEL_2440_MVG/State_Running.cpp similarity index 100% rename from src/EPMS/MVG/SEL_2440 (MVG)/State_Running.cpp rename to src/EPMS/MVG/SEL_2440_MVG/State_Running.cpp diff --git a/src/EPMS/MVG/SEL_2440 (MVG)/State_Standby.cpp b/src/EPMS/MVG/SEL_2440_MVG/State_Standby.cpp similarity index 100% rename from src/EPMS/MVG/SEL_2440 (MVG)/State_Standby.cpp rename to src/EPMS/MVG/SEL_2440_MVG/State_Standby.cpp diff --git a/src/EPMS/MVG/SEL_2440 (MVG)/config.h b/src/EPMS/MVG/SEL_2440_MVG/config.h similarity index 88% rename from src/EPMS/MVG/SEL_2440 (MVG)/config.h rename to src/EPMS/MVG/SEL_2440_MVG/config.h index 3b97232..88714a4 100644 --- a/src/EPMS/MVG/SEL_2440 (MVG)/config.h +++ b/src/EPMS/MVG/SEL_2440_MVG/config.h @@ -21,10 +21,10 @@ * @{ */ #include - 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; diff --git a/src/EPMS/MVG/SEL_2440 (MVG)/main.cpp b/src/EPMS/MVG/SEL_2440_MVG/main.cpp similarity index 100% rename from src/EPMS/MVG/SEL_2440 (MVG)/main.cpp rename to src/EPMS/MVG/SEL_2440_MVG/main.cpp From 210a53800e824f143ea458c8e63c0d4141ea6465 Mon Sep 17 00:00:00 2001 From: Emmanuel HC Date: Mon, 10 Nov 2025 08:22:18 -0600 Subject: [PATCH 07/16] MVG template added --- platformio.ini | 13 +- src/EPMS/MVG/MVG_SC_EC_M505_TCP/README.md | 33 +++ .../MVG/MVG_SC_EC_M505_TCP/State_Fail.cpp | 81 ++++++ .../MVG/MVG_SC_EC_M505_TCP/State_Running.cpp | 272 ++++++++++++++++++ .../MVG/MVG_SC_EC_M505_TCP/State_Standby.cpp | 90 ++++++ src/EPMS/MVG/MVG_SC_EC_M505_TCP/config.h | 86 ++++++ src/EPMS/MVG/MVG_SC_EC_M505_TCP/main.cpp | 86 ++++++ 7 files changed, 659 insertions(+), 2 deletions(-) create mode 100644 src/EPMS/MVG/MVG_SC_EC_M505_TCP/README.md create mode 100644 src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Fail.cpp create mode 100644 src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Running.cpp create mode 100644 src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Standby.cpp create mode 100644 src/EPMS/MVG/MVG_SC_EC_M505_TCP/config.h create mode 100644 src/EPMS/MVG/MVG_SC_EC_M505_TCP/main.cpp diff --git a/platformio.ini b/platformio.ini index 2ff69aa..12dc711 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ [platformio] -default_envs = CH_York_YVAA_RTU ; Select here the name of the configuration you want to download +default_envs = MVG_SC_EC_M505_TCP ; Select here the name of the configuration you want to download [env] upload_port = COM16 @@ -245,4 +245,13 @@ platform = espressif32 board = dfrobot_firebeetle2_esp32e extends = common_env_options build_flags = -D USE_MODBUS_IP -build_src_filter = -<*> + \ No newline at end of file +build_src_filter = -<*> + + +[env:MVG_SC_EC_M505_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = + -D USE_MODBUS_IP, + -D USE_LED +build_src_filter = -<*> + \ No newline at end of file diff --git a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/README.md b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/README.md new file mode 100644 index 0000000..355156f --- /dev/null +++ b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/README.md @@ -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 diff --git a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Fail.cpp b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Fail.cpp new file mode 100644 index 0000000..8bc0385 --- /dev/null +++ b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Fail.cpp @@ -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 +#else + #include +#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::FailState(const std::vector& 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* FailState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Fail State..."); +} \ No newline at end of file diff --git a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Running.cpp b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Running.cpp new file mode 100644 index 0000000..5215ef6 --- /dev/null +++ b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Running.cpp @@ -0,0 +1,272 @@ +/** + * @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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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::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* RunningState::update(Equipment* 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 RunningState(); + } + + 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"); + + switch (static_cast(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(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(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(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(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(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; + } + + + + // 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::enterState(Equipment* 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::exitState(Equipment* 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); +} \ No newline at end of file diff --git a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Standby.cpp b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Standby.cpp new file mode 100644 index 0000000..92daf4c --- /dev/null +++ b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Standby.cpp @@ -0,0 +1,90 @@ +/** + * @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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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::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* StandbyState::update(Equipment* 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(); + } + + + // 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Standby State..."); +} \ No newline at end of file diff --git a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/config.h b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/config.h new file mode 100644 index 0000000..a29ec84 --- /dev/null +++ b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/config.h @@ -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 + 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 + 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 diff --git a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/main.cpp b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/main.cpp new file mode 100644 index 0000000..286a98c --- /dev/null +++ b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/main.cpp @@ -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 +#include "config.h" +#include "ModbusPoints/Modbus_PointFactory.h" +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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* 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); + } +} From 587945cf1f117af3531d3cb999179a5b20febb13 Mon Sep 17 00:00:00 2001 From: Emmanuel HC Date: Mon, 10 Nov 2025 09:24:44 -0600 Subject: [PATCH 08/16] MVG Template created --- platformio.ini | 9 ++- src/EPMS/MVG/MVG_SC_EC_M505_TCP/README.md | 59 ++++++++++++------- .../MVG/MVG_SC_EC_M505_TCP/State_Running.cpp | 11 ++-- .../MVG/MVG_SC_EC_M505_TCP/State_Standby.cpp | 10 ++-- src/EPMS/MVG/MVG_SC_EC_M505_TCP/config.h | 10 ++-- 5 files changed, 55 insertions(+), 44 deletions(-) diff --git a/platformio.ini b/platformio.ini index 12dc711..97e5cbb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,7 +12,7 @@ default_envs = MVG_SC_EC_M505_TCP ; Select here the name of the configuration you want to download [env] -upload_port = COM16 +upload_port = COM26 [common_env_options] framework = arduino @@ -251,7 +251,6 @@ build_src_filter = -<*> + platform = espressif32 board = dfrobot_firebeetle2_esp32e extends = common_env_options -build_flags = - -D USE_MODBUS_IP, - -D USE_LED -build_src_filter = -<*> + \ No newline at end of file +build_flags = -D USE_MODBUS_IP, +build_src_filter = -<*> + + diff --git a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/README.md b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/README.md index 355156f..4f156e3 100644 --- a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/README.md +++ b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/README.md @@ -1,33 +1,48 @@ -# EQUIPMENT_TYPE MANUFACTURER MODEL TCP +# Daikin Chiller (RTU) Emulator -## Brief Introduction -Equipment specifc details that make it different from other devices +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. -## List of Equipmentt -This cofiguration has been used for these models: -* **Model**: 09-15-22 -* **Model**: 09-15-23 -* **Model**: 09-15-25 +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. -* **Microcontroller**: [Firebeetle 2 ESP32.](https://www.dfrobot.com/product-2231.html) +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`. --- -## States and Strategies -Provide a brief description of what variables and strategies were used in this configuraiton +## How to Customize for a New Chiller -### Standby State -* **Equipment running**: set to 0 -* **Common Alarm**: set to 0 -* **SAT temperature**: set to 85 +To adapt this template for a new chiller, follow these steps. -### Running State -* **Equipment running**: set to 1 -* **SAT temperature**: **Ramp Strategy** set to 65 deg setpoint +### 1. Configure Device-Specific Parameters (`config.h`) -### Fail State -* **Commong Alarm**: set to 1 -* **SAT temperature**: **Ramp Strategy** set to 105 deg setpointset +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 \ No newline at end of file diff --git a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Running.cpp b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Running.cpp index 5215ef6..f3faa44 100644 --- a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Running.cpp +++ b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Running.cpp @@ -38,6 +38,7 @@ */ template<> RunningState::RunningState() { + } /** @@ -59,7 +60,7 @@ State* RunningState::update(Equipment* equipment) Serial.println("Running update function"); float StateCtrl = getPointValue(equipment, "Px_Mode"); if (StateCtrl == 1.0f) { - return new RunningState(); + return new StandbyState(); } float W1 = getPointValue(equipment, "Px_W1"); @@ -68,6 +69,7 @@ State* RunningState::update(Equipment* equipment) 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(W1)){ case 0: @@ -236,10 +238,6 @@ State* RunningState::update(Equipment* equipment) setBitValue(equipment, "MVG_STS_03", 1, false); break; } - - - - // Apply any strategies defined for the standby state _applyStrategies(equipment); return nullptr; } @@ -254,7 +252,7 @@ void RunningState::enterState(Equipment* 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 - + } /** @@ -269,4 +267,5 @@ void RunningState::exitState(Equipment* equipment) { setPointValue(equipment, "MVG_STS_01", 0); setPointValue(equipment, "MVG_STS_02", 0); setPointValue(equipment, "MVG_STS_03", 0); + } \ No newline at end of file diff --git a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Standby.cpp b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Standby.cpp index 92daf4c..6dad7d4 100644 --- a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Standby.cpp +++ b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/State_Standby.cpp @@ -38,8 +38,7 @@ template<> StandbyState::StandbyState() { // You can add initialization code here if needed - - + } /** @@ -60,9 +59,6 @@ State* StandbyState::update(Equipment* equipment) if (StateCtrl == 2.0f) { return new RunningState(); } - - - // Apply any strategies defined for the standby state _applyStrategies(equipment); return nullptr; } @@ -77,8 +73,10 @@ template<> void StandbyState::enterState(Equipment* 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. diff --git a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/config.h b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/config.h index a29ec84..3be4ccc 100644 --- a/src/EPMS/MVG/MVG_SC_EC_M505_TCP/config.h +++ b/src/EPMS/MVG/MVG_SC_EC_M505_TCP/config.h @@ -21,10 +21,10 @@ * @{ */ #include - 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, 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; @@ -70,7 +70,7 @@ modbusMap mb_map[] = {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. /** From bd3814aca7fc2024771dda8ca34e03922dc4554f Mon Sep 17 00:00:00 2001 From: Emmanuel HC Date: Mon, 10 Nov 2025 16:28:31 -0600 Subject: [PATCH 09/16] gen --- platformio.ini | 9 +- src/EPMS/GEN/GEN_CAT_EMCP4_TCP/config.h | 1 + src/EPMS/GEN/GEN_CAT_GCCP_TCP/README.md | 33 +++++ src/EPMS/GEN/GEN_CAT_GCCP_TCP/State_Fail.cpp | 81 +++++++++++ .../GEN/GEN_CAT_GCCP_TCP/State_Running.cpp | 92 ++++++++++++ .../GEN/GEN_CAT_GCCP_TCP/State_Standby.cpp | 89 ++++++++++++ src/EPMS/GEN/GEN_CAT_GCCP_TCP/config.h | 133 ++++++++++++++++++ src/EPMS/GEN/GEN_CAT_GCCP_TCP/main.cpp | 86 +++++++++++ 8 files changed, 523 insertions(+), 1 deletion(-) create mode 100644 src/EPMS/GEN/GEN_CAT_GCCP_TCP/README.md create mode 100644 src/EPMS/GEN/GEN_CAT_GCCP_TCP/State_Fail.cpp create mode 100644 src/EPMS/GEN/GEN_CAT_GCCP_TCP/State_Running.cpp create mode 100644 src/EPMS/GEN/GEN_CAT_GCCP_TCP/State_Standby.cpp create mode 100644 src/EPMS/GEN/GEN_CAT_GCCP_TCP/config.h create mode 100644 src/EPMS/GEN/GEN_CAT_GCCP_TCP/main.cpp diff --git a/platformio.ini b/platformio.ini index 97e5cbb..5552fe6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ [platformio] -default_envs = MVG_SC_EC_M505_TCP ; Select here the name of the configuration you want to download +default_envs = GEN_CAT_GCCP_TCP ; Select here the name of the configuration you want to download [env] upload_port = COM26 @@ -254,3 +254,10 @@ extends = common_env_options build_flags = -D USE_MODBUS_IP, build_src_filter = -<*> + +[env:GEN_CAT_GCCP_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP, +build_src_filter = -<*> + + diff --git a/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/config.h b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/config.h index b45aea7..76b42f4 100644 --- a/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/config.h +++ b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/config.h @@ -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 diff --git a/src/EPMS/GEN/GEN_CAT_GCCP_TCP/README.md b/src/EPMS/GEN/GEN_CAT_GCCP_TCP/README.md new file mode 100644 index 0000000..355156f --- /dev/null +++ b/src/EPMS/GEN/GEN_CAT_GCCP_TCP/README.md @@ -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 diff --git a/src/EPMS/GEN/GEN_CAT_GCCP_TCP/State_Fail.cpp b/src/EPMS/GEN/GEN_CAT_GCCP_TCP/State_Fail.cpp new file mode 100644 index 0000000..8bc0385 --- /dev/null +++ b/src/EPMS/GEN/GEN_CAT_GCCP_TCP/State_Fail.cpp @@ -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 +#else + #include +#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::FailState(const std::vector& 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* FailState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Fail State..."); +} \ No newline at end of file diff --git a/src/EPMS/GEN/GEN_CAT_GCCP_TCP/State_Running.cpp b/src/EPMS/GEN/GEN_CAT_GCCP_TCP/State_Running.cpp new file mode 100644 index 0000000..44afe79 --- /dev/null +++ b/src/EPMS/GEN/GEN_CAT_GCCP_TCP/State_Running.cpp @@ -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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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::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* RunningState::update(Equipment* 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(Mode) == 2 ){ + return new StandbyState(); + } + // 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Running State..."); + +} \ No newline at end of file diff --git a/src/EPMS/GEN/GEN_CAT_GCCP_TCP/State_Standby.cpp b/src/EPMS/GEN/GEN_CAT_GCCP_TCP/State_Standby.cpp new file mode 100644 index 0000000..90f8eb3 --- /dev/null +++ b/src/EPMS/GEN/GEN_CAT_GCCP_TCP/State_Standby.cpp @@ -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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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::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* StandbyState::update(Equipment* 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(Mode) == 2 ){ + return new RunningState(); + } + + // 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Standby State..."); +} \ No newline at end of file diff --git a/src/EPMS/GEN/GEN_CAT_GCCP_TCP/config.h b/src/EPMS/GEN/GEN_CAT_GCCP_TCP/config.h new file mode 100644 index 0000000..72959e4 --- /dev/null +++ b/src/EPMS/GEN/GEN_CAT_GCCP_TCP/config.h @@ -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 + 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 + 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 diff --git a/src/EPMS/GEN/GEN_CAT_GCCP_TCP/main.cpp b/src/EPMS/GEN/GEN_CAT_GCCP_TCP/main.cpp new file mode 100644 index 0000000..286a98c --- /dev/null +++ b/src/EPMS/GEN/GEN_CAT_GCCP_TCP/main.cpp @@ -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 +#include "config.h" +#include "ModbusPoints/Modbus_PointFactory.h" +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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* 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); + } +} From 96f68f8d43aa4dc07a56e23e7667d0ae5e169fc8 Mon Sep 17 00:00:00 2001 From: Emmanuel HC Date: Fri, 14 Nov 2025 11:24:55 -0600 Subject: [PATCH 10/16] Breaker ABB Emax 2 Configuration of Breaker ABB Emax 2 Template --- platformio.ini | 4 +- .../BKR_ABB_EMax2_TCP/State_Running.cpp | 50 ++++++++++++++++++- .../BKR_ABB_EMax2_TCP/State_Standby.cpp | 28 ++++++++++- src/EPMS/Breaker/BKR_ABB_EMax2_TCP/config.h | 44 ++++++++-------- 4 files changed, 101 insertions(+), 25 deletions(-) diff --git a/platformio.ini b/platformio.ini index 5552fe6..bf5c678 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,10 +9,10 @@ [platformio] -default_envs = GEN_CAT_GCCP_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 = COM26 +upload_port = COM19 [common_env_options] framework = arduino diff --git a/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Running.cpp b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Running.cpp index b9e4a99..6d6c693 100644 --- a/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Running.cpp +++ b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Running.cpp @@ -38,6 +38,13 @@ */ template<> RunningState::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* RunningState::update(Equipment* 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(); + } + 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(); + } + + 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(I_load); + float rating = static_cast(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; diff --git a/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Standby.cpp b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Standby.cpp index 20029d1..51e0f25 100644 --- a/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Standby.cpp +++ b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Standby.cpp @@ -56,7 +56,18 @@ template<> State* StandbyState::update(Equipment* 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(); + } + 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::enterState(Equipment* 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); } /** diff --git a/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/config.h b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/config.h index 22baf7d..7728a3c 100644 --- a/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/config.h +++ b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/config.h @@ -21,10 +21,10 @@ * @{ */ #include - 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, 90); /**< @brief The static IP address for the device. */ - IPAddress gateway(172, 17, 32, 1); /**< @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. From 48f0e4837a004b2c666c98e0d7888bbf841bffae Mon Sep 17 00:00:00 2001 From: DohnJev18 Date: Mon, 5 Jan 2026 15:20:52 -0600 Subject: [PATCH 11/16] Created new TCP_CRAH program names HTS_PLC Created new TCP_CRAH program names HTS_PLC --- platformio.ini | 7 + src/BMS/CRAH/CRAH_HTS_PLC_TCP/README.md | 33 +++++ src/BMS/CRAH/CRAH_HTS_PLC_TCP/State_Fail.cpp | 81 +++++++++++ .../CRAH/CRAH_HTS_PLC_TCP/State_Running.cpp | 89 ++++++++++++ .../CRAH/CRAH_HTS_PLC_TCP/State_Standby.cpp | 85 +++++++++++ src/BMS/CRAH/CRAH_HTS_PLC_TCP/config.h | 134 ++++++++++++++++++ src/BMS/CRAH/CRAH_HTS_PLC_TCP/main.cpp | 86 +++++++++++ 7 files changed, 515 insertions(+) create mode 100644 src/BMS/CRAH/CRAH_HTS_PLC_TCP/README.md create mode 100644 src/BMS/CRAH/CRAH_HTS_PLC_TCP/State_Fail.cpp create mode 100644 src/BMS/CRAH/CRAH_HTS_PLC_TCP/State_Running.cpp create mode 100644 src/BMS/CRAH/CRAH_HTS_PLC_TCP/State_Standby.cpp create mode 100644 src/BMS/CRAH/CRAH_HTS_PLC_TCP/config.h create mode 100644 src/BMS/CRAH/CRAH_HTS_PLC_TCP/main.cpp diff --git a/platformio.ini b/platformio.ini index bf5c678..e0efd5c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -35,6 +35,13 @@ extends = common_env_options build_flags = -D USE_MODBUS_IP ;Importat configuration, this flags is used to configure the program build_src_filter = -<*> + ;Add the specific folder path here ;---------------------------------------------------------------------------------------------------- +[env:CRAH_HTS_PLC_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + + [env:CRAH_PETRA_PAHHC_600_C6_TCP] platform = espressif32 board = dfrobot_firebeetle2_esp32e diff --git a/src/BMS/CRAH/CRAH_HTS_PLC_TCP/README.md b/src/BMS/CRAH/CRAH_HTS_PLC_TCP/README.md new file mode 100644 index 0000000..355156f --- /dev/null +++ b/src/BMS/CRAH/CRAH_HTS_PLC_TCP/README.md @@ -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 diff --git a/src/BMS/CRAH/CRAH_HTS_PLC_TCP/State_Fail.cpp b/src/BMS/CRAH/CRAH_HTS_PLC_TCP/State_Fail.cpp new file mode 100644 index 0000000..8bc0385 --- /dev/null +++ b/src/BMS/CRAH/CRAH_HTS_PLC_TCP/State_Fail.cpp @@ -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 +#else + #include +#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::FailState(const std::vector& 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* FailState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Fail State..."); +} \ No newline at end of file diff --git a/src/BMS/CRAH/CRAH_HTS_PLC_TCP/State_Running.cpp b/src/BMS/CRAH/CRAH_HTS_PLC_TCP/State_Running.cpp new file mode 100644 index 0000000..b9e4a99 --- /dev/null +++ b/src/BMS/CRAH/CRAH_HTS_PLC_TCP/State_Running.cpp @@ -0,0 +1,89 @@ +/** + * @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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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::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* RunningState::update(Equipment* equipment) { + // STATE control, add conditions if change to a different state is needed + Serial.println("Running update function"); + + // 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Running State..."); + +} \ No newline at end of file diff --git a/src/BMS/CRAH/CRAH_HTS_PLC_TCP/State_Standby.cpp b/src/BMS/CRAH/CRAH_HTS_PLC_TCP/State_Standby.cpp new file mode 100644 index 0000000..20029d1 --- /dev/null +++ b/src/BMS/CRAH/CRAH_HTS_PLC_TCP/State_Standby.cpp @@ -0,0 +1,85 @@ +/** + * @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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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::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* StandbyState::update(Equipment* equipment) { + // STATE control, add conditions if change to a different state is needed + Serial.println("Standby update function"); + + // 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Standby State..."); +} \ No newline at end of file diff --git a/src/BMS/CRAH/CRAH_HTS_PLC_TCP/config.h b/src/BMS/CRAH/CRAH_HTS_PLC_TCP/config.h new file mode 100644 index 0000000..21a339a --- /dev/null +++ b/src/BMS/CRAH/CRAH_HTS_PLC_TCP/config.h @@ -0,0 +1,134 @@ +/** + * @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 + 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, 123); /**< @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; +#else + /** + * @defgroup ModbusRTUConfig Modbus RTU Configuration + * @brief Parameters for serial Modbus RTU communication. + * @{ + */ + #include + 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, 49, 0, "Total Ariflow"}, + {HR_FLOAT, 31, 0, "Airflow Effectiveness"}, + {HR_FLOAT, 33, 0, "Return Humidity"}, + {HR_FLOAT, 35, 0, "Return Air Temp"}, + {HR_FLOAT, 37, 0, "Return Dew Point"}, + {HR_FLOAT, 55, 0, "Supply Air Temp"}, + {HR_FLOAT, 27, 0, "Cooling Valve Output"}, + {HR_FLOAT, 29, 0, "Feedback Differential"}, + {HR, 23, 0, "Airflow Used"}, + {HR, 24, 0, "Available Airflow"}, + {HR_FLOAT, 47, 0, "Cooling Capacity"}, + {HR_FLOAT, 45, 0, "Net Sensible Cooling Capacity"}, + {HR_FLOAT, 43, 0, "Fan Time in Hrs"}, + {HR_FLOAT, 51, 0, "Differential Air Temp"}, + {HR_FLOAT, 39, 0, "Fan Speed"}, + {HR, 20, 0, "Heartbeat"}, + + {HR_FLOAT, 41, 0, "Air Temp Setpoint"}, + {HR_FLOAT, 25, 0, "Fan Speed Setpoint"}, + + {HR, 17, 0, "Pump Run Status"}, + {HR, 18, 0, "Pump Health"}, + {HR, 22, 0, "Pump High Float"}, + + {DI, 2, 0, "Common Alarm"}, + {DI, 12, 0, "Smoke Detected"}, + {DI, 13, 0, "Water Under Foot"}, + {DI, 14, 0, "Check Air Filter"}, + {DI, 15, 0, "Fan Issue"}, + {DI, 16, 0, "Alternate Power Source"}, + {DI, 8, 0, "Unit Status"}, + {DI, 7, 0, "Loss of Air Flow"}, + {DI, 8, 0, "Cooling State Input"}, + {DI, 6, 0, "Unit Local"}, + {HR, 4, 0, "Alarm Acknowledged"}, + + //{DI, 2, 0, "Operator Status (Input)"}, + //{COIL, 2, 0, "Operator Status (Output)"}, + //{DI, 2, 0, "Program Status (Input)"}, + //{COIL, 2, 0, "Program Status (Output)"}, + //{DI, 2, 0, "Running Status"}, + //{DI, 2, 0, "Not Ready Status"}, + //{DI, 2, 0, "Start Command (Input)"}, + //{COIL, 2, 0, "Start Command (Output)"}, + //{DI, 2, 0, "Stop Command (Input)"}, + //{COIL, 2, 0, "Stop Command (Output)"}, + //{DI, 2, 0, "Reset (Input)"}, + //{COIL, 2, 0, "Reset (Output)"}, + //{DI, 2, 0, "Start Command (Input)"}, + //{DI, 2, 0, "Stopped Status"}, + //{DI, 2, 0, "Error Status"}, + //{DI, 2, 0, "Not Ready Fail"}, + //{DI, 2, 0, "Starting Status"}, + //{DI, 2, 0, "Stopping Status"}, + // + //{HR_FLOAT, 2, 0, "Air Temp Setpoint (Output)"}, + //{HR_FLOAT, 2, 0, "Fan Speed Setpoint (Output)"}, + + +}; +//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 diff --git a/src/BMS/CRAH/CRAH_HTS_PLC_TCP/main.cpp b/src/BMS/CRAH/CRAH_HTS_PLC_TCP/main.cpp new file mode 100644 index 0000000..286a98c --- /dev/null +++ b/src/BMS/CRAH/CRAH_HTS_PLC_TCP/main.cpp @@ -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 +#include "config.h" +#include "ModbusPoints/Modbus_PointFactory.h" +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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* 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); + } +} From d792990bee9d5e07adbf2abfecca342faa7c3664 Mon Sep 17 00:00:00 2001 From: Emmanuel HC Date: Fri, 9 Jan 2026 10:47:04 -0600 Subject: [PATCH 12/16] q --- platformio.ini | 4 ++-- src/Base_TCP/config.h | 8 ++++---- src/EPMS/Breaker/BKR_ABB_XT_TCP/State_Standby.cpp | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/platformio.ini b/platformio.ini index 97e5cbb..7cf38b6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,10 +9,10 @@ [platformio] -default_envs = MVG_SC_EC_M505_TCP ; Select here the name of the configuration you want to download +default_envs = Base_TCP ; Select here the name of the configuration you want to download [env] -upload_port = COM26 +upload_port = COM15 [common_env_options] framework = arduino diff --git a/src/Base_TCP/config.h b/src/Base_TCP/config.h index 09bf37f..ca0d770 100644 --- a/src/Base_TCP/config.h +++ b/src/Base_TCP/config.h @@ -21,10 +21,10 @@ * @{ */ #include - 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; diff --git a/src/EPMS/Breaker/BKR_ABB_XT_TCP/State_Standby.cpp b/src/EPMS/Breaker/BKR_ABB_XT_TCP/State_Standby.cpp index 7d19437..e065339 100644 --- a/src/EPMS/Breaker/BKR_ABB_XT_TCP/State_Standby.cpp +++ b/src/EPMS/Breaker/BKR_ABB_XT_TCP/State_Standby.cpp @@ -98,6 +98,7 @@ void StandbyState::enterState(Equipment* equipment) { setPointValue(equipment, "kW", 0.0f); setPointValue(equipment, "kVA", 0.0f); setPointValue(equipment, "kWh", 0.0f); + setBitValue(equipment, "Alarm General", 0, false); } /** From be348deee3f9816f2f094a619e457b87869b1ceb Mon Sep 17 00:00:00 2001 From: Emmanuel HC Date: Thu, 5 Feb 2026 14:43:19 -0600 Subject: [PATCH 13/16] CoolIT CDU equipment added to library --- platformio.ini | 8 +- src/BMS/CDU/CDU_CoolIT_Oracle_TCP/README.md | 33 +++++ .../CDU/CDU_CoolIT_Oracle_TCP/State_Fail.cpp | 81 +++++++++++ .../CDU_CoolIT_Oracle_TCP/State_Running.cpp | 136 ++++++++++++++++++ .../CDU_CoolIT_Oracle_TCP/State_Standby.cpp | 130 +++++++++++++++++ src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h | 129 +++++++++++++++++ src/BMS/CDU/CDU_CoolIT_Oracle_TCP/main.cpp | 86 +++++++++++ 7 files changed, 602 insertions(+), 1 deletion(-) create mode 100644 src/BMS/CDU/CDU_CoolIT_Oracle_TCP/README.md create mode 100644 src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Fail.cpp create mode 100644 src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Running.cpp create mode 100644 src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Standby.cpp create mode 100644 src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h create mode 100644 src/BMS/CDU/CDU_CoolIT_Oracle_TCP/main.cpp diff --git a/platformio.ini b/platformio.ini index bf5c678..1781736 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ [platformio] -default_envs = BKR_ABB_EMax2_TCP ; Select here the name of the configuration you want to download +default_envs = CDU_CoolIT_Oracle_TCP ; Select here the name of the configuration you want to download [env] upload_port = COM19 @@ -261,3 +261,9 @@ extends = common_env_options build_flags = -D USE_MODBUS_IP, build_src_filter = -<*> + +[env:CDU_CoolIT_Oracle_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + \ No newline at end of file diff --git a/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/README.md b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/README.md new file mode 100644 index 0000000..355156f --- /dev/null +++ b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/README.md @@ -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 diff --git a/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Fail.cpp b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Fail.cpp new file mode 100644 index 0000000..8bc0385 --- /dev/null +++ b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Fail.cpp @@ -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 +#else + #include +#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::FailState(const std::vector& 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* FailState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Fail State..."); +} \ No newline at end of file diff --git a/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Running.cpp b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Running.cpp new file mode 100644 index 0000000..ce88f62 --- /dev/null +++ b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Running.cpp @@ -0,0 +1,136 @@ +/** + * @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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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::RunningState() { + addStrategy("TT01", new SingleValueStrategy(870.0F, 10.0f, 1000)); + addStrategy("TT02", new SingleValueStrategy(880.0F, 10.0f, 1000)); + addStrategy("TT31", new SingleValueStrategy(670.0F, 10.0f, 1000)); + addStrategy("TT41", new SingleValueStrategy(660.0F, 10.0f, 1000)); + addStrategy("PT01", new SingleValueStrategy(350.0F, 10.0f, 1000)); + addStrategy("PT02", new SingleValueStrategy(380.0F, 10.0f, 1000)); + addStrategy("PT31", new SingleValueStrategy(340.0F, 10.0f, 1000)); + addStrategy("PT41", new SingleValueStrategy(370.0F, 10.0f, 1000)); + addStrategy("PT32", new SingleValueStrategy(380.0F, 10.0f, 1000)); + addStrategy("PT42", new SingleValueStrategy(350.0F, 10.0f, 1000)); + addStrategy("PT21", new SingleValueStrategy(370.0F, 10.0f, 1000)); + addStrategy("PT11", new SingleValueStrategy(390.0F, 10.0f, 1000)); + addStrategy("AirTemp", new SingleValueStrategy(660.0F, 1.0f, 1000)); + addStrategy("DP31", new SingleValueStrategy(150.0F, 10.0f, 1000)); + addStrategy("DP41", new SingleValueStrategy(180.0F, 10.0f, 1000)); + addStrategy("DP", new SingleValueStrategy(160.0F, 10.0f, 1000)); + addStrategy("FL01", new SingleValueStrategy(7420.0F, 10.0f, 1000)); + addStrategy("P31_Speed", new SingleValueStrategy(300.0F, 10.0f, 1000)); + addStrategy("P41_Speed", new SingleValueStrategy(410.0F, 10.0f, 1000)); + addStrategy("F1_Speed", new SingleValueStrategy(180.0F, 10.0f, 1000)); + addStrategy("F2_Speed", new SingleValueStrategy(190.0F, 10.0f, 1000)); + addStrategy("F3_Speed", new SingleValueStrategy(170.0F, 10.0f, 1000)); + addStrategy("F4_Speed", new SingleValueStrategy(200.0F, 10.0f, 1000)); + addStrategy("F5_Speed", new SingleValueStrategy(250.0F, 10.0f, 1000)); + addStrategy("F6_Speed", new SingleValueStrategy(210.0F, 10.0f, 1000)); + addStrategy("F7_Speed", new SingleValueStrategy(200.0F, 10.0f, 1000)); + addStrategy("F8_Speed", new SingleValueStrategy(180.0F, 10.0f, 1000)); + addStrategy("AirTemp", new SingleValueStrategy(680.0f, 100.0f, 5000)); + addStrategy("Group_Flow", new SingleValueStrategy(7510.0F, 10.0f, 1000)); + addStrategy("Group_DP", new SingleValueStrategy(200.0F, 10.0f, 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. + * + * 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* RunningState::update(Equipment* equipment) { + // STATE control, add conditions if change to a different state is needed + Serial.println("Running update function"); + float State_Ctrl = getPointValue(equipment, "Remote_Start"); + if (State_Ctrl == 0){ + return new StandbyState(); + } + + float TT01 = getPointValue(equipment, "TT01"); + float TT02 = getPointValue(equipment, "TT02"); + float TT31 = getPointValue(equipment, "TT31"); + float TT41 = getPointValue(equipment, "TT41"); + float PT01 = getPointValue(equipment, "PT01"); + float PT02 = getPointValue(equipment, "PT02"); + float PT31 = getPointValue(equipment, "PT31"); + float PT41 = getPointValue(equipment, "PT41"); + setPointValue(equipment, "TT01_TT02", (TT01 + TT02)/2.0f); + setPointValue(equipment, "TT31_TT41", (TT31 + TT41)/2.0f); + setPointValue(equipment, "PT01_PT02", (PT01 + PT02)/2.0f); + setPointValue(equipment, "PT31_PT41", (PT31 + PT41)/2.0f); + + // 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::enterState(Equipment* 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, "Status", 1); +} + +/** + * @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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Running State..."); + +} \ No newline at end of file diff --git a/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Standby.cpp b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Standby.cpp new file mode 100644 index 0000000..c525d95 --- /dev/null +++ b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Standby.cpp @@ -0,0 +1,130 @@ +/** + * @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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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::StandbyState() { + // You can add initialization code here if needed + addStrategy("TT01", new SingleValueStrategy(870.0F, 10.0f, 1000)); + addStrategy("TT02", new SingleValueStrategy(870.0F, 10.0f, 1000)); + addStrategy("TT31", new SingleValueStrategy(870.0F, 10.0f, 1000)); + addStrategy("TT41", new SingleValueStrategy(870.0F, 10.0f, 1000)); + addStrategy("PT01", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("PT02", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("PT31", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("PT41", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("PT32", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("PT42", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("PT21", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("PT11", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("DP31", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("DP41", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("DP", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("FL01", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("AirTemp", new SingleValueStrategy(870.0F, 10.0f, 1000)); + addStrategy("P31_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("P41_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("F1_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("F2_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("F3_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("F4_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("F5_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("F6_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("F7_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("F8_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("Group_Flow", new SingleValueStrategy(1.0F, 1.0f, 1000)); + addStrategy("Group_DP", new SingleValueStrategy(1.0F, 1.0f, 1000)); + + +} + +/** + * @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* StandbyState::update(Equipment* equipment) { + // STATE control, add conditions if change to a different state is needed + Serial.println("Standby update function"); + float State_Ctrl = getPointValue(equipment, "Remote_Start"); + if (State_Ctrl == 1){ + return new RunningState(); + } + float TT01 = getPointValue(equipment, "TT01"); + float TT02 = getPointValue(equipment, "TT02"); + float TT31 = getPointValue(equipment, "TT31"); + float TT41 = getPointValue(equipment, "TT41"); + float PT01 = getPointValue(equipment, "PT01"); + float PT02 = getPointValue(equipment, "PT02"); + float PT31 = getPointValue(equipment, "PT31"); + float PT41 = getPointValue(equipment, "PT41"); + setPointValue(equipment, "TT01_TT02", (TT01 + TT02)/2.0f); + setPointValue(equipment, "TT31_TT41", (TT31 + TT41)/2.0f); + setPointValue(equipment, "PT01_PT02", (PT01 + PT02)/2.0f); + setPointValue(equipment, "PT31_PT41", (PT31 + PT41)/2.0f); + // 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::enterState(Equipment* equipment) { + // Logic to run when the equipment enters this state + Serial.println("Enter Standby State..."); + setPointValue(equipment, "Status", 0); +} + +/** + * @brief Logic to execute once when exiting the standby state. + * @param equipment Pointer to the Equipment instance. + */ +template<> +void StandbyState::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Standby State..."); +} \ No newline at end of file diff --git a/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h new file mode 100644 index 0000000..94179a2 --- /dev/null +++ b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h @@ -0,0 +1,129 @@ +/** + * @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 + const char *ssid = "Oracle_SA"; /**< @brief The SSID of the WiFi network. */ + const char *password = "Prime!123"; /**< @brief The password for the WiFi network. */ + IPAddress local_IP(192, 168, 1, 110); /**< @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 + 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, 0, 0, "Status"}, + {HR, 1, 0, "Group"}, + {HR, 2, 0, "TT01"}, + {HR, 3, 0, "TT02"}, + {HR, 4, 0, "TT31"}, + {HR, 5, 0, "TT41"}, + {HR, 6, 0, "PT01"}, + {HR, 7, 0, "PT02"}, + {HR, 8, 0, "PT31"}, + {HR, 9, 0, "PT41"}, + {HR, 10, 0, "PT32"}, + {HR, 11, 0, "PT42"}, + {HR, 12, 0, "PT21"}, + {HR, 13, 0, "PT11"}, + {HR, 14, 0, "TT01_TT02"}, + {HR, 15, 0, "TT31_TT41"}, + {HR, 16, 0, "PT01_PT02"}, + {HR, 17, 0, "PT31_PT41"}, + {HR, 18, 0, "DP31"}, + {HR, 19, 0, "DP41"}, + {HR, 20, 0, "DP"}, + {HR, 21, 0, "FL01"}, + {HR, 22, 0, "P31_Speed"}, + {HR, 23, 0, "P41_Speed"}, + {HR, 24, 0, "F1_Speed"}, + {HR, 25, 0, "F2_Speed"}, + {HR, 26, 0, "F3_Speed"}, + {HR, 27, 0, "F4_Speed"}, + {HR, 28, 0, "F5_Speed"}, + {HR, 29, 0, "F6_Speed"}, + {HR, 30, 0, "F7_Speed"}, + {HR, 31, 0, "F8_Speed"}, + {HR, 33, 0, "AirTemp"}, + {HR_FLOAT, 40, 0, "Group_Flow"}, + {HR_FLOAT, 42, 0, "Group_DP"}, + {HR, 44, 0, "Version"}, + {HR, 200, 0, "Temp_SP"}, + {HR, 201, 0, "DP_SP"}, + {HR, 202, 0, "Flow_SP"}, + + {COIL, 0, 0, "Alarm"}, + {COIL, 1, 0, "Alarm_Ack"}, + {COIL, 5, 0, "OvrPressure"}, + {COIL, 14, 0, "Ntwk_Fault"}, + {COIL, 15, 0, "Unit_Available"}, + {COIL, 33, 0, "OvrTemp"}, + {COIL, 86, 0, "LD01"}, + {COIL, 87, 0, "StpBtn"}, + {COIL, 131, 0, "Critical_Fault"}, + {COIL, 132, 0, "Power_Fault"}, + {COIL, 133, 0, "PLC_Fault"}, + {COIL, 200, 0, "Remote_Start"}, + +}; +//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 diff --git a/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/main.cpp b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/main.cpp new file mode 100644 index 0000000..286a98c --- /dev/null +++ b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/main.cpp @@ -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 +#include "config.h" +#include "ModbusPoints/Modbus_PointFactory.h" +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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* 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); + } +} From 09be54e33098c47b7adbbe12a71ad88e32e0779c Mon Sep 17 00:00:00 2001 From: Emmanuel HC Date: Thu, 12 Feb 2026 11:35:04 -0600 Subject: [PATCH 14/16] RPP program added --- platformio.ini | 11 +- src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h | 4 +- src/EPMS/RPP/RPP_Cortex_TCP/README.md | 33 +++ src/EPMS/RPP/RPP_Cortex_TCP/State_Fail.cpp | 81 +++++++ src/EPMS/RPP/RPP_Cortex_TCP/State_Running.cpp | 99 ++++++++ src/EPMS/RPP/RPP_Cortex_TCP/State_Standby.cpp | 224 ++++++++++++++++++ src/EPMS/RPP/RPP_Cortex_TCP/config.h | 219 +++++++++++++++++ src/EPMS/RPP/RPP_Cortex_TCP/main.cpp | 86 +++++++ 8 files changed, 753 insertions(+), 4 deletions(-) create mode 100644 src/EPMS/RPP/RPP_Cortex_TCP/README.md create mode 100644 src/EPMS/RPP/RPP_Cortex_TCP/State_Fail.cpp create mode 100644 src/EPMS/RPP/RPP_Cortex_TCP/State_Running.cpp create mode 100644 src/EPMS/RPP/RPP_Cortex_TCP/State_Standby.cpp create mode 100644 src/EPMS/RPP/RPP_Cortex_TCP/config.h create mode 100644 src/EPMS/RPP/RPP_Cortex_TCP/main.cpp diff --git a/platformio.ini b/platformio.ini index 1781736..82ff56a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ [platformio] -default_envs = CDU_CoolIT_Oracle_TCP ; Select here the name of the configuration you want to download +default_envs = RPP_Cortex_TCP ; Select here the name of the configuration you want to download [env] upload_port = COM19 @@ -266,4 +266,11 @@ platform = espressif32 board = dfrobot_firebeetle2_esp32e extends = common_env_options build_flags = -D USE_MODBUS_IP -build_src_filter = -<*> + \ No newline at end of file +build_src_filter = -<*> + + +[env:RPP_Cortex_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + \ No newline at end of file diff --git a/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h index 94179a2..9112a8c 100644 --- a/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h +++ b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h @@ -23,8 +23,8 @@ #include const char *ssid = "Oracle_SA"; /**< @brief The SSID of the WiFi network. */ const char *password = "Prime!123"; /**< @brief The password for the WiFi network. */ - IPAddress local_IP(192, 168, 1, 110); /**< @brief The static IP address for the device. */ - IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */ + IPAddress local_IP(172, 17, 38, 22); /**< @brief The static IP address for the device. */ + IPAddress gateway(172, 17, 38, 1); /**< @brief The gateway IP address. */ IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ ModbusIP mb; diff --git a/src/EPMS/RPP/RPP_Cortex_TCP/README.md b/src/EPMS/RPP/RPP_Cortex_TCP/README.md new file mode 100644 index 0000000..355156f --- /dev/null +++ b/src/EPMS/RPP/RPP_Cortex_TCP/README.md @@ -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 diff --git a/src/EPMS/RPP/RPP_Cortex_TCP/State_Fail.cpp b/src/EPMS/RPP/RPP_Cortex_TCP/State_Fail.cpp new file mode 100644 index 0000000..8bc0385 --- /dev/null +++ b/src/EPMS/RPP/RPP_Cortex_TCP/State_Fail.cpp @@ -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 +#else + #include +#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::FailState(const std::vector& 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* FailState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Fail State..."); +} \ No newline at end of file diff --git a/src/EPMS/RPP/RPP_Cortex_TCP/State_Running.cpp b/src/EPMS/RPP/RPP_Cortex_TCP/State_Running.cpp new file mode 100644 index 0000000..5b5350c --- /dev/null +++ b/src/EPMS/RPP/RPP_Cortex_TCP/State_Running.cpp @@ -0,0 +1,99 @@ +/** + * @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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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::RunningState() { + addStrategy("TT01", new SingleValueStrategy(870.0F, 10.0f, 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. + * + * 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* RunningState::update(Equipment* equipment) { + // STATE control, add conditions if change to a different state is needed + Serial.println("Running update function"); + float State_Ctrl = getPointValue(equipment, "Remote_Start"); + if (State_Ctrl == 0){ + return new StandbyState(); + } + + float TT01 = getPointValue(equipment, "TT01"); + float TT02 = getPointValue(equipment, "TT02"); + setPointValue(equipment, "TT01_TT02", (TT01 + TT02)/2.0f); + + // 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::enterState(Equipment* 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, "Status", 1); +} + +/** + * @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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Running State..."); + +} \ No newline at end of file diff --git a/src/EPMS/RPP/RPP_Cortex_TCP/State_Standby.cpp b/src/EPMS/RPP/RPP_Cortex_TCP/State_Standby.cpp new file mode 100644 index 0000000..cf74d5b --- /dev/null +++ b/src/EPMS/RPP/RPP_Cortex_TCP/State_Standby.cpp @@ -0,0 +1,224 @@ +/** + * @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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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::StandbyState() { + // You can add initialization code here if needed + addStrategy("In_freq", new SingleValueStrategy(60.0F, 1.0f, 1000)); + addStrategy("InV_L1N", new SingleValueStrategy(220.0F, 1.0f, 1000)); + addStrategy("InV_L2N", new SingleValueStrategy(220.0F, 1.0f, 1000)); + addStrategy("InV_L3N", new SingleValueStrategy(220.0F, 1.0f, 1000)); + addStrategy("InV_L12", new SingleValueStrategy(480.0F, 1.0f, 1000)); + addStrategy("InV_L23", new SingleValueStrategy(480.0F, 1.0f, 1000)); + addStrategy("InV_L31", new SingleValueStrategy(480.0F, 1.0f, 1000)); + addStrategy("InTHD_L1N", new SingleValueStrategy(2.5F, 0.5f, 1000)); + addStrategy("InTHD_L2N", new SingleValueStrategy(3.1F, 0.5f, 1000)); + addStrategy("InTHD_L3N", new SingleValueStrategy(2.4F, 0.5f, 1000)); + addStrategy("InTHD_L1_1st", new SingleValueStrategy(2.4F, 0.2f, 1000)); + addStrategy("InTHD_L1_3rd", new SingleValueStrategy(2.1F, 0.2f, 1000)); + addStrategy("InTHD_L1_5th", new SingleValueStrategy(1.9F, 0.2f, 1000)); + addStrategy("InTHD_L1_7th", new SingleValueStrategy(2.1F, 0.2f, 1000)); + addStrategy("InTHD_L1_9th", new SingleValueStrategy(1.8F, 0.2f, 1000)); + addStrategy("InTHD_L2_1st", new SingleValueStrategy(2.3F, 0.2f, 1000)); + addStrategy("InTHD_L2_3rd", new SingleValueStrategy(2.2F, 0.2f, 1000)); + addStrategy("InTHD_L2_5th", new SingleValueStrategy(2.4F, 0.2f, 1000)); + addStrategy("InTHD_L2_7th", new SingleValueStrategy(2.5F, 0.2f, 1000)); + addStrategy("InTHD_L2_9th", new SingleValueStrategy(2.6F, 0.2f, 1000)); + addStrategy("InTHD_L3_1st", new SingleValueStrategy(2.2F, 0.2f, 1000)); + addStrategy("InTHD_L3_3rd", new SingleValueStrategy(2.3F, 0.2f, 1000)); + addStrategy("InTHD_L3_5th", new SingleValueStrategy(2.1F, 0.2f, 1000)); + addStrategy("InTHD_L3_7th", new SingleValueStrategy(2.4F, 0.2f, 1000)); + addStrategy("InTHD_L3_9th", new SingleValueStrategy(2.5F, 0.2f, 1000)); + addStrategy("InTHD_L12", new SingleValueStrategy(3.1F, 0.2f, 1000)); + addStrategy("InTHD_L23", new SingleValueStrategy(2.1F, 0.2f, 1000)); + addStrategy("InTHD_L31", new SingleValueStrategy(1.8F, 0.2f, 1000)); + + addStrategy("CB1_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB2_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB3_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB4_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB5_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB6_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB7_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB8_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB9_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB10_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB11_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB12_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB13_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB14_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB15_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + addStrategy("CB16_kW", new SingleValueStrategy(3.1F, 3.0f, 1000)); + + addStrategy("MainCB_PF", new SingleValueStrategy(0.9F, 0.05f, 1000)); + +} + +/** + * @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* StandbyState::update(Equipment* equipment) { + // STATE control, add conditions if change to a different state is needed + Serial.println("Standby update function"); + + // Calculate Avergae for voltage LN points + float InV_L1N = getPointValue(equipment, "InV_L1N"); + float InV_L2N = getPointValue(equipment, "InV_L2N"); + float InV_L3N = getPointValue(equipment, "InV_L3N"); + setPointValue(equipment, "InV_LN_avg", (InV_L1N + InV_L2N + InV_L3N)/3.0f); + // Calculate Avergae for voltage LL points + float InV_L12 = getPointValue(equipment, "InV_L12"); + float InV_L23 = getPointValue(equipment, "InV_L23"); + float InV_L31 = getPointValue(equipment, "InV_L31"); + setPointValue(equipment, "InV_LL_avg", (InV_L12 + InV_L23 + InV_L31)/3.0f); + + + for (int i = 1; i <= 16; i++) { + std::string cb_name = "CB" + std::to_string(i); + std::string kw_name = cb_name + "_kW"; + std::string max_kw_name = cb_name + "_max_kW"; + std::string max_current_name = cb_name + "_maxCurrent"; + + float cb_value = getPointValue(equipment, cb_name.c_str()); + if (cb_value == 1.0f){ + float kw = 350.0f; + Strategy_Behavior* svs_cb_kW = getStrategy(kw_name.c_str()); + static_cast(svs_cb_kW)->setSetpoint(kw); + + float in_v_ll_avg = getPointValue(equipment, "InV_LL_avg"); + float current = (kw*1000.0f)/(in_v_ll_avg*1.73f); + setPointValue(equipment, max_current_name.c_str(), current); + + float max_kw = getPointValue(equipment, max_kw_name.c_str()); + if (kw > max_kw){ + setPointValue(equipment, max_kw_name.c_str(), kw); + } + + float max_current = getPointValue(equipment, max_current_name.c_str()); + if (current > max_current){ + setPointValue(equipment, max_current_name.c_str(), current); + } + } + + + } + + float mainCB_total_kW = 0.0f; + float mainCB_maxCurrent = 0.0f; + float mainCB_neutralCurrent = 0.0f; + float mainCB_maxTotalKw = 0.0f; + float mainCB_maxTotalCurrent = 0.0f; + for (int i = 1; i <= 16; i++) { + std::string kw_name = "CB" + std::to_string(i) + "_kW"; + std::string max_current_name = "CB" + std::to_string(i) + "_maxCurrent"; + mainCB_total_kW += getPointValue(equipment, kw_name.c_str()); + mainCB_maxCurrent += getPointValue(equipment, max_current_name.c_str()); + float max_kw = getPointValue(equipment, ("CB" + std::to_string(i) + "_max_kW").c_str()); + if (max_kw > mainCB_maxTotalKw) { + mainCB_maxTotalKw = max_kw; + } + float max_current = getPointValue(equipment, max_current_name.c_str()); + if (max_current > mainCB_maxTotalCurrent) { + mainCB_maxTotalCurrent = max_current; + } + } + + float mainCB_PF = getPointValue(equipment, "MainCB_PF"); + setPointValue(equipment, "MainCB_Total_kW", mainCB_total_kW); + setPointValue(equipment, "MainCB_maxCurrent", mainCB_maxCurrent); + setPointValue(equipment, "MainCB_neutralCurrent", mainCB_neutralCurrent); + setPointValue(equipment, "MainCB_maxTotalkW", mainCB_maxTotalKw); + setPointValue(equipment, "MainCB_maxTotalCurrent", mainCB_maxTotalCurrent); + + setPointValue(equipment, "MainCB_L1_kW", mainCB_total_kW); + setPointValue(equipment, "MainCB_L1_kVA", mainCB_total_kW*1.3f); + setPointValue(equipment, "MainCB_L1_Current", mainCB_maxCurrent); + setPointValue(equipment, "MainCB_L1_PF", mainCB_PF); + setPointValue(equipment, "MainCB_L1_max_kW", mainCB_maxTotalKw); + setPointValue(equipment, "MainCB_L1_max_current", mainCB_maxTotalCurrent); + + setPointValue(equipment, "MainCB_L2_kW", mainCB_total_kW); + setPointValue(equipment, "MainCB_L2_kVA", mainCB_total_kW*1.3f); + setPointValue(equipment, "MainCB_L2_Current", mainCB_maxCurrent); + setPointValue(equipment, "MainCB_L2_PF", mainCB_PF); + setPointValue(equipment, "MainCB_L2_max_kW", mainCB_maxTotalKw); + setPointValue(equipment, "MainCB_L2_max_current", mainCB_maxTotalCurrent); + + setPointValue(equipment, "MainCB_L3_kW", mainCB_total_kW); + setPointValue(equipment, "MainCB_L3_kVA", mainCB_total_kW*1.3f); + setPointValue(equipment, "MainCB_L3_Current", mainCB_maxCurrent); + setPointValue(equipment, "MainCB_L3_PF", mainCB_PF); + setPointValue(equipment, "MainCB_L3_max_kW", mainCB_maxTotalKw); + setPointValue(equipment, "MainCB_L3_max_current", mainCB_maxTotalCurrent); + + + // 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::enterState(Equipment* equipment) { + // Logic to run when the equipment enters this state + Serial.println("Enter Standby State..."); + setPointValue(equipment, "Status", 0); +} + +/** + * @brief Logic to execute once when exiting the standby state. + * @param equipment Pointer to the Equipment instance. + */ +template<> +void StandbyState::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Standby State..."); +} + diff --git a/src/EPMS/RPP/RPP_Cortex_TCP/config.h b/src/EPMS/RPP/RPP_Cortex_TCP/config.h new file mode 100644 index 0000000..a1de0d7 --- /dev/null +++ b/src/EPMS/RPP/RPP_Cortex_TCP/config.h @@ -0,0 +1,219 @@ +/** + * @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 + const char *ssid = "Oracle_SA"; /**< @brief The SSID of the WiFi network. */ + const char *password = "Prime!123"; /**< @brief The password for the WiFi network. */ + IPAddress local_IP(172, 17, 38, 72); /**< @brief The static IP address for the device. */ + IPAddress gateway(172, 17, 38, 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 + 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, 2046, 0, "CB1"}, + {HR, 2047, 0, "CB2"}, + {HR, 2048, 0, "CB3"}, + {HR, 2049, 0, "CB4"}, + {HR, 2050, 0, "CB5"}, + {HR, 2051, 0, "CB6"}, + {HR, 2052, 0, "CB7"}, + {HR, 2053, 0, "CB8"}, + {HR, 2054, 0, "CB9"}, + {HR, 2055, 0, "CB10"}, + {HR, 2056, 0, "CB11"}, + {HR, 2057, 0, "CB12"}, + {HR, 2058, 0, "CB13"}, + {HR, 2059, 0, "CB14"}, + {HR, 2060, 0, "CB15"}, + {HR, 2061, 0, "CB16"}, + {HR_FLOAT, 9000, 0, "In_freq"}, + {HR_FLOAT, 9002, 0, "InV_L1N"}, + {HR_FLOAT, 9004, 0, "InV_L2N"}, + {HR_FLOAT, 9006, 0, "InV_L3N"}, + {HR_FLOAT, 9008, 0, "InV_LN_avg"}, + {HR_FLOAT, 9010, 0, "InV_L12"}, + {HR_FLOAT, 9012, 0, "InV_L23"}, + {HR_FLOAT, 9014, 0, "InV_L31"}, + {HR_FLOAT, 9016, 0, "InV_LL_avg"}, + {HR_FLOAT, 9018, 0, "InTHD_L1N"}, + {HR_FLOAT, 9020, 0, "InTHD_L2N"}, + {HR_FLOAT, 9022, 0, "InTHD_L3N"}, + {HR_FLOAT, 9036, 0, "InTHD_L1_1st"}, + {HR_FLOAT, 9040, 0, "InTHD_L1_3rd"}, + {HR_FLOAT, 9044, 0, "InTHD_L1_5th"}, + {HR_FLOAT, 9048, 0, "InTHD_L1_7th"}, + {HR_FLOAT, 9052, 0, "InTHD_L1_9th"}, + {HR_FLOAT, 9162, 0, "InTHD_L2_1st"}, + {HR_FLOAT, 9166, 0, "InTHD_L2_3rd"}, + {HR_FLOAT, 9170, 0, "InTHD_L2_5th"}, + {HR_FLOAT, 9174, 0, "InTHD_L2_7th"}, + {HR_FLOAT, 9178, 0, "InTHD_L2_9th"}, + {HR_FLOAT, 9288, 0, "InTHD_L3_1st"}, + {HR_FLOAT, 9292, 0, "InTHD_L3_3rd"}, + {HR_FLOAT, 9296, 0, "InTHD_L3_5th"}, + {HR_FLOAT, 9300, 0, "InTHD_L3_7th"}, + {HR_FLOAT, 9304, 0, "InTHD_L3_9th"}, + {HR_FLOAT, 9018, 0, "InTHD_L12"}, + {HR_FLOAT, 9020, 0, "InTHD_L23"}, + {HR_FLOAT, 9022, 0, "InTHD_L31"}, + + {HR_FLOAT, 13456, 0, "CB1_kW"}, + {HR_FLOAT, 13460, 0, "CB2_kW"}, + {HR_FLOAT, 13464, 0, "CB3_kW"}, + {HR_FLOAT, 13468, 0, "CB4_kW"}, + {HR_FLOAT, 13472, 0, "CB5_kW"}, + {HR_FLOAT, 13476, 0, "CB6_kW"}, + {HR_FLOAT, 13480, 0, "CB7_kW"}, + {HR_FLOAT, 13484, 0, "CB8_kW"}, + {HR_FLOAT, 13488, 0, "CB9_kW"}, + {HR_FLOAT, 13492, 0, "CB10_kW"}, + {HR_FLOAT, 13496, 0, "CB11_kW"}, + {HR_FLOAT, 13500, 0, "CB12_kW"}, + {HR_FLOAT, 13504, 0, "CB13_kW"}, + {HR_FLOAT, 13508, 0, "CB14_kW"}, + {HR_FLOAT, 13512, 0, "CB15_kW"}, + {HR_FLOAT, 13516, 0, "CB16_kW"}, + + {HR_FLOAT, 14608, 0, "CB1_Current"}, + {HR_FLOAT, 14612, 0, "CB2_Current"}, + {HR_FLOAT, 14616, 0, "CB3_Current"}, + {HR_FLOAT, 14620, 0, "CB4_Current"}, + {HR_FLOAT, 14624, 0, "CB5_Current"}, + {HR_FLOAT, 14628, 0, "CB6_Current"}, + {HR_FLOAT, 14632, 0, "CB7_Current"}, + {HR_FLOAT, 14636, 0, "CB8_Current"}, + {HR_FLOAT, 14640, 0, "CB9_Current"}, + {HR_FLOAT, 14644, 0, "CB10_Current"}, + {HR_FLOAT, 14648, 0, "CB11_Current"}, + {HR_FLOAT, 14652, 0, "CB12_Current"}, + {HR_FLOAT, 14656, 0, "CB13_Current"}, + {HR_FLOAT, 14660, 0, "CB14_Current"}, + {HR_FLOAT, 14664, 0, "CB15_Current"}, + {HR_FLOAT, 14668, 0, "CB16_Current"}, + + {HR_FLOAT, 16912, 0, "CB1_max_kW"}, + {HR_FLOAT, 16916, 0, "CB2_max_kW"}, + {HR_FLOAT, 16920, 0, "CB3_max_kW"}, + {HR_FLOAT, 16924, 0, "CB4_max_kW"}, + {HR_FLOAT, 16928, 0, "CB5_max_kW"}, + {HR_FLOAT, 16932, 0, "CB6_max_kW"}, + {HR_FLOAT, 16936, 0, "CB7_max_kW"}, + {HR_FLOAT, 16940, 0, "CB8_max_kW"}, + {HR_FLOAT, 16944, 0, "CB9_max_kW"}, + {HR_FLOAT, 16948, 0, "CB10_max_kW"}, + {HR_FLOAT, 16952, 0, "CB11_max_kW"}, + {HR_FLOAT, 16956, 0, "CB12_max_kW"}, + {HR_FLOAT, 16960, 0, "CB13_max_kW"}, + {HR_FLOAT, 16964, 0, "CB14_max_kW"}, + {HR_FLOAT, 16968, 0, "CB15_max_kW"}, + {HR_FLOAT, 16972, 0, "CB16_max_kW"}, + + {HR_FLOAT, 17296, 0, "CB1_maxCurrent"}, + {HR_FLOAT, 17300, 0, "CB2_maxCurrent"}, + {HR_FLOAT, 17304, 0, "CB3_maxCurrent"}, + {HR_FLOAT, 17308, 0, "CB4_maxCurrent"}, + {HR_FLOAT, 17312, 0, "CB5_maxCurrent"}, + {HR_FLOAT, 17316, 0, "CB6_maxCurrent"}, + {HR_FLOAT, 17320, 0, "CB7_maxCurrent"}, + {HR_FLOAT, 17324, 0, "CB8_maxCurrent"}, + {HR_FLOAT, 17328, 0, "CB9_maxCurrent"}, + {HR_FLOAT, 17332, 0, "CB10_maxCurrent"}, + {HR_FLOAT, 17336, 0, "CB11_maxCurrent"}, + {HR_FLOAT, 17340, 0, "CB12_maxCurrent"}, + {HR_FLOAT, 17344, 0, "CB13_maxCurrent"}, + {HR_FLOAT, 17348, 0, "CB14_maxCurrent"}, + {HR_FLOAT, 17352, 0, "CB15_maxCurrent"}, + {HR_FLOAT, 17356, 0, "CB16_maxCurrent"}, + + {HR_FLOAT, 40058, 0, "MainCB_Total_kW"}, + {HR_FLOAT, 40064, 0, "MainCB_maxCurrent"}, + {HR_FLOAT, 40068, 0, "MainCB_neutralCurrent"}, + {HR_FLOAT, 40070, 0, "MainCB_PF"}, + {HR_FLOAT, 40074, 0, "MainCB_maxTotalkW"}, + {HR_FLOAT, 40076, 0, "MainCB_maxTotalCurrent"}, + + {HR_FLOAT, 40108, 0, "MainCB_L1_kW"}, + {HR_FLOAT, 40112, 0, "MainCB_L1_kVA"}, + {HR_FLOAT, 40114, 0, "MainCB_L1_Current"}, + {HR_FLOAT, 40116, 0, "MainCB_L1_PF"}, + {HR_FLOAT, 40126, 0, "MainCB_L1_max_kW"}, + {HR_FLOAT, 40128, 0, "MainCB_L1_max_current"}, + + {HR_FLOAT, 40158, 0, "MainCB_L2_kW"}, + {HR_FLOAT, 40162, 0, "MainCB_L2_kVA"}, + {HR_FLOAT, 40164, 0, "MainCB_L2_Current"}, + {HR_FLOAT, 40166, 0, "MainCB_L2_PF"}, + {HR_FLOAT, 40176, 0, "MainCB_L2_max_kW"}, + {HR_FLOAT, 40178, 0, "MainCB_L2_max_current"}, + + {HR_FLOAT, 40208, 0, "MainCB_L3_kW"}, + {HR_FLOAT, 40212, 0, "MainCB_L3_kVA"}, + {HR_FLOAT, 40214, 0, "MainCB_L3_Current"}, + {HR_FLOAT, 40216, 0, "MainCB_L3_PF"}, + {HR_FLOAT, 40226, 0, "MainCB_L3_max_kW"}, + {HR_FLOAT, 40228, 0, "MainCB_L3_max_current"}, + +}; +//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 diff --git a/src/EPMS/RPP/RPP_Cortex_TCP/main.cpp b/src/EPMS/RPP/RPP_Cortex_TCP/main.cpp new file mode 100644 index 0000000..286a98c --- /dev/null +++ b/src/EPMS/RPP/RPP_Cortex_TCP/main.cpp @@ -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 +#include "config.h" +#include "ModbusPoints/Modbus_PointFactory.h" +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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* 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); + } +} From c075b2c0ea526f2eee8936c388a984244bba5cb2 Mon Sep 17 00:00:00 2001 From: DohnJev18 Date: Thu, 12 Feb 2026 11:54:36 -0600 Subject: [PATCH 15/16] upload upload --- platformio.ini | 4 ++-- src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index 8a950e5..d1e4db7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,10 +9,10 @@ [platformio] -default_envs = RPP_Cortex_TCP ; Select here the name of the configuration you want to download +default_envs = CDU_CoolIT_Oracle_TCP ; Select here the name of the configuration you want to download [env] -upload_port = COM19 +upload_port = COM3 [common_env_options] framework = arduino diff --git a/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h index 9112a8c..fbd0547 100644 --- a/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h +++ b/src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h @@ -23,7 +23,7 @@ #include const char *ssid = "Oracle_SA"; /**< @brief The SSID of the WiFi network. */ const char *password = "Prime!123"; /**< @brief The password for the WiFi network. */ - IPAddress local_IP(172, 17, 38, 22); /**< @brief The static IP address for the device. */ + IPAddress local_IP(172, 17, 38, 23); /**< @brief The static IP address for the device. */ IPAddress gateway(172, 17, 38, 1); /**< @brief The gateway IP address. */ IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ From e1d43e9de8cfce7cf43f05bd59ce665dc3abf6ee Mon Sep 17 00:00:00 2001 From: DohnJev18 Date: Mon, 16 Feb 2026 16:03:09 -0600 Subject: [PATCH 16/16] changes changes --- platformio.ini | 2 +- src/EPMS/RPP/RPP_Cortex_TCP/config.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index d1e4db7..e7b43cc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ [platformio] -default_envs = CDU_CoolIT_Oracle_TCP ; Select here the name of the configuration you want to download +default_envs = RPP_Cortex_TCP ; Select here the name of the configuration you want to download [env] upload_port = COM3 diff --git a/src/EPMS/RPP/RPP_Cortex_TCP/config.h b/src/EPMS/RPP/RPP_Cortex_TCP/config.h index a1de0d7..ac5d0bf 100644 --- a/src/EPMS/RPP/RPP_Cortex_TCP/config.h +++ b/src/EPMS/RPP/RPP_Cortex_TCP/config.h @@ -23,7 +23,7 @@ #include const char *ssid = "Oracle_SA"; /**< @brief The SSID of the WiFi network. */ const char *password = "Prime!123"; /**< @brief The password for the WiFi network. */ - IPAddress local_IP(172, 17, 38, 72); /**< @brief The static IP address for the device. */ + IPAddress local_IP(172, 17, 38, 51); /**< @brief The static IP address for the device. */ IPAddress gateway(172, 17, 38, 1); /**< @brief The gateway IP address. */ IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */