Linuxcnc on Raspberry

More
30 Dec 2017 10:29 - 30 Dec 2017 13:35 #103846 by goofy
goofy created the topic: Linuxcnc on Raspberry
Hi,

its probably the hundreds post to Linuxcnc on Raspberry. And I know, arm is not supported by Linuxcnc. But...

This year I build my first Milling machine using Linuxcnc. I got a lot of help from many people around this forum and especially in the chartroom, mostly for typical noobs problems. Linuxcnc is a great peace of software!

On the other hand, I once bought an arduino starter kit and blinked LEDs in many different ways. Of course, I learned a lot on the way doing all the tutorials. The next step was quite obvious, get a Raspberry. I did all the blinkings again, but in a more advanced way. I played with the pigpio library, tested their socket functionality, tried kivy on top, etc. Slowly you start to think of many applications, which all need other actuators than LEDs. I want to be able to move something.

I would like to use (to test) the ability of Linuxcnc and Raspberry to expand my opportunities, not drive a cnc.

To start exploring RPI and Linuxcnc, I compiled the Preemt rt kernel module and installed Linuxcnc from source on Raspian stretch lite. Here is how I did that:
Download Raspian from
        https://downloads.raspberrypi.org/raspbian_latest
Use Etcher under Windows to flash image to SD Card
create empty file ssh on SD Card boot
create file wpa_supplicant.conf on SD Card boot
write to wpa_supplicant.conf
        ctrl_interface=/var/run/wpa_supplicant GROUP=netdev
        update_config=1
        country=DE
        network={
                ssid = "myNewtwork"
                psk = "myPassword"
        }
power RPI, find his IP Adress and login with
        ssh -X pi@192.168.188.21
for cross compiling the RT Kernel I followed mainly
        https://autostatic.com/2017/06/27/rpi-3-and-the-real-time-kernel/
        https://www.raspberrypi.org/documentation/linux/kernel/building.md
crosscompiled on my local Ubuntu machine:
        mkdir ~/RT-CrossCompile
        cd ~/RT-CrossCompile
        uname -a > oldKernel.txt
        sudo apt-get install bc libncurses5-dev
        git clone https://github.com/raspberrypi/tools.git
        git clone --depth=1 https://github.com/raspberrypi/linux
        echo PATH=\$PATH:~/RT-CrossCompile/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin >> ~/.bashrc
        source ~/.bashrc
        cd linux
        export KERNEL=kernel7
        export ARCH=arm
        export CROSS_COMPILE=arm-linux-gnueabihf-
        export CONCURRENCY_LEVEL=$(nproc)
        make bcm2709_defconfig
        cd ..
        wget https://www.kernel.org/pub/linux/kernel/projects/rt/4.9/patch-4.9.68-rt60.patch.xz
        cd linux
        xzcat ../patch-4.9.68-rt60.patch.xz | patch -p1
        cd ..
        wget https://www.osadl.org/monitoring/patches/rbs3s/usb-dwc_otg-fix-system-lockup-when-interrupts-are-threaded.patch
        cd linux
        patch -i ../usb-dwc_otg-fix-system-lockup-when-interrupts-are-threaded.patch -p1 --dry-run -l
        patch -i ../usb-dwc_otg-fix-system-lockup-when-interrupts-are-threaded.patch -p1 -l
        make menuconfig
                Kernel Features -> Preemption Model -> Fully Preemptible Kernel (RT)
        scripts/config --disable DEBUG_INFO
        make -j$(nproc) deb-pkg
you will find several *.deb packages under ~/RT-CrossCompile, try to move them to your RPI and install them there
        sudo dpkg -i *.deb
        sudo nano /boot/config.txt -> kernel=vmlinuz-4.9.70-rt60-v7+
        sudo shutdown -r now

#LinuxCNC from source under ~/
sudo apt-git install git dpkg-dev
git clone git://github.com/linuxcnc/linuxcnc.git
cd linuxcnc/src
sudo apt-get install autoconf
./autogen.sh
./configure --with-realtime=uspace
cd ../debian
./configure uspace
cd ..
dpkg-checkbuilddeps
sudo apt -get install [all the packages]
sudo apt-get install bwidget libtk-img tclx python-gtk2
cd src
grep "\ install\ " /var/log/apt/history.log > ~/linuxcnc/installedPackages.log
./configure --with-realtime=uspace | tee ~/linuxcnc/config.log
make | tee ~/linuxcnc/make.log
sudo make setuid
source ~/linuxcnc/scripts/rip-environment
runtests | tee ~/linuxcnc/runtests.log

The next step would be to get an idea of how to access the gpios of the RPI. So, a little blinking LED through Linuxcnc would be great ;)
If anyone can give me some help to get started, I would appreciate.

