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

Merge branch 'V3.1_182' of https://code.ill.fr/instrument-control/nomad-modules.git into V3.1_182

parents e03c0e0b 994dacbe
<module name="d50">
<controller class="d50::Dan"/>
<controller class="d50::SampleChanger"/>
</module>
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include "SampleChanger.h"
#include <boost/lexical_cast.hpp>
#include "controllers/common/family/Families.h"
using namespace std;
using namespace boost;
namespace d50 {
const string SampleChanger::TYPE = "d50samplechanger";
const float64 SampleChanger::SAMPLECHANGER_TOLERANCE_LINES =0.1;
const float64 SampleChanger::SAMPLECHANGER_TOLERANCE_COLOMNS =0.1;
const int32 SampleChanger::SAMPLECHANGER_MAX =75;
const int32 SampleChanger::SAMPLECHANGER_LINES =5;
const int32 SampleChanger::SAMPLECHANGER_COLOMNS=15;
/*
* Constructor
*/
SampleChanger::SampleChanger(const string& name) :
ExperimentController(name), Load(this), controller::Stoppable(this) {
setFamily(family::ACQUISITION);
registerFunction(TYPE);
Cha.init(this, SAVE , "actual_cha" , "wanted_cha","CHA");
ChaIndiceLine.init(this, SAVE , "ind_cha_line" , "wanted_cha_line");
ChaIndiceColumns.init(this, SAVE , "ind_cha_col" , "wanted_cha_col");
useOneCha.init(this, SAVE , "use_one_cha");
useOneChaIndice.init(this, SAVE , "use_one_cha_indice","wanted_use_one_cha_indice");
trsValue.init(this, NOSAVE , "actual_trs_position" ,"wanted_trs_position");
shtValue.init(this, NOSAVE, "actual_sht_position","wanted_sht_position" );
trsGapValue.init(this, SAVE , "trsGapValue");
shtGapValue.init(this, SAVE , "shtGapValue");
shtGap2Value.init(this, SAVE , "shtGap2Value");
nChanger.init(this, SAVE, "number_changer");
trsSlots.init(this, NOSAVE, "trs_slots");
shtSlots.init(this, NOSAVE, "sht_slots");
ChangerIndice.init(this, SAVE, "ChangerIndice");
changerSubTitle .init(this, SAVE, "changerSubTitle");
string_actual_cha.init(this, SAVE| SPY , "string_actual_cha","Pos");
string_actual_cha_subT.init(this, SAVE| SPY , "string_actual_cha_subT","SubT");
// Count parameters
countMode.init(this, SAVE, "count_mode", "Modedy");
counts.init(this, SAVE, "wanted_counts", "Countsdy");
time.init(this, SAVE, "wanted_time", "Timedy");
timeType.init(this, SAVE, "time_type", "Unitdy");
// changerLabels.init(this, NOSAVE , "changer_labels");
// changerValues.init(this, NOSAVE , "changer_values");
int32 size = SAMPLECHANGER_MAX ;
nChanger = SAMPLECHANGER_MAX ;
trsSlots.resize(size);
shtSlots.resize(size);
ChangerIndice.resize(size);
changerSubTitle.resize(size);
// changerName.resize(size);
// changerValues.resize(size);
// changerLabels.resize(size);
axisTRS.init(this, "trs");
axisSHT.init(this, "sht");
count.init(this, "count");
}
/*
* Destructor
*/
SampleChanger::~SampleChanger() {
}
/*
* postConfiguration
*/
void SampleChanger::postConfiguration() {
registerRefresher(Cha.setpoint , &SampleChanger::refreshWantedCha , this);
registerUpdater(axisTRS->position , &SampleChanger::updateTRS, this);
registerUpdater(axisSHT->position , &SampleChanger::updateSHT, this);
// const int32 SampleChanger::SAMPLECHANGER_LINES =15;
// const int32 SampleChanger::SAMPLECHANGER_COLOMNS=5;
int32 lindiceCHA;
int32 lind = 0;
for (int32 ki = 0; ki < SAMPLECHANGER_LINES ; ki++) {
for (int32 kj = 0; kj < SAMPLECHANGER_COLOMNS ; kj++) {
string lChangerName;
lChangerName = "Changer " + lexical_cast<string>(lind+1);
lindiceCHA = 1000*ki +kj;
ChangerIndice.set(lind, lindiceCHA);
//changerSubTitle.set(lind, lChangerName);
trsSlots.set(lind, kj);
shtSlots.set(lind, ki);
lind++;
// changerName.set(i, lChangerName);
// changerLabels.set(i, lChangerName);
// changerValues.set(i, i+1);
}
}
// Cha.setpoint.setEnumeratedValues(changerValues);
// Cha.setpoint.setEnumeratedLabels(changerLabels);
trsValue=axisTRS->position();
shtValue=axisSHT->position();
caculate_CHAposition();
}
void SampleChanger::refreshWantedCha(int32 value) throw (CannotSetValue) {
try {
Cha.setpoint.update(value);
} catch (CannotSetValue&) {
cerr << "Bad SampleChanger Indice " << endl;
// Not possible with combo !!
return;
}
}
void SampleChanger::updateTRS( ){
trsValue=axisTRS->position();
caculate_CHAposition();
}
void SampleChanger::updateSHT( ){
shtValue=axisSHT->position();
caculate_CHAposition();
}
void SampleChanger::caculate_CHAposition() {
Cha = 777;
float64 fLineInd,fColInd;
int32 iLineInd,iColInd;
if (shtValue() < 60){
fLineInd = fabs(shtValue() / shtGapValue());
} else {
fLineInd = fabs( (shtValue()-shtGap2Value()) / shtGapValue());
}
fColInd = trsValue() / trsGapValue();
if ( fabs(fLineInd - round(fLineInd) ) > SAMPLECHANGER_TOLERANCE_LINES){
Cha = 777;
ChaIndiceColumns = 777;
ChaIndiceLine = 777;
string_actual_cha = "not a Changer";
commandStatus.setUnknown();
return;
}
if ( fabs(fColInd - round(fColInd) ) > SAMPLECHANGER_TOLERANCE_COLOMNS){
Cha = 777;
ChaIndiceColumns = 777;
ChaIndiceLine = 777;
string_actual_cha = "not a Changer";
commandStatus.setUnknown();
return;
}
iLineInd = round(fLineInd);
iColInd = round(fColInd) ;
Cha = iLineInd*15 + iColInd;
ChaIndiceLine = iLineInd;
ChaIndiceColumns = iColInd;
Cha = 1000*(iLineInd+1) + (iColInd+1);
string_actual_cha = "Cha " + lexical_cast<string>(Cha());
if ((SAMPLECHANGER_COLOMNS*iLineInd + iColInd) <SAMPLECHANGER_MAX ){
string_actual_cha_subT = changerSubTitle.get(SAMPLECHANGER_COLOMNS*iLineInd + iColInd);
}
//cout << " string_actual_cha_subT " << string_actual_cha_subT() << endl;
commandStatus.setIdle();
}
/*
* start
*/
void SampleChanger::start() {
commandProgression = 5;
commandStatus.setRunning();
m_stopped = false;
if ((Cha.setpoint() < 1) || ((Cha.setpoint() > nChanger()))) {
Cha.setpoint = 1;
commandStatus.setWarning();
commandProgression = 100;
}
int32 wcal = 0;
int32 wline = 0;
shtValue.setpoint = 0;
int32 indiCHAcur = 0;
bool doCHA = true;
while (doCHA) {
trsValue.setpoint = wcal * trsGapValue();
try {
axisTRS->position.setpoint = trsValue.setpoint();
axisSHT->position.setpoint = shtValue.setpoint();
} catch (CannotSetValue&) {
stringstream message;
message << "SampleChanger : outside limits";
sendErrorEvent(WARNING_ERROR, message.str());
commandProgression = 100;
return;
}
Parallel::begin();
axisTRS->startParallel(false);
axisSHT->startParallel(false);
Parallel::end();
log(Level::s_Info) << Cha << " (" << Cha.setpoint << ")" << endlog;
count->mode = acquisition::TimeAcquisitionController::TIME_MODE;
// count->timeType = timeType();
count->time.setpoint = time();
count->saveData = true;
count->totalReps = 1;
// count->counts.setpoint = counts();
if (indiCHAcur < SAMPLECHANGER_MAX){
count->subtitle = changerSubTitle.get(indiCHAcur);
}
//count->startCommand(true);
usleep(100);
wcal++;
if (wcal == SAMPLECHANGER_COLOMNS){
wcal = 0;
wline++;
if (wline == 2){
shtValue.setpoint = shtValue.setpoint()+( shtGapValue()+ shtGap2Value());
}else {
shtValue.setpoint = shtValue.setpoint()+ shtGapValue();
}
}
indiCHAcur++;
cout << " wline "<< wline << endl;
if ( ( wline == SAMPLECHANGER_LINES ) || (m_stopped == true) ) {
doCHA = false;
}
}
commandProgression = 100;
}
/*
* stop
*/
void SampleChanger::stop() {
Parallel::begin();
axisTRS->stopParallel(false);
axisSHT->stopParallel(false);
count->stopParallel(false);
Parallel::end();
m_stopped = true;
log(Level::s_Info) << "stopped " << Cha << " (" << Cha.setpoint << ")" << endlog;
commandStatus.setIdle();
}
void SampleChanger::load() {
typedef tokenizer<char_separator<char> > tokenizer;
char_separator<char> sep(" \t");
sendProgressEvent(0);
//cout << " SampleChanger::load SampleChanger::load SampleChanger::load SampleChanger::load " << endl;
int32 i = 0;
try {
string fileName = "/users/d50/Desktop/SampleList.txt";
ifstream ifs;
ifs.open(fileName.c_str());
if (ifs.is_open()) {
string tmp;
while (ifs.eof() == false) {
getline(ifs, tmp);
if (i < SAMPLECHANGER_MAX) {
if (tmp.size() > 0) {
tokenizer tok1(tmp, sep);
tokenizer::iterator iter = tok1.begin();
if (iter == tok1.end()) {
log(Level::s_Error) << "File " << fileName << " contains bad data" << endlog;
cout << "File " << fileName << " contains bad data" << endl;
}
iter++;
if (iter != tok1.end()) {
string lpp = *iter;
changerSubTitle.set(i,lpp);
//cout << lpp << endl;
}
} else {
log(Level::s_Warning) << "File " << fileName << " empty line" << endlog;
cout << "File " << fileName << " empty line" << endl;
}
}
i++;
}
} else {
cout << "FileNotFound" << fileName << endl;
}
} catch (...) {
//
}
sendProgressEvent(100);
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef D50SAMPLECHANGER_H
#define D50SAMPLECHANGER_H
#include <Controller.h>
#include "controllers/common/axis/AxisController.h"
#include "controllers/common/acquisition/TimeCount.h"
namespace d50 {
class Load: private controller::Command {
public:
Load(ExperimentController * c) :
controller::Command(c, "load", &Load::load, this) {
}
virtual void load() = 0;
void loadCommand(bool logging = false) {
command(logging, true);
}
};
class SampleChanger: public ExperimentController, public Load, public controller::Stoppable {
public:
//! Type of controller
static const std::string TYPE;
static const float64 SAMPLECHANGER_TOLERANCE_LINES ;
static const float64 SAMPLECHANGER_TOLERANCE_COLOMNS ;
static const int32 SAMPLECHANGER_MAX;
static const int32 SAMPLECHANGER_LINES;
static const int32 SAMPLECHANGER_COLOMNS;
/*!
* \brief Constructor
* \param[in] name the name of the experiment controller
*/
SampleChanger(const std::string& name);
/*!
* \brief Destructor
*/
virtual ~SampleChanger();
/*!
* \brief Method called before changing the property value
*
* This method is called after setting configuration during the creation of controller.
*/
virtual void postConfiguration();
virtual void load();
/*!
* Properties
*/
Property<int32, SETPOINT> Cha; //!
Property<int32, SETPOINT> ChaIndiceLine; //!
Property<int32, SETPOINT> ChaIndiceColumns; //!
Property<bool> useOneCha;
Property<int32,SETPOINT> useOneChaIndice;
Property<float64 , SETPOINT> trsValue;
Property<float64 , SETPOINT> shtValue;
Property<float64> trsGapValue;
Property<float64 > shtGapValue;
Property<float64 > shtGap2Value;
Property<int32 > nChanger;
DynamicProperty <float64> trsSlots;
DynamicProperty <float64> shtSlots;
DynamicProperty <int32> ChangerIndice;
DynamicProperty <std::string> changerSubTitle;
Property<std::string> string_actual_cha;
Property<std::string> string_actual_cha_subT;
// DynamicProperty<std::string> changerLabels; // Possible states
// DynamicProperty<int32> changerValues; // Possible state values
Property<std::string> countMode;
Property<int32> counts;
Property<float64> time;
Property<std::string> timeType;
private:
virtual void start();
/*!
* \brief Stop command
*/
virtual void stop();
ControllerPtr<axis::AxisController> axisTRS; //! Axis SHT2 link
ControllerPtr<axis::AxisController> axisSHT; //! Axis SHT2 link
ControllerPtr<acquisition::TimeCount> count;
virtual void updateTRS();
virtual void updateSHT();
//virtual void updateLaser(float64);
virtual void caculate_CHAposition();
void refreshWantedCha(int32 value) throw (CannotSetValue) ;
bool m_stopped;
};
}
#endif // D17SAMPLECHANGER_H
# Labels
d50samplechanger.T1=Advanced parameters
d50samplechanger.Title=Sample Changer
d50samplechanger.trsPrefix=Actual TRS
d50samplechanger.trs2Prefix=TRS
d50samplechanger.shtPrefix=Actual SHT
d50samplechanger.sht2Prefix=SHT
d50samplechanger.chaPrefix=Actual
d50samplechanger.chaLabel=Wanted Changer
d50samplechanger.st1Label=SAMPLE CHANGER OK
d50samplechanger.st2Label=SAMPLE CHANGER MOVING
d50samplechanger.st4Label=SAMPLE CHANGER UNKNOWN
d50samplechanger.TimePrefix=Time
d50samplechanger.TimeSuffix=sec
d50samplechanger.changerSubTPrefix=Sub Title
d50samplechanger.changerNamePrefix=Indice Changer
d50samplechanger.load2Prefix=file Desktop/SampleList.txt
d50samplechanger.loadPrefix=Reload
<plugin>
<text role="d50samplechanger1" property="wanted_time" prefix="d50samplechanger.TimePrefix" suffix="d50samplechanger.TimeSuffix"/>
</plugin>
<controller_plugin_config type="d50samplechanger">
<image key="SAMPLE_CHANGER"/>
<settings view="d50samplechangerView.xml"/>
<command view="d50samplechangerCommandView.xml"/>
</controller_plugin_config>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<controller type="d50samplechanger">
<property name="actual_cha" type="long">
</property>
<property name="wanted_cha" type="long">
</property>
<property name="actual_sht_position" type="double" max_length="8">
<decimal_format nb_decimal_places="3"/>
</property>
<property name="actual_trs_position" type="double" max_length="8">
<decimal_format nb_decimal_places="3"/>
</property>
<property name="wanted_sht_position" type="double" max_length="8">
<decimal_format nb_decimal_places="3"/>
</property>
<property name="string_actual_cha" type="trsing">
</property>
<property name="wanted_trs_position" type="double" max_length="8">
<decimal_format nb_decimal_places="3"/>
</property>
<property name="number_changer" type="int32">
</property>
<dynamic_property name="trs_slots" size_property="number_changer" type="Double" max_length="6">
<decimal_format nb_decimal_places="3"/>
</dynamic_property>
<dynamic_property name="sht_slots" size_property="number_changer" type="Double" max_length="9">
<decimal_format nb_decimal_places="3"/>
</dynamic_property>
<dynamic_property name="changer_labels" size_property="number_changer" type="String" max_length="8" >
</dynamic_property>
<dynamic_property name="changer_values" size_property="number_changer" type="Long" >
</dynamic_property>
<property name="count_mode" type="string"/>
<property name="wanted_counts" type="int32" max_length="6">
<strictly_positive/>
</property>
<property name="time_type" type="string">
<specific_values values="h,m,s"/>
</property>
<property name="wanted_time" type="float64" max_length="6">
<strictly_positive/>
<decimal_format nb_decimal_places="1"/>
</property>
<dynamic_property name="ChangerIndice" size_property="number_changer" type="String" max_length="8" >
</dynamic_property>
<dynamic_property name="changerSubTitle" size_property="number_changer" type="String" max_length="40" >
</dynamic_property>
<!-- <dynamic_property name="changerName" size_property="number_changer" type="String">
</dynamic_property>
-->
</controller>
<plugin>
<controller type="d50samplechanger" role="d50samplechanger1"/>
<form_composite>
<positionnable_composite x="80" y="10" width="100" height="20">
<label role="d50samplechanger1" property="string_actual_cha"/>
</positionnable_composite>
</form_composite>
</plugin>
<plugin>
<controller type="d50samplechanger" role="d50samplechanger1"/>
<!-- <property_combo role="d50samplechanger1" property="wanted_cha" prefix="d50samplechanger.chaLabel"/> -->
<text role="d50samplechanger1" property="wanted_time" prefix="d50samplechanger.TimePrefix" suffix="d50samplechanger.TimeSuffix"/>
<newLine/>
<switchable_composite switcher_key="simpleAdvancedModeSwitcher" switch_values="MORE_OPTIONS_BUTTON"/>
<switchable_composite switcher_key="simpleAdvancedModeSwitcher" switch_values="LESS_OPTIONS_BUTTON">
<group title="d50samplechanger.T1">
<simple_label prefix="d50samplechanger.load2Prefix" spaceBefore="false"/>
<button role="d50samplechanger1" command="load" prefix="d50samplechanger.loadPrefix" key="load" />
<newLine/>
<table_composite nbColumns="2">
<simple_label prefix="d50samplechanger.changerNamePrefix" font_style="BOLD" hAlignment="center"/>
<simple_label prefix="d50samplechanger.changerSubTPrefix" font_style="BOLD" hAlignment="center"/>
<dynamic_composite role="d50samplechanger1" properties="ChangerIndice,changerSubTitle">
<label role="d50samplechanger1" property="ChangerIndice"/>
<text role="d50samplechanger1" property="changerSubTitle"/>
</dynamic_composite>
</table_composite>
-
</group>
</switchable_composite>
<title>
<graphical_switcher switcher_key="simpleAdvancedModeSwitcher" switcher_type="button"/>
</title>
<summary>
<summary_content>
<simple_label prefix="Actual" spaceBefore="false"/>
<label role="d50samplechanger1" property="string_actual_cha" font_style="BOLD" spaceBefore="false"/>
<newLine/>
<label role="d50samplechanger1" property="actual_trs_position" prefix="d50samplechanger.trsPrefix"/>
<newLine/>
<label role="d50samplechanger1" property="actual_sht_position" prefix="d50samplechanger.shtPrefix"/>
</summary_content>
</summary>
</plugin>
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