When I have added velocity estimation in hal_pru_generic, I have
validated with a python script and a wire between a pwmgen output and
the encoder input.
Results are here:
http://blog.f1oat.org/2016/04/10/adding-velocity-estimation-in-hal_pru_generic-encoder/
And the scripts are attached to this email.
You can use that method to make additional testing if needed.
Frederic.
On 29/03/2017 23:10, Charles Steinkuehler wrote:
On 3/29/2017 4:01 PM, Russell Gower wrote:
Its the velocity estimates that are causing my issue, It is very
jittery and the pyvcp panel (a dial showing spindle speed) crashes
with a float to string error. There is a lot in that commit, I
think i’m going to split it in to two, one for the general tidy up
and type corrections and another for the period based velocity
changes and see where that leads me.
Just a guess, but there may need to be some hysteresis to the decision
regarding which velocity estimator to use. Or you might be getting
discontinuities because of a coding error that hasn't bothered anyone
else yet.
If you can wire the encoder to two sets of input pins, you could run
the PRU encoder and the eQEP encoder in parallel and probably spot
what's going wrong pretty quickly with halscope.
--
website: http://www.machinekit.io blog: http://blog.machinekit.io github:
https://github.com/machinekit
---
You received this message because you are subscribed to the Google Groups "Machinekit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/machinekit.
For more options, visit https://groups.google.com/d/optout.
loadusr -w ../setup.sh
loadrt threads name1=servo-thread period1=1000000
loadrt hal_pru_generic prucode=$(HAL_RTMOD_DIR)/xenomai/pru_generic.bin pru=0
num_encoders=1 num_pwmgens=1 pru_period=2500 halname=hpg
addf hpg.update servo-thread
addf hpg.capture-position servo-thread
setp hpg.encoder.00.chan.00.A-pin 7 #925 ENCxI
setp hpg.encoder.00.chan.00.counter-mode 2 #Up Counter (counts rising edges on
A, always counts up, B ignored)
setp hpg.pwmgen.00.out.00.pin 921 #PWM1
setp hpg.pwmgen.00.out.00.enable 1
setp hpg.pwmgen.00.pwm_period 1000000
setp hpg.pwmgen.00.out.00.value 0.5
start
loadusr -w sleep 1
loadusr -w python encoder_test.py
#!/usr/bin/python
import subprocess
import time
import os
def readpin(p):
r = subprocess.check_output('halcmd -s show pin ' + p + '|head
-1',shell=True)
lst = r.split()
return lst[3]
def setpin(p, v):
subprocess.check_output('halcmd -s setp %s %d' % (p, v), shell=True)
freq = 5.0
prev_freq = 0.0
maxerror = 0
f = open('result.csv', 'w')
line = 'in(Hz), out(Hz), err(%), latency(ms)'
print line
f.write(line + '\n')
time.sleep(2)
while freq < 100e3:
period = int(1e9/freq/2500) * 2500 # because pru_period=2500
real_freq = 1e9/period
if (real_freq <> prev_freq):
prev_freq = real_freq
setpin('hpg.pwmgen.00.pwm_period', period)
time.sleep(0.2)
measured_freq =
float(readpin('hpg.encoder.00.chan.00.velocity'))
latency = float(readpin('hpg.encoder.00.chan.00.latency')) *
1e-6
error = abs(real_freq / measured_freq - 1.0)
maxerror = max(maxerror, error)
line = "%8.1f, %8.1f, %4.2f, %3.0f" % (real_freq,
measured_freq, error*100.0, latency)
print line
f.write(line + '\n')
freq = 1.1*freq
f.close()
print "Max error %.1f%s" % (maxerror*100.0, '%')