Thanks a lot, regards

File Attachment:

File Name: installedP....log.txt
File Size:1 KB

File Attachment:

File Name: config.log.txt
File Size:8 KB

File Attachment:

File Name: make.log.txt
File Size:52 KB

File Attachment:

File Name: lshw.log.txt
File Size:3 KB
Attachments:
Last Edit: 30 Dec 2017 13:35 by goofy. Reason: added logfiles
More
30 Dec 2017 23:07 - 30 Dec 2017 23:09 #103881 by ozzyrob
ozzyrob replied the topic: Linuxcnc on Raspberry
So from your post you just want to use linuxcnc to control gpio's ?

IMHO machinekit maybe a better choice as there are Rpi gpio drivers.

This is a little bit overkill for what you want to do.

In a nut shell what you would have to do is create a hal file that loads the gpio driver (if there is one for the raspberry pi, machinekit does provide one but the realtime ability is not all that great), creates the threads and creates the required nets.

To make it interactive you would write a Pyvcp file with the required widgets and connect them to your gpios via the hal file.

I have done a similar thing, on a Beaglebone Black running machine kit, to test a cape and daughter board setup I am using to run my mill.

These will require modification to work with a Rpi, which I can try to help with but as I don't have a Rpi you will need to do some home work in regards to which driver to load and any required pin setup.

To help understand the xml file the Linuxcnc docs linuxcnc.org/docs/2.7/html/gui/pyvcp.html & linuxcnc.org/docs/2.7/html/gui/pyvcp-examples.html is a good place to start.

The hal file is for the BBB but should be able to be modified for the RPi.

setup.sh sets up the pins for the BBB, I am not sure if this is required for the RPi.

2-Port-Test.sh is just a convenient way of running the example.

All files are available here:

github.com/ozzyrob/pp_cape/tree/master/Test-Panel


I feel once you can get this working everything else is just a case of reading the hal docs and experimenting.

In The beginning you may just want to try something simple, such as reading a single pin and using a Led widget to display the status and use a button to write to a single pin. The example I've shown is just built on those 2 simple uses.

But in reality unless your are looking into suing the RPi as a cnc controller not a lot of benefit will come from this, you will gain more knowledge into the workings of linuxcnc but not a great deal of knowledge relating to the RPi.

Knowledge is knowledge and should not be discounted.
Last Edit: 30 Dec 2017 23:09 by ozzyrob.
More
31 Dec 2017 10:52 #103893 by goofy
goofy replied the topic: Linuxcnc on Raspberry
Thanks a lot for your answer and the provided path. So when start to read and think about it, a lot of questions come up. Yes, you are right, most of them belong to Linuxcnc. Anyway...

Lets start with the first part of the chain, the driver. Imagine you want to blink an LED on GPIO 25 on the Raspberry. with the pigpio lib you could do that with
#inlude <stdio.h>
#include <pigpio.h>

int main(int argc, char **argv)
{
	if (gpioInitialise()<0)
	{
		fprintf(stderr, "Initialise() failed\n");
	}
	else
	{
		gpioSetMode(25,PI_OUTPUT);
		gpioWrite(25,1);
		time_sleep(0.5);
		gpioWrite(25,0);
	}
	gpioTerminate();
	return 0;
}

Which part of it (setMode, write, wait) belongs to the driver, which to the hal? If I have a look to hal_sceleton (Im not a programmer!), there is mainly a write function. Would a hardware driver for the Raspberry make use of a library like pigpio, or would it do what pigpio does, accessing the hardware directly?

With halcomp, is it possible to compile drivers into a existing Linuxcnc installation or is it necessary to compile the whole?

A lot of maybe too basic questions. If you (anyone) are patiently enough to give an answer to, I really would appreciate.
More
31 Dec 2017 12:30 #103895 by ozzyrob
ozzyrob replied the topic: Linuxcnc on Raspberry
Before you go too much further I think it may be best to define your project, want you want to do.

IMHO what you are wanting to do (from your opening post) is not what Linuxcnc is about.
The core of what Linuxcnc (and machinekit) is about is running CNC type machines. What you are wanting to do is using the wrong tool for the job.

Here is a link to the machinekit Rpi driver.

github.com/machinekit/machinekit/blob/ma...l/drivers/hal_gpio.c

I can not see the benefit in using Linuxcnc to flash a LED, unless it is something you would want to incorporate into a control panel to give a visual status indication.

To manipulate Rpi gpios stick to the available libraries, be they python c or whatever, I think you will find them more flexible, if you want to run a machine then Linuxcnc is the tool you want.

