#linuxcnc-devel Logs

Oct 06 2022

#linuxcnc-devel Calendar

12:25 AM pere: perhaps, if we know what it did.
07:43 AM -!- #linuxcnc-devel mode set to +vv by ChanServ
08:14 AM -!- #linuxcnc-devel mode set to +v by ChanServ
08:14 AM -!- #linuxcnc-devel mode set to +v by ChanServ
12:35 PM pere: hi
12:35 PM pere: SkoFyx: which adaptive pid tuning did you have in mind?
12:35 PM SkoFyx: pere: In PID, feedback derivative is basically a velocity calculation. When calculating the velocity of a digital encoder, the accuracy of that calculation is dependant on the number of edge changes in the sampling period.
12:36 PM pcw---home: Nope
12:37 PM pcw---home: Its more dependent on quadrature accuracy if you have decent velocity estimation
12:38 PM SkoFyx: When you have have only 1 edge change every 4 or 5 periods, those velocity calculations are, what I like to call, garbage. Basically, the PID thinks for 4 periods that the motor isn't turning, then suddenly it thinks its turning at 1 edge per period, when in fact it was turing the whole time at 0.2 edges per period.
12:38 PM pcw---home: That's because you don't have velocity estimation
12:41 PM pcw---home: what you want for velocity is 1/(time between quadrature edges) not 1/( counts per sample period)
12:42 PM pcw---home: sorry what you want for velocity is 1/(time between quadrature edges) not ( counts per sample period)
12:42 PM SkoFyx: pcw---home: I'm looking at src/hal/components/pid.c: *(pid->feedbackvds) = (feedback - pid->prev_fb) * periodrecip;
12:44 PM pcw---home: for encoder feedback, you would not use that path
12:45 PM pcw---home: You would connect the PIDs feedback derivative pin to the encoders velocity pin
12:45 PM SkoFyx: I'm only trying to address the result of that calculation, and how it contributes to the PWM output.
12:46 PM pcw---home: you would not use that calculation
12:47 PM pcw---home: its ignored if you connect the PID feedback derivative hal pin
12:51 PM SkoFyx: So the backstory is, my hardware isn't suitable for linux realtime kernels so I wrote my own bare metal solution using the linuxcnc pid as inspiration. I run my PID at 10khz with a rather aggressive tune to compensate for low resolution encoders and the traditional derivative calculation method in all the PID examples was giving me low speed nasties.
12:52 PM SkoFyx: My solution was to only calculate the derivative when the encoder changed, or if the encoder didn't change, slowing attenuate the last derivative value.
12:53 PM SkoFyx: Am interested in how linuxcnc calculates the feedback derivative. What file do I look in?
12:54 PM pcw---home: Its done by velocity estimation at the encoder level
12:55 PM pcw---home: (its not calculated in the PID component unless you leave the feedback derivative pin unconnected)
12:56 PM pcw---home: can your encoder hardware timestamp edges?
12:58 PM SkoFyx: No.
12:59 PM pcw---home: yeah so velocity with a low-res encoder will be crunchy
01:00 PM SkoFyx: Exactly! And my tweak almost completely eliminated the crunchy!
01:01 PM pcw---home: It will still make big jumps between say 1 and 2 counts per sample (this is why better velocity estimation is desirable)
01:02 PM SkoFyx: Anyway, its a bit of a kludge but it makes cheap hardware work much better. I've learned so much from linuxcnc and I though I'd just throw it out there in case it might be useful.
01:03 PM pcw---home: Yes counts/sample_interval is pretty nasty
01:09 PM SkoFyx: In case anyone is interested: https://pastebin.com/w8KEm6eP
02:04 PM andypugh: Can LinuxCNC do simultaneous circles in XY and UV (for a foam or wire edm setup). My feeling that it can’t?
02:09 PM seb_kuzminsky: i've been playing with preempt-rt on raspberry pi 4, and got it down to 10µs latency: http://highlab.com/~seb/linuxcnc/rpi4-10us-latency.png
02:09 PM seb_kuzminsky: i'm pretty excited about this
02:09 PM pcw---home: That's great
02:09 PM seb_kuzminsky: it involves running each RT thread on its own dedicated CPU, and using busywait instead of sleep to start the next thread invocation
02:10 PM seb_kuzminsky: that's running on the arm64/aarch64 debian bookworm image from raspi.debian.net, not Raspberry Pi OS/raspbian
02:11 PM seb_kuzminsky: it's just a proof of concept at this point, i hope to clean it up and push it for review in the next week or two
02:13 PM pere: seb_kuzminsky: that is cool. did you have to patch the kernel, or could you control it all from userspace?
02:15 PM seb_kuzminsky: no kernel patches, just some kernel command-line arguments (highlighted in the screenshot), the rest is userspace
02:16 PM seb_kuzminsky: nearly identical to the current uspace rtapi_app, just using busywait instead of clock_nanosleep() for timing
02:17 PM seb_kuzminsky: busywaiting on arm's cntvct or x86's rdtsc cycle counter
02:17 PM seb_kuzminsky: gotta run, talk more later
02:18 PM pere: btw, it occured to me the other day that it would be useful it the latency tools were separate packages.
02:18 PM pere: It is painful to have to install the full linuxcnc in a small image just to test the latency.
03:40 PM -!- #linuxcnc-devel mode set to +v by ChanServ
04:32 PM Tom_L: seb_kuzminsky, which bookworm image? the latest tested build?
04:34 PM Tom_L: interested in trying it out..
07:10 PM -!- #linuxcnc-devel mode set to +v by ChanServ
08:24 PM -!- #linuxcnc-devel mode set to +v by ChanServ
08:24 PM -!- #linuxcnc-devel mode set to +v by ChanServ
08:54 PM Tom_itx is now known as Tom_L
09:05 PM -!- #linuxcnc-devel mode set to +v by ChanServ
09:05 PM -!- #linuxcnc-devel mode set to +v by ChanServ
09:21 PM -!- #linuxcnc-devel mode set to +v by ChanServ
09:21 PM -!- #linuxcnc-devel mode set to +v by ChanServ
09:52 PM -!- #linuxcnc-devel mode set to +v by ChanServ
09:52 PM -!- #linuxcnc-devel mode set to +v by ChanServ
11:08 PM seb_kuzminsky: Tom_L: yes, the 2022-08-08 rpi4 bookworm image from https://raspi.debian.net/tested-images/
11:09 PM seb_kuzminsky: but with some changes to rtapi that i haven't pushed yet, without the busywait/multi-cpu stuff the latency is 150-300 µs, significantly worse than the raspbian image on wlo
11:34 PM CaptHindsight[m]: https://forum.linuxcnc.org/media/kunena/attachments/19995/hysto.jpg
11:37 PM CaptHindsight[m]: https://forum.linuxcnc.org/9-installing-linuxcnc/39779-rpi4-raspbian-64-bit-linuxcnc?start=150#253623