Merge pull request #35 from emmanuelsrlok/rdavis/PHX3_VFD_ABB_ACH580_RTU
Rdavis/phx3 vfd abb ach580 rtu
This commit is contained in:
@@ -43,7 +43,7 @@ float SingleValueStrategy::execute(float currentValue) {
|
||||
}
|
||||
int noiseInt = rand() % 201;
|
||||
noiseInt -= 100;
|
||||
float noise = (static_cast<float>(noiseInt) / 100) * _noiseMagnitude;
|
||||
float noise = (static_cast<float>(noiseInt) / 100.0f) * _noiseMagnitude;
|
||||
Serial.printf("Single value strategy with noise. %f \n", noise);
|
||||
return _setpoint + noise;
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
[platformio]
|
||||
|
||||
|
||||
default_envs = PDU_Maverick_Power_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 = COM50
|
||||
@@ -200,3 +200,9 @@ platform = espressif32
|
||||
board = dfrobot_firebeetle2_esp32e
|
||||
extends = common_env_options
|
||||
build_src_filter = -<*> +<BMS/CHILLER/CH_York_YVAA_RTU>
|
||||
|
||||
[env:PHX3_VFD_ABB_ACH580_RTU]
|
||||
platform = espressif32
|
||||
board = dfrobot_firebeetle2_esp32e
|
||||
extends = common_env_options
|
||||
build_src_filter = -<*> +<BMS/VFD/PHX3_VFD_ABB_ACH580_RTU>
|
||||
40
src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/README.md
Normal file
40
src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/README.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# VFD ABB ACH580 RTU
|
||||
|
||||
## Brief Introduction
|
||||
This is based on a 50hp motor, 480V, 65 FLA, 60Hz, 1800 rpm (PHX3 DC1/2)
|
||||
|
||||
## List of Equipment
|
||||
This configuration has been used for these models:
|
||||
* **ACH580**: 10-23-2025
|
||||
* **Model**: 09-15-23
|
||||
* **Model**: 09-15-25
|
||||
|
||||
## Hardware Prerequisites
|
||||
|
||||
The code is written for an ESP8266/ESP32-style microcontroller with WiFi capabilities and at least one hardware serial port for RS485 communication.
|
||||
|
||||
* **Microcontroller**: [Firebeetle 2 ESP32.](https://www.dfrobot.com/product-2231.html)
|
||||
* **RS485 Transceiver**: [RS485 Shield for Arduino.](https://www.dfrobot.com/product-1024.html)
|
||||
|
||||
---
|
||||
|
||||
## States and Strategies
|
||||
The hardwire IO signals to/from VFD/PLC are Start Cmd, Stop Cmd, Speed Command, Speed Feedback, VFD Run Status, VFD Fault.
|
||||
User needs to set the speed command (HR 150) in RPM from the PLC
|
||||
User needs to set the Start command (HR 151) from the PLC
|
||||
It appears these registers were arbitrarily chosen for the purpose of this Arduino simulation.
|
||||
The registers selected are based on FS Config file from CDR project.
|
||||
Currently there is no connection on Speed Feedback, Run Status, or Fault from Arduino to PICS
|
||||
|
||||
### Standby State
|
||||
* **Equipment**: Equipment parameters go back to 0
|
||||
|
||||
### Running State
|
||||
* **Ramp Strategy**: The following regisers will dynamically ramp based upon the Speed Cmd:
|
||||
* Motor Speed Used, Motor Speed estimated, Output Frequency, Motor Current, Motor Torque, DC Voltage, Output Voltage, Output Power
|
||||
* The logic is based on Affinity laws and nominal motor values stated in the Introduction section.
|
||||
* **Square Strategy**: Inverter Temperature switches between 40 and 80 based on inherited code.
|
||||
* **Totalizers Strategy**: Inverter kWh cnt, Hours Run
|
||||
|
||||
### Fail State
|
||||
* Not used
|
||||
77
src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Fail.cpp
Normal file
77
src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Fail.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @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 "States/State_Standby.h"
|
||||
#include "States/State_Fail.h"
|
||||
#include "ModbusPoints/Modbus_Point.h"
|
||||
#include "Equipment/Equipment.h"
|
||||
#include "Strategies/Strategy_SingleValue.h"
|
||||
#include "Strategies/Strategy_PID.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#if defined(USE_MODBUS_IP)
|
||||
#include <ModbusIP_ESP8266.h>
|
||||
#else
|
||||
#include <ModbusRTU.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Constructs a new FailState object.
|
||||
*
|
||||
* This constructor receives a list of alarm descriptions and creates strategies
|
||||
* to set the corresponding Modbus points to a value of 1, indicating an
|
||||
* active alarm. It also initializes a PID strategy for the valve position.
|
||||
*/
|
||||
template<>
|
||||
FailState<ModbusRTU>::FailState(const std::vector<std::string>& 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 "Clear Alm" 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.
|
||||
*
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
|
||||
*/
|
||||
template<>
|
||||
State<ModbusRTU>* FailState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
|
||||
// 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 main alarm bit.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void FailState<ModbusRTU>::enterState(Equipment<ModbusRTU>* equipment) {
|
||||
// Logic to run when the equipment enters this state
|
||||
Serial.println("Enter Fail State...");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic to execute once when exiting the fail state. Clears the main alarm bit.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void FailState<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
|
||||
// Cleanup logic to run when the equipment leaves this state
|
||||
Serial.println("Exit Fail State...");
|
||||
|
||||
}
|
||||
163
src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Running.cpp
Normal file
163
src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Running.cpp
Normal file
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* @file State_Running.cpp
|
||||
* @brief Implementation of the RunningState class.
|
||||
* @author Emmanuel Hernandez Cruz, Robert J Davis
|
||||
* @date 2025-10-22
|
||||
*
|
||||
* This file contains the implementation for the RunningState, which defines
|
||||
* the behavior of the equipment when it is actively running.
|
||||
*/
|
||||
|
||||
#include "States/State_Standby.h"
|
||||
#include "States/State_Running.h"
|
||||
#include "States/State_Fail.h"
|
||||
#include "Strategies/Strategy_Behavior.h"
|
||||
#include "Strategies/Strategy_PID.h"
|
||||
#include "Strategies/Strategy_Ramp.h"
|
||||
#include "Strategies/Strategy_Totalizer.h"
|
||||
#include "Strategies/Strategy_Random.h"
|
||||
#include "Strategies/Strategy_SingleValue.h"
|
||||
#include "Strategies/Strategy_Saw.h"
|
||||
#include "Strategies/Strategy_Square.h"
|
||||
#include "Equipment/Equipment.h"
|
||||
#include "ModbusPoints/Modbus_Point.h"
|
||||
#include "ModbusPoints/Modbus_FloatDecorator.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#if defined(USE_MODBUS_IP)
|
||||
#include <ModbusIP_ESP8266.h>
|
||||
#else
|
||||
#include <ModbusRTU.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Constructs a new RunningState object.
|
||||
*
|
||||
* This constructor initializes behavior strategies active during the running
|
||||
* state, such as a PID controller for the 'CW Valve Position' and totalizers
|
||||
* for the run-hours of each EC fan.
|
||||
*/
|
||||
template<>
|
||||
RunningState<ModbusRTU>::RunningState() {
|
||||
addStrategy("Motor Speed Used", 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));
|
||||
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
|
||||
// STATE control, add conditions if change to a different state is needed
|
||||
Serial.println("Running update function");
|
||||
|
||||
float speed_pct = getPointValue(equipment, "Speed Cmd") / 1800.0f;
|
||||
// Based on Affinity Laws. Motor: 65 FLA, 480V, 60Hz, 1800 rpm, 50hp
|
||||
float voltage_update = speed_pct * 480;
|
||||
float dc_voltage_update = speed_pct * 678;
|
||||
float current_update = speed_pct * speed_pct * 65;
|
||||
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
|
||||
|
||||
int VFD_Start_Stop = getPointValue(equipment, "Start/Stop");
|
||||
if (VFD_Start_Stop == 0){
|
||||
return new StandbyState<ModbusRTU>();
|
||||
}
|
||||
|
||||
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<RampStrategy*>(motorSpeedUsed)->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<RampStrategy*>(motorSpeedEst)->setTarget(rpm_est);
|
||||
}
|
||||
|
||||
Strategy_Behavior* frequencystrategy = getStrategy("Output Frequency");
|
||||
if (frequencystrategy) {
|
||||
static_cast<RampStrategy*>(frequencystrategy)->setTarget(freq_update);
|
||||
}
|
||||
|
||||
Strategy_Behavior* currentstrategy = getStrategy("Motor Current");
|
||||
if (currentstrategy) {
|
||||
static_cast<RampStrategy*>(currentstrategy)->setTarget(current_update);
|
||||
}
|
||||
|
||||
Strategy_Behavior* torquestrategy = getStrategy("Motor Torque");
|
||||
if (torquestrategy) {
|
||||
static_cast<RampStrategy*>(torquestrategy)->setTarget(torque_update);
|
||||
}
|
||||
|
||||
Strategy_Behavior* dcvoltagestrategy = getStrategy("DC Voltage");
|
||||
if (dcvoltagestrategy) {
|
||||
static_cast<RampStrategy*>(dcvoltagestrategy)->setTarget(dc_voltage_update);
|
||||
}
|
||||
|
||||
Strategy_Behavior* voltagestrategy = getStrategy("Output Voltage");
|
||||
if (voltagestrategy) {
|
||||
static_cast<RampStrategy*>(voltagestrategy)->setTarget(voltage_update);
|
||||
}
|
||||
|
||||
Strategy_Behavior* powerstrategy = getStrategy("Output Power");
|
||||
if (powerstrategy) {
|
||||
static_cast<RampStrategy*>(powerstrategy)->setTarget(power_update);
|
||||
}
|
||||
|
||||
// Apply any strategies defined for the standby state
|
||||
_applyStrategies(equipment);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic to execute once when entering the running state.
|
||||
* Sets the "Chiller Sts" point to indicate the unit is running.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void RunningState<ModbusRTU>::enterState(Equipment<ModbusRTU>* equipment) {
|
||||
// Logic to run when the equipment enters this state
|
||||
Serial.println("Enter Running State...");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic to execute once when exiting the running state.
|
||||
* Sets the "Chiller Sts" point to indicate the unit is no longer running.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void RunningState<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
|
||||
// Cleanup logic to run when the equipment leaves this state
|
||||
Serial.println("Exit Running State...");
|
||||
setPointValue(equipment, "Output Frequency", 0.0f);
|
||||
}
|
||||
90
src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Standby.cpp
Normal file
90
src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/State_Standby.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* @file State_Standby.cpp
|
||||
* @brief Implementation of the StandbyState class.
|
||||
* @author Emmanuel Hernandez Cruz, Robert J Davis
|
||||
* @date 2025-10-23
|
||||
*
|
||||
* 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 "States/State_Running.h"
|
||||
#include "States/State_Fail.h"
|
||||
#include "ModbusPoints/Modbus_Point.h"
|
||||
#include "ModbusPoints/Modbus_FloatDecorator.h"
|
||||
#include "Equipment/Equipment.h"
|
||||
#include "Strategies/Strategy_Ramp.h"
|
||||
#include "Strategies/Strategy_SingleValue.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#if defined(USE_MODBUS_IP)
|
||||
#include <ModbusIP_ESP8266.h>
|
||||
#else
|
||||
#include <ModbusRTU.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Constructs a new StandbyState object.
|
||||
*
|
||||
* In this state, the equipment is idle. This constructor initializes several
|
||||
* strategies to generate random values for various status points, simulating
|
||||
* a live but non-operational unit.
|
||||
*/
|
||||
template<>
|
||||
StandbyState<ModbusRTU>::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 Speed Used", 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 ));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Executes the standby state's logic for one update cycle.
|
||||
*
|
||||
* This method checks the "Chiller On-Off" Modbus point for a command to
|
||||
* transition to the Running state. If no transition is requested, it applies
|
||||
* the strategies defined for the standby state.
|
||||
*
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
|
||||
*/
|
||||
template<>
|
||||
State<ModbusRTU>* StandbyState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
|
||||
// STATE control, add conditions if change to a different state is needed
|
||||
Serial.println("Standby update function");
|
||||
int VFD_Start_Stop = getPointValue(equipment, "Start/Stop");
|
||||
if (VFD_Start_Stop == 1){
|
||||
return new RunningState<ModbusRTU>();
|
||||
}
|
||||
// Apply any strategies defined for the standby state
|
||||
_applyStrategies(equipment);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic to execute once when entering the standby state.
|
||||
* Sets the "Chiller Sts" point to indicate the unit is not running.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void StandbyState<ModbusRTU>::enterState(Equipment<ModbusRTU>* equipment) {
|
||||
// Logic to run when the equipment enters this state
|
||||
Serial.println("Enter Standby State...");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic to execute once when exiting the standby state.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void StandbyState<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
|
||||
// Cleanup logic to run when the equipment leaves this state
|
||||
|
||||
}
|
||||
100
src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h
Normal file
100
src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/config.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* @file config.h
|
||||
* @brief Main configuration file for the ABB ACH580 (VFD) emulator.
|
||||
* @author Emmanuel Hernandez Cruz, Robert J Davis
|
||||
* @date 2025-10-22
|
||||
*
|
||||
* This file contains important configurations for the Modbus RTU communication
|
||||
* and the specific register map for the emulated device.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
#include <ModbusRTU.h>
|
||||
#include "core.h"
|
||||
#include "Equipment/Equipment.h"
|
||||
|
||||
|
||||
#if defined(USE_MODBUS_IP)
|
||||
/**
|
||||
* @defgroup ModbusTCPConfig Modbus IP Configuration
|
||||
* @brief Parameters for Modbus TCP communication.
|
||||
* @{
|
||||
*/
|
||||
#include <ModbusIP_ESP8266.h>
|
||||
const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */
|
||||
const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */
|
||||
IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */
|
||||
IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */
|
||||
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
|
||||
|
||||
ModbusIP mb;
|
||||
#else
|
||||
/**
|
||||
* @defgroup ModbusRTUConfig Modbus RTU Configuration
|
||||
* @brief Parameters for serial Modbus RTU communication.
|
||||
* @{
|
||||
*/
|
||||
#include <ModbusRTU.h>
|
||||
const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */
|
||||
const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */
|
||||
const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */
|
||||
const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */
|
||||
const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */
|
||||
/** @} */
|
||||
|
||||
/** @brief Global instance of the Modbus RTU server. */
|
||||
ModbusRTU mb;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief The Modbus map for the Equipment device.
|
||||
* This array defines all the Modbus points available on the emulated device.
|
||||
* The `description` field is crucial as it's used to look up points within the application logic.
|
||||
*/
|
||||
modbusMap mb_map[] =
|
||||
{
|
||||
{HR, 149, 0, "Speed Cmd"}, // expecting rpm (1800 rpm max)
|
||||
{HR, 151, 0, "Start/Stop"},
|
||||
{HR, 152, 0, "HOA Command"},
|
||||
{HR, 100, 0, "Motor Speed Used"}, // RJD: 1800 rpm max
|
||||
{HR, 101, 0, "Motor Speed estimated"}, // RJD: 1800 rpm max
|
||||
{HR_10x, 105, 0, "Output Frequency"}, // 60 Hz @100% speed
|
||||
{HR, 106, 0, "Motor Current"}, // RJD: Changed from HR_10x to HR, 65 FLA
|
||||
{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"}, // RJD: 480 VAC
|
||||
{HR, 113, 0, "Output Power"}, //max 372580 // RJD: Changed from HR_10x to HR, 50 hp ~ 36.77 kW
|
||||
{HR_10x, 119, 0, "Inverter kWh cnt"},
|
||||
|
||||
{HR, 502, 0, "Hours Run"},
|
||||
{HR, 510, 0, "Inverter Temperature"}, // RJD: Changed from HR_10x to HR, % of fault limit
|
||||
{HR, 521, 0, "HOA Status Word"},
|
||||
|
||||
{HR, 410, 0, "Last Fault"},
|
||||
{HR, 411, 0, "2nd to last Fault"},
|
||||
{HR, 412, 0, "3rd to last Fault"},
|
||||
{HR, 439, 0, "Event Word Param"},
|
||||
|
||||
{HR, 610, 0, "Status Word 1"},
|
||||
{HR, 615, 0, "Status Word 2"},
|
||||
{HR, 616, 0, "Status Word 3"},
|
||||
{HR, 617, 0, "Status Word 4"},
|
||||
{HR, 618, 0, "Status Word 5"},
|
||||
{HR, 619, 0, "Status Word 6"},
|
||||
{HR, 620, 0, "Status Word 7"},
|
||||
{HR, 621, 0, "Status Word 8"},
|
||||
};
|
||||
//Size of modbus map used in FOR cycles, automatically calculated.
|
||||
/**
|
||||
* @brief The total number of entries in the `mb_map` array.
|
||||
* This is calculated at compile time and used for iterating over the map.
|
||||
*/
|
||||
const int map_size = sizeof(mb_map) / sizeof(mb_map[0]);
|
||||
|
||||
/**
|
||||
* @brief The main loop update interval in milliseconds.
|
||||
*/
|
||||
int interval = 250;
|
||||
|
||||
#endif // CONFIG_H
|
||||
78
src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/main.cpp
Normal file
78
src/BMS/VFD/PHX3_VFD_ABB_ACH580_RTU/main.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main execution program for the Daikin Chiller (RTU) Emulator.
|
||||
* @author Emmanuel Hernandez Cruz
|
||||
* @date 2025-09-02
|
||||
*
|
||||
* @details This file contains the main execution program for an Arduino-based
|
||||
* emulator of a Daikin Chiller unit. The program communicates via the
|
||||
* Modbus RTU protocol over a serial connection.
|
||||
*
|
||||
* The setup() function initializes the following:
|
||||
* - Serial communication for debugging.
|
||||
* - A Modbus RTU server with parameters from config.h.
|
||||
* - Modbus points (Coils, Holding Registers, etc.) based on a predefined map in config.h.
|
||||
*
|
||||
* The loop() function continuously:
|
||||
* - Services the Modbus RTU server to handle incoming requests.
|
||||
* - Periodically calls the main update loop for the emulated equipment, which
|
||||
* manages state transitions and behavior strategies.
|
||||
*
|
||||
* @see config.h for Modbus RTU and register map configuration.
|
||||
* @see Equipment.h for the main equipment logic.
|
||||
* @see State.h for different equipment states.
|
||||
* @see Strategies/Strategy_Behavior.h for value generation strategies.
|
||||
* @see Modbus_Point.h for the base class for all Modbus points.
|
||||
*/
|
||||
//=================================================================================================================================
|
||||
//Libraries and declaration of variables.
|
||||
#include <Arduino.h>
|
||||
#include "config.h"
|
||||
#include "ModbusPoints/Modbus_PointFactory.h"
|
||||
|
||||
//=================================================================================================================================
|
||||
/**
|
||||
* @brief Initializes the application.
|
||||
* @details This function runs once at startup. It configures the serial communication
|
||||
* for debugging and the Modbus RTU server. It then creates and initializes all
|
||||
* the Modbus points based on the `mb_map` array in `config.h`.
|
||||
*/
|
||||
const int rtsPin = 4;
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Setup function started");
|
||||
|
||||
Serial2.begin(BAUDRATE, SERIAL_8N1, RX_PIN, TX_PIN);
|
||||
mb.begin(&Serial2, RST_PIN); // Start the server
|
||||
mb.slave(MODBUS_ID); // Set the slave ID
|
||||
|
||||
for(int i = 0; i < map_size; i++){
|
||||
Modbus_Point<ModbusRTU>* point = createModbus_Point(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
|
||||
if (point) {
|
||||
point->addToModbusServer();
|
||||
EquipmentInstance.addModbus_Point(mb_map[i].description, point);
|
||||
}
|
||||
}
|
||||
Serial.println("Setup function ended");
|
||||
}
|
||||
//=================================================================================================================================
|
||||
/**
|
||||
* @brief The main application loop.
|
||||
* @details This function runs repeatedly after setup() has completed. It performs two main actions:
|
||||
* 1. It continuously services the Modbus server by calling `mb.task()` to handle
|
||||
* incoming requests from a Modbus master.
|
||||
* 2. At a fixed interval (defined in `config.h`), it calls `EquipmentInstance.update()`
|
||||
* to run the emulator's internal state machine and behavior logic.
|
||||
*/
|
||||
void loop() {
|
||||
mb.task();
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - previousMillis >= interval) {
|
||||
previousMillis = currentMillis;
|
||||
unsigned long startTime = millis();
|
||||
EquipmentInstance.update();
|
||||
unsigned long endTime = millis();
|
||||
unsigned long elapsedTime = endTime - startTime;
|
||||
Serial.printf("Control Execution time: %d ms\n", elapsedTime);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* @file State_Running.cpp
|
||||
* @brief Implementation of the RunningState class.
|
||||
* @author Emmanuel Hernandez Cruz
|
||||
* @date 2025-09-05
|
||||
* @author Emmanuel Hernandez Cruz, Robert J Davis
|
||||
* @date 2025-10-22
|
||||
*
|
||||
* This file contains the implementation for the RunningState, which defines
|
||||
* the behavior of the equipment when it is actively running.
|
||||
@@ -41,8 +41,11 @@
|
||||
*/
|
||||
template<>
|
||||
RunningState<ModbusRTU>::RunningState() {
|
||||
|
||||
addStrategy("Inverter Temperature", new SquareStrategy(40.0f, 80.0f,1000));
|
||||
addStrategy("Inverter Temperature", new SquareStrategy(40.0f, 80.0f, 1000));
|
||||
addStrategy("Motor Speed Used", new RampStrategy(100.0f, 10.0f, 1000));
|
||||
addStrategy("Motor Speed Estimated", new RampStrategy(80.0f, 10.0f, 1000));
|
||||
addStrategy("Motor Current", new RampStrategy(65.0f, 2.0f, 1000));
|
||||
addStrategy("Motor Torque", new RampStrategy(200.0f, 10.0f, 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user