ATS logic added
This commit is contained in:
@@ -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<float>(noiseInt) / 100) * _noiseMagnitude;
|
||||
Serial.printf("Single value strategy with noise. %f \n", noise);
|
||||
return _setpoint + noise;
|
||||
}
|
||||
@@ -11,9 +11,6 @@
|
||||
[platformio]
|
||||
default_envs = ATS_800_RPD ; Select here the name of the configuration you want to download
|
||||
|
||||
[env]
|
||||
upload_port = COM100
|
||||
|
||||
[common_env_options]
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
|
||||
@@ -38,6 +38,22 @@
|
||||
*/
|
||||
template<>
|
||||
RunningState<ModbusIP>::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<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
|
||||
// STATE control, add conditions if change to a different state is needed
|
||||
Serial.println("Running update function");
|
||||
|
||||
float State_Ctrl = getPointValue(equipment, "ATS_Source");
|
||||
if (State_Ctrl == 1){
|
||||
return new StandbyState<ModbusIP>();
|
||||
}
|
||||
|
||||
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<SingleValueStrategy*>(svs_Amps_A)->setSetpoint(load*7500);
|
||||
static_cast<SingleValueStrategy*>(svs_Amps_B)->setSetpoint(load*7500);
|
||||
static_cast<SingleValueStrategy*>(svs_Amps_C)->setSetpoint(load*7500);
|
||||
|
||||
// Apply any strategies defined for the standby state
|
||||
_applyStrategies(equipment);
|
||||
return nullptr;
|
||||
@@ -73,7 +102,15 @@ void RunningState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
|
||||
// Logic to run when the equipment enters this state
|
||||
Serial.println("Enter Running State...");
|
||||
// You could also update a Modbus register to show the "standby" state
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,8 +38,20 @@
|
||||
template<>
|
||||
StandbyState<ModbusIP>::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<ModbusIP>* StandbyState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
|
||||
// STATE control, add conditions if change to a different state is needed
|
||||
Serial.println("Standby update function");
|
||||
|
||||
float State_Ctrl = getPointValue(equipment, "ATS_Source");
|
||||
if (State_Ctrl ==2){
|
||||
return new RunningState<ModbusIP>();
|
||||
}
|
||||
|
||||
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<SingleValueStrategy*>(svs_Amps_A)->setSetpoint(load*7500);
|
||||
static_cast<SingleValueStrategy*>(svs_Amps_B)->setSetpoint(load*7500);
|
||||
static_cast<SingleValueStrategy*>(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<ModbusIP>::enterState(Equipment<ModbusIP>* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
* @{
|
||||
*/
|
||||
#include <ModbusIP_ESP8266.h>
|
||||
const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */
|
||||
const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */
|
||||
IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */
|
||||
IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */
|
||||
const char *ssid = "QTS_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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user