Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
NomadSpecialModules
Commits
d3286b86
Commit
d3286b86
authored
Jan 02, 2020
by
yannick legoc
Browse files
Spy in VEXPController
parent
e987655b
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/controllers/nomad3d/Nomad3DController.h
View file @
d3286b86
...
...
@@ -21,12 +21,12 @@
#include "controllers/common/axis/AxisController.h"
#include "controllers/common/axis/VirtualAxisController.h"
#include <rapidjson/stringbuffer.h>
#include <cameo/cameo.h>
#include <memory>
#include <utility>
#include <thread>
#include <atomic>
#include <rapidjson/stringbuffer.h>
namespace
nomad3d
{
...
...
src/controllers/vexp/VEXPController.cpp
View file @
d3286b86
...
...
@@ -18,15 +18,16 @@
#include "VEXPController.h"
#include "controllers/common/family/Families.h"
#include <rapidjson/document.h>
#include <rapidjson/prettywriter.h>
#include <rapidjson/reader.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/prettywriter.h>
#include <rapidjson/writer.h>
using
namespace
boost
;
using
namespace
cameo
;
using
namespace
std
;
using
namespace
rapidjson
;
namespace
vexp
{
...
...
@@ -87,6 +88,8 @@ VEXPController::VEXPController(const string& name) :
errorMessage
.
init
(
this
,
NOSAVE
,
"error_message"
);
moveModel
.
init
(
this
,
SAVE
,
"move_model"
);
spyPeriod
.
init
(
this
,
SAVE
,
"spy_period"
);
qhScan
.
init
(
this
,
NOSAVE
,
"qh_scan"
);
qkScan
.
init
(
this
,
NOSAVE
,
"qk_scan"
);
qlScan
.
init
(
this
,
NOSAVE
,
"ql_scan"
);
...
...
@@ -127,6 +130,11 @@ VEXPController::VEXPController(const VEXPController& controller) :
}
VEXPController
::~
VEXPController
()
{
m_running
.
store
(
false
);
if
(
m_periodicUpdateThread
.
get
()
!=
nullptr
)
{
m_periodicUpdateThread
->
join
();
}
}
void
VEXPController
::
updateUMatrix
()
{
...
...
@@ -191,37 +199,37 @@ void VEXPController::refreshFloat64PropertyToMoveModel(SimpleProperty<float64>&
void
VEXPController
::
updateScanReference
(
int
index
)
{
if
(
index
==
0
)
{
qhScan
.
update
(
scanController
->
reference
.
get
(
0
));
updateFloat64PropertyValue
(
qhScan
,
scanController
->
reference
.
get
(
0
));
}
else
if
(
index
==
1
)
{
qkScan
.
update
(
scanController
->
reference
.
get
(
1
));
updateFloat64PropertyValue
(
qkScan
,
scanController
->
reference
.
get
(
1
));
}
else
if
(
index
==
2
)
{
qlScan
.
update
(
scanController
->
reference
.
get
(
2
));
updateFloat64PropertyValue
(
qlScan
,
scanController
->
reference
.
get
(
2
));
}
else
if
(
index
==
3
)
{
enScan
.
update
(
scanController
->
reference
.
get
(
3
));
updateFloat64PropertyValue
(
enScan
,
scanController
->
reference
.
get
(
3
));
}
}
void
VEXPController
::
updateScanDelta
(
int
index
)
{
if
(
index
==
0
)
{
dqhScan
.
update
(
scanController
->
delta
.
get
(
0
));
updateFloat64PropertyValue
(
dqhScan
,
scanController
->
delta
.
get
(
0
));
}
else
if
(
index
==
1
)
{
dqkScan
.
update
(
scanController
->
delta
.
get
(
1
));
updateFloat64PropertyValue
(
dqkScan
,
scanController
->
delta
.
get
(
1
));
}
else
if
(
index
==
2
)
{
dqlScan
.
update
(
scanController
->
delta
.
get
(
2
));
updateFloat64PropertyValue
(
dqlScan
,
scanController
->
delta
.
get
(
2
));
}
else
if
(
index
==
3
)
{
denScan
.
update
(
scanController
->
delta
.
get
(
3
));
updateFloat64PropertyValue
(
denScan
,
scanController
->
delta
.
get
(
3
));
}
}
void
VEXPController
::
updateNbPoints
(
int
index
)
{
nbPointsScan
.
update
(
scanController
->
nSteps
.
get
(
0
));
updateInt32PropertyValue
(
nbPointsScan
,
scanController
->
nSteps
.
get
(
0
));
}
void
VEXPController
::
updateScanStatus
()
{
...
...
@@ -231,42 +239,42 @@ void VEXPController::updateScanStatus() {
if
(
running
)
{
// Get ki, kf, fixed, ss when the scan is starting.
kiScan
=
ki
();
kfScan
=
kf
();
fxScan
=
fx
();
ssScan
=
ss
();
updateFloat64PropertyValue
(
kiScan
,
ki
()
)
;
updateFloat64PropertyValue
(
kfScan
,
kf
()
)
;
updateInt32PropertyValue
(
fxScan
,
fx
()
)
;
updateInt32PropertyValue
(
ssScan
,
ss
()
)
;
}
}
void
VEXPController
::
updateProperties
()
{
// Copy the values.
as
.
update
(
tasSettings
->
as
());
bs
.
update
(
tasSettings
->
bs
());
cs
.
update
(
tasSettings
->
cs
());
aa
.
update
(
tasSettings
->
aa
());
bb
.
update
(
tasSettings
->
bb
());
cc
.
update
(
tasSettings
->
cc
());
ax
.
update
(
tasSettings
->
ax
());
ay
.
update
(
tasSettings
->
ay
());
az
.
update
(
tasSettings
->
az
());
bx
.
update
(
tasSettings
->
bx
());
by
.
update
(
tasSettings
->
by
());
bz
.
update
(
tasSettings
->
bz
());
update
Float64PropertyValue
(
as
,
tasSettings
->
as
());
update
Float64PropertyValue
(
bs
,
tasSettings
->
bs
());
update
Float64PropertyValue
(
cs
,
tasSettings
->
cs
());
update
Float64PropertyValue
(
aa
,
tasSettings
->
aa
());
update
Float64PropertyValue
(
bb
,
tasSettings
->
bb
());
update
Float64PropertyValue
(
cc
,
tasSettings
->
cc
());
update
Float64PropertyValue
(
ax
,
tasSettings
->
ax
());
update
Float64PropertyValue
(
ay
,
tasSettings
->
ay
());
update
Float64PropertyValue
(
az
,
tasSettings
->
az
());
update
Float64PropertyValue
(
bx
,
tasSettings
->
bx
());
update
Float64PropertyValue
(
by
,
tasSettings
->
by
());
update
Float64PropertyValue
(
bz
,
tasSettings
->
bz
());
updateUMatrix
();
updateBMatrix
();
qh
.
update
(
scattering
->
qh
());
qk
.
update
(
scattering
->
qk
());
ql
.
update
(
scattering
->
ql
());
en
.
update
(
scattering
->
en
());
qm
.
update
(
scattering
->
qm
());
fx
.
update
(
scattering
->
fx
());
ss
.
update
(
scattering
->
sens
());
update
Float64PropertyValue
(
qh
,
scattering
->
qh
());
update
Float64PropertyValue
(
qk
,
scattering
->
qk
());
update
Float64PropertyValue
(
ql
,
scattering
->
ql
());
update
Float64PropertyValue
(
en
,
scattering
->
en
());
update
Float64PropertyValue
(
qm
,
scattering
->
qm
());
update
Int32PropertyValue
(
fx
,
scattering
->
fx
());
update
Int32PropertyValue
(
ss
,
scattering
->
sens
());
ki
.
update
(
incidentBeam
->
ki
());
kf
.
update
(
scatteredBeam
->
kf
());
update
Float64PropertyValue
(
ki
,
incidentBeam
->
ki
());
update
Float64PropertyValue
(
kf
,
scatteredBeam
->
kf
());
a1
.
update
(
a1Controller
->
position
());
a2
.
update
(
a2Controller
->
position
());
...
...
@@ -276,49 +284,73 @@ void VEXPController::updateProperties() {
a5
.
update
(
a5Controller
->
position
());
a6
.
update
(
a6Controller
->
position
());
qhScan
.
update
(
scanController
->
reference
.
get
(
0
));
qkScan
.
update
(
scanController
->
reference
.
get
(
1
));
qlScan
.
update
(
scanController
->
reference
.
get
(
2
));
enScan
.
update
(
scanController
->
reference
.
get
(
3
));
updateFloat64PropertyValue
(
qhScan
,
scanController
->
reference
.
get
(
0
));
updateFloat64PropertyValue
(
qkScan
,
scanController
->
reference
.
get
(
1
));
updateFloat64PropertyValue
(
qlScan
,
scanController
->
reference
.
get
(
2
));
updateFloat64PropertyValue
(
enScan
,
scanController
->
reference
.
get
(
3
));
dqhScan
.
update
(
scanController
->
delta
.
get
(
0
));
dqkScan
.
update
(
scanController
->
delta
.
get
(
1
));
dqlScan
.
update
(
scanController
->
delta
.
get
(
2
));
denScan
.
update
(
scanController
->
delta
.
get
(
3
));
updateFloat64PropertyValue
(
dqhScan
,
scanController
->
delta
.
get
(
0
));
updateFloat64PropertyValue
(
dqkScan
,
scanController
->
delta
.
get
(
1
));
updateFloat64PropertyValue
(
dqlScan
,
scanController
->
delta
.
get
(
2
));
updateFloat64PropertyValue
(
denScan
,
scanController
->
delta
.
get
(
3
));
nbPointsScan
.
update
(
scanController
->
nSteps
.
get
(
0
));
updateInt32PropertyValue
(
nbPointsScan
,
scanController
->
nSteps
.
get
(
0
));
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
()
{
// Register the property updaters.
registerProperty
CopierBy
Update
(
tasSettings
->
as
,
as
);
registerProperty
CopierBy
Update
(
tasSettings
->
bs
,
bs
);
registerProperty
CopierBy
Update
(
tasSettings
->
cs
,
cs
);
registerProperty
CopierBy
Update
(
tasSettings
->
aa
,
aa
);
registerProperty
CopierBy
Update
(
tasSettings
->
bb
,
bb
);
registerProperty
CopierBy
Update
(
tasSettings
->
cc
,
cc
);
registerProperty
CopierBy
Update
(
tasSettings
->
ax
,
ax
);
registerProperty
CopierBy
Update
(
tasSettings
->
ay
,
ay
);
registerProperty
CopierBy
Update
(
tasSettings
->
az
,
az
);
registerProperty
CopierBy
Update
(
tasSettings
->
bx
,
bx
);
registerProperty
CopierBy
Update
(
tasSettings
->
by
,
by
);
registerProperty
CopierBy
Update
(
tasSettings
->
bz
,
bz
);
register
Float64
PropertyUpdate
r
(
tasSettings
->
as
,
as
);
register
Float64
PropertyUpdate
r
(
tasSettings
->
bs
,
bs
);
register
Float64
PropertyUpdate
r
(
tasSettings
->
cs
,
cs
);
register
Float64
PropertyUpdate
r
(
tasSettings
->
aa
,
aa
);
register
Float64
PropertyUpdate
r
(
tasSettings
->
bb
,
bb
);
register
Float64
PropertyUpdate
r
(
tasSettings
->
cc
,
cc
);
register
Float64
PropertyUpdate
r
(
tasSettings
->
ax
,
ax
);
register
Float64
PropertyUpdate
r
(
tasSettings
->
ay
,
ay
);
register
Float64
PropertyUpdate
r
(
tasSettings
->
az
,
az
);
register
Float64
PropertyUpdate
r
(
tasSettings
->
bx
,
bx
);
register
Float64
PropertyUpdate
r
(
tasSettings
->
by
,
by
);
register
Float64
PropertyUpdate
r
(
tasSettings
->
bz
,
bz
);
registerUpdater
(
sample
->
uRef
,
&
VEXPController
::
updateUMatrix
,
this
);
registerUpdater
(
sample
->
b
,
&
VEXPController
::
updateBMatrix
,
this
);
registerProperty
CopierBy
Update
(
scattering
->
qh
,
qh
);
registerProperty
CopierBy
Update
(
scattering
->
qk
,
qk
);
registerProperty
CopierBy
Update
(
scattering
->
ql
,
ql
);
registerProperty
CopierBy
Update
(
scattering
->
en
,
en
);
registerProperty
CopierBy
Update
(
scattering
->
qm
,
qm
);
registerProperty
CopierBy
Update
(
scattering
->
fx
,
fx
);
registerProperty
CopierBy
Update
(
scattering
->
sens
,
ss
);
register
Float64
PropertyUpdate
r
(
scattering
->
qh
,
qh
);
register
Float64
PropertyUpdate
r
(
scattering
->
qk
,
qk
);
register
Float64
PropertyUpdate
r
(
scattering
->
ql
,
ql
);
register
Float64
PropertyUpdate
r
(
scattering
->
en
,
en
);
register
Float64
PropertyUpdate
r
(
scattering
->
qm
,
qm
);
register
Int32
PropertyUpdate
r
(
scattering
->
fx
,
fx
);
register
Int32
PropertyUpdate
r
(
scattering
->
sens
,
ss
);
registerProperty
CopierBy
Update
(
incidentBeam
->
ki
,
ki
);
registerProperty
CopierBy
Update
(
scatteredBeam
->
kf
,
kf
);
register
Float64
PropertyUpdate
r
(
incidentBeam
->
ki
,
ki
);
register
Float64
PropertyUpdate
r
(
scatteredBeam
->
kf
,
kf
);
registerPropertyCopierByUpdate
(
a1Controller
->
position
,
a1
);
registerPropertyCopierByUpdate
(
a2Controller
->
position
,
a2
);
...
...
@@ -348,6 +380,11 @@ void VEXPController::postConfiguration() {
registerStatus
(
scanController
,
&
VEXPController
::
updateScanStatus
,
this
);
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
)
{
...
...
@@ -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
);
}
}
}
src/controllers/vexp/VEXPController.h
View file @
d3286b86
...
...
@@ -25,10 +25,12 @@
#include "controllers/tas/common/IncidentBeam.h"
#include "controllers/tas/common/TasScatteredBeam.h"
#include "controllers/common/scanlegacy/ParameterizableScan1D.h"
#include <boost/thread/thread.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread/mutex.hpp>
#include <cameo/cameo.h>
#include <rapidjson/stringbuffer.h>
#include <memory>
#include <unordered_map>
#include <thread>
#include <atomic>
namespace
vexp
{
...
...
@@ -63,6 +65,14 @@ public:
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
updateScanDelta
(
int
index
);
void
updateNbPoints
(
int
index
);
...
...
@@ -72,6 +82,10 @@ public:
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
>
bs
;
Property
<
float64
>
cs
;
...
...
@@ -143,6 +157,15 @@ public:
Property
<
int32
>
nbPointsScan
;
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.
ControllerPtr
<
tas
::
TasSettings
>
tasSettings
;
ControllerPtr
<
tas
::
Sample
>
sample
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment