Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
calng
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
calibration
calng
Commits
ca4f12eb
Commit
ca4f12eb
authored
1 year ago
by
David Hammer
Browse files
Options
Downloads
Patches
Plain Diff
Start sketching changes based on dev meeting
parent
a8b13319
No related branches found
No related tags found
1 merge request
!53
Train picker arbiter kernel
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/calng/PickyBoi.py
+76
-23
76 additions, 23 deletions
src/calng/PickyBoi.py
with
76 additions
and
23 deletions
src/calng/PickyBoi.py
+
76
−
23
View file @
ca4f12eb
...
...
@@ -10,6 +10,7 @@ from karabo.bound import (
KARABO_CLASSINFO
,
NDARRAY_ELEMENT
,
NODE_ELEMENT
,
OUTPUT_CHANNEL
,
OVERWRITE_ELEMENT
,
SLOT_ELEMENT
,
STRING_ELEMENT
,
...
...
@@ -50,6 +51,23 @@ class PickyBoi(PythonDevice):
.
reconfigurable
()
.
commit
(),
UINT64_ELEMENT
(
expected
)
.
key
(
"
numTrainToCatch
"
)
.
assignmentOptional
()
.
defaultValue
(
1
)
.
reconfigurable
()
.
commit
(),
STRING_ELEMENT
(
expected
)
.
key
(
"
ppuDevice
"
)
.
assignmentOptional
()
.
defaultValue
(
""
)
.
commit
(),
SLOT_ELEMENT
(
expected
)
.
key
(
"
watchPpu
"
)
.
commit
(),
SLOT_ELEMENT
(
expected
)
.
key
(
"
resetCapturedSchema
"
)
.
commit
(),
...
...
@@ -63,7 +81,7 @@ class PickyBoi(PythonDevice):
super
().
__init__
(
config
)
self
.
registerInitialFunction
(
self
.
_initialization
)
self
.
_schema_is_set
=
False
self
.
_previous_t
rain_seen
=
0
self
.
_previous_t
id
=
0
self
.
_just_capture_next
=
False
self
.
KARABO_SLOT
(
self
.
resetCapturedSchema
)
self
.
KARABO_SLOT
(
self
.
captureNextTrain
)
...
...
@@ -74,37 +92,51 @@ class PickyBoi(PythonDevice):
def
captureNextTrain
(
self
):
self
.
_just_capture_next
=
True
def
watchPpu
(
self
):
ppu_device_id
=
self
.
get
(
"
ppuDevice
"
)
client
=
self
.
remote
()
conf
=
client
.
getConfiguration
(
ppu_device_id
)
self
.
handlePpuDeviceConfiguration
(
conf
)
client
.
registerDeviceMonitor
(
ppu_device_id
,
self
.
handlePpuDeviceConfiguration
)
def
handlePpuDeviceConfiguration
(
self
,
conf
):
...
# TODO
self
.
_set_new_target_tid
(
new_target_tid
)
self
.
set
(
"
nextTrainToCatch
"
,
new_target_tid
)
def
_initialization
(
self
):
self
.
KARABO_ON_DATA
(
"
input
"
,
self
.
input_handler
)
def
input_handler
(
self
,
data
,
meta
):
state
=
self
.
get
(
"
state
"
)
current
=
Timestamp
.
fromHashAttributes
(
meta
.
getAttributes
(
"
timestamp
"
)
).
getTrainId
()
if
self
.
_just_capture_next
:
self
.
set
(
"
nextTrainToCatch
"
,
current
)
self
.
_just_capture_next
=
False
target
=
self
.
get
(
"
nextTrainToCatch
"
)
if
not
self
.
_schema_is_set
:
self
.
updateState
(
State
.
ROTATING
)
schema_update
=
Schema
()
(
NODE_ELEMENT
(
schema_update
)
.
key
(
"
captured
"
)
.
commit
()
OUTPUT_CHANNEL
(
schema_update
)
.
key
(
"
output
"
)
.
dataSchema
(
hash_to_schema
(
data
))
.
commit
(),
)
hash_to_schema
(
data
,
schema_update
,
"
captured.
"
)
self
.
updateSchema
(
schema_update
)
self
.
_schema_is_set
=
True
if
target
>
current
:
# TODO: handle multiple (consecutive) trains picked
state
=
self
.
get
(
"
state
"
)
current_tid
=
Timestamp
.
fromHashAttributes
(
meta
.
getAttributes
(
"
timestamp
"
)
).
getTrainId
()
if
self
.
_just_capture_next
:
self
.
set
(
"
nextTrainToCatch
"
,
current_tid
)
self
.
_just_capture_next
=
False
target_tid
=
self
.
get
(
"
nextTrainToCatch
"
)
if
target_tid
>
current_tid
:
if
state
is
not
State
.
MONITORING
:
self
.
updateState
(
State
.
MONITORING
)
elif
target
<
current
:
if
self
.
_previous_t
rain_seen
<
target
:
self
.
log
.
ERROR
(
f
"
Missed target train of
{
target
}
:(
"
)
elif
target
_tid
<
current
_tid
:
if
self
.
_previous_t
id
<
target_tid
and
state
is
not
State
.
ERROR
:
self
.
log
.
ERROR
(
f
"
Missed target train of
{
target
_tid
}
:(
"
)
self
.
updateState
(
State
.
ERROR
)
else
:
if
state
is
not
State
.
PASSIVE
:
...
...
@@ -112,12 +144,33 @@ class PickyBoi(PythonDevice):
else
:
self
.
updateState
(
State
.
FILLING
)
self
.
log
.
INFO
(
f
"
Got target train
{
target
}
now :D
"
)
new_hash
=
Hash
()
for
path
in
data
.
getPaths
():
new_hash
[
f
"
captured.
{
path
}
"
]
=
data
[
path
]
self
.
set
(
new_hash
)
# TODO: copy train ID on metadata
self
.
writeChannel
(
"
output
"
,
data
)
self
.
updateState
(
State
.
DISENGAGED
)
self
.
_previous_train_seen
=
current
self
.
_previous_tid
=
current
def
_set_new_target_tid
(
self
,
new_target_tid
):
# assumes nextTrainToCatch gets set *after* this function
current_target_tid
=
self
.
get
(
"
nextTrainToCatch
"
)
if
self
.
_previous_tid
>=
new_target_tid
:
self
.
log
.
INFO
(
f
"
Moved target train to
{
new_target_tid
}
even though last seen was
"
f
"
{
self
.
_previous_tid
}
- will not be able to retroactively catch this.
"
)
self
.
updateState
(
State
.
ERROR
)
else
:
if
current_target_tid
<
new_target_tid
:
self
.
log
.
INFO
(
f
"
Moved target train from
{
current_target_tid
}
to
{
new_target_tid
}
"
f
"
even though last seen was
{
self
.
_previous_tid
}
"
f
"
effectively skipping
{
current_target_tid
}
"
)
self
.
updateState
(
State
.
MONITORING
)
def
preReconfigure
(
self
,
config
):
super
().
preReconfigure
(
config
)
if
config
.
has
(
"
nextTrainToCatch
"
):
self
.
_set_new_target_tid
(
config
[
"
nextTrainToCatch
"
])
def
hash_to_schema
(
h
,
root
=
None
,
prefix
=
""
):
...
...
This diff is collapsed.
Click to expand it.
David Hammer
@hammerd
mentioned in commit
3944f163
·
1 year ago
mentioned in commit
3944f163
mentioned in commit 3944f1635711303a5efda425309be87d8c8fd88a
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment