-
Notifications
You must be signed in to change notification settings - Fork 162
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 hw timed examples for exisiting sw timed examples #561
Add hw timed examples for exisiting sw timed examples #561
Conversation
examples/ai_voltage_hw_timed.py
Outdated
@@ -0,0 +1,43 @@ | |||
"""Example of AI voltage sw operation.""" |
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.
"""Example of AI voltage sw operation.""" | |
"""Example of AI voltage hardware-timed finite acquisition.""" |
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.
English has a standard order for using multiple adjectives: https://www.grammarly.com/blog/adjective-order/ . If you don't follow this order, it sounds slightly awkward.
The existing examples don't follow this order and have other style problems like lowercase "sw".
It would be better to reword the text so that it doesn't contain a long list of adjectives. Consider reusing text from the LabVIEW, ANSI C, CVI, or .NET examples. For example:
This example demonstrates how to acquire a finite amount of data
using the DAQ device's internal clock.
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.
The description is updated by referring LabVIEW examples.
examples/ai_voltage_hw_timed.py
Outdated
|
||
with nidaqmx.Task() as task: | ||
task.ai_channels.add_ai_voltage_chan("cDAQ1Mod1/ai0") | ||
task.timing.cfg_samp_clk_timing(1000) |
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.
Specify these two optional params
task.timing.cfg_samp_clk_timing(1000) | |
task.timing.cfg_samp_clk_timing(1000, sample_mode=AcquisitionType.FINITE, samps_per_chan=1000) |
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.
noted, optional params are added for the files which called cfg_samp_clk_timing
.
examples/ai_voltage_hw_timed.py
Outdated
print("1 Channel 1 Sample Read: ") | ||
data = task.read() | ||
pp.pprint(data) | ||
task.wait_until_done() | ||
task.stop() | ||
|
||
data = task.read(number_of_samples_per_channel=1) | ||
pp.pprint(data) | ||
task.wait_until_done() | ||
task.stop() | ||
|
||
print("1 Channel N Samples Read: ") | ||
data = task.read(number_of_samples_per_channel=8) | ||
pp.pprint(data) | ||
task.wait_until_done() | ||
task.stop() | ||
|
||
task.ai_channels.add_ai_voltage_chan("cDAQ1Mod1/ai1:3") | ||
|
||
print("N Channel 1 Sample Read: ") | ||
data = task.read() | ||
pp.pprint(data) | ||
task.wait_until_done() | ||
task.stop() | ||
|
||
print("N Channel N Samples Read: ") | ||
data = task.read(number_of_samples_per_channel=2) | ||
print(data) | ||
task.wait_until_done() | ||
task.stop() |
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.
Let's simplify
print("1 Channel 1 Sample Read: ") | |
data = task.read() | |
pp.pprint(data) | |
task.wait_until_done() | |
task.stop() | |
data = task.read(number_of_samples_per_channel=1) | |
pp.pprint(data) | |
task.wait_until_done() | |
task.stop() | |
print("1 Channel N Samples Read: ") | |
data = task.read(number_of_samples_per_channel=8) | |
pp.pprint(data) | |
task.wait_until_done() | |
task.stop() | |
task.ai_channels.add_ai_voltage_chan("cDAQ1Mod1/ai1:3") | |
print("N Channel 1 Sample Read: ") | |
data = task.read() | |
pp.pprint(data) | |
task.wait_until_done() | |
task.stop() | |
print("N Channel N Samples Read: ") | |
data = task.read(number_of_samples_per_channel=2) | |
print(data) | |
task.wait_until_done() | |
task.stop() | |
print("Reading Data: ") | |
task.start() | |
data = task.read() | |
print(data) | |
task.stop() |
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.
Done, it's updated.
examples/ai_voltage_hw_timed.py
Outdated
@@ -0,0 +1,43 @@ | |||
"""Example of AI voltage sw operation.""" |
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.
Rename this file ai_voltage_hw_timed_finite.py
and let's create one more that is a duplicate, but called ai_voltage_hw_timed_continues.py
. The main difference will be:
- change the params to
cfg_samp_clk_timing
- pass in
number_of_samples_per_channel
totask.read
(1/10th of your sample rate) - loop forever reading between start/stop
- try/catch waiting for a keyboard interrupt to stop (user presses Ctrl+C, ask them to do that in a print)
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.
@zhindes Have you considered copying the naming of the LabVIEW, ANSI C, CVI, or .NET examples, e.g. ai_acq_int_clk.py
, ai_cont_acq_int_clk.py
?
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.
or even analog_in/acq_int_clk.py
etc.
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.
Yeah, I like that!
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.
@zhindes I'm not sure should we add continuous example as the examples will be run together with the pytest under acceptance folder, I think that will break the pytest.
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.
Oh, that's a fair point. We'll need some way to not run tests that are continuous. We should still have the examples, though.
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.
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.
Created sub folders for AI, AO, DI, DO, CI and CO examples, including continuous examples.
examples/ci_hw_count_edges.py
Outdated
task.ci_channels.add_ci_count_edges_chan("Dev1/ctr0") | ||
task.timing.cfg_samp_clk_timing(1000, "/Dev1/PFI6") |
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.
sample clocks with event counts aren't common. I think this is what you want:
task.ci_channels.add_ci_count_edges_chan("Dev1/ctr0") | |
task.timing.cfg_samp_clk_timing(1000, "/Dev1/PFI6") | |
task.ci_channels.add_ci_count_edges_chan("Dev1/ctr0").ci_count_edges_term = "Dev1/PFI6" |
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.
probably cleaner on two lines. save the channel to a variable then set the ci_count_edges_term
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.
ci_hw_count_edges.py
is renamed to ci_count_edges_ext_clk.py
. I still keep the cfg_samp_clk_timing
in example to align with LabVIEW example Counter - Count Edges (Finite Clock).vi
.
examples/di_hw_timed.py
Outdated
with nidaqmx.Task() as task: | ||
task.di_channels.add_di_chan("Dev1/port0/line0:3", line_grouping=LineGrouping.CHAN_PER_LINE) | ||
task.timing.cfg_samp_clk_timing(1000) | ||
|
||
print("N Channel 1 Sample Read: ") | ||
data = task.read() | ||
pp.pprint(data) | ||
task.wait_until_done() | ||
task.stop() | ||
|
||
print("N Channel N Samples Read: ") | ||
data = task.read(number_of_samples_per_channel=3) | ||
print(data) | ||
task.wait_until_done() | ||
task.stop() |
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.
follow AI review comments
- two examples - finite, continuous
- etcetc
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.
Okay, all examples are updated according to your suggestions.
examples/do_hw_timed.py
Outdated
print("1 Channel N Lines 1 Sample Unsigned Integer Write: ") | ||
print(task.write(8)) |
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.
delete
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.
It's deleted.
examples/do_hw_timed.py
Outdated
task.do_channels.add_do_chan( | ||
"Dev1/port0/line0:3", line_grouping=LineGrouping.CHAN_FOR_ALL_LINES | ||
) | ||
task.timing.cfg_samp_clk_timing(1000) |
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.
specify optional params
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.
Optional params are added.
examples/do_hw_timed.py
Outdated
print(task.write(8)) | ||
|
||
print("1 Channel N Lines N Samples Unsigned Integer Write: ") | ||
print(task.write([1, 2, 4, 8], auto_start=True)) |
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.
for finite, wait for done then stop task
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.
Okay, it's updated according to your suggestion.
examples/do_hw_timed.py
Outdated
@@ -0,0 +1,16 @@ | |||
"""Example for writing digital signal.""" |
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.
add continuous, too
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.
Continuous example is added.
examples/ai_voltage_hw_timed.py
Outdated
@@ -0,0 +1,43 @@ | |||
"""Example of AI voltage sw operation.""" |
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.
English has a standard order for using multiple adjectives: https://www.grammarly.com/blog/adjective-order/ . If you don't follow this order, it sounds slightly awkward.
The existing examples don't follow this order and have other style problems like lowercase "sw".
It would be better to reword the text so that it doesn't contain a long list of adjectives. Consider reusing text from the LabVIEW, ANSI C, CVI, or .NET examples. For example:
This example demonstrates how to acquire a finite amount of data
using the DAQ device's internal clock.
examples/ai_voltage_hw_timed.py
Outdated
@@ -0,0 +1,43 @@ | |||
"""Example of AI voltage sw operation.""" |
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.
@zhindes Have you considered copying the naming of the LabVIEW, ANSI C, CVI, or .NET examples, e.g. ai_acq_int_clk.py
, ai_cont_acq_int_clk.py
?
examples/ci_hw_count_edges.py
Outdated
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.
"ci_hw_count_edges.py" makes this sound less advanced / corner-case than it is.
The examples for other ADEs tend to use "buffered" and/or "external clock" to describe this use case.
Cnt-Buf-Cont-ExtClk
Counter - Count Edges (Continuous Clock).vi
etc.
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.
All example files are renamed by referring LabVIEW examples.
@@ -0,0 +1,31 @@ | |||
"""Example of analog input voltage acquisition continuously. |
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.
The adverb "continuously" normally modifies a verb, but this is a noun phrase that has no verb.
"""Example of analog input voltage acquisition continuously. | |
"""Example of continuous analog input voltage acquisition. |
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.
I think you should rename this to dig_pulse.py
and copy the logic used in the ANSI C DigPulse.c
.
Removing implicit timing changes this from a pulse train to a single pulse.
If it generates a single pulse, "changing pulse specification" no longer has any effect, unless task.write() auto-starts the task, in which case it generates two pulses, which is weird.
time.sleep(2)
is the wrong way to wait for a pulse to complete. We should use task.wait_until_done()
. (time.sleep(2)
was reasonable when this generated a pulse train and we wanted to change the pulse specification while it was running.)
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.
Rename to dig_pulse_train_cont.py
as per ANSI C example DigPulseTrain-Cont.c
sample = CtrTime(high_time=0.001, low_time=0.002) | ||
print("Press Ctrl+C to stop") | ||
print("1 Channel 1 Sample Write: ") | ||
print(task.write(sample, auto_start=True)) |
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.
Writing during the pulse train is a more advanced use case and we don't have a basic pulse train example. See DigPulseTrain-Cont.c
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.
This does a finite pulse train.
Do we need an example of this? We don't have one in C.
sample = CtrTime(high_time=0.001, low_time=0.002) | ||
|
||
print("1 Channel 1 Sample Write: ") | ||
print(task.write(sample)) |
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.
Again, this is a more advanced use case, and we don't have an example of the basic finite pulse train.
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.
CI pulse channels are an advanced feature that is only supported on devices introduced in 2009 and later. I don't understand why we have examples of these and not the basic stuff:
- Measure frequency (with
add_ci_freq_chan
) - Measure period or pulse width (with
add_ci_period_chan
) - Measure position (encoders)
- Measure 2 edge separation (ok, this is kind of intermediate?)
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.
read_dig_chan.py
?
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.
At this rate, this PR review is going to take forever.
Here's a proposal for speeding it up:
- PR 1: reorganize the existing examples into folders, with no code changes
- Let's use Teams to discuss which examples should exist, since many of the existing examples demonstrate advanced features and overlook the basics
- PRs 2-7: for each folder, update/rename the examples or replace them with new examples based on the ANSI C examples, when appropriate
ok?
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.
I agree! I added my first pass thoughts on Teams!
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.
Agree, I created PR for reorganizing example files, #565.
I will close this PR, new changes will be made in another PRs as per suggestion.
What does this Pull Request accomplish?
Added HW timed examples for existing SW timed examples.
Why should this Pull Request be merged?
Currently, we only have SW timed examples except
ao_voltage_hw_timed.py
, this PR is to add HW timed examples for the rest of SW timed examples.What testing has been done?
poetry run pytest tests/ -q
- pass