Commit 6f563046 authored by locatelli's avatar locatelli

Test new IN5 Magnetic field controller at SANE lab

parent 65fbc0b1
......@@ -52,12 +52,16 @@ static const char MID[] = "MID";
static const char OUTPUT[] = "OUTPUT";
static const char PLUS[] = "+";
static const char MINUS[] = "-";
static const char POSITIVE[] = "POSITIVE";
static const char NEGATIVE[] = "NEGATIVE";
static const char ZERO[] = "ZERO";
static const char STATUS[] = "STATUS";
static const char QUENCH[] = "STATUS";
static const char QUENCH[] = "QUENCH";
static const char HOLDING[] = "HOLDING";
static const char RAMPING[] = "RAMPING";
static const char EXTERNAL[] = "EXTERNAL";
static const char DIRECTION[] = "DIRECTION";
static const char UNIT[] = "UNIT";
static const char TERMINATOR[] = "\r\n";
......@@ -65,7 +69,7 @@ static const char TERMINATOR[] = "\r\n";
* Properties
*/
enum ProcessStep {
DUMMY, INIT, HEATER_ON, FIELD_CHANGING, STABILISATION, HEATER_OFF, AUTO_POWERED, HOLD
DUMMY, INIT, HEATER_ON, FIELD_CHANGING, STABILISATION, HEATER_OFF, AUTO_POWERED, HOLD, CHANGE_DIRECTION
};
}
......
......@@ -29,7 +29,7 @@ namespace cryogenic_sms {
*/
RealCryogenicSmsDriver::RealCryogenicSmsDriver(CryogenicSmsDriver* owner) :
CryogenicSmsState(owner), m_step(DUMMY), m_level(0), m_etapCurrent(0.), m_deltaTime(0.) {
/* Empty */
m_ChangeDirection = false;
}
/*
......@@ -58,26 +58,22 @@ void RealCryogenicSmsDriver::readStatus() {
ostringstream sbuf;
sbuf << RAMP_COMMAND << " " << STATUS;
vector<string> bufs = writeSms(sbuf.str(), STATUS);
if (bufs.size() >= 2) {
if (bufs[2].find(QUENCH) != string::npos) {
local_status += QUENCH_TRIP_STATUS;
} else if (bufs[2].find(HOLDING) != string::npos) {
local_status += HOLDING_ON_STATUS;
} else if (bufs[2].find(RAMPING) != string::npos) {
local_status += RAMPING_ON_STATUS;
} else if (bufs[2].find(EXTERNAL) != string::npos) {
local_status += EXTERNAL_TRIP_STATUS;
}
string buf = writeSms(sbuf.str(), STATUS);
if (buf.find(QUENCH) != string::npos) {
local_status += QUENCH_TRIP_STATUS;
} else if (buf.find(HOLDING) != string::npos) {
local_status += HOLDING_ON_STATUS;
} else if (buf.find(RAMPING) != string::npos) {
local_status += RAMPING_ON_STATUS;
} else if (buf.find(EXTERNAL) != string::npos) {
local_status += EXTERNAL_TRIP_STATUS;
}
bufs = writeSms(HEATER_COMMAND, HEATER_COMMAND);
if (bufs.size() >= 2) {
if (bufs[2].find(ON) != string::npos) {
m_switchHeater = true;
local_status += HEATER_ON_STATUS;
} else {
m_switchHeater = false;
}
buf = writeSms(HEATER_COMMAND, HEATER_COMMAND);
if (buf.find(ON) != string::npos) {
m_switchHeater = true;
local_status += HEATER_ON_STATUS;
} else {
m_switchHeater = false;
}
if (owner()->startActivated() == true) {
......@@ -160,6 +156,15 @@ void RealCryogenicSmsDriver::readStatus() {
}
m_ChangeDirection = false;
if (((owner()->m_WantedCurrent < 0) && (actualCurrent > 0)) ||
((owner()->m_WantedCurrent > 0) && (actualCurrent < 0))) {
m_ChangeDirection = true;
m_ChangeDirectionCurrent = owner()->m_WantedCurrent;
owner()->m_WantedCurrent = 0;
// cout << "Change Direction" << endl;
}
// It's a new command there are some calculations to perform
// -1- the differents steps
// cout << "calculateLevels" << endl;
......@@ -181,7 +186,11 @@ void RealCryogenicSmsDriver::readStatus() {
// "buf_in" must have the persistence value
//if (owner()->m_PersistentCurrent != 0.0) {
// cout << "writeCurrent : " << owner()->m_PersistentCurrent << endl;
writeCurrentRate(600);
writeCurrent(owner()->m_PersistentCurrent);
ostringstream scom1;
scom1 << RAMP_COMMAND << " " << MID << TERMINATOR;
owner()->write(scom1.str());
//}
// Hold off
// cout << "setHoldOff" << endl;
......@@ -231,7 +240,36 @@ void RealCryogenicSmsDriver::readStatus() {
}
// Is the new value reached ?
// if ((owner()->m_WantedCurrent < 0) && (owner()->m_OutputCurrent < 0)
if (fabs(owner()->m_WantedCurrent - owner()->m_OutputCurrent) < tolerance) {
if (m_ChangeDirection == true) {
if (owner()->m_OutputCurrent != 0) {
if (m_level == 0) {
nextCurrent();
}
break;
}
m_ChangeDirection = false;
owner()->m_WantedCurrent = m_ChangeDirectionCurrent;
ostringstream scom1;
scom1 << DIRECTION_COMMAND << " ";
if (owner()->m_WantedCurrent < 0) {
scom1 << MINUS;
}
else {
scom1 << PLUS;
}
owner()->write(scom1.str());
// It's a new command there are some calculations to perform
// -1- the differents steps
// cout << "calculateLevels" << endl;
m_level = 0;
calculateLevels();
// -2- An evaluation of the total time linked with the differents steps
// cout << "calculateTotalTime" << endl;
calculateTotalTime();
break;
}
owner()->startActivated = false;
// cout << "setHoldOn" << endl;
setHoldOn();
......@@ -289,7 +327,7 @@ void RealCryogenicSmsDriver::readStatus() {
// cout << "toZero" << endl;
toZero();
// cout << "setHoldOff" << endl;
// setHoldOff();
setHoldOff();
// // Set field to zero
// cout << "writeCurrent(0.0)" << endl;
// writeCurrent(0.0);
......@@ -358,18 +396,18 @@ void RealCryogenicSmsDriver::read() {
float64 outputCurrent;
float64 outputField;
ostringstream sbuf1;
sbuf1 << DIRECTION_COMMAND;
vector<string> strings = writeSms(sbuf1.str(), DIRECTION_COMMAND);
// ostringstream sbuf1;
// sbuf1 << DIRECTION_COMMAND;
// string strings = writeSms(sbuf1.str(), DIRECTION);
ostringstream sbuf;
sbuf << GET_OUTPUT_COMMAND;
vector<string> strings1 = writeSms(sbuf.str(), OUTPUT);
vector<string> strings1 = writeSmsDecode(sbuf.str(), OUTPUT);
try {
if ((strings.size() >= 2) && (strings1.size() >= 2)) {
if (strings1.size() >= 2) {
outputCurrent = lexical_cast<float64>(strings1[2]);
if (strings[2].find(MINUS) != string::npos) {
outputCurrent = -outputCurrent;
}
// if (strings.find(NEGATIVE) != string::npos) {
// outputCurrent = -outputCurrent;
// }
owner()->m_OutputCurrent = outputCurrent;
outputField = outputCurrent / owner()->maxCurrent() * owner()->maxField();
} else {
......@@ -382,16 +420,18 @@ void RealCryogenicSmsDriver::read() {
float64 persistentField;
ostringstream sbuf2;
sbuf2 << GET_PER_COMMAND;
vector<string> strings2 = writeSms(sbuf2.str(), "");
vector<string> strings2 = writeSmsDecode(sbuf2.str(), "");
try {
if ((strings.size() >= 2) && (strings2.size() >= 2)) {
if (strings2[2].find("off") != string::npos) {
if (strings2.size() >= 4) {
if (strings2[4].find("off") != string::npos) {
persistentCurrent = outputCurrent;
}
outputCurrent = lexical_cast<float64>(strings2[2]);
if (strings[2].find(MINUS) != string::npos) {
persistentCurrent = -persistentCurrent;
else {
persistentCurrent = lexical_cast<float64>(strings2[4]);
}
// if (strings.find(NEGATIVE) != string::npos) {
// persistentCurrent = -persistentCurrent;
// }
owner()->m_PersistentCurrent = persistentCurrent;
persistentField = persistentCurrent / owner()->maxCurrent() * owner()->maxField();
} else {
......@@ -433,7 +473,7 @@ void RealCryogenicSmsDriver::start() {
m_level = 0;
ostringstream sbuf;
sbuf << TESLA_COMMAND << " " << OFF;
vector<string> strings = writeSms(sbuf.str(), OFF);
writeSms(sbuf.str(), UNIT);
}
/*
......@@ -510,8 +550,8 @@ void RealCryogenicSmsDriver::toZero() {
scom << SET_COMMAND << " " << RAMP << " " << 10.;
writeSms(scom.str(), RAMP);
ostringstream scom1;
scom1 << RAMP << " " << ZERO;
writeSms(scom.str(), ZERO);
scom1 << RAMP_COMMAND << " " << ZERO << TERMINATOR;
owner()->write(scom1.str());
}
/*
......@@ -521,27 +561,25 @@ void RealCryogenicSmsDriver::nextCurrent() {
string buf_out;
//float64 local_current,local_rate;
// Hold on(to freeze parameters)
setHoldOn();
// Get next field and rate
//
//local_current = m_levelTable[m_level++];
m_etapCurrent = m_levelTable[m_level++];
//local_rate = m_levelTable[m_level++];
// cout << "NEXT >>>> " << m_etapCurrent << " A , " << m_levelTable[m_level] << " A/min" << endl;
ostringstream scom;
scom << DIRECTION_COMMAND << " ";
if (m_etapCurrent < 0) {
scom << MINUS;
} else {
scom << PLUS;
bool donext = true;
if (donext == true) {
// Get next field and rate
//
//local_current = m_levelTable[m_level++];
m_etapCurrent = m_levelTable[m_level++];
//local_rate = m_levelTable[m_level++];
// cout << "NEXT >>>> " << m_etapCurrent << " A , " << m_levelTable[m_level] << " A/min" << endl;
writeCurrent(m_etapCurrent);
writeCurrentRate(m_levelTable[m_level]);
owner()->actualRate = m_levelTable[m_level++];
ostringstream scom1;
scom1 << RAMP_COMMAND << " " << MID << TERMINATOR;
owner()->write(scom1.str());
}
writeSms(scom.str(), DIRECTION_COMMAND);
writeCurrent(m_etapCurrent);
writeCurrentRate(m_levelTable[m_level]);
owner()->actualRate = m_levelTable[m_level++];
// Hold off (to validate values)
setHoldOff();
}
......@@ -709,17 +747,45 @@ void RealCryogenicSmsDriver::calculateTotalTime() {
/*
* writeSms
*/
std::vector<std::string> RealCryogenicSmsDriver::writeSms(const std::string& cmd, const std::string& ack) {
std::string RealCryogenicSmsDriver::writeSms(const std::string& cmd, const std::string& ack) {
ostringstream scom;
vector<string> decodevector;
// cout << "<---- " << cmd << endl;
scom << cmd << TERMINATOR;
string buf;
uint32 i = 0;
do {
owner()->write(scom.str());
owner()->read(buf, driver::RS232::DC3);
// cout << "----> " << buf << endl;
if (buf.find(ack) != string::npos) {
break;
}
} while (i++ < 6);
if (i == 6) {
ostringstream serr;
serr << "Problem write command : " << cmd;
throw DeviceDriver::TimeOut(owner()->getType(), owner()->getName(), owner(), serr.str());
}
return buf;
}
/*
* writeSmsDecode
*/
std::vector<std::string> RealCryogenicSmsDriver::writeSmsDecode(const std::string& cmd, const std::string& ack) {
ostringstream scom;
vector<string> decodevector;
cout << "<---- " << cmd << endl;
// cout << "<---- " << cmd << endl;
scom << cmd << TERMINATOR;
uint32 i = 0;
do {
owner()->write(scom.str());
string buf;
owner()->read(buf, driver::RS232::DC3);
cout << "----> " << buf << endl;
// cout << "----> " << buf << endl;
if (buf.find(ack) != string::npos) {
typedef tokenizer<char_separator<char> > tokenizer;
char_separator<char> sep(" ");
......
......@@ -135,7 +135,8 @@ private:
*/
void setHeaterOff();
std::vector<std::string> writeSms(const std::string& cmd, const std::string& ack);
std::string writeSms(const std::string& cmd, const std::string& ack);
std::vector<std::string> writeSmsDecode(const std::string& cmd, const std::string& ack);
//! local values
ProcessStep m_step;
......@@ -152,6 +153,8 @@ private:
float64 m_actualCurrent;
bool m_Init;
bool m_AutoPowered;
bool m_ChangeDirection;
float64 m_ChangeDirectionCurrent;
};
}
......
Markdown is supported
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