Skip to content
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

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

hnez
Copy link
Member

@hnez hnez commented Mar 14, 2024

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:

@hnez hnez force-pushed the optick branch 8 times, most recently from 8229e4c to fa8abc5 Compare March 18, 2024 14:06
@hnez hnez marked this pull request as ready for review March 18, 2024 14:06
@hnez hnez force-pushed the optick branch 6 times, most recently from 3a5b872 to 52d6f96 Compare March 21, 2024 15:03
@SmithChart
Copy link
Member

#38 has been merged. Please rebase.

@hnez
Copy link
Member Author

hnez commented Mar 22, 2024

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.

Comment on lines +81 to +125
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?")
Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

@hnez hnez force-pushed the optick branch 3 times, most recently from 3a5d7ca to a03de47 Compare March 27, 2024 06:19
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]>
@hnez hnez marked this pull request as ready for review March 28, 2024 14:13
@hnez
Copy link
Member Author

hnez commented Mar 28, 2024

Alright, we now have an Optick firmware image and are ready for review! 🎉

@hnez hnez removed their assignment Mar 28, 2024
lxa_iobus/node/products.py Outdated Show resolved Hide resolved
Comment on lines +81 to +125
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?")
Copy link
Member

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.

@hnez
Copy link
Member Author

hnez commented Apr 3, 2024

I think we are ready to merge this. @SmithChart will you do the honors?

@SmithChart SmithChart merged commit e104569 into linux-automation:master Apr 3, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants