ni / ni/nidaqmx-python

Reading position from a quadrature encoder

Open
#619 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
592
Forks
199
Avg merge
1d 16h
Merged PRs (30d)
10

Description

I am using an NI cDAQ-9184 with the NI 9411 module to read a quadrature encoder, but I can't seem to figure out how to get position readings from it. I have a voltage pulse signal wired into the 9411 to act as my external sample clock, and the sample timestamps seem to be right, but I seem to be getting edge counts or something rather than actual angular position measurements. I'm assuming I need to use some other piece of the library to convert to position, but I can't seem to figure that part out. I would welcome any help!

    task_a = nidaqmx.Task()
    sample_rate = 2000  # Hz
    n_tot = sample_rate*seconds_to_record
    data_matrix = np.zeros((n_tot,))

    task_a.ci_channels.add_ci_ang_encoder_chan(
        counter="cDAQ9184-1C3169FMod3/ctr0",
        name_to_assign_to_channel="encoder 1",
        decoding_type=nidaqmx.constants.EncoderType.X_1,
        zidx_enable=True,
        units=nidaqmx.constants.AngleUnits.DEGREES,
        pulses_per_rev=4096
    )

    task_a.timing.cfg_samp_clk_timing(
        rate=sample_rate,
        source="/cDAQ9184-1C3169FMod3/PFI3",  
        sample_mode=AcquisitionType.CONTINUOUS,
        samps_per_chan=sample_rate*seconds_to_record
    )

    print("beginning data collection. time of collection is approx ", seconds_to_record, " seconds.")

    task_a.start()
    stream = stream_readers.CounterReader(task_a.in_stream)

    stream.read_many_sample_double(
        data=data_matrix,
        number_of_samples_per_channel=n_tot
    )

    task_a.stop()
    task_a.close()

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the add_ci_ang_encoder_chan configuration and the CounterReader.read_many_sample_double call shown in the issue. Check the encoder-channel and counter-reader documentation to determine whether the returned values represent angular position and what configuration is required; done means identifying a confirmed library change or documenting the correct usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.