ATS logic added
This commit is contained in:
@@ -37,14 +37,13 @@ void SingleValueStrategy::setSetpoint(float setpoint) {
|
|||||||
* @return The setpoint with added random noise.
|
* @return The setpoint with added random noise.
|
||||||
*/
|
*/
|
||||||
float SingleValueStrategy::execute(float currentValue) {
|
float SingleValueStrategy::execute(float currentValue) {
|
||||||
if(_noiseMagnitude <= 0){
|
if(_noiseMagnitude <= 0.0f){
|
||||||
Serial.println("Single value strategy static.");
|
Serial.printf("Single value strategy static. %f \n", _setpoint);
|
||||||
return _setpoint;
|
return _setpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
int noiseInt = rand() % 201;
|
int noiseInt = rand() % 201;
|
||||||
noiseInt -= 100;
|
noiseInt -= 100;
|
||||||
float noise = (noiseInt / 100) * _noiseMagnitude;
|
float noise = (static_cast<float>(noiseInt) / 100) * _noiseMagnitude;
|
||||||
Serial.println("Single value strategy with noise.");
|
Serial.printf("Single value strategy with noise. %f \n", noise);
|
||||||
return _setpoint + noise;
|
return _setpoint + noise;
|
||||||
}
|
}
|
||||||
@@ -11,9 +11,6 @@
|
|||||||
[platformio]
|
[platformio]
|
||||||
default_envs = ATS_800_RPD ; Select here the name of the configuration you want to download
|
default_envs = ATS_800_RPD ; Select here the name of the configuration you want to download
|
||||||
|
|
||||||
[env]
|
|
||||||
upload_port = COM100
|
|
||||||
|
|
||||||
[common_env_options]
|
[common_env_options]
|
||||||
framework = arduino
|
framework = arduino
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|||||||
@@ -38,6 +38,22 @@
|
|||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
RunningState<ModbusIP>::RunningState() {
|
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,6 +73,19 @@ template<>
|
|||||||
State<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
|
State<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
|
||||||
// STATE control, add conditions if change to a different state is needed
|
// STATE control, add conditions if change to a different state is needed
|
||||||
Serial.println("Running update function");
|
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
|
// Apply any strategies defined for the standby state
|
||||||
_applyStrategies(equipment);
|
_applyStrategies(equipment);
|
||||||
@@ -73,7 +102,15 @@ void RunningState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
|
|||||||
// Logic to run when the equipment enters this state
|
// Logic to run when the equipment enters this state
|
||||||
Serial.println("Enter Running State...");
|
Serial.println("Enter Running State...");
|
||||||
// You could also update a Modbus register to show the "standby" 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<>
|
template<>
|
||||||
StandbyState<ModbusIP>::StandbyState() {
|
StandbyState<ModbusIP>::StandbyState() {
|
||||||
// You can add initialization code here if needed
|
// 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<ModbusIP>* StandbyState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
|
||||||
// STATE control, add conditions if change to a different state is needed
|
// STATE control, add conditions if change to a different state is needed
|
||||||
Serial.println("Standby update function");
|
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
|
// Apply any strategies defined for the standby state
|
||||||
_applyStrategies(equipment);
|
_applyStrategies(equipment);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -72,6 +96,15 @@ template<>
|
|||||||
void StandbyState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
|
void StandbyState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
|
||||||
// Logic to run when the equipment enters this state
|
// Logic to run when the equipment enters this state
|
||||||
Serial.println("Enter Standby 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>
|
#include <ModbusIP_ESP8266.h>
|
||||||
const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */
|
const char *ssid = "QTS_CDR_Arduino"; /**< @brief The SSID of the WiFi network. */
|
||||||
const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */
|
const char *password = "123abc456"; /**< @brief The password for the WiFi network. */
|
||||||
IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */
|
IPAddress local_IP(172, 17, 30, 241); /**< @brief The static IP address for the device. */
|
||||||
IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */
|
IPAddress gateway(172, 17, 30, 1); /**< @brief The gateway IP address. */
|
||||||
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
|
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
|
||||||
|
|
||||||
ModbusIP mb;
|
ModbusIP mb;
|
||||||
@@ -60,35 +60,37 @@
|
|||||||
*/
|
*/
|
||||||
modbusMap mb_map[] =
|
modbusMap mb_map[] =
|
||||||
{
|
{
|
||||||
{HR, 15, 0, "State Control"}, //Internal to control from Modscan
|
{HR, 9, 0, "ATS_Source"}, //Internal to control from Modscan
|
||||||
{HR, 16, 0, "Fault Code"}, //Internal Fault code from Modscan
|
{HR, 10, 0, "ATS_Load"}, //Internal Fault code from Modscan
|
||||||
{IR, 6298, 0, "Alarm Status Bits"},
|
{HR, 11, 0, "ATS_Input"}, //Internal Fault code from Modscan
|
||||||
{IR, 6159, 0, "Amps A"},
|
{HR, 12, 0, "ATS_Fault"}, //Internal Fault code from Modscan
|
||||||
{IR, 6160, 0, "Amps B"},
|
{DI, 999, 0, "Source 1 Available"},
|
||||||
{IR, 6161, 0, "Amps C"},
|
{DI, 1000, 0, "Source 2 Available"},
|
||||||
{IR, 6172, 0, "Power Factor (PF)"},
|
{DI, 1001, 0, "Source 1 Active"},
|
||||||
{IR, 6264, 0, "Number of Transfers"},
|
{DI, 1002, 0, "Source 2 Active"},
|
||||||
{IR, 6152, 0, "Volts AB"},
|
{DI, 1003, 0, "Source 1 Preferred"},
|
||||||
{IR, 6153, 0, "Volts BC"},
|
{DI, 1004, 0, "Source 2 Preferred"},
|
||||||
{IR, 6154, 0, "Volts CA"},
|
{DI, 1013, 0, "Summary Alarm"},
|
||||||
{IR, 6155, 0, "Source 1 Frequency"},
|
{DI, 1019, 0, "Transfer Inhibit"},
|
||||||
{IR, 6145, 0, "Source 1 Volts AB"},
|
{IR, 6144, 0, "Source 1 Volts AB"},
|
||||||
{IR, 6146, 0, "Source 1 Volts BC"},
|
{IR, 6145, 0, "Source 1 Volts BC"},
|
||||||
{IR, 6147, 0, "Source 1 Volts CA"},
|
{IR, 6146, 0, "Source 1 Volts CA"},
|
||||||
{IR, 6156, 0, "Source 2 Frequency"},
|
{IR, 6147, 0, "Source 2 Volts AB"},
|
||||||
{IR, 6148, 0, "Source 2 Volts AB"},
|
{IR, 6148, 0, "Source 2 Volts BC"},
|
||||||
{IR, 6149, 0, "Source 2 Volts BC"},
|
{IR, 6149, 0, "Source 2 Volts CA"},
|
||||||
{IR, 6150, 0, "Source 2 Volts CA"},
|
{IR, 6151, 0, "Volts AB"},
|
||||||
{IR_LONG, 6170, 0, "Total Apparent Power (kVA)"},
|
{IR, 6152, 0, "Volts BC"},
|
||||||
{IR_LONG, 6166, 0, "Total Active Power (kW)"},
|
{IR, 6153, 0, "Volts CA"},
|
||||||
{DI, 1014, 0, "Summary Alarm"},
|
{IR, 6154, 0, "Source 1 Frequency"},
|
||||||
{DI, 1020, 0, "Transfer Inhibit"},
|
{IR, 6155, 0, "Source 2 Frequency"},
|
||||||
{DI, 1002, 0, "Source 1 Active"},
|
{IR, 6158, 0, "Amps A"},
|
||||||
{DI, 1000, 0, "Source 1 Available"},
|
{IR, 6159, 0, "Amps B"},
|
||||||
{DI, 1004, 0, "Source 1 Preferred"},
|
{IR, 6160, 0, "Amps C"},
|
||||||
{DI, 1003, 0, "Source 2 Active"},
|
{IR_LONG, 6165, 0, "Total Active Power"},
|
||||||
{DI, 1001, 0, "Source 2 Available"},
|
{IR_LONG, 6169, 0, "Total Apparent Power"},
|
||||||
{DI, 1005, 0, "Source 2 Preferred"},
|
{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.
|
//Size of modbus map used in FOR cycles, automatically calculated.
|
||||||
|
|||||||
Reference in New Issue
Block a user