-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for the LXA Optick latency measurement util #39
Conversation
8229e4c
to
fa8abc5
Compare
3a5b872
to
52d6f96
Compare
#38 has been merged. Please rebase. |
Great to see that we are coming along with merging the PRs so nicely! I've rebased this PR on top of recent master, but have also converted it to a draft PR, since it should not be merged before we have a released version of the Optick Firmware to include in the firmware folder. I've created #40, which breaks out the first two commits of this PR so we are not held back too much by the firmware blob. |
low_mean, low_std = mean_std(adc_when_low) | ||
high_mean, high_std = mean_std(adc_when_high) | ||
|
||
if low_mean > high_mean: | ||
low_mean, low_std, high_mean, high_std = ( | ||
high_mean, | ||
high_std, | ||
low_mean, | ||
low_std, | ||
) | ||
|
||
# Set the decision boundary at the center point between the average | ||
# measurements for high and low values. | ||
mid = (low_mean + high_mean) / 2 | ||
|
||
# Approximate the distribution of the measurements using a gaussian | ||
# distribution ... | ||
mid_low_norm = (mid - low_mean) / low_std | ||
mid_high_norm = (high_mean - mid) / high_std | ||
|
||
# ... and give a measure of how good the decision boundary is based | ||
# on that. | ||
low_correct = math.erf(mid_low_norm) | ||
high_correct = math.erf(mid_high_norm) | ||
|
||
print() | ||
print(f"Trigger level {mid:0.2f} provides:") | ||
print(f" - {int(low_correct * 100)}% correct low estimates") | ||
print(f" - {int(high_correct * 100)}% correct high estimates") | ||
print() | ||
|
||
if mid < 0.05: | ||
print("WARNING: The trigger level is very low.") | ||
print("Are all connections okay and the display set to its maximum brightness?") | ||
print() | ||
|
||
if mid > 0.95: | ||
print("WARNING: The trigger level is very high.") | ||
print("Is the sensor protected from light sources like e.g. direct sunlight?") | ||
print() | ||
|
||
if low_correct < 0.95 or high_correct < 0.95: | ||
print("WARNING: The trigger level has bad separation") | ||
print("Are all connections good, no stray light entering the setup") | ||
print("and automatic brightness adjustments disabled as much as possuble?") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing this part may be a good fit for @ukleinek, who has a knack for math stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be ok to merge this as-is?
I mean: It works and the actual business-logic for the optick is meant to be a prototype.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sure. I am not sure if the percent values I print here are statistically sound, but they have been helpful enough, so I think we are good here.
3a5d7ca
to
a03de47
Compare
The LXA Optick board is an utility for measuring latencies, that supports both measuring the latencies involved in realtime Linux and microcontroller applications (on the order of nanoseconds), as well as light source -> camera -> computer -> display -> light sensor round trip latencies. (Hence the name, Op-Tick, like being something visual but also clock like, you know ... a play on words ... nevermind). The Optick board comes with support hardware for these optical latency measurements. The board has two event-generating output ports and two event-capturing input ports, that capture and generate events relative to a local 64 bit counter running at 48MHz. The counters from different Optick devices can be synchronized using the PPS output of a GPS module, to support e.g. time sensitive networking latency measurements over some distance. The inputs are analog and feature an on-board comparator that compares the input voltage to a software configurable reference voltage to form a basic input trigger. This commit also contains a commandline utility that implements the basic optick usecase of measuring a glass to glass camera / display latency, by first determining the correct trigger level, generating and capturing events and lastly generating a histogram of measured latencies. Signed-off-by: Leonard Göhrs <[email protected]>
Alright, we now have an Optick firmware image and are ready for review! 🎉 |
low_mean, low_std = mean_std(adc_when_low) | ||
high_mean, high_std = mean_std(adc_when_high) | ||
|
||
if low_mean > high_mean: | ||
low_mean, low_std, high_mean, high_std = ( | ||
high_mean, | ||
high_std, | ||
low_mean, | ||
low_std, | ||
) | ||
|
||
# Set the decision boundary at the center point between the average | ||
# measurements for high and low values. | ||
mid = (low_mean + high_mean) / 2 | ||
|
||
# Approximate the distribution of the measurements using a gaussian | ||
# distribution ... | ||
mid_low_norm = (mid - low_mean) / low_std | ||
mid_high_norm = (high_mean - mid) / high_std | ||
|
||
# ... and give a measure of how good the decision boundary is based | ||
# on that. | ||
low_correct = math.erf(mid_low_norm) | ||
high_correct = math.erf(mid_high_norm) | ||
|
||
print() | ||
print(f"Trigger level {mid:0.2f} provides:") | ||
print(f" - {int(low_correct * 100)}% correct low estimates") | ||
print(f" - {int(high_correct * 100)}% correct high estimates") | ||
print() | ||
|
||
if mid < 0.05: | ||
print("WARNING: The trigger level is very low.") | ||
print("Are all connections okay and the display set to its maximum brightness?") | ||
print() | ||
|
||
if mid > 0.95: | ||
print("WARNING: The trigger level is very high.") | ||
print("Is the sensor protected from light sources like e.g. direct sunlight?") | ||
print() | ||
|
||
if low_correct < 0.95 or high_correct < 0.95: | ||
print("WARNING: The trigger level has bad separation") | ||
print("Are all connections good, no stray light entering the setup") | ||
print("and automatic brightness adjustments disabled as much as possuble?") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be ok to merge this as-is?
I mean: It works and the actual business-logic for the optick is meant to be a prototype.
I think we are ready to merge this. @SmithChart will you do the honors? |
The LXA Optick board is an utility for measuring latencies, that supports both measuring the latencies involved in realtime Linux
and microcontroller applications (on the order of nanoseconds), as well as light source -> camera -> computer -> display -> light sensor round trip latencies.
(Hence the name, Op-Tick, like being something visual but also clock like, you know ... a play on words ... nevermind).
The Optick board comes with support hardware for these optical latency measurements.
The board has two event-generating output ports and two event-capturing input ports, that capture and generate events relative to a local 64 bit counter running at 48MHz.
The counters from different Optick devices can be synchronized using the PPS output of a GPS module, to support e.g. time sensitive networking latency measurements over some distance.
The inputs are analog and feature an on-board comparator that compares the input voltage to a software configurable reference voltage to form a basic input trigger.
This commit also contains a commandline utility that implements the basic optick usecase of measuring a glass to glass camera / display latency, by first determining the correct trigger level, generating and capturing events and lastly generating a histogram of measured latencies.
TODO before merging: