Commit dee78399 authored by yannick legoc's avatar yannick legoc
Browse files

Adapted D22AutoConfig to many results in dynamic properties

parent 3c4a35ad
......@@ -39,26 +39,35 @@ const std::string AutoConfig::REMOTE_APPLICATION = "autoconfig";
const std::string AutoConfig::RESPONDER = "responder";
AutoConfig::AutoConfig(const std::string& name) :
ExperimentController(name), controller::Start(this), m_countSpy(nullptr) {
ExperimentController(name), controller::Start(this), Apply(this),
m_countSpy(nullptr) {
setFamily(family::ACQUISITION, family::SETTING);
serverEndpoint.init(this, SAVE, "cameo_server");
initialized.init(this, NOSAVE, "initialized");
scatterModelType.init(this, NOSAVE, "scatter_model_type");
sampleRadius.init(this, NOSAVE, "sample_radius");
resultSize.init(this, NOSAVE, "result_size");
type.init(this, NOSAVE, "type");
distance.init(this, NOSAVE, "distance");
wavelength.init(this, NOSAVE, "wavelength");
collimation.init(this, NOSAVE, "collimation");
scatterModelType.init(this, NOSAVE, "scatter_model_type");
type.init(this, NOSAVE, "type");
sampleRadius.init(this, NOSAVE, "sample_radius");
wantedType.init(this, NOSAVE, "wanted_type");
wantedType.setEnumeratedValues(type);
wantedType.setEnumeratedLabels(type);
m_d22settings.init(this, "settings");
m_driver.init(this, "driver");
}
AutoConfig::AutoConfig(const AutoConfig& controller) :
ExperimentController(controller), controller::Start(this), m_countSpy(nullptr) {
ExperimentController(controller), controller::Start(this), Apply(this),
m_countSpy(nullptr) {
}
AutoConfig::~AutoConfig() {
......@@ -154,9 +163,10 @@ void AutoConfig::start() {
// Set the request parameters.
request.set_instrumentname("D22");
request.mutable_parameters()->set_distance(m_d22settings->detPosition());
request.mutable_parameters()->set_wavelength(m_d22settings->wavelengthPosition());
request.mutable_parameters()->set_collimation(m_d22settings->colSetupPosition());
// Change to real values in the future?
request.mutable_parameters()->set_distance(m_d22settings->detPosition.setpoint());
request.mutable_parameters()->set_wavelength(m_d22settings->wavelengthPosition.setpoint());
request.mutable_parameters()->set_collimation(m_d22settings->colSetupPosition.setpoint());
request.set_type(lssautoconfig::NumorRequest_Type::NumorRequest_Type_Background);
......@@ -198,13 +208,38 @@ void AutoConfig::start() {
lssautoconfig::Response autoConfigResponse;
autoConfigResponse.ParseFromString(response);
distance = autoConfigResponse.mutable_parameters()->distance();
wavelength = autoConfigResponse.mutable_parameters()->wavelength();
collimation = autoConfigResponse.mutable_parameters()->collimation();
int size = autoConfigResponse.results_size();
resultSize = size;
type.resize(size);
distance.resize(size);
wavelength.resize(size);
collimation.resize(size);
for (int i = 0; i < size; ++i) {
type.set(i, autoConfigResponse.results(i).type());
distance.set(i, autoConfigResponse.results(i).parameters().distance());
wavelength.set(i, autoConfigResponse.results(i).parameters().wavelength());
collimation.set(i, autoConfigResponse.results(i).parameters().collimation());
}
scatterModelType = autoConfigResponse.scattermodeltype();
type = autoConfigResponse.type();
sampleRadius = autoConfigResponse.sampleradius();
}
void AutoConfig::apply() {
int32 size = resultSize();
for (int i = 0; i < size; ++i) {
if (type.get(i) == wantedType()) {
m_d22settings->detPosition.setpoint = distance.get(i);
m_d22settings->wavelengthPosition.setpoint = wavelength.get(i);
m_d22settings->colSetupPosition.setpoint = collimation.get(i); // check with tolerance
}
}
}
}
......@@ -27,8 +27,23 @@
namespace d22 {
class Apply : private controller::Command {
public:
Apply(ExperimentController * c) :
controller::Command(c, "apply", &Apply::apply, this) {
}
virtual void apply() = 0;
void applyCommand(bool logging = false) {
command(logging, true);
}
};
class AutoConfig : public ExperimentController,
public controller::Start {
public controller::Start,
public Apply {
public:
//! Type of controller
......@@ -41,17 +56,22 @@ public:
virtual void postConfiguration();
virtual void start();
virtual void apply();
Property<std::string> serverEndpoint;
Property<bool> initialized;
Property<float64> distance;
Property<float64> wavelength;
Property<float64> collimation;
Property<std::string> scatterModelType;
Property<std::string> type;
Property<float64> sampleRadius;
Property<int32> resultSize;
DynamicProperty<std::string> type;
DynamicProperty<float64> distance;
DynamicProperty<float64> wavelength;
DynamicProperty<float64> collimation;
Property<std::string> wantedType;
private:
bool initApplication();
......
......@@ -26,10 +26,15 @@ message NumorRequest {
required bytes data = 6;
}
message Response {
message Result {
required InstrumentParameters parameters = 1;
required string scatterModelType = 2;
required string type = 3;
required double sampleRadius = 4;
required string type = 2;
}
message Response {
required string scatterModelType = 1;
required double sampleRadius = 2;
repeated Result results = 3;
}
......@@ -4,4 +4,6 @@ d22_auto_config.collimationPrefix=Collimation
d22_auto_config.scatter_model_typePrefix=Scatter Model Type
d22_auto_config.typePrefix=Type
d22_auto_config.sample_radiusPrefix=Sample Radius
\ No newline at end of file
d22_auto_config.resultsPrefix=Results
d22_auto_config.applyPrefix=Apply
d22_auto_config.wantedTypePrefix=Type
\ No newline at end of file
......@@ -2,11 +2,16 @@
<controller type="d22_auto_config">
<property name="distance" type="float64"/>
<property name="wavelength" type="float64"/>
<property name="collimation" type="float64"/>
<property name="scatter_model_type" type="string"/>
<property name="type" type="string"/>
<property name="sample_radius" type="float64"/>
<property name="result_size" type="int32"/>
<dynamic_property name="type" type="string" size_property="result_size"/>
<dynamic_property name="distance" type="float64" size_property="result_size"/>
<dynamic_property name="wavelength" type="float64" size_property="result_size"/>
<dynamic_property name="collimation" type="float64" size_property="result_size"/>
<property name="wanted_type" type="string"/>
</controller>
<plugin>
<controller type="d22_auto_config" role="d22_auto_config1"/>
<table_composite nbColumns="2">
<simple_label prefix="d22_auto_config.distancePrefix"/>
<label role="d22_auto_config1" property="distance"/>
<simple_label prefix="d22_auto_config.wavelengthPrefix"/>
<label role="d22_auto_config1" property="wavelength"/>
<simple_label prefix="d22_auto_config.collimationPrefix"/>
<label role="d22_auto_config1" property="collimation"/>
<simple_label prefix="d22_auto_config.scatter_model_typePrefix"/>
<label role="d22_auto_config1" property="scatter_model_type"/>
<simple_label prefix="d22_auto_config.typePrefix"/>
<label role="d22_auto_config1" property="type"/>
<simple_label prefix="d22_auto_config.sample_radiusPrefix"/>
<label role="d22_auto_config1" property="sample_radius"/>
</table_composite>
<group title="d22_auto_config.resultsPrefix">
<table_composite nbColumns="2">
<simple_label prefix="d22_auto_config.scatter_model_typePrefix"/>
<label role="d22_auto_config1" property="scatter_model_type"/>
<simple_label prefix="d22_auto_config.sample_radiusPrefix"/>
<label role="d22_auto_config1" property="sample_radius"/>
</table_composite>
<newLine/>
<table_composite nbColumns="4">
<simple_label prefix="d22_auto_config.typePrefix" font_style="BOLD" hAlignment="center"/>
<simple_label prefix="d22_auto_config.distancePrefix" font_style="BOLD" hAlignment="center"/>
<simple_label prefix="d22_auto_config.wavelengthPrefix" font_style="BOLD" hAlignment="center"/>
<simple_label prefix="d22_auto_config.collimationPrefix" font_style="BOLD" hAlignment="center"/>
<dynamic_composite role="d22_auto_config1" properties="type,distance,collimation,wavelength">
<label role="d22_auto_config1" property="type" hAlignment="center"/>
<label role="d22_auto_config1" property="distance" hAlignment="center"/>
<label role="d22_auto_config1" property="collimation" hAlignment="center"/>
<label role="d22_auto_config1" property="wavelength" hAlignment="center"/>
</dynamic_composite>
</table_composite>
</group>
<newLine/>
<group title="d22_auto_config.applyPrefix">
<property_combo role="d22_auto_config1" property="wanted_type" prefix="d22_auto_config.wantedTypePrefix"/>
<button role="d22_auto_config1" command="apply" prefix="d22_auto_config.applyPrefix"/>
</group>
</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