Skip to content
Snippets Groups Projects
Commit 83f12f30 authored by Claudio Scafuri's avatar Claudio Scafuri :speech_balloon:
Browse files

added CEV handling - to be tested

parent 9a04c489
No related branches found
No related tags found
No related merge requests found
......@@ -381,8 +381,8 @@ void E2Sextupole::init_device()
try {
std::string meas_strength_file_name = calibrationPath + "/" + cEVCalibrationFileName;
std::string param_file_name = calibrationPath + "/" + parameterFileName;
ceh = new MagnetModel::Corrector();
ceh->init(true,1.0, meas_strength_file_name, param_file_name, cEVName);
cev = new MagnetModel::Corrector();
cev->init(true,1.0, meas_strength_file_name, param_file_name, cEVName);
} catch (std::exception &e) {
std::cerr << "fatalerror "<< e.what() << std::endl;
ERROR_STREAM << "failed to create CEV corrector model " << currentDevice;
......@@ -1307,6 +1307,15 @@ void E2Sextupole::write_CEVStrength(Tango::WAttribute &attr)
/*----- PROTECTED REGION ID(E2Sextupole::write_CEVStrength) ENABLED START -----*/
/* clang-format on */
// Add your own code
omni_mutex_lock guardio(iomutex);
std::vector<double> req_strength;
std::vector<double> curr_out;
req_strength.push_back(w_val);
cev->compute_currents(magnet_rigidity, req_strength, curr_out);
Tango::DeviceAttribute watt("Current",curr_out[0]);
cev_current_dev->write_attribute(watt);
cev_set_strength[0] = w_val;
wValCevCorrStrength = w_val - wValCevResStrength;
/* clang-format off */
/*----- PROTECTED REGION END -----*/ // E2Sextupole::write_CEVStrength
}
......@@ -1387,6 +1396,19 @@ void E2Sextupole::write_CEVResonanceStrength(Tango::WAttribute &attr)
/*----- PROTECTED REGION ID(E2Sextupole::write_CEVResonanceStrength) ENABLED START -----*/
/* clang-format on */
// Add your own code
omni_mutex_lock guardio(iomutex);
Tango::DevDouble newStrength;
newStrength = w_val + wValCevCorrStrength + cev_design_strength;
std::vector<double> req_strength;
std::vector<double> curr_out;
req_strength.push_back(newStrength);
cev->compute_currents(magnet_rigidity, req_strength, curr_out);
Tango::DeviceAttribute watt("Current", curr_out[0]);
cev_current_dev->write_attribute(watt);
wValCevResStrength = w_val;
*attr_CEVResonanceStrength_read = w_val;
cev_set_strength[0] = newStrength;
cevStrengthAtt->set_write_value(ceh_set_strength[0]);
/* clang-format off */
/*----- PROTECTED REGION END -----*/ // E2Sextupole::write_CEVResonanceStrength
}
......@@ -1853,8 +1875,22 @@ void E2Sextupole::update_values_read_ceh(void)
ceh->compute_strengths(magnet_rigidity_inv, read_curr, read_strength);
attr_CEHStrength_read[0] = read_strength[0];
attr_CEHCorrectionStrength_read[0] = attr_CEHStrength_read[0] - ( ceh_design_strength + attr_CEHResonanceStrength_read[0]);
}
void E2Sextupole::update_values_read_cev(void)
{
if (isnan(*attr_CEVCurrent_read)){ //handle error
attr_CEHStrength_read[0] = NAN;
return;
}
INFO_STREAM << "update values read cev";
std::vector<Tango::DevDouble> read_curr;
std::vector<Tango::DevDouble> read_strength;
omni_mutex_lock guardio(iomutex);
read_curr.push_back(*attr_CEVCurrent_read);
cev->compute_strengths(magnet_rigidity_inv, read_curr, read_strength);
attr_CEVStrength_read[0] = read_strength[0];
attr_CEVCorrectionStrength_read[0] = attr_CEVStrength_read[0] - ( cev_design_strength + attr_CEVResonanceStrength_read[0]);
}
//------------------------------------------------------------
// handle change of write set point of power supplies current
......@@ -1889,6 +1925,20 @@ void E2Sextupole::update_values_write_ceh(void)
cehCorrectionAtt->set_write_value(wValCehCorrStrength);
}
// handle change of write set point of cev power supply current
void E2Sextupole::update_values_write_cev(void)
{
INFO_STREAM << "update values write cev";
std::vector<Tango::DevDouble> read_curr;
std::vector<Tango::DevDouble> read_strength;
omni_mutex_lock guardio(iomutex);
read_curr.push_back(cev_set_current[0]); //must use the write value
cev->compute_strengths(magnet_rigidity_inv, read_curr, read_strength);
wValCevCorrStrength = read_strength[0] - (wValCevResStrength + cev_design_strength);
cevCorrectionAtt->set_write_value(wValCevCorrStrength);
}
//------------------------------------------------------------
// handles change of power supples state - may just filter values
void E2Sextupole::update_values_state(void)
......@@ -1986,6 +2036,8 @@ void MainCurrentEventCallback::push_event(Tango::EventData* ev) //callback core
bool update_write_main = false;
bool update_read_ceh = false;
bool update_write_ceh = false;
bool update_read_cev = false;
bool update_write_cev = false;
bool update_state = false;
if (ev->err) {
//std::cerr << ev->err << " " << ev->attr_name << std::endl;
......@@ -2009,7 +2061,7 @@ void MainCurrentEventCallback::push_event(Tango::EventData* ev) //callback core
case CeHPS:
*(ev->attr_value) >> *(e2_sext->attr_CEHCurrent_read); update_read_ceh = true; break;
case CeVPS:
*(ev->attr_value) >> *(e2_sext->attr_CEVCurrent_read); break;
*(ev->attr_value) >> *(e2_sext->attr_CEVCurrent_read); update_read_cev = true; break;
}
}
......@@ -2022,7 +2074,7 @@ void MainCurrentEventCallback::push_event(Tango::EventData* ev) //callback core
case CeHPS:
e2_sext->set_ceh_current_write(newcurr); update_write_ceh = true; break;
case CeVPS:
e2_sext->set_cev_current_write(newcurr); break;
e2_sext->set_cev_current_write(newcurr); update_write_cev = true; break;
}
}
......@@ -2047,6 +2099,8 @@ void MainCurrentEventCallback::push_event(Tango::EventData* ev) //callback core
if (update_write_main) e2_sext->update_values_write_main();
if (update_read_ceh) e2_sext->update_values_read_ceh();
if (update_write_ceh) e2_sext->update_values_write_ceh();
if (update_read_cev) e2_sext->update_values_read_cev();
if (update_write_cev) e2_sext->update_values_write_cev();
if (update_state) e2_sext->update_values_state();
}
//--------------------------------------------------------
......
......@@ -147,6 +147,10 @@ public:
// ceh current
Tango::DevDouble wValCehCorrStrength; //last CorrectionStrength write value
Tango::DevDouble wValCehResStrength; //last ResonanceStrength write value
// cev current
Tango::DevDouble wValCevCorrStrength; //last CorrectionStrength write value
Tango::DevDouble wValCevResStrength; //last ResonanceStrength write value
/* clang-format off */
/*----- PROTECTED REGION END -----*/ // E2Sextupole::Data Members
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment