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

Spy in VEXPController

parent e987655b
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
#include "controllers/common/axis/AxisController.h" #include "controllers/common/axis/AxisController.h"
#include "controllers/common/axis/VirtualAxisController.h" #include "controllers/common/axis/VirtualAxisController.h"
#include <rapidjson/stringbuffer.h>
#include <cameo/cameo.h> #include <cameo/cameo.h>
#include <memory> #include <memory>
#include <utility> #include <utility>
#include <thread> #include <thread>
#include <atomic> #include <atomic>
#include <rapidjson/stringbuffer.h>
namespace nomad3d { namespace nomad3d {
......
...@@ -18,15 +18,16 @@ ...@@ -18,15 +18,16 @@
#include "VEXPController.h" #include "VEXPController.h"
#include "controllers/common/family/Families.h" #include "controllers/common/family/Families.h"
#include <rapidjson/document.h> #include <rapidjson/document.h>
#include <rapidjson/prettywriter.h> #include <rapidjson/prettywriter.h>
#include <rapidjson/reader.h> #include <rapidjson/reader.h>
#include <rapidjson/stringbuffer.h> #include <rapidjson/stringbuffer.h>
#include <rapidjson/prettywriter.h>
#include <rapidjson/writer.h> #include <rapidjson/writer.h>
using namespace boost; using namespace cameo;
using namespace std; using namespace std;
using namespace rapidjson;
namespace vexp { namespace vexp {
...@@ -87,6 +88,8 @@ VEXPController::VEXPController(const string& name) : ...@@ -87,6 +88,8 @@ VEXPController::VEXPController(const string& name) :
errorMessage.init(this, NOSAVE, "error_message"); errorMessage.init(this, NOSAVE, "error_message");
moveModel.init(this, SAVE, "move_model"); moveModel.init(this, SAVE, "move_model");
spyPeriod.init(this, SAVE, "spy_period");
qhScan.init(this, NOSAVE, "qh_scan"); qhScan.init(this, NOSAVE, "qh_scan");
qkScan.init(this, NOSAVE, "qk_scan"); qkScan.init(this, NOSAVE, "qk_scan");
qlScan.init(this, NOSAVE, "ql_scan"); qlScan.init(this, NOSAVE, "ql_scan");
...@@ -127,6 +130,11 @@ VEXPController::VEXPController(const VEXPController& controller) : ...@@ -127,6 +130,11 @@ VEXPController::VEXPController(const VEXPController& controller) :
} }
VEXPController::~VEXPController() { VEXPController::~VEXPController() {
m_running.store(false);
if (m_periodicUpdateThread.get() != nullptr) {
m_periodicUpdateThread->join();
}
} }
void VEXPController::updateUMatrix() { void VEXPController::updateUMatrix() {
...@@ -191,37 +199,37 @@ void VEXPController::refreshFloat64PropertyToMoveModel(SimpleProperty<float64>& ...@@ -191,37 +199,37 @@ void VEXPController::refreshFloat64PropertyToMoveModel(SimpleProperty<float64>&
void VEXPController::updateScanReference(int index) { void VEXPController::updateScanReference(int index) {
if (index == 0) { if (index == 0) {
qhScan.update(scanController->reference.get(0)); updateFloat64PropertyValue(qhScan, scanController->reference.get(0));
} }
else if (index == 1) { else if (index == 1) {
qkScan.update(scanController->reference.get(1)); updateFloat64PropertyValue(qkScan, scanController->reference.get(1));
} }
else if (index == 2) { else if (index == 2) {
qlScan.update(scanController->reference.get(2)); updateFloat64PropertyValue(qlScan, scanController->reference.get(2));
} }
else if (index == 3) { else if (index == 3) {
enScan.update(scanController->reference.get(3)); updateFloat64PropertyValue(enScan, scanController->reference.get(3));
} }
} }
void VEXPController::updateScanDelta(int index) { void VEXPController::updateScanDelta(int index) {
if (index == 0) { if (index == 0) {
dqhScan.update(scanController->delta.get(0)); updateFloat64PropertyValue(dqhScan, scanController->delta.get(0));
} }
else if (index == 1) { else if (index == 1) {
dqkScan.update(scanController->delta.get(1)); updateFloat64PropertyValue(dqkScan, scanController->delta.get(1));
} }
else if (index == 2) { else if (index == 2) {
dqlScan.update(scanController->delta.get(2)); updateFloat64PropertyValue(dqlScan, scanController->delta.get(2));
} }
else if (index == 3) { else if (index == 3) {
denScan.update(scanController->delta.get(3)); updateFloat64PropertyValue(denScan, scanController->delta.get(3));
} }
} }
void VEXPController::updateNbPoints(int index) { void VEXPController::updateNbPoints(int index) {
nbPointsScan.update(scanController->nSteps.get(0)); updateInt32PropertyValue(nbPointsScan, scanController->nSteps.get(0));
} }
void VEXPController::updateScanStatus() { void VEXPController::updateScanStatus() {
...@@ -231,42 +239,42 @@ void VEXPController::updateScanStatus() { ...@@ -231,42 +239,42 @@ void VEXPController::updateScanStatus() {
if (running) { if (running) {
// Get ki, kf, fixed, ss when the scan is starting. // Get ki, kf, fixed, ss when the scan is starting.
kiScan = ki(); updateFloat64PropertyValue(kiScan, ki());
kfScan = kf(); updateFloat64PropertyValue(kfScan, kf());
fxScan = fx(); updateInt32PropertyValue(fxScan, fx());
ssScan = ss(); updateInt32PropertyValue(ssScan, ss());
} }
} }
void VEXPController::updateProperties() { void VEXPController::updateProperties() {
// Copy the values. // Copy the values.
as.update(tasSettings->as()); updateFloat64PropertyValue(as, tasSettings->as());
bs.update(tasSettings->bs()); updateFloat64PropertyValue(bs, tasSettings->bs());
cs.update(tasSettings->cs()); updateFloat64PropertyValue(cs, tasSettings->cs());
aa.update(tasSettings->aa()); updateFloat64PropertyValue(aa, tasSettings->aa());
bb.update(tasSettings->bb()); updateFloat64PropertyValue(bb, tasSettings->bb());
cc.update(tasSettings->cc()); updateFloat64PropertyValue(cc, tasSettings->cc());
ax.update(tasSettings->ax()); updateFloat64PropertyValue(ax, tasSettings->ax());
ay.update(tasSettings->ay()); updateFloat64PropertyValue(ay, tasSettings->ay());
az.update(tasSettings->az()); updateFloat64PropertyValue(az, tasSettings->az());
bx.update(tasSettings->bx()); updateFloat64PropertyValue(bx, tasSettings->bx());
by.update(tasSettings->by()); updateFloat64PropertyValue(by, tasSettings->by());
bz.update(tasSettings->bz()); updateFloat64PropertyValue(bz, tasSettings->bz());
updateUMatrix(); updateUMatrix();
updateBMatrix(); updateBMatrix();
qh.update(scattering->qh()); updateFloat64PropertyValue(qh, scattering->qh());
qk.update(scattering->qk()); updateFloat64PropertyValue(qk, scattering->qk());
ql.update(scattering->ql()); updateFloat64PropertyValue(ql, scattering->ql());
en.update(scattering->en()); updateFloat64PropertyValue(en, scattering->en());
qm.update(scattering->qm()); updateFloat64PropertyValue(qm, scattering->qm());
fx.update(scattering->fx()); updateInt32PropertyValue(fx, scattering->fx());
ss.update(scattering->sens()); updateInt32PropertyValue(ss, scattering->sens());
ki.update(incidentBeam->ki()); updateFloat64PropertyValue(ki, incidentBeam->ki());
kf.update(scatteredBeam->kf()); updateFloat64PropertyValue(kf, scatteredBeam->kf());
a1.update(a1Controller->position()); a1.update(a1Controller->position());
a2.update(a2Controller->position()); a2.update(a2Controller->position());
...@@ -276,49 +284,73 @@ void VEXPController::updateProperties() { ...@@ -276,49 +284,73 @@ void VEXPController::updateProperties() {
a5.update(a5Controller->position()); a5.update(a5Controller->position());
a6.update(a6Controller->position()); a6.update(a6Controller->position());
qhScan.update(scanController->reference.get(0)); updateFloat64PropertyValue(qhScan, scanController->reference.get(0));
qkScan.update(scanController->reference.get(1)); updateFloat64PropertyValue(qkScan, scanController->reference.get(1));
qlScan.update(scanController->reference.get(2)); updateFloat64PropertyValue(qlScan, scanController->reference.get(2));
enScan.update(scanController->reference.get(3)); updateFloat64PropertyValue(enScan, scanController->reference.get(3));
dqhScan.update(scanController->delta.get(0)); updateFloat64PropertyValue(dqhScan, scanController->delta.get(0));
dqkScan.update(scanController->delta.get(1)); updateFloat64PropertyValue(dqkScan, scanController->delta.get(1));
dqlScan.update(scanController->delta.get(2)); updateFloat64PropertyValue(dqlScan, scanController->delta.get(2));
denScan.update(scanController->delta.get(3)); updateFloat64PropertyValue(denScan, scanController->delta.get(3));
nbPointsScan.update(scanController->nSteps.get(0)); updateInt32PropertyValue(nbPointsScan, scanController->nSteps.get(0));
runningScan.update(scanController->commandStatus.isRunning()); runningScan.update(scanController->commandStatus.isRunning());
} }
void VEXPController::updateFloat64PropertyValue(SimpleProperty<float64>& property, float64 value) {
property.update(value);
}
void VEXPController::updateFloat64Property(SimpleProperty<float64>& property, SimpleProperty<float64>& sourceProperty) {
updateFloat64PropertyValue(property, sourceProperty());
}
void VEXPController::updateInt32PropertyValue(SimpleProperty<int32>& property, int32 value) {
property.update(value);
}
void VEXPController::updateInt32Property(SimpleProperty<int32>& property, SimpleProperty<int32>& sourceProperty) {
updateInt32PropertyValue(property, sourceProperty());
}
void VEXPController::registerFloat64PropertyUpdater(SimpleProperty<float64>& property, SimpleProperty<float64>& targetProperty) {
registerUpdater(property, &VEXPController::updateFloat64Property, this, targetProperty, property);
}
void VEXPController::registerInt32PropertyUpdater(SimpleProperty<int32>& property, SimpleProperty<int32>& targetProperty) {
registerUpdater(property, &VEXPController::updateInt32Property, this, targetProperty, property);
}
void VEXPController::postConfiguration() { void VEXPController::postConfiguration() {
// Register the property updaters. // Register the property updaters.
registerPropertyCopierByUpdate(tasSettings->as, as); registerFloat64PropertyUpdater(tasSettings->as, as);
registerPropertyCopierByUpdate(tasSettings->bs, bs); registerFloat64PropertyUpdater(tasSettings->bs, bs);
registerPropertyCopierByUpdate(tasSettings->cs, cs); registerFloat64PropertyUpdater(tasSettings->cs, cs);
registerPropertyCopierByUpdate(tasSettings->aa, aa); registerFloat64PropertyUpdater(tasSettings->aa, aa);
registerPropertyCopierByUpdate(tasSettings->bb, bb); registerFloat64PropertyUpdater(tasSettings->bb, bb);
registerPropertyCopierByUpdate(tasSettings->cc, cc); registerFloat64PropertyUpdater(tasSettings->cc, cc);
registerPropertyCopierByUpdate(tasSettings->ax, ax); registerFloat64PropertyUpdater(tasSettings->ax, ax);
registerPropertyCopierByUpdate(tasSettings->ay, ay); registerFloat64PropertyUpdater(tasSettings->ay, ay);
registerPropertyCopierByUpdate(tasSettings->az, az); registerFloat64PropertyUpdater(tasSettings->az, az);
registerPropertyCopierByUpdate(tasSettings->bx, bx); registerFloat64PropertyUpdater(tasSettings->bx, bx);
registerPropertyCopierByUpdate(tasSettings->by, by); registerFloat64PropertyUpdater(tasSettings->by, by);
registerPropertyCopierByUpdate(tasSettings->bz, bz); registerFloat64PropertyUpdater(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, qh); registerFloat64PropertyUpdater(scattering->qh, qh);
registerPropertyCopierByUpdate(scattering->qk, qk); registerFloat64PropertyUpdater(scattering->qk, qk);
registerPropertyCopierByUpdate(scattering->ql, ql); registerFloat64PropertyUpdater(scattering->ql, ql);
registerPropertyCopierByUpdate(scattering->en, en); registerFloat64PropertyUpdater(scattering->en, en);
registerPropertyCopierByUpdate(scattering->qm, qm); registerFloat64PropertyUpdater(scattering->qm, qm);
registerPropertyCopierByUpdate(scattering->fx, fx); registerInt32PropertyUpdater(scattering->fx, fx);
registerPropertyCopierByUpdate(scattering->sens, ss); registerInt32PropertyUpdater(scattering->sens, ss);
registerPropertyCopierByUpdate(incidentBeam->ki, ki); registerFloat64PropertyUpdater(incidentBeam->ki, ki);
registerPropertyCopierByUpdate(scatteredBeam->kf, kf); registerFloat64PropertyUpdater(scatteredBeam->kf, kf);
registerPropertyCopierByUpdate(a1Controller->position, a1); registerPropertyCopierByUpdate(a1Controller->position, a1);
registerPropertyCopierByUpdate(a2Controller->position, a2); registerPropertyCopierByUpdate(a2Controller->position, a2);
...@@ -348,6 +380,11 @@ void VEXPController::postConfiguration() { ...@@ -348,6 +380,11 @@ void VEXPController::postConfiguration() {
registerStatus(scanController, &VEXPController::updateScanStatus, this); registerStatus(scanController, &VEXPController::updateScanStatus, this);
updateProperties(); updateProperties();
m_spyPublisher = application::Publisher::create("vexp_spy");
m_running.store(true);
m_periodicUpdateThread.reset(new std::thread(std::bind(&VEXPController::periodicUpdate, this)));
} }
void VEXPController::calculate(float64 ki, float64 kf, float64 qh, float64 qk, float64 ql, int32 fx, int32 ss) { void VEXPController::calculate(float64 ki, float64 kf, float64 qh, float64 qk, float64 ql, int32 fx, int32 ss) {
...@@ -442,4 +479,73 @@ void VEXPController::calculate(float64 ki, float64 kf, float64 qh, float64 qk, f ...@@ -442,4 +479,73 @@ void VEXPController::calculate(float64 ki, float64 kf, float64 qh, float64 qk, f
// } // }
} }
std::string VEXPController::getSpyData() {
PrettyWriter<StringBuffer> writer(s);
s.Clear();
writer.StartObject();
writer.Key("as"); writer.Double(as());
writer.Key("bs"); writer.Double(bs());
writer.Key("cs"); writer.Double(cs());
writer.Key("aa"); writer.Double(aa());
writer.Key("bb"); writer.Double(bb());
writer.Key("cc"); writer.Double(cc());
writer.Key("ax"); writer.Double(ax());
writer.Key("ay"); writer.Double(ay());
writer.Key("az"); writer.Double(az());
writer.Key("bx"); writer.Double(bx());
writer.Key("by"); writer.Double(by());
writer.Key("bz"); writer.Double(bz());
writer.Key("qh"); writer.Double(qh());
writer.Key("qk"); writer.Double(qk());
writer.Key("ql"); writer.Double(ql());
writer.Key("en"); writer.Double(en());
writer.Key("qm"); writer.Double(qm());
writer.Key("fx"); writer.Int(fx());
writer.Key("ss"); writer.Int(ss());
writer.Key("ki"); writer.Double(ki());
writer.Key("kf"); writer.Double(kf());
writer.Key("qhScan"); writer.Double(qhScan());
writer.Key("qkScan"); writer.Double(qkScan());
writer.Key("qlScan"); writer.Double(qlScan());
writer.Key("enScan"); writer.Double(enScan());
writer.Key("dqhScan"); writer.Double(dqhScan());
writer.Key("dqkScan"); writer.Double(dqkScan());
writer.Key("dqlScan"); writer.Double(dqlScan());
writer.Key("denScan"); writer.Double(denScan());
writer.Key("nbPointsScan"); writer.Int(nbPointsScan());
writer.Key("kiScan"); writer.Double(kiScan());
writer.Key("kfScan"); writer.Double(kfScan());
writer.Key("fxScan"); writer.Int(fxScan());
writer.Key("ssScan"); writer.Int(ssScan());
writer.EndObject();
return s.GetString();
}
void VEXPController::periodicUpdate() {
while (m_running.load()) {
std::this_thread::yield();
std::this_thread::sleep_for(std::chrono::seconds(spyPeriod()));
std::lock_guard<std::mutex> lock(m_publisherMutex);
// Send using the publisher.
string spyData = getSpyData();
m_spyPublisher->send(spyData);
}
}
} }
...@@ -25,10 +25,12 @@ ...@@ -25,10 +25,12 @@
#include "controllers/tas/common/IncidentBeam.h" #include "controllers/tas/common/IncidentBeam.h"
#include "controllers/tas/common/TasScatteredBeam.h" #include "controllers/tas/common/TasScatteredBeam.h"
#include "controllers/common/scanlegacy/ParameterizableScan1D.h" #include "controllers/common/scanlegacy/ParameterizableScan1D.h"
#include <boost/thread/thread.hpp> #include <cameo/cameo.h>
#include <boost/thread/condition.hpp> #include <rapidjson/stringbuffer.h>
#include <boost/thread/mutex.hpp>
#include <memory> #include <memory>
#include <unordered_map>
#include <thread>
#include <atomic>
namespace vexp { namespace vexp {
...@@ -63,6 +65,14 @@ public: ...@@ -63,6 +65,14 @@ public:
void updateProperties(); void updateProperties();
void updateFloat64PropertyValue(SimpleProperty<float64>& property, float64 value);
void updateFloat64Property(SimpleProperty<float64>& property, SimpleProperty<float64>& sourceProperty);
void updateInt32PropertyValue(SimpleProperty<int32>& property, int32 value);
void updateInt32Property(SimpleProperty<int32>& property, SimpleProperty<int32>& sourceProperty);
void registerFloat64PropertyUpdater(SimpleProperty<float64>& property, SimpleProperty<float64>& targetProperty);
void registerInt32PropertyUpdater(SimpleProperty<int32>& property, SimpleProperty<int32>& targetProperty);
void updateScanReference(int index); void updateScanReference(int index);
void updateScanDelta(int index); void updateScanDelta(int index);
void updateNbPoints(int index); void updateNbPoints(int index);
...@@ -72,6 +82,10 @@ public: ...@@ -72,6 +82,10 @@ public:
void calculate(float64 ki, float64 kf, float64 qh, float64 qk, float64 ql, int32 fx, int32 ss); void calculate(float64 ki, float64 kf, float64 qh, float64 qk, float64 ql, int32 fx, int32 ss);
void periodicUpdate();
std::string getSpyData();
Property<float64> as; Property<float64> as;
Property<float64> bs; Property<float64> bs;
Property<float64> cs; Property<float64> cs;
...@@ -143,6 +157,15 @@ public: ...@@ -143,6 +157,15 @@ public:
Property<int32> nbPointsScan; Property<int32> nbPointsScan;
Property<bool> runningScan; Property<bool> runningScan;
// Spy.
Property<int32> spyPeriod;
rapidjson::StringBuffer s;
std::atomic<bool> m_running;
std::unique_ptr<cameo::application::Publisher> m_spyPublisher;
std::mutex m_publisherMutex;
std::unique_ptr<std::thread> m_periodicUpdateThread;
// Controllers. // Controllers.
ControllerPtr<tas::TasSettings> tasSettings; ControllerPtr<tas::TasSettings> tasSettings;
ControllerPtr<tas::Sample> sample; ControllerPtr<tas::Sample> sample;
......
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