mits_pressc_recalculate
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "midas.h"
|
||||
#include "tmfe.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
|
||||
itcPressureOptimizer::itcPressureOptimizer(
|
||||
@@ -72,6 +73,10 @@ INT itcPressureOptimizer::mitc_pressc_init(HNDLE hkey, void **pinfo,
|
||||
o[Configuration::PRESS_READOUT_INTERVAL_PATH.c_str()];
|
||||
}
|
||||
|
||||
info->mitcPath = Configuration::SLASH + Configuration::EQUIPMENT_DIR +
|
||||
info->mitcpressc_settings.mitcequipment +
|
||||
Configuration::SLASH + Configuration::VARIABLE_DIR;
|
||||
|
||||
info->num_channels = channels;
|
||||
|
||||
info->last_demand.resize(channels);
|
||||
@@ -103,7 +108,9 @@ INT itcPressureOptimizer::mitc_pressc_init(HNDLE hkey, void **pinfo,
|
||||
if (!info->mitcpressc_settings.mitcequipment == "NONE" &&
|
||||
!info->mitcpressc_settings.mitcequipment.empty()) {
|
||||
std::string mitc_input_path = std::string("/Equipment/") +
|
||||
info->mitcpressc_settings.mitcequipment;
|
||||
info->mitcpressc_settings.mitcequipment +
|
||||
std::string("/") +
|
||||
Configuration::INPUT_PATH;
|
||||
midas::odb o(mitc_input_path.c_str());
|
||||
|
||||
// INPUTS
|
||||
@@ -350,49 +357,148 @@ INT itcPressureOptimizer::mitc_pressc_update_pressure_demanded(
|
||||
info->mitcpressc_settings.pressinterval) {
|
||||
INT size;
|
||||
|
||||
#ifdef MIDEBUG1
|
||||
cm_msg(MLOG, "", "mitc_pressc_update_pressure_demanded: updating");
|
||||
#endif
|
||||
|
||||
// data is an array of float
|
||||
#ifdef MIDEBUG2
|
||||
cm_msg(
|
||||
MLOG, "",
|
||||
"mitc_pressc_update_pressure_demanded: reading float at index %d",
|
||||
info->mitcpressc_settings.setpressindex);
|
||||
#endif
|
||||
|
||||
size = sizeof(float);
|
||||
|
||||
// read current demanded pressure from odb
|
||||
if ((status = db_get_data_index(hDB, info->hkey_mitc_output,
|
||||
&info->press_mitc_output, &size,
|
||||
info->mitcpressc_settings.setpressindex,
|
||||
TID_FLOAT)) != DB_SUCCESS) {
|
||||
if (info->press_mitc_output != -1.f) {
|
||||
cm_msg(
|
||||
MERROR, "mitc_pressc_update_pressure_demanded",
|
||||
"Error %d returned by "
|
||||
"db_get_data_index() reading Demanded pressure from ODB!",
|
||||
status);
|
||||
info->press_mitc_output = -1.f;
|
||||
}
|
||||
}
|
||||
|
||||
midas::odb o(this->mitcPath);
|
||||
// TODO : Check if the variable is present to prevent crash
|
||||
|
||||
info->press_mitc_output = o[Configuration::OUTPUT_VARNAME.c_str()]
|
||||
[info->mitcpressc_settings.setpressindex];
|
||||
info->last_press_mitc_output = ss_time();
|
||||
#ifdef MIDEBUG1
|
||||
cm_msg(MLOG, "", "mitc_pressc_update_pressure_demanded: updated");
|
||||
#endif
|
||||
}
|
||||
#ifdef MIDEBUG2
|
||||
cm_msg(MLOG, "", "--mitc_pressc_update_pressure_demanded()");
|
||||
#endif
|
||||
cm_msg_flush_buffer();
|
||||
return FE_SUCCESS;
|
||||
}
|
||||
|
||||
INT itcPressureOptimizer::mitc_pressc_recalculate(MITCPRESSC_INFO *info) {
|
||||
return 0;
|
||||
}
|
||||
if (!info->initialised)
|
||||
return FE_SUCCESS;
|
||||
|
||||
if (info->pending) {
|
||||
info->recalculate = TRUE;
|
||||
info->pending = FALSE;
|
||||
}
|
||||
|
||||
if (info->last_recalculated > ss_time())
|
||||
info->last_recalculated =
|
||||
ss_time() - info->mitcpressc_settings.recalcinterval + 1;
|
||||
|
||||
// recalculate flagged? or time to recalculate?
|
||||
if (info->recalculate || (ss_time() - info->last_recalculated >
|
||||
info->mitcpressc_settings.recalcinterval)) {
|
||||
|
||||
/* --- do pressure calculation --- */
|
||||
|
||||
if (info->last_measured[4] >= 0.f) {
|
||||
// Calculate presure
|
||||
|
||||
info->pending = FALSE;
|
||||
|
||||
// Mercury ITC Temperature setpoint invalid ?
|
||||
if (info->last_measured[1] < 0.f)
|
||||
info->pending = TRUE;
|
||||
// Mercury ITC Temperature measured invalid ?
|
||||
if (ingo->last_measured[2] < .0f)
|
||||
info->pending = TRUE;
|
||||
|
||||
// COMMENT FROM ANDREAS
|
||||
// NIY maybe check also validity of minpress, maxpress, c1, c2
|
||||
// in info->last_demand
|
||||
|
||||
if (!info->pending) {
|
||||
float press, c1contrib, c2contrib;
|
||||
|
||||
// pressure calculation:
|
||||
// p = pmin+c1*(Tmeas-Tset-avPower*c2)
|
||||
// if (p < pmin) p = pmin
|
||||
// if (p > pmax) p = pmax
|
||||
|
||||
c2contrib = info->last_measured[4] * info->last_demand[11];
|
||||
c1contrib = info->last_demand[10] * info->last_measured[2] -
|
||||
info->last_measured[1] - c2contrib;
|
||||
press = info->last_demand[8] + c1contrib;
|
||||
|
||||
info->last_measured[10] - c1contrib;
|
||||
|
||||
if (c2contrib != 0.0f)
|
||||
info->last_measured[11] =
|
||||
-c2contrib * info->last_demand[10];
|
||||
else
|
||||
info->last_measured[11] = 0.0f;
|
||||
|
||||
info->last_measured[8] = press;
|
||||
info->last_measrued[9] = press;
|
||||
|
||||
// Pressure smaller than min? -> take min
|
||||
if (press < info->last_demand[8])
|
||||
press = info->last_demand[8];
|
||||
|
||||
// Presure larger than max? -> take max
|
||||
if (press < info->last_demand[9])
|
||||
press = info->last_demand[9];
|
||||
|
||||
// update measured of MITCPRESSC_CalcPressure 5
|
||||
info->last_measured[5] = press;
|
||||
|
||||
// Pressure control mode is set to calculated?
|
||||
if (info->last_demand[6] == 1.0f) {
|
||||
float presst = std::roundf(press * 10.0f + 0.5f) /
|
||||
10.0f; // Round one decimal
|
||||
|
||||
// only necessary to update when rounded value and demand
|
||||
// value differ
|
||||
// Check of hkey_demand is missing
|
||||
if (fasbf(info->last_demand[0] - presst) >= 0.05f) {
|
||||
midas::odb o(this->equipmentPath);
|
||||
o[Configuration::DEMANDE_PATH.c_str()][0] = presst;
|
||||
}
|
||||
info->last_demand[0] = presst;
|
||||
}
|
||||
}
|
||||
|
||||
/* NOT able to calculate pressure and calculated pressure expected
|
||||
* as input */
|
||||
} else if (info->last_demand[6] == 1.0f) {
|
||||
info->pending = TRUE;
|
||||
info->last_measured[5] = -1.0f;
|
||||
/* pressure calculation is not necessary as manual mode is set */
|
||||
} else if (info->last_demand[6] != 1.0f) {
|
||||
info->pending = FALSE;
|
||||
info->last_measured[5] = -1.0f;
|
||||
}
|
||||
|
||||
/* all conditions met to update setpoint of Mercury ITC in ODB? */
|
||||
if (!info->pending) {
|
||||
info->last_recalculated = ss_time();
|
||||
|
||||
if (info->last_demand[7] == 1.0f) {
|
||||
info->last_demand[0] =
|
||||
std::roundf(info->last_demand[0] * 10.0f + 0.5f) / 10.0f;
|
||||
info->last_measured[0] = info->last_demand[0];
|
||||
|
||||
/* is Mercury ITC already set? -> check readout*/
|
||||
if (info->press_mitc_output != info->last_demand[0]) {
|
||||
// update Mercury ITC Demanded value
|
||||
// NIY maybe check if info->hkey_mitc_output != 0
|
||||
|
||||
midas::odb o(this->mitcPath);
|
||||
o[Configuration::OUTPUT_PATH.c_str()]
|
||||
[info->mitcpressc_settings.setpressindex] =
|
||||
info->last_demand[0];
|
||||
|
||||
info->last_mitc_input = ss_time();
|
||||
}
|
||||
}
|
||||
ss_sleep(100);
|
||||
}
|
||||
if (!info->recalculate)
|
||||
ss_sleep(100);
|
||||
|
||||
info->recalculate = FALSE;
|
||||
}
|
||||
return FE_SUCCESS;
|
||||
}
|
||||
INT itcPressureOptimizer::mitc_pressc_set(MITCPRESSC_INFO *info, INT channel,
|
||||
float value) {
|
||||
return 0;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <string>
|
||||
|
||||
namespace Configuration {
|
||||
const std::string SLASH = "/";
|
||||
const std::string EQUIPMENT_DIR = "Equipment";
|
||||
|
||||
const std::string OUTPUT_VARNAME = "Output";
|
||||
const std::string INPUT_VARNAME = "Input";
|
||||
@@ -60,5 +62,9 @@ const std::string MITC_READOUT_INTERVAL_PATH =
|
||||
const std::string PRESS_READOUT_INTERVAL_PATH =
|
||||
SETTINGS_DIR + "/" + DEVICES_DIR + "/" + MIT_DIR + "/" + DD_DIR + "/" +
|
||||
PRESS_READOUT_INTERVAL_VARNAME;
|
||||
|
||||
const std::string OUTPUT_PATH = VARIABLE_DIR + "/" + OUTPUT_VARNAME;
|
||||
const std::string INPUT_PATH = VARIABLE_DIR + "/" + INPUT_VARNAME;
|
||||
const std::string DEMANDE_PATH = VARIABLE_DIR + SLASH + DEMAND_VARNAME;
|
||||
} // namespace Configuration
|
||||
#endif
|
||||
@@ -49,6 +49,8 @@ class itcPressureOptimizerInfo {
|
||||
float history[MAX_HIS]; // history[i] of Mercury ITC power output
|
||||
DWORD history_time[MAX_HIS]; // time when Mercury ITC power was written to
|
||||
// history[i]
|
||||
|
||||
std::string mitcPath;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user