Commit 75bd23ce authored by Hélène Ortiz's avatar Hélène Ortiz

Implement not equidistant slots sample changer for d11

parent bac99534
......@@ -19,7 +19,10 @@
#include "SampleChangerController.h"
#include "controllers/common/family/Families.h"
#include <boost/tokenizer.hpp>
using namespace std;
using namespace boost;
namespace lss {
......@@ -37,7 +40,7 @@ const int32 SampleChangerController::ERROR_STATUS = 7;
//const int32 SampleChangerController::OUT_TOLERANCE_STATUS = 8;
SampleChangerController::SampleChangerController(const std::string& name) :
ExperimentController(name), controller::Stoppable(this), controller::Pausable(this) {
ExperimentController(name), controller::Stoppable(this), controller::Pausable(this) {
setFamily(family::SAMPLE_ENVIRONMENT); //think if it is necessary to have a subfamily
......@@ -105,6 +108,9 @@ SampleChangerController::SampleChangerController(const std::string& name) :
adjustSlot.setEnumeratedValues(adjustSlotValues);
adjustSlot = 1;
equidistantSlots.init(this, SAVE, "equidistantSlots");
spaces.init(this, SAVE, "spaces");
//Init pointers to other controllers
str1.init(this, "str1");
by.init(this, "by");
......@@ -117,16 +123,18 @@ SampleChangerController::SampleChangerController(const std::string& name) :
registerRefresher(strDSlots, &SampleChangerController::refreshStrDSlotsProperty, this);
registerRefresher(strOrigin, &SampleChangerController::refreshStrOriginProperty, this);
registerRefresher(useStr2, &SampleChangerController::refreshUseStr2, this);
registerRefresher(slotMaxNum, &SampleChangerController::refreshSlotMaxNum, this);
}
SampleChangerController::~SampleChangerController() {
}
void SampleChangerController::postConfiguration() {
// Register the refresher for strName here because str can be null.
registerRefresher(strName, &SampleChangerController::refreshStrName, this);
registerRefresher(spaces, &SampleChangerController::refreshSpaces, this);
registerRefresher(equidistantSlots, &SampleChangerController::refreshEquidistantSlots, this);
//Set values attenuator: copy one by one values and labels
if (att.isAssigned()) {
......@@ -177,7 +185,7 @@ void SampleChangerController::refreshChangerNumProperty(int32 number) throw (Can
int32 oldNumber = changerNum();
//Initialize all values
changerValues.resize(number);
// changerLabels.resize(number);
// changerLabels.resize(number);
slotMaxNum.resize(number);
strDSlots.resize(number);
......@@ -187,19 +195,102 @@ void SampleChangerController::refreshChangerNumProperty(int32 number) throw (Can
for (int i = oldNumber; i < number; i++) {
int32 index = i + 1;
// ostringstream os;
// os << "Changer#" << index;
// ostringstream os;
// os << "Changer#" << index;
//std::string name = os.str();
changerValues.set(i, index);
// changerLabels.set(i, name);
// changerLabels.set(i, name);
}
changer.setEnumeratedValues(changerValues);
changer.setEnumeratedLabels(nicknameValues);
//changer = 1; H.ORTIZ 23 MAY 2016: do not override changer value saved in InstrumentConfig !
equidistantSlots.resize(number);
m_slotSpaces.resize(number);
spaces.resize(number);
}
void SampleChangerController::refreshSlotMaxNum(int32 i, int32 value) throw (CannotSetValue) {
// Check that slotSpaces property matches number of slots
cout << "Size of sample changer " << i << " goes from " << m_slotSpaces[i].size() << " to " << value << endl;
if (m_slotSpaces[i].size() != value) {
if (value > m_slotSpaces[i].size()) {
// Missing values => add zeros
for (int j = m_slotSpaces[i].size(); j < value; j++) {
m_slotSpaces[i].push_back(0.);
}
} else if (value < m_slotSpaces[i].size()) {
// Extra values => remove them
m_slotSpaces[i].resize(value);
}
// Update spaces property
string spacesAsString = "";
for (int j = 0; j < m_slotSpaces[i].size(); j++) {
string sep = ",";
if (spacesAsString.empty()) {
sep = "";
}
spacesAsString.append(sep);
std::ostringstream ss;
ss << m_slotSpaces[i][j];
spacesAsString.append(ss.str());
}
// Force slotMaxNum update so that method refreshSpaces works with the right value
slotMaxNum.update(i, value);
spaces.update(i, spacesAsString);
}
}
void SampleChangerController::refreshEquidistantSlots(int32 i, bool value) throw (CannotSetValue) {
if (!value) {
if (spaces.get(i).size() != slotMaxNum.get(i)) {
refreshSlotMaxNum(i, slotMaxNum.get(i));
}
}
}
void SampleChangerController::refreshSpaces(int32 i, const std::string& spaces) throw (CannotSetValue) {
// Check that value is a sequence of slotMaxNum(i) float values separated by ","
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(",");
tokenizer tok1(spaces, sep);
tokenizer::iterator iter = tok1.begin();
int j = 0;
vector<float64> value_array;
while(iter != tok1.end()) {
string value = *iter;
try {
float64 floatValue = lexical_cast<float64>(value);
value_array.push_back(floatValue);
j = j + 1;
} catch (...) {
stringstream message;
message << "Wrong float value for slot spaces (sample changer #" << i << "): " << value << endl;
sendErrorEvent(BAD_VALUE_ERROR, message.str());
throw CannotSetValue();
}
++iter;
}
if (j == slotMaxNum.get(i)) {
// Correct number of values
m_slotSpaces[i] = value_array;
} else {
m_slotSpaces[i].clear();
stringstream message;
message << "Wrong number of values for changer #" << i <<". Have " << j << ", expecting " << slotMaxNum.get(i) << endl;
sendErrorEvent(BAD_VALUE_ERROR, message.str());
throw CannotSetValue();
}
}
void SampleChangerController::refreshChangerProperty(int32 number) throw (CannotSetValue) {
//Update slotMaxNum
int32 index = number - 1;
......@@ -284,7 +375,7 @@ void SampleChangerController::refreshStrName(int32 value) throw (CannotSetValue)
void SampleChangerController::updateOptimizationPlotX() {
if (scanStr.isAssigned()) {
// optimizationPlotX = scanStr->optimizationPlotX();
// optimizationPlotX = scanStr->optimizationPlotX();
optimizationPlotX.update(scanStr->optimizationPlotX());
optimizationPlotX.setSize(scanStr->optimizationPlotX.getSize());
optimizationPlotX.sendEvent();
......@@ -293,7 +384,7 @@ void SampleChangerController::updateOptimizationPlotX() {
void SampleChangerController::updateOptimizationPlotY(int32 nplot) {
if (scanStr.isAssigned()) {
// optimizationPlotY = scanStr->optimizationPlotY();
// optimizationPlotY = scanStr->optimizationPlotY();
if (nplot == 0) {
optimizationPlotY.update(scanStr->optimizationPlotY.get(0));
optimizationPlotY.setSize(scanStr->optimizationPlotY.getSize(0));
......@@ -310,7 +401,7 @@ void SampleChangerController::updateOptimizationFitPlot() {
void SampleChangerController::updateOptimizationFitPlotY() {
if (scanStr.isAssigned()) {
// optimizationFitPlotY = scanStr->optimizationFitPlotY();
// optimizationFitPlotY = scanStr->optimizationFitPlotY();
optimizationFitPlotY.update(scanStr->optimizationFitPlotY());
optimizationFitPlotY.setSize(scanStr->optimizationFitPlotY.getSize());
optimizationFitPlotY.sendEvent();
......@@ -375,32 +466,55 @@ void SampleChangerController::start() {
log(Level::s_Info) << name << cursor << slot.setpoint() << " (changer " << changer() << ")" << endlog;
if (useAdjust()) {
adjust();
int i = changer() - 1;
if (equidistantSlots.get(i)) {
//Calculate position
adjust();
} else {
stringstream message;
message << "Adjust mode not available for a changer with not equidistant slots !" << endl;
sendErrorEvent(BAD_VALUE_ERROR, message.str());
}
} else {
startInNoAdjustMode();
}
commandProgression = 100;
commandStatus.setIdle();
cout << "at the end of start method setting idle status" << endl;
}
void SampleChangerController::startInNoAdjustMode() {
//In this mode we only move the related axis (str or strVac)
commandStatus.setRunning();
//Check changer selected is correct
if ((changer() > 0) && (changer() <= changerNum())) {
//Calculate position
int i = changer() - 1;
strPosition.setpoint = (slot.setpoint() - 1) * strDSlots.get(i) + strOrigin.get(i);
if (equidistantSlots.get(i)) {
// Space between two slots is constant
strPosition.setpoint = (slot.setpoint() - 1) * strDSlots.get(i) + strOrigin.get(i);
} else {
// Space between two slots is variable and stored in slotSpaces(i)
float64 distance = 0;
// Compute space from first slot to wanted slot by adding distance between slots
int wantedSlot = slot.setpoint();
for (int slot = 0; slot < wantedSlot; slot++) {
distance = distance + m_slotSpaces[i][slot];
}
strPosition.setpoint = strOrigin.get(i) + distance;
}
try {
str->position.setpoint = strPosition.setpoint();
str->startCommand();
log(Level::s_Info) << name << emptycursor << slot() << " (changer " << changer() << ")" << endlog;
} catch (CannotSetValue &) {
cerr << "Over limits" << endl;
}
} else {
log(Level::s_Error) << name << emptycursor << " tries to set changer " << changer() << " in wrong channel " << slot.setpoint() << endlog;
}
......@@ -426,7 +540,7 @@ void SampleChangerController::pause() {
if (useAdjust()) {
//just pause everything
str->pauseCommand();
// att->pauseCommand(); //TODO: attenuator (state_axis) is not pausable!
// att->pauseCommand(); //TODO: attenuator (state_axis) is not pausable!
by->pauseCommand();
scanStr->pauseCommand();
......@@ -440,7 +554,7 @@ void SampleChangerController::resume() {
if (useAdjust()) {
//just pause everything
str->resumeCommand();
// att->resumeCommand(); //TODO: attenuator (state_axis) is not pausable!
// att->resumeCommand(); //TODO: attenuator (state_axis) is not pausable!
by->resumeCommand();
scanStr->resumeCommand();
......@@ -587,7 +701,7 @@ void SampleChangerController::doScan() {
cout << "No optimum found " << endl;
log(Level::s_Info) << "no optimum found." << endlog;
}
// TODO Check error
// TODO Check error
}
}
......
......@@ -112,6 +112,11 @@ public:
Property<bool> optimization1dResultFound;
Property<float64> optimization1dXResult;
DynamicProperty<bool> equidistantSlots;
DynamicProperty<std::string> spaces;
virtual void start();
private:
......@@ -138,6 +143,9 @@ private:
void refreshStrName(int32 value) throw (CannotSetValue);
void refreshStrDSlotsProperty(int32 i, float64 value) throw (CannotSetValue);
void refreshStrOriginProperty(int32 i, float64 value) throw (CannotSetValue);
void refreshSpaces(int32 i, const std::string&) throw (CannotSetValue);
void refreshSlotMaxNum(int32 i, int32 number) throw (CannotSetValue);
void refreshEquidistantSlots(int32 i, bool value) throw (CannotSetValue);
virtual void updateOptimizationPlotX();
virtual void updateOptimizationPlotY(int32 nplot);
......@@ -158,6 +166,8 @@ private:
bool m_scanRunning;
bool m_isClosingAdjust;
std::vector<std::vector<float64>> m_slotSpaces;
};
}
......
......@@ -299,6 +299,7 @@ void SampleSequencer::start() {
try {
if (apply_acquisitionTime[i] != 0.0) {
currentAcquisitionTime = apply_acquisitionTime[i];
sampleChanger->useAdjust = false;
sampleChanger->slot.setpoint = apply_samplePosition[i];
sampleChanger->changer = changer();
......
......@@ -54,4 +54,10 @@ sample_changer.rebymovingValue=5
sample_changer.reattmovingLabel=Change Attenuator to original one
sample_changer.reattmovingValue=6
sample_changer.errorLabel=Error
sample_changer.errorValue=7
\ No newline at end of file
sample_changer.errorValue=7
sample_changer.equidistantPrefix=Equidistant
sample_changer.equidistantCheckedValue=true
sample_changer.equidistantUncheckedValue=false
sample_changer.spacesPrefix=Spaces between slots (CSV)
\ No newline at end of file
......@@ -147,4 +147,11 @@
<dynamic_property size_property="changer_num" name="nick_name_values" type="String" max_length="30">
</dynamic_property>
<dynamic_property size_property="changer_num" name="equidistantSlots" type="boolean">
</dynamic_property>
<dynamic_property size_property="changer_num" name="spaces" type="String" max_length="100">
</dynamic_property>
</controller>
\ No newline at end of file
......@@ -15,19 +15,28 @@
<newLine />
<switchable_composite switcher_key="simpleAdvancedModeSwitcher" switch_values="MORE_OPTIONS_BUTTON" />
<switchable_composite switcher_key="simpleAdvancedModeSwitcher" switch_values="LESS_OPTIONS_BUTTON">
<table_composite nbColumns="5">
<table_composite nbColumns="6">
<simple_label prefix="sample_changer.nicknamePrefix" />
<simple_label prefix="sample_changer.str_dslotsPrefix" />
<simple_label prefix="sample_changer.str_originePrefix" />
<simple_label prefix="sample_changer.cha_maxPrefix" />
<simple_label prefix="sample_changer.slot_widthPrefix" />
<simple_label prefix="sample_changer.equidistantPrefix" horizontal_span="2"/>
<dynamic_composite role="sample_changer1" properties="str_dSlots,str_origin,slot_max_num,slot_width,nick_name_values">
<dynamic_composite role="sample_changer1" properties="str_dSlots,str_origin,slot_max_num,slot_width,nick_name_values,equidistantSlots,spaces">
<property_switcher role="sample_changer1" property="equidistantSlots" switcher_key="equidistantSlots"/>
<text role="sample_changer1" property="nick_name_values" />
<text role="sample_changer1" property="str_dSlots" />
<text role="sample_changer1" property="str_origin" />
<text role="sample_changer1" property="slot_max_num" />
<text role="sample_changer1" property="slot_width" />
<check role="sample_changer1" property="equidistantSlots" checkBoxValues="sample_changer.equidistant" />
<switchable_composite switcher_key="equidistantSlots" switch_values="true">
<text role="sample_changer1" property="str_dSlots" prefix="sample_changer.str_dslotsPrefix"/>
</switchable_composite>
<switchable_composite switcher_key="equidistantSlots" switch_values="false">
<text role="sample_changer1" property="spaces" prefix="sample_changer.spacesPrefix"/>
</switchable_composite>
</dynamic_composite>
</table_composite>
<newLine/>
......
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