Commit e1436d9c authored by legoc's avatar legoc
Browse files

Removed calculate loop in VEXPController, using the calca1, calca2, ...

from IncidentBeam and TasScatteredBeam.
parent 9214b370
...@@ -25,9 +25,6 @@ namespace vexp { ...@@ -25,9 +25,6 @@ namespace vexp {
const string VEXPController::TYPE = "vexp_controller"; const string VEXPController::TYPE = "vexp_controller";
const int32 VEXPController::PARAMETERS_OK = 1;
const int32 VEXPController::BAD_PARAMETERS = 2;
VEXPController::VEXPController(const string& name) : VEXPController::VEXPController(const string& name) :
ExperimentController(name), m_running(true), m_errorDuringCalculation(false) { ExperimentController(name), m_running(true), m_errorDuringCalculation(false) {
...@@ -66,7 +63,7 @@ VEXPController::VEXPController(const string& name) : ...@@ -66,7 +63,7 @@ VEXPController::VEXPController(const string& name) :
a5.init(this, NOSAVE, "a5"); a5.init(this, NOSAVE, "a5");
a6.init(this, NOSAVE, "a6"); a6.init(this, NOSAVE, "a6");
state.init(this, NOSAVE, "state"); calculationStatus.init(this, NOSAVE, "calculation_status");
errorMessage.init(this, NOSAVE, "error_message"); errorMessage.init(this, NOSAVE, "error_message");
tasSettings.init(this, "tas_settings"); tasSettings.init(this, "tas_settings");
...@@ -97,7 +94,7 @@ VEXPController::~VEXPController() { ...@@ -97,7 +94,7 @@ VEXPController::~VEXPController() {
m_waitCondition.notify_one(); m_waitCondition.notify_one();
} }
if (m_loopThread.get() != NULL) { if (m_loopThread.get() != 0) {
m_loopThread->join(); m_loopThread->join();
}} }}
...@@ -113,6 +110,30 @@ void VEXPController::updateBMatrix() { ...@@ -113,6 +110,30 @@ void VEXPController::updateBMatrix() {
b.sendEvent(); b.sendEvent();
} }
void VEXPController::refreshKi(float64 value) {
// calca1, calca2, calcStatus are calculated by refresh.
incidentBeam->calcki = value;
a1 = incidentBeam->calca1();
a2 = incidentBeam->calca2();
// Copy the status.
calculationStatus.set(incidentBeam->calcStatus);
}
void VEXPController::refreshKf(float64 value) {
// calca1, calca2, calcStatus are calculated by refresh.
scatteredBeam->calckf = value;
a5 = scatteredBeam->calca5();
a6 = scatteredBeam->calca6();
// Copy the status.
calculationStatus.set(scatteredBeam->calcStatus);
}
void VEXPController::refreshFloat64Property(SimpleProperty<float64>& property, float64 value) { void VEXPController::refreshFloat64Property(SimpleProperty<float64>& property, float64 value) {
// Update the value. // Update the value.
...@@ -144,67 +165,74 @@ void VEXPController::postConfiguration() { ...@@ -144,67 +165,74 @@ void VEXPController::postConfiguration() {
updateUMatrix(); updateUMatrix();
updateBMatrix(); updateBMatrix();
qh.update(scattering->qh.setpoint()); // Not used anymore
qk.update(scattering->qk.setpoint());
ql.update(scattering->ql.setpoint()); // qh.update(scattering->qh.setpoint());
en.update(scattering->en.setpoint()); // qk.update(scattering->qk.setpoint());
qm.update(scattering->qm.setpoint()); // ql.update(scattering->ql.setpoint());
// en.update(scattering->en.setpoint());
ki.update(incidentBeam->ki.setpoint()); // qm.update(scattering->qm.setpoint());
kf.update(scatteredBeam->kf.setpoint()); //
// ki.update(incidentBeam->ki.setpoint());
a1.update(a1Controller->position.setpoint()); // kf.update(scatteredBeam->kf.setpoint());
a2.update(a2Controller->position.setpoint()); //
a3.update(a3Controller->position.setpoint()); // a1.update(a1Controller->position.setpoint());
a4.update(a4Controller->position.setpoint()); // a2.update(a2Controller->position.setpoint());
a5.update(a5Controller->position.setpoint()); // a3.update(a3Controller->position.setpoint());
a6.update(a6Controller->position.setpoint()); // a4.update(a4Controller->position.setpoint());
// a5.update(a5Controller->position.setpoint());
// Register the property updaters. // a6.update(a6Controller->position.setpoint());
registerPropertyCopierByUpdate(tasSettings->as, as); //
registerPropertyCopierByUpdate(tasSettings->bs, bs); // // Register the property updaters.
registerPropertyCopierByUpdate(tasSettings->cs, cs); // registerPropertyCopierByUpdate(tasSettings->as, as);
registerPropertyCopierByUpdate(tasSettings->aa, aa); // registerPropertyCopierByUpdate(tasSettings->bs, bs);
registerPropertyCopierByUpdate(tasSettings->bb, bb); // registerPropertyCopierByUpdate(tasSettings->cs, cs);
registerPropertyCopierByUpdate(tasSettings->cc, cc); // registerPropertyCopierByUpdate(tasSettings->aa, aa);
registerPropertyCopierByUpdate(tasSettings->ax, ax); // registerPropertyCopierByUpdate(tasSettings->bb, bb);
registerPropertyCopierByUpdate(tasSettings->ay, ay); // registerPropertyCopierByUpdate(tasSettings->cc, cc);
registerPropertyCopierByUpdate(tasSettings->az, az); // registerPropertyCopierByUpdate(tasSettings->ax, ax);
registerPropertyCopierByUpdate(tasSettings->bx, bx); // registerPropertyCopierByUpdate(tasSettings->ay, ay);
registerPropertyCopierByUpdate(tasSettings->by, by); // registerPropertyCopierByUpdate(tasSettings->az, az);
registerPropertyCopierByUpdate(tasSettings->bz, bz); // registerPropertyCopierByUpdate(tasSettings->bx, bx);
// registerPropertyCopierByUpdate(tasSettings->by, by);
// registerPropertyCopierByUpdate(tasSettings->bz, bz);
registerUpdater(sample->uRef, &VEXPController::updateUMatrix, this); registerUpdater(sample->uRef, &VEXPController::updateUMatrix, this);
registerUpdater(sample->b, &VEXPController::updateBMatrix, this); registerUpdater(sample->b, &VEXPController::updateBMatrix, this);
registerPropertyCopierByUpdate(scattering->qh.setpoint, qh); // Not used anymore
registerPropertyCopierByUpdate(scattering->qk.setpoint, qk);
registerPropertyCopierByUpdate(scattering->ql.setpoint, ql); // registerPropertyCopierByUpdate(scattering->qh.setpoint, qh);
registerPropertyCopierByUpdate(scattering->en.setpoint, en); // registerPropertyCopierByUpdate(scattering->qk.setpoint, qk);
registerPropertyCopierByUpdate(scattering->qm.setpoint, qm); // registerPropertyCopierByUpdate(scattering->ql.setpoint, ql);
// registerPropertyCopierByUpdate(scattering->en.setpoint, en);
registerPropertyCopierByUpdate(incidentBeam->ki.setpoint, ki); // registerPropertyCopierByUpdate(scattering->qm.setpoint, qm);
registerPropertyCopierByUpdate(scatteredBeam->kf.setpoint, kf); //
// registerPropertyCopierByUpdate(incidentBeam->ki.setpoint, ki);
registerPropertyCopierByUpdate(a1Controller->position.setpoint, a1); // registerPropertyCopierByUpdate(scatteredBeam->kf.setpoint, kf);
registerPropertyCopierByUpdate(a2Controller->position.setpoint, a2); //
registerPropertyCopierByUpdate(a3Controller->position.setpoint, a3); // registerPropertyCopierByUpdate(a1Controller->position.setpoint, a1);
registerPropertyCopierByUpdate(a4Controller->position.setpoint, a4); // registerPropertyCopierByUpdate(a2Controller->position.setpoint, a2);
registerPropertyCopierByUpdate(a5Controller->position.setpoint, a5); // registerPropertyCopierByUpdate(a3Controller->position.setpoint, a3);
registerPropertyCopierByUpdate(a6Controller->position.setpoint, a6); // registerPropertyCopierByUpdate(a4Controller->position.setpoint, a4);
// registerPropertyCopierByUpdate(a5Controller->position.setpoint, a5);
// Register the refreshers. // registerPropertyCopierByUpdate(a6Controller->position.setpoint, a6);
registerRefresher(qh, &VEXPController::refreshFloat64Property, this, scattering->qh.setpoint); //
registerRefresher(qk, &VEXPController::refreshFloat64Property, this, scattering->qk.setpoint); // // Register the refreshers.
registerRefresher(ql, &VEXPController::refreshFloat64Property, this, scattering->ql.setpoint); // registerRefresher(qh, &VEXPController::refreshFloat64Property, this, scattering->qh.setpoint);
registerRefresher(en, &VEXPController::refreshFloat64Property, this, scattering->en.setpoint); // registerRefresher(qk, &VEXPController::refreshFloat64Property, this, scattering->qk.setpoint);
registerRefresher(qm, &VEXPController::refreshFloat64Property, this, scattering->qm.setpoint); // registerRefresher(ql, &VEXPController::refreshFloat64Property, this, scattering->ql.setpoint);
// registerRefresher(en, &VEXPController::refreshFloat64Property, this, scattering->en.setpoint);
registerRefresher(ki, &VEXPController::refreshFloat64Property, this, incidentBeam->ki.setpoint); // registerRefresher(qm, &VEXPController::refreshFloat64Property, this, scattering->qm.setpoint);
registerRefresher(kf, &VEXPController::refreshFloat64Property, this, scatteredBeam->kf.setpoint); //
// registerRefresher(ki, &VEXPController::refreshFloat64Property, this, incidentBeam->ki.setpoint);
// Start the thread. // registerRefresher(kf, &VEXPController::refreshFloat64Property, this, scatteredBeam->kf.setpoint);
m_loopThread.reset(new thread(bind(&VEXPController::loop, this)));
registerRefresher(ki, &VEXPController::refreshKi, this);
registerRefresher(kf, &VEXPController::refreshKf, this);
// // Start the thread.
// m_loopThread.reset(new thread(bind(&VEXPController::loop, this)));
} }
void VEXPController::loop() { void VEXPController::loop() {
...@@ -238,10 +266,10 @@ void VEXPController::calculate() { ...@@ -238,10 +266,10 @@ void VEXPController::calculate() {
// Check if an error occurred. // Check if an error occurred.
if (m_errorDuringCalculation) { if (m_errorDuringCalculation) {
state = BAD_PARAMETERS; //state = BAD_PARAMETERS;
} }
else { else {
state = PARAMETERS_OK; //state = PARAMETERS_OK;
} }
cout << "Calculate in " << (common::Date() - begin).getMilliseconds() << "ms" << endl; cout << "Calculate in " << (common::Date() - begin).getMilliseconds() << "ms" << endl;
......
...@@ -44,6 +44,11 @@ public: ...@@ -44,6 +44,11 @@ public:
void updateUMatrix(); void updateUMatrix();
void updateBMatrix(); void updateBMatrix();
void refreshKi(float64 value);
void refreshKf(float64 value);
// Not used anymore.
void refreshFloat64Property(SimpleProperty<float64>& property, float64 value); void refreshFloat64Property(SimpleProperty<float64>& property, float64 value);
virtual void postConfiguration(); virtual void postConfiguration();
...@@ -80,7 +85,7 @@ public: ...@@ -80,7 +85,7 @@ public:
Property<float64> a5; Property<float64> a5;
Property<float64> a6; Property<float64> a6;
Property<int32> state; StatusProperty calculationStatus;
Property<std::string> errorMessage; Property<std::string> errorMessage;
ControllerPtr<tas::TasSettings> tasSettings; ControllerPtr<tas::TasSettings> tasSettings;
...@@ -102,14 +107,11 @@ protected: ...@@ -102,14 +107,11 @@ protected:
virtual void updateError(ChangeAspect* aspect); virtual void updateError(ChangeAspect* aspect);
std::auto_ptr<boost::thread> m_loopThread; std::auto_ptr<boost::thread> m_loopThread; // Not used
boost::mutex m_mutex; boost::mutex m_mutex;
boost::condition m_waitCondition; boost::condition m_waitCondition;
bool m_running; bool m_running;
bool m_errorDuringCalculation; bool m_errorDuringCalculation;
static const int32 PARAMETERS_OK;
static const int32 BAD_PARAMETERS;
}; };
} }
......
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