|running on workbench||16 September 2018|
The result of these instructions:
The result will have:
The hardware used:
All software compilation done on the Pi
I used a Raspbian Debian Jessie Full Desktop image,
create a directory for this project.
cd into it
Issue this command on the HOST system ( you dont have a useable RPI yet )
check the downloaded file
you should see
you want to see
Everything is Ok Size: 4661483821 Compressed: 1656816607
the _exact_ command I use is _NOT_ the command you need to use.
you need to know how to use dd or you can wipe your main harddrive.
my command was
dd if=2017-07-05-raspbian-jessie.img of=/dev/sdc bs=1M
This command takes a _long_ time and has _NO_ visual feedback It wil be nerve racking for the newbies, it will be coffee time for the wizards.
Next, do a initial booting of the SD card and do some minor configurations.
Boot the Pi by turning on the power,
Turn on the monitor likewise.
Log in _on_ the PI.
( using the connected keyboard (usb) mouse (usb) and monitor (hdmi) )
It takes almost a full minute ( seems very long )
I do the initial bootup right on the Pi,
I think it is simple and it works.
You will be automatically logged in as user 'pi'
you will be able to use sudo if neccesary your password ( unneeded ) is 'raspberry'
Run the raspi-config program.
This program is an easy way to configure your Pi.
Please use your own informations and preferences
Using raspi-config, I change these informations
use whatever you like, but remember it, you wont get back in without it the username will remain 'pi'
boot options | desktop/clI | text console require login
this removes the automatic entry to the desktop guI , I wont be using it later
boot options | splash screen | NO
else messy screen from graphic getting text written over it
localisation | locale | remove mark on en_GB add en_US UTF-8 UTF-8
I chose en_US.UTF-8, you choose what you need
localisation | time zone | asia bangkok
I doubt this is your choice
localisation | keyboard layout | generic 105key intl
interface options | SSH enable
Advanced options | Expand filesystem
YES you get a message "Root partition has been resized, will be enlarged on next reboot'
you get one more message "reboot now?"
The system will reboot, The screen will be all text The change for 'no splash' seems to fail for me, so I just repeat that step and it works
OK, that was just a test boot, now get a clean shutdown before try using ssh
sudo halt -n
NB: __ALWAYS__ shutdown clean, dont pull the power cord or kill the outlet
now wait, this is practice on how to shutdown the PI and not harm it or the SD card.
the screen will blank. wait longer for no green led flashes. wait for another green led hiccup then wait some more, at least 30 seconds after last green led flash. the red led will stay on, that just means the power supply is on and plugged in. NOW turn off the power supply and wait another 30 seconds after the red led is off.
Plug in an ethernet cable from your router to the pi
Power the PI back on ( it still has monitor keyboard and mouse ) and wait When you get login on the terminal screen, just let it sit there
SSH into the Pi from another computer (the HOST) connected to your lan.
Find the IP address of the HOST (not Pi) computer ( I use 'sudo ifconfig')
Find the IP addess of the PI ( I use 'ping' )
Now SSH into the Pi from the HOST.
example sudo ssh firstname.lastname@example.org
if you get
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
this means that the pi is at an address that _was_ known to belong to a different computer and we need to tell the system that its ok. (these are not the droids you seek) so, just delete the file /root/.ssh/known_hosts
then you should get the following messageOR
you had no problem and already got the following message.
(a sort of 'virgin found' message)
The authenticity of host '192.168.1.2 (192.168.1.2)' can't be established.
Are you sure you want to continue connecting (yes/no)?
the the system will add the new address to its allowed list after challenging you for the password of user 'pi'
... Warning: Permanently added '192.168.1.2' (ECDSA) to the list of known hosts. email@example.com's password:
enter PI's password here
pi@raspberrypi:~ $ <pi's_password>
lets check what the PI is running,uname -a
later, after we add the RT PREEMPT kernel, you'll see it change so its good to see a before & after report later, you'll also see these words 'PREEMPT RT'
After a proper shutdown,
you can remove from the Pi:
there are images that you can use
unless you BUILD it you dont have the tools or the sources for other , later purposes
so get dirty, build it
sudo apt-get update
sudo apt-get install git bc mc libncurses5-dev
git clone --depth=1 https://github.com/raspberrypi/linux -b rpi-4.14.y-rt
here i'm getting a specific branch, the ONLY realtime branch available on Raspbian (so far)
during the 'make menuconfig' you'll get an old school text gui ( a tui )
Kernel features | Preemption Model | mark FULLY PREEMPTABLE KERNEL RT
this step makes sure Fully Preemptble Kernel(RT) is chosen
(mine was ALREADY set, but its good to check )
make -j4 zImage modules dtbs this takes under 2 hrs (it all being done ON the Pi)
sudo make modules_install
I wasted DAYS here because it failed with my typo 'sudo make modules install' I had no underscore!
when you get HERE you have built the new RT Prempt Kernel, YAY!
then check that youhave an RT kernel running with
$ uname -a
Linux raspberrypI 4.14.66-rt40-v7+ #1 SMP PREEMPT RT Sat Sep 1 16:17:01 +07 2018 armv7l GNU/Linux
YAY It says PREEMPT RT (your version numbers may vary )
git clone git://github.com/linuxcnc/linuxcnc.git linuxcnc-dev
sudo apt-get install dpkg-dev
now find the dependancies ( most of them, )
the next cmd will report MOST ofthe missing dependancies for linuxcnc, we'll get the remaining few later
You need to build a shopping list from the result of the command,
the command returns something like this:
pi@raspberrypi:~/linuxcnc-dev $ dpkg-checkbuilddeps
dpkg-checkbuilddeps: Unmet build dependencies: debhelper (>= 6) tcl8.6-dev tk8.6-dev libreadline-gplv2-dev asciidoc (>= 8.5) dblatex (>= 0.2.12) \
docbook-xsl dvipng ghostscript graphviz groff imagemagick inkscape python-lxml source-highlight texlive-extra-utils texlive-font-utils texlive-fonts-recommended \
texlive-lang-cyrillic texlive-lang-french texlive-lang-german texlive-lang-polish texlive-lang-spanish texlive-latex-recommended w3c-linkchecker xsltproc python-dev \
libxmu-dev libglu1-mesa-dev libgl1-mesa-dev | libgl1-mesa-swx11-dev libgtk2.0-dev gettext intltool libboost-python-dev yapps2
then get these deps ( from the report, remove the versions, and pick one mesa )
I copied the output of dpkg-checkbuilddeps and turned it into an apt-get command _like_ this:
sudo apt-get install debhelper tcl8.6-dev tk8.6-dev libreadline-gplv2-dev asciidoc dblatex docbook-xsl dvipng ghostscript graphviz groff \
imagemagick inkscape python-lxml source-highlight texlive-extra-utils texlive-font-utils texlive-fonts-recommended texlive-lang-cyrillic \
texlive-lang-french texlive-lang-german texlive-lang-polish texlive-lang-spanish texlive-latex-recommended w3c-linkchecker xsltproc \
python-dev libxmu-dev libglu1-mesa-dev libgl1-mesa-dev libgtk2.0-dev gettext intltool libboost-python-dev yapps2
some sites may fail, its a LONG list and the interweb can be flaky
If your attempt fails, just doggedly keep trying till it succeeds,
use the same command, so its in your history, available using the UP arrow key
I had to run it up to 3 times to succeed
these files may take a long time to get ( depends on interweb )
and will take a VERY long time to install ( maybe 1 1/2 hours )
if its quick, then its wrong !
after a VERY long time you will get an annoying error
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)
I dont know how to avoid this error,
I do know how to fix it.
The problem is that there is a file in the apr-get download, that refers to a bad path
That file needs editing and you dont have the file until midway thru the install!
( bite bullet here )
Here's how to edit it
the offending file is /var/lib/dpkg/info/w3c-markup-validator.postinst
change the stanza that MOSTLY looks like this to EXACTLY THIS
if [ ! -s /etc/$server/conf.d/w3c-markup-validator.conf ]; then
ln -s /etc/w3c/httpd.conf \
( you are changing the 3rd line of this stanza FROM "conf.d" TO "conf-enabled" )
run the apt-get command AGAIN...
now you will get ANOTHER message that requires some attention, its simple though...
Enabling module include.
To activate the new configuration, you need to run:
service apache2 restart
Enabling module rewrite.
To activate the new configuration, you need to run:
service apache2 restart
ok, you type:
sudo service apache2 restart
next, you need a few more missed deps ( yes STILL missing some )
sudo apt-get install bwidget libtk-img tclx autoconf
NOW you finally have all the deps (afaict)
for me, the 'make' took just over 1/2 hour
sudo make setuid
OK, LinuxCNC is built, and set up for user permissions, now we can test it.
NOTE: We built this as a RIP ( run-in-place ),
Get used to this litany of commands.
Open a new terminal and say the following everytime you use LinuxCNC or Hal etc
do a clean shutdown
then bring it all back up and from the HOST
sudo ssh -X firstname.lastname@example.org
This will enable X forwarding and we can see the program window from the PI on the HOST screen.
You will still see just a text terminal output UNTIL we open an xwindows app on the PI.
Now to improve latency before testing latency:
Add to cmdline.txt
It _was_ this:
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=0358fc90-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
I added to end of the line :
quiet splash lapic noxsave acpi_osi= isolcpus=2,3 idle=poll acpi_irq_nobalance noirqbalance vmalloc=32MB clocksource=acpi_pm
( this 'improve latency' is from notes at https://groups.google.com/forum/#!msg/machinekit/t2eCs09EvrU/r4Ta5GtGDgAJ a discussion of rpI rtpreempt and machinekit)
For testing the realtimey-ness of your new system, you need more.
sudo apt-get install mesa-utils
This is for glxgears , used in latency testing to load the cpu.
latency-histogram --base 100000 --servo 1000000
A base thread is important for parport type stepping systems using 'double-step'.
We may NOT need it but I plan on implementing double step for hal_gpio .
Once it is running, you can open 4 glxgears ( theres a button )
Let this run overnight or a day or so, I did :-)
I expect you will see the largest reported latency to be near 70 uSec.
update 24sep2018 I saw one latency of 83uS during a 36hr test
I have not seen any realtime errors in use of linuxcnc,
so one occurred when it didnt get detected( linuxcnc was not running )
copy bcm2835.h , cpuinfo.h and hal_gpio.c files to linuxcnc-dev/src/hal/drivers set owner pi:pi set permissions rwxr-wr-w
copy new Makefile to linuxcnc-dev/src/ The new Makefile has rules to compile and link hal_gpio.c.
execute: make modules
done building stuff, begin using stuff :-) !
You can edit your .inI file similar to what I did to get similar results
[EMC_MOT] ... BASE_PERIOD = 100000 SERVO_PERIOD = 1000000
Your .inI file BASE_PERIOD value should be slightly larger than...
the largest number seen PLUS your .hal file step timing values for stepgen.<chan>.steplen + stepgen.<chan>.stepspace
Be a little generous here, a few additional microseconds is good ( unscientific fudge factor, but good practice )
You will NOT be able to use any step wizardy tools here, you will need to hand edit a file from the wiz or some supplied example. Because the wizards wont work with latencies as large as yours ( if you can get less than 50uS, go for it )
My BASE_PERIOD is 100000 and my RPI runs for weeks now with no Unexpected Reatime Delays. My resultant step rate is 5000
You can ease up the load that AXIS places on the system by increasing the CYCLE_TIME [TASK] ... CYCLE_TIME = 0.010
After this step, and the RPi's strength, Axis is a bit choppy, but there are no 'latency excursions' ( non-rt, TASK related delays ).
Axis is very useable, I can rotate 3D, zoom and pan without pain, it aint fast but it dont crash neither.
Just as examples, here are my .ini and .hal files.
I Almost forgot, but making the masks up for hal_gpio is tough!
I need to write up how to do that or get permissions to use a spreadsheet I saw.
There are some notes in the above .hal file.
You can have uo to 26 i/o pins, or 22 with SPI or less with serial ports or ( theres a lot of ways to use pins on the Pi )
here is some more info https://groups.google.com/forum/#!msg/machinekit/t2eCs09EvrU/r4Ta5GtGDgAJ
Hardware Step Generator: see: https://github.com/kinsamanka/PICnc-V2/wiki Kinsa Manka's PICnc is a hardware step generator that is suited to the RPi Its hardware and a software module, allowing up to 40kHz pukse rates
Double Step for hal_gpio: see: https://emergent.unpythonic.net/01188134101 There's a trick that Jepler created back in the day, so that a single servo cycle could produce a high AND a low ( the stepgen module has a kind of soft one-shot timer ) Without this, your step rate is halfed! so it is a _very_ good thing to have
Test TB6560 with FullStep? to get 10x faster than G540 ( and 10x coarser ).
Get rid of breadboard and make circuit board. Breadboards have terrible connections!
back to outline 
|fairly stiff||comparitively cheap|
|1.5mm pitch screw|
|tiny workvolume||fun for me|
|G540, AC entry||48V Kelling|
parts suppliers ( not an endorsement )
Raspberry PI 3B with official power supply https://www.raspberrypi.org/products/raspberry-pi-3-model-b/
SD card ( 10x rated ) similar to https://www.sparkfun.com/products/14832
3.3V to 5V bidirectional i/o modules similar to https://www.sparkfun.com/products/12009
Gecko G540 4 axis stepper driver https://www.geckodrive.com/g540.html
great drive, but the 10x microstepping is problematic in that it requires 10x higher Step ratesSable 2015 minI mill http://www.cnc-sable.nl/sable-2015-tafelfrees-p-21.html?language=en
I bought mine direct from mfctr when I was working in Taiwan, great little desktop machinePalm router for spindle similar to Makita cheap line http://makitathailand.com/mt370trimmer
The 10mm dia 1.5mm pitych screws and round linear rails are ok
The stroke is short but the machine is pretty stiff.
As cheap as you can get, i got one for about 14USD on salehockey puck SSR for Spindle power similar to http://www.crydom.com/en/products/panel-mount/
The single oddball collet gives me .0053" tir,
I will replace as soon as possible with an older German Overarm router with better collets and runout.
back to outline