Be aware that the Rpi is not really suited for software stepgen.
More
31 Dec 2017 13:48 - 31 Dec 2017 14:28 #103897 by goofy
goofy replied the topic: Linuxcnc on Raspberry
Thanks for the link to the driver. Actually it uses an existing library like bcm2835.

Your are right, to just to blink an LED, Linuxcnc is proberbly not the best choice. But when I use the home buttons on my cnc and jog arround, I have so many ideas to do exactly the same in other applications. I do have actually a little project in mind: I want to pimp my table saw. I want to add steppers to the ballsrews for adjusting the hide of the blade and the angle of. Add a XHC-HB04 (like I use on my mill) to control blade hight and the angle.

My mill runs perfectly under Linuxcnc. It does what it is meant for. But to be honest, I even did not understand my hal file completely. I thought it would be nice to go the whole process trough Linuxcnc to get an LED blinking (Output), maybe combined with a push button (Input). As a non programmer with a RPI on the table, Linuxcnc has everything on board what I can imagine to test things out. Handle Inputs and Outputs, combine them (logic) and build nice GUI (pyVCP) on it.

The next step for me will be to get your posted hal.gpio via halcomp into Linuxcnc. Right?
Last Edit: 31 Dec 2017 14:28 by goofy.
More
31 Dec 2017 22:02 #103910 by ozzyrob
ozzyrob replied the topic: Linuxcnc on Raspberry
If you read through the pyvcp documentation you will see that you can experiment just using pyvcp widgets to simulate a blinking LED.

The docs are a very good resource for information on hal and have some experiments you can perform without access to physical gpios. Going through these will give you a basic grounding that you should be able to adapt. What I am basically saying is what you want to experiment with need not affect actual hardware, it can all be done via pyvcp without even having to run axis. All the info is there in the docs.

Most users seem to be using an x86 platform for Linuxcnc, either using the various mesa cards or parallel port. Those that use an RPi tend to use external hardware for step-dir generation.

I have no idea how difficult it would be to port a machinekit driver to linuxcnc, a quite difficult task for a non programmer I would imagine.

From what I have been able to deduce Linuxcnc is best suited for x86 platforms and Machinekit for other non x86 platforms. As far as I can tell, through my own experimentation, what works on Linuxcnc will work on MK, apart from the hardware drivers for the particular platform.

As an example, I recently started on a project to that allows me to jog my machine, either step by step or continuously via a custom usb device. I did all my development on my laptop that runs linuxcnc that had been built as a "run-in-place" with realtime=user. So I would program a mcu with the usb firmware and run an instance of Linuxcnc in simulator mode to test. Once I was happy I gathered up my config files and moved them across to my Beaglebone Black running MK and merged the changes to the ini & hal file in. All worked as intended. It's much easier to develop in an air-con room than a 40' Centigrade shed. Gotta love summer. I used a lot of the information I found on the forums & wiki to complete my project.

One of the members of the forum has post some great tutorials on hal, pyvcp and hal:
gnipsel.com/linuxcnc/

I suggest you have a read.

Also read through the forums and make notes to gather as much info as you can.

And that my friend is about as much advice as I can give.
More
01 Jan 2018 21:46 #103936 by goofy
goofy replied the topic: Linuxcnc on Raspberry
Thanks a lot for your answer. Im a bit like a child, I have to try to get a LED turned on through Linuxcnc because I just want it;)

At the moment I try to get the machinekit gpio driver to Linuxcnc. Theres one user michael.oosten, he got it running. I don't know how to tell halcomp to use the needed cpuinfo.c and cpuinfo.h. I tried also to copy the relevant parts for generating hal_gpio while building from source from machinekit Makefile to Linuxcnc Makefile... it fails too.

Does anyone know how to do that?
More
02 Jan 2018 08:19 #103946 by ozzyrob
ozzyrob replied the topic: Linuxcnc on Raspberry
Stop wasting your time

Install machinekit then work out how to blink your LED, rather than trying to port a driver.

www.machinekit.io/docs/getting-started/installing-packages/

Or don't and waste time trying to port the MK driver to Linuxcnc
More
12 Jan 2018 17:19 #104349 by andypugh
andypugh replied the topic: Linuxcnc on Raspberry

goofy wrote: Hi,

its probably the hundreds post to Linuxcnc on Raspberry. And I know, arm is not supported by Linuxcnc. But...


That isn't entirely true. LinuxCNC is routinely compiled on the Arm platform by the builedbot to check that is is possible, and there are even arm binary packages made:

buildbot.linuxcnc.org/dists/wheezy/maste...reempt/binary-armhf/
Moderators: ArcEye
Time to create page: 0.269 seconds
Powered by Kunena Forum