- LinuxCNC
- Installing LinuxCNC
- How can I optimize latency for LinuxCNC on Raspberry Pi 4B with Debian12?
How can I optimize latency for LinuxCNC on Raspberry Pi 4B with Debian12?
06 Sep 2023 04:45 #280050
by MakerYang
I am trying to install Debian12 and LinuxCNC on a Raspberry Pi 4B. Apart from the system being Debian12, I have followed the guidelines in the documentation for all other settings.
After the configuration was complete, I used the LinuxCNC test software to conduct a latency test, and the results are as follows:
I'm not quite sure what caused the issue. Can you provide some guidance and suggestions?
apt update
apt upgrade
apt install linux-image-rt-arm64 linux-headers-rt-arm64
nano /etc/default/raspi-extra-cmdline
processor.max_cstate=1 isolcpus=2,3
nano /etc/default/raspi-firmware-custom
#dtoverlay=vc4-fkms-v3d-pi4
disable_overscan=1
dtparam=audio=off
sudo nano /etc/lightdm/lightdm.conf
autologin-user=matt
autologin-user-timeout=0
update-initramfs -u -k all
apt install task-xfce-desktop
sudo reboot
After the configuration was complete, I used the LinuxCNC test software to conduct a latency test, and the results are as follows:
I'm not quite sure what caused the issue. Can you provide some guidance and suggestions?
Attachments:
Please Log in or Create an account to join the conversation.
06 Sep 2023 04:50 #280051
by MakerYang
Replied by MakerYang on topic How can I optimize latency for LinuxCNC on Raspberry Pi 4B with Debian12?
lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
uname -a
Linux armcnc 6.1.0-10-rt-arm64 #1 SMP PREEMPT_RT Debian 6.1.38-1 (2023-07-14) aarch64 GNU/Linux
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
uname -a
Linux armcnc 6.1.0-10-rt-arm64 #1 SMP PREEMPT_RT Debian 6.1.38-1 (2023-07-14) aarch64 GNU/Linux
Please Log in or Create an account to join the conversation.
06 Sep 2023 06:22 #280058
by cornholio
Replied by cornholio on topic How can I optimize latency for LinuxCNC on Raspberry Pi 4B with Debian12?
drive.google.com/file/d/1i4flcwKPysOzlks.../view?usp=drive_link
user:cnc
passwd:linuxcnc
has 2 cores isolated.
cmdline.txt is here (can change to isolate up 3 cores)
/boot/broadcom/cmdline.txt
config.txt you can turn wifi off here
/boot/broadcom/config.txt
Just reboot after editing files as sudo
Is built form ofiicial Rpi kernel sources with kernel.org real time patch. Pretty much Debian 12 with an xfce desktop and Linuxcnc 2.9 pre-installed. Looking or those willing to test. I've only got a RP400 to test with that has a slightly faster core compared to a Raspberry Pi-4B.
Are you planning on software stepping via GPIO ?
If you are going to use an external motion control board for stepping you will only need a servo thread and latency is pretty relaxed.
user:cnc
passwd:linuxcnc
has 2 cores isolated.
cmdline.txt is here (can change to isolate up 3 cores)
/boot/broadcom/cmdline.txt
config.txt you can turn wifi off here
/boot/broadcom/config.txt
Just reboot after editing files as sudo
Is built form ofiicial Rpi kernel sources with kernel.org real time patch. Pretty much Debian 12 with an xfce desktop and Linuxcnc 2.9 pre-installed. Looking or those willing to test. I've only got a RP400 to test with that has a slightly faster core compared to a Raspberry Pi-4B.
Are you planning on software stepping via GPIO ?
If you are going to use an external motion control board for stepping you will only need a servo thread and latency is pretty relaxed.
The following user(s) said Thank You: MakerYang
Please Log in or Create an account to join the conversation.
06 Sep 2023 06:46 #280062
by MakerYang
Replied by MakerYang on topic How can I optimize latency for LinuxCNC on Raspberry Pi 4B with Debian12?
Thank you for your help and guidance. I'll start testing immediately. Is it necessary to disable wifi to improve latency? Wifi is very important to me. I might use external devices for stepper motor control in the future.
Please Log in or Create an account to join the conversation.
06 Sep 2023 07:16 #280063
by cornholio
Replied by cornholio on topic How can I optimize latency for LinuxCNC on Raspberry Pi 4B with Debian12?
Just test & see. You may have to raise your base thread a little to work with software stepping.
Please Log in or Create an account to join the conversation.
06 Sep 2023 07:37 #280064
by MakerYang
Replied by MakerYang on topic How can I optimize latency for LinuxCNC on Raspberry Pi 4B with Debian12?
I tested it, and the runtime seems to be about the same as what I built myself.
Please Log in or Create an account to join the conversation.
06 Sep 2023 08:27 - 06 Sep 2023 08:30 #280072
by cornholio
Replied by cornholio on topic How can I optimize latency for LinuxCNC on Raspberry Pi 4B with Debian12?
Did you isolate another Core ? As built only 2 cores are isolated.
If you really need to use software stepping you can try upping the base thread but that will lower your step frequency.
latency-histogram --base 30000
Or as another option have a look around the forum there might be another image based on Raspbian OS that is Debian 11 (bullseye) that might get you better results.
There's some info here wiki.linuxaudio.org/wiki/raspberrypi whilst it's aimed at audio applications you might get some luck. To be honest an external motion card will more than likely be the better option as latency isn't such a big issue.
Another thing to think about is the Debian kernels don't appear to allow loading of overlays, the kernel from the Raspberry guys have the patch for the required infrastructure.
If you really need to use software stepping you can try upping the base thread but that will lower your step frequency.
latency-histogram --base 30000
Or as another option have a look around the forum there might be another image based on Raspbian OS that is Debian 11 (bullseye) that might get you better results.
There's some info here wiki.linuxaudio.org/wiki/raspberrypi whilst it's aimed at audio applications you might get some luck. To be honest an external motion card will more than likely be the better option as latency isn't such a big issue.
Another thing to think about is the Debian kernels don't appear to allow loading of overlays, the kernel from the Raspberry guys have the patch for the required infrastructure.
Last edit: 06 Sep 2023 08:30 by cornholio.
Please Log in or Create an account to join the conversation.
06 Sep 2023 08:41 #280073
by MakerYang
Replied by MakerYang on topic How can I optimize latency for LinuxCNC on Raspberry Pi 4B with Debian12?
This is a new continent, I will continue to try.
Please Log in or Create an account to join the conversation.
06 Sep 2023 08:45 #280075
by cornholio
Replied by cornholio on topic How can I optimize latency for LinuxCNC on Raspberry Pi 4B with Debian12?
No worries mate, maybe someone else will chime in with far better answers than myself.
Please Log in or Create an account to join the conversation.
06 Sep 2023 09:23 #280076
by rodw
Replied by rodw on topic How can I optimize latency for LinuxCNC on Raspberry Pi 4B with Debian12?
I don't know the pi well but developed the Debian 12 installer using the debian images and pioneered the approach Cornholio is using to make the Debian image.
What I don't understand is why you would use software stepping on a pi. Wouldn't you be better off using a hardware or timer interupt on the GPIO pins? Andy Pugh has a new device driver for gpiod but I think he's stilll working on how to get it to build within linuxcnc
github.com/LinuxCNC/linuxcnc/blob/andypu...l/drivers/hal_gpio.c
This is the more generic approach to deal with gpio on most SBC's
He says this reads in 16 usec and writes in 8 usec. I have run steppers with a simple on/off square wave pulse (2 writes per pulse) but linuxcnc is a bit smarter and sets a shorter pulse in the operating frequency. I think that is still only 2 writes per step. That gets you up to around 62 kHz step max frequency. I think that would be quite a reasonable performance. My tests found step frequency was limited to about 90-100 kHz from memory for a stepper. You guys should investigate how feasible that would be to implement. Me, I will stick to Mesa or ethercat.
What I don't understand is why you would use software stepping on a pi. Wouldn't you be better off using a hardware or timer interupt on the GPIO pins? Andy Pugh has a new device driver for gpiod but I think he's stilll working on how to get it to build within linuxcnc
github.com/LinuxCNC/linuxcnc/blob/andypu...l/drivers/hal_gpio.c
This is the more generic approach to deal with gpio on most SBC's
He says this reads in 16 usec and writes in 8 usec. I have run steppers with a simple on/off square wave pulse (2 writes per pulse) but linuxcnc is a bit smarter and sets a shorter pulse in the operating frequency. I think that is still only 2 writes per step. That gets you up to around 62 kHz step max frequency. I think that would be quite a reasonable performance. My tests found step frequency was limited to about 90-100 kHz from memory for a stepper. You guys should investigate how feasible that would be to implement. Me, I will stick to Mesa or ethercat.
Please Log in or Create an account to join the conversation.
- LinuxCNC
- Installing LinuxCNC
- How can I optimize latency for LinuxCNC on Raspberry Pi 4B with Debian12?
Time to create page: 0.118 seconds