cRIO 9053
9411 module
Wheel encoder GKZ-1000
https://cdn.automationdirect.com/static/specs/encoderhd.pdfPython 3.9.5 with nidaqmx API
I can read the counter and see it increasing as I rotate the wheel, but I need to detect changes in both directions, so my preference would be that the counter decrease in one direction, increase in the other.
Here's a snippet of what I am doing (With some leftovers from previous attempts).
def startUsingRotation(self):
global running
total = 0.0
task = ni.Task(new_task_name="readCtr0")
# Can't seem to make this work, and perhaps this is not what we need, as direction matters
#channelA = task.ci_channels.add_ci_ang_encoder_chan(counter = 'Mod3/ctr0', decoding_type = EncoderType.X_1, zidx_enable=True, units=AngleUnits.DEGREES, pulses_per_rev=4000, initial_angle=0.0)
#channelA = task.ci_channels.add_ci_ang_encoder_chan(counter = 'Mod3/ctr0', decoding_type = EncoderType.X_1, zidx_phase=nidaqmx.constants.EncoderZIndexPhase.AHIGH_BHIGH, zidx_val=0, zidx_enable=True, units=AngleUnits.DEGREES, pulses_per_rev=1000, initial_angle=0.0)
#task.timing.cfg_samp_clk_timing(rate=10000, sample_mode=AcquisitionType.CONTINUOUS,samps_per_chan=100)
#task.timing.samp_timing_type = nidaqmx.constants.SampleTimingType.ON_DEMAND
channelA = task.ci_channels.add_ci_count_edges_chan(counter='Mod3/ctr0')
channelA.ci_count_edges_dig_fltr_min_pulse_width = 0.0003
channelA.ci_count_edges_dig_fltr_enable = True
#task.timing.samp_clk_dig_sync_enable = True
task.timing.samp_clk_overrun_behavior = nidaqmx.constants.OverflowBehavior.TOP_TASK_AND_ERROR
#channelA.ci_encoder_decoding_type = nidaqmx.constants.EncoderType.X_1
#channelA.ci_count_edges_active_edge = nidaqmx.constants.Edge.RISING
task.start()
previous = [0.0]
running = True
while running:
try:
count=task.read(number_of_samples_per_channel=nidaqmx.constants.READ_ALL_AVAILABLE)
print("Current register is {}".format(channelA.ci_count))
except nidaqmx.errors.DaqError:
print("Read error encountered")
continue
if count[0] != previous[0]:
if count[0] != previous[0] + 1:
print("Increased count by more than one")
#total += (count[0] - previous[0])
total = count[0]
print("Total movement {:.3f} Total clicks {}".format(total, count[0]))
if total % self._encode_clicks == 0:
print("revolution complete")
previous=count
print("Cleanup")
task.stop()