diff --git a/lib/Core/Strategies/Strategy_SingleValue.cpp b/lib/Core/Strategies/Strategy_SingleValue.cpp index 7ae4eab..b1402cd 100644 --- a/lib/Core/Strategies/Strategy_SingleValue.cpp +++ b/lib/Core/Strategies/Strategy_SingleValue.cpp @@ -37,14 +37,13 @@ void SingleValueStrategy::setSetpoint(float setpoint) { * @return The setpoint with added random noise. */ float SingleValueStrategy::execute(float currentValue) { - if(_noiseMagnitude <= 0){ - Serial.println("Single value strategy static."); + if(_noiseMagnitude <= 0.0f){ + Serial.printf("Single value strategy static. %f \n", _setpoint); return _setpoint; } - int noiseInt = rand() % 201; noiseInt -= 100; - float noise = (noiseInt / 100) * _noiseMagnitude; - Serial.println("Single value strategy with noise."); + float noise = (static_cast(noiseInt) / 100) * _noiseMagnitude; + Serial.printf("Single value strategy with noise. %f \n", noise); return _setpoint + noise; } \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 2ab396e..f5a6d1c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,10 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = Base_RTU ; Select here the name of the configuration you want to download - -[env] -upload_port = COM100 +default_envs = ATS_800_RPD ; Select here the name of the configuration you want to download [common_env_options] framework = arduino @@ -108,7 +105,6 @@ build_src_filter = -<*> + platform = espressif32 board = dfrobot_firebeetle2_esp32e extends = common_env_options -upload_port = COM100 build_src_filter = -<*> + [env:CRAH_PAHHC_600_C6_TCP] @@ -130,3 +126,10 @@ board = dfrobot_firebeetle2_esp32e extends = common_env_options build_src_filter = -<*> + +[env:ATS_800_RPD] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + + diff --git a/src/EPMS/ATS/ATS_800_RPD/State_Running.cpp b/src/EPMS/ATS/ATS_800_RPD/State_Running.cpp index b9e4a99..e42661a 100644 --- a/src/EPMS/ATS/ATS_800_RPD/State_Running.cpp +++ b/src/EPMS/ATS/ATS_800_RPD/State_Running.cpp @@ -38,6 +38,22 @@ */ template<> RunningState::RunningState() { + + addStrategy("Source 1 Volts AB", new SingleValueStrategy(0.0F, 0.0f, 1000)); + addStrategy("Source 1 Volts BC", new SingleValueStrategy(0.0F, 0.0f, 1000)); + addStrategy("Source 1 Volts AC", new SingleValueStrategy(0.0F, 0.0f, 1000)); + addStrategy("Source 2 Volts AB", new SingleValueStrategy(480.0F, 2.0f, 1000)); + addStrategy("Source 2 Volts BC", new SingleValueStrategy(480.0F, 2.0f, 1000)); + addStrategy("Source 2 Volts AC", new SingleValueStrategy(480.0F, 2.0f, 1000)); + addStrategy("Source 1 Frequency", new SingleValueStrategy(0.0f, 0.0f, 1000)); + addStrategy("Source 2 Frequency", new SingleValueStrategy(60.0f, 1.0f, 1000)); + + addStrategy("Power Factor", new SingleValueStrategy(90.0f, 2.0f, 1000)); + + addStrategy("Amps A", new SingleValueStrategy(1.0f, 5.0f, 1000)); + addStrategy("Amps B", new SingleValueStrategy(1.0f, 5.0f, 1000)); + addStrategy("Amps C", new SingleValueStrategy(1.0f, 5.0f, 1000)); + } /** @@ -57,7 +73,20 @@ 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, "ATS_Source"); + if (State_Ctrl == 1){ + return new StandbyState(); + } + + float load = getPointValue(equipment, "ATS_Load"); + load = load/100; + Strategy_Behavior* svs_Amps_A = getStrategy("Amps A"); + Strategy_Behavior* svs_Amps_B = getStrategy("Amps B"); + Strategy_Behavior* svs_Amps_C = getStrategy("Amps C"); + static_cast(svs_Amps_A)->setSetpoint(load*7500); + static_cast(svs_Amps_B)->setSetpoint(load*7500); + static_cast(svs_Amps_C)->setSetpoint(load*7500); + // Apply any strategies defined for the standby state _applyStrategies(equipment); return nullptr; @@ -73,7 +102,15 @@ 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, "Source 1 Available", 1); + setPointValue(equipment, "Source 2 Available", 0); + setPointValue(equipment, "Source 1 Active", 0); + setPointValue(equipment, "Source 2 Active", 1); + setPointValue(equipment, "Source 1 Preferred", 1); + setPointValue(equipment, "Source 2 Preferred", 0); + int transferQty = getPointValue(equipment, "Number of Transfers"); + setPointValue(equipment, "Number of Transfers", transferQty + 1); } /** diff --git a/src/EPMS/ATS/ATS_800_RPD/State_Standby.cpp b/src/EPMS/ATS/ATS_800_RPD/State_Standby.cpp index 20029d1..0995d17 100644 --- a/src/EPMS/ATS/ATS_800_RPD/State_Standby.cpp +++ b/src/EPMS/ATS/ATS_800_RPD/State_Standby.cpp @@ -38,8 +38,20 @@ template<> StandbyState::StandbyState() { // You can add initialization code here if needed - + addStrategy("Source 1 Volts AB", new SingleValueStrategy(480.0F, 2.0f, 1000)); + addStrategy("Source 1 Volts BC", new SingleValueStrategy(480.0F, 2.0f, 1000)); + addStrategy("Source 1 Volts AC", new SingleValueStrategy(480.0F, 2.0f, 1000)); + addStrategy("Source 2 Volts AB", new SingleValueStrategy(0.0F, 0.0f, 1000)); + addStrategy("Source 2 Volts BC", new SingleValueStrategy(0.0F, 0.0f, 1000)); + addStrategy("Source 2 Volts AC", new SingleValueStrategy(0.0F, 0.0f, 1000)); + addStrategy("Source 1 Frequency", new SingleValueStrategy(60.0f, 1.0f, 1000)); + addStrategy("Source 2 Frequency", new SingleValueStrategy(0.0f, 0.0f, 1000)); + addStrategy("Power Factor", new SingleValueStrategy(90.0f, 2.0f, 1000)); + + addStrategy("Amps A", new SingleValueStrategy(1.0f, 5.0f, 1000)); + addStrategy("Amps B", new SingleValueStrategy(1.0f, 5.0f, 1000)); + addStrategy("Amps C", new SingleValueStrategy(1.0f, 5.0f, 1000)); } /** @@ -56,7 +68,19 @@ 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, "ATS_Source"); + if (State_Ctrl ==2){ + return new RunningState(); + } + + float load = getPointValue(equipment, "ATS_Load"); + load = load/100; + Strategy_Behavior* svs_Amps_A = getStrategy("Amps A"); + Strategy_Behavior* svs_Amps_B = getStrategy("Amps B"); + Strategy_Behavior* svs_Amps_C = getStrategy("Amps C"); + static_cast(svs_Amps_A)->setSetpoint(load*7500); + static_cast(svs_Amps_B)->setSetpoint(load*7500); + static_cast(svs_Amps_C)->setSetpoint(load*7500); // Apply any strategies defined for the standby state _applyStrategies(equipment); return nullptr; @@ -72,6 +96,15 @@ template<> void StandbyState::enterState(Equipment* equipment) { // Logic to run when the equipment enters this state Serial.println("Enter Standby State..."); + setPointValue(equipment, "Source 1 Available", 0); + setPointValue(equipment, "Source 2 Available", 1); + setPointValue(equipment, "Source 1 Active", 1); + setPointValue(equipment, "Source 2 Active", 0); + setPointValue(equipment, "Source 1 Preferred", 0); + setPointValue(equipment, "Source 2 Preferred", 1); + + int transferQty = getPointValue(equipment, "Number of Transfers"); + setPointValue(equipment, "Number of Transfers", transferQty + 1); } /** diff --git a/src/EPMS/ATS/ATS_800_RPD/config.h b/src/EPMS/ATS/ATS_800_RPD/config.h index cb9ec7a..b75f77b 100644 --- a/src/EPMS/ATS/ATS_800_RPD/config.h +++ b/src/EPMS/ATS/ATS_800_RPD/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_CDR_Arduino"; /**< @brief The SSID of the WiFi network. */ + const char *password = "123abc456"; /**< @brief The password for the WiFi network. */ + IPAddress local_IP(172, 17, 30, 241); /**< @brief The static IP address for the device. */ + IPAddress gateway(172, 17, 30, 1); /**< @brief The gateway IP address. */ IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ ModbusIP mb; @@ -60,36 +60,38 @@ */ modbusMap mb_map[] = { - {HR, 15, 0, "State Control"}, //Internal to control from Modscan - {HR, 16, 0, "Fault Code"}, //Internal Fault code from Modscan - {IR, 6298, 0, "Alarm Status Bits"}, - {IR, 6159, 0, "Amps A"}, - {IR, 6160, 0, "Amps B"}, - {IR, 6161, 0, "Amps C"}, - {IR, 6172, 0, "Power Factor (PF)"}, - {IR, 6264, 0, "Number of Transfers"}, - {IR, 6152, 0, "Volts AB"}, - {IR, 6153, 0, "Volts BC"}, - {IR, 6154, 0, "Volts CA"}, - {IR, 6155, 0, "Source 1 Frequency"}, - {IR, 6145, 0, "Source 1 Volts AB"}, - {IR, 6146, 0, "Source 1 Volts BC"}, - {IR, 6147, 0, "Source 1 Volts CA"}, - {IR, 6156, 0, "Source 2 Frequency"}, - {IR, 6148, 0, "Source 2 Volts AB"}, - {IR, 6149, 0, "Source 2 Volts BC"}, - {IR, 6150, 0, "Source 2 Volts CA"}, - {IR_LONG, 6170, 0, "Total Apparent Power (kVA)"}, - {IR_LONG, 6166, 0, "Total Active Power (kW)"}, - {DI, 1014, 0, "Summary Alarm"}, - {DI, 1020, 0, "Transfer Inhibit"}, - {DI, 1002, 0, "Source 1 Active"}, - {DI, 1000, 0, "Source 1 Available"}, - {DI, 1004, 0, "Source 1 Preferred"}, - {DI, 1003, 0, "Source 2 Active"}, - {DI, 1001, 0, "Source 2 Available"}, - {DI, 1005, 0, "Source 2 Preferred"}, - + {HR, 9, 0, "ATS_Source"}, //Internal to control from Modscan + {HR, 10, 0, "ATS_Load"}, //Internal Fault code from Modscan + {HR, 11, 0, "ATS_Input"}, //Internal Fault code from Modscan + {HR, 12, 0, "ATS_Fault"}, //Internal Fault code from Modscan + {DI, 999, 0, "Source 1 Available"}, + {DI, 1000, 0, "Source 2 Available"}, + {DI, 1001, 0, "Source 1 Active"}, + {DI, 1002, 0, "Source 2 Active"}, + {DI, 1003, 0, "Source 1 Preferred"}, + {DI, 1004, 0, "Source 2 Preferred"}, + {DI, 1013, 0, "Summary Alarm"}, + {DI, 1019, 0, "Transfer Inhibit"}, + {IR, 6144, 0, "Source 1 Volts AB"}, + {IR, 6145, 0, "Source 1 Volts BC"}, + {IR, 6146, 0, "Source 1 Volts CA"}, + {IR, 6147, 0, "Source 2 Volts AB"}, + {IR, 6148, 0, "Source 2 Volts BC"}, + {IR, 6149, 0, "Source 2 Volts CA"}, + {IR, 6151, 0, "Volts AB"}, + {IR, 6152, 0, "Volts BC"}, + {IR, 6153, 0, "Volts CA"}, + {IR, 6154, 0, "Source 1 Frequency"}, + {IR, 6155, 0, "Source 2 Frequency"}, + {IR, 6158, 0, "Amps A"}, + {IR, 6159, 0, "Amps B"}, + {IR, 6160, 0, "Amps C"}, + {IR_LONG, 6165, 0, "Total Active Power"}, + {IR_LONG, 6169, 0, "Total Apparent Power"}, + {IR, 6171, 0, "Power Factor"}, + {IR, 6263, 0, "Number of Transfers"}, + {IR, 6297, 0, "Alarm Status Bits"}, + }; //Size of modbus map used in FOR cycles, automatically calculated.