This document describes the setup of Machinekit on a Thinkpad X200 running Debian/Jessie with a Xenomai real-time kernel. This setup is used to control a CNC machine with Beckhoff EtherCAT components.
-
2016-04-19: Successfully tested MachinekitClient.
- Server: Machinekit, QtQuickVcp, Cetus, and mklauncher on Debian/Jessie x64 (Thinkpad X200).
- Client 1: MachinekitClient on Ubuntu 16.04 x64 (Thinkpad X220).

- Client 2: Machinekit App on Android 5.0 (Nexus 4).

- Config files for this setup are in the
mklauncherbranch: https://github.com/koppi/mk/commits/mklauncher
-
2015-05-30: Current version based on Debian/Jessie
-
2015-05-26: Older version based on Debian/Wheezy
- IBM Thinkpad X200: Running Debian Jessie / Linux 3.8.1 / Machinekit 0.1 / Xenomai 2.6.4
- 24VDC 50W Power Supply
- Beckhoff EtherCAT Components
- SSR-40 DA Solid State Relay Module: (Currently unused, replaced by an EL2622 terminal)
- Power Supply for Kress Spindle / Vacuum Cleaner
- 24V Power Supply Input
- Ethernet Cable: From Thinkpad to EK1100 (EtherCAT Coupler)
- Output 1 (EL2004): To Solid State Relay Module
- Input 1 (EL1004): From Emergency Stop Button
- Input 2 (EL1004): From Touch Probe
- 24V Supply: From EL9184 distribution terminal to EL9100 bus terminal
- 24V Supply: For EL7041-1000 Stepper Motor Drivers
- Stepper Motor Outputs
- Small CNC Machine: Portal 210 x 230 x 70
- Nema23 Stepper Motor: 57BYGH627 - Wantai
- Kress 1050 FME-1 Spindle Motor
- Emergency Stop Push Button
- Touch Probe Input: For tool length sensor
- Machine Vise: 60x65mm
- https://www.youtube.com/watch?v=0LI99cNjB_c
- https://www.youtube.com/watch?v=2nGcliWefek
- https://www.youtube.com/watch?v=F3YbdD2OPRA
- https://www.youtube.com/watch?v=WRgyBxaeoAo
First, reset the BIOS to factory settings.
Then, disable the "Legacy USB" support in the BIOS. This can help with real-time performance.
Download the Debian Jessie 8.0.0 live ISO with non-free firmware.
# Primary URL
wget -c http://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/8.0.0-live+nonfree/amd64/iso-hybrid/debian-live-8.0.0-amd64-gnome-desktop+nonfree.iso
# Archive URL if the primary fails
wget -c http://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/archive/8.0.0-live+nonfree/amd64/iso-hybrid/debian-live-8.0.0-amd64-gnome-desktop+nonfree.isoVerify the checksum against the official MD5SUMS.
md5sum debian-live-8.0.0-amd64-gnome-desktop+nonfree.iso
7a56cc2f78f8ea90d0c78fc462f95b95 debian-live-8.0.0-amd64-gnome-desktop+nonfree.isoWrite the ISO to a USB stick. Warning: This will erase all data on the target device (/dev/sdX).
sudo dd if=debian-live-8.0.0-amd64-gnome-desktop+nonfree.iso of=/dev/sdX bs=4M status=progressInstall Debian from the USB stick and reboot.
To enable automatic login for your user, edit the GDM3 configuration.
# Replace 'koppi' with your username
sudo sed -i "s|^#\?.*AutomaticLoginEnable.*|AutomaticLoginEnable = true|" /etc/gdm3/daemon.conf
sudo sed -i "s|^#\?.*AutomaticLogin .*=.*|AutomaticLogin = koppi\nTimedLoginEnable = true\nTimedLogin = koppi\nTimedLoginDelay = 0|" /etc/gdm3/daemon.confThese settings optimize the Gnome desktop for a CNC controller environment.
gsettings set org.gnome.desktop.background primary-color '#000000'
gsettings set org.gnome.desktop.wm.preferences titlebar-font 'Cantarell Bold 8'
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 0
gsettings set org.gnome.desktop.lockdown disable-lock-screen true
gsettings set org.gnome.settings-daemon.plugins.xrandr default-monitors-setup do-nothing
gsettings set org.gnome.SessionManager logout-prompt false
gsettings set org.gnome.desktop.interface cursor-blink false
gsettings set org.gnome.settings-daemon.peripherals.mouse middle-button-enabled true
gsettings set org.gnome.Terminal.Legacy.Settings confirm-close false
gsettings set org.gnome.desktop.interface enable-animations false
gsettings set org.gnome.settings-daemon.plugins.cursor active false
sudo sed -i "/title_vertical_pad/s/value=\"[0-9]\\{1,2\\}\"/value=\"0\"/g" \
/usr/share/themes/Adwaita/metacity-1/metacity-theme-3.xmlEdit the systemd logind configuration to ignore the lid switch.
sudo vi /etc/systemd/logind.confChange #HandleLidSwitch=suspend to:
HandleLidSwitch=ignore
Restart the service to apply the change.
sudo systemctl restart systemd-logindSet up a static IP for the wireless interface by editing /etc/network/interfaces.
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.3
netmask 255.255.255.0
gateway 192.168.0.1
wpa-ssid "YOUR_SSID"
wpa-psk "YOUR_PASSWORD"Bring the interface up.
sudo ifup wlan0
/sbin/ifconfig wlan0Configure sudo to not require a password for your user group.
su -
# visudoChange this line:
%sudo ALL=(ALL:ALL) ALL
to:
%sudo ALL=(ALL:ALL) NOPASSWD: ALL
Add your user to the sudo group.
# usermod -aG sudo koppi # replace 'koppi' with your user idLog out and log back in for the group change to take effect.
To speed up SSH logins, disable DNS lookups on the server.
sudo sh -c 'echo "UseDNS no" >> /etc/ssh/sshd_config'To suppress the "last login" message, create a .hushlogin file in your home directory.
touch ~/.hushloginFollow the instructions from the official Machinekit documentation.
Add the Machinekit package repository key and source list.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 43DDF224
sudo sh -c \
"echo 'deb http://deb.machinekit.io/debian jessie main' > \
/etc/apt/sources.list.d/machinekit.list"
sudo apt-get updateInstall the Xenomai kernel and the Machinekit packages.
sudo apt-get -y install linux-image-xenomai.x86-amd64 linux-headers-xenomai.x86-amd64
sudo apt-get -y install machinekit machinekit-xenomai machinekit-posix machinekit-devEdit /etc/default/grub to add kernel parameters required for Xenomai.
# Find this line:
# GRUB_CMDLINE_LINUX_DEFAULT="quiet"
# And replace it with this:
GRUB_CMDLINE_LINUX_DEFAULT="quiet xeno_nucleus.xenomai_gid=120 xeno_hal.smi=1 lapic=notscdeadline hpet=disable i915.i915_enable_rc6=0 i915.powersave=0 intel_idle.max_cstate=1 processor.max_cstate=1 isolcpus=1 idle=poll"xeno_nucleus.xenomai_gid=120: Sets the group ID for Xenomai access. See Running a Xenomai application as a regular user.- The other parameters are for disabling power management features that can interfere with real-time performance.
Update the bootloader and reboot.
sudo update-grub
sudo rebootDuring reboot, select the Xenomai kernel from the "Advanced Options" in the GRUB menu.
After rebooting, verify that the Xenomai kernel is running.
uname -a
Linux x200 3.8-1-xenomai.x86-amd64 #1 SMP Debian 3.8.13-12~1jessie~1da x86_64 GNU/LinuxOnce confirmed, you can remove the standard Debian kernel.
sudo apt-get -y remove --purge linux-image-amd64 linux-headers-amd64 linux-image-3.16.*-amd64 linux-headers-3.16.*-common linux-headers-3.16.*-amd64 linux-kbuild-3.16Check if the Xenomai SMI (System Management Interrupt) workaround is enabled.
dmesg | grep Xeno
[ 0.632334] Xenomai: SMI-enabled chipset found
[ 0.632346] Xenomai: SMI workaround enabled
...Run the latency test for at least 10 minutes (24 hours is recommended for production systems).
sudo sh -c 'echo 0 > /proc/xenomai/latency'
timeout 600 xeno latencyNote the worst-case latency (lat min from the output, which is actually the max latency). Create an init script to set this value on boot. Multiply the value by 1000 (ns).
sudo nano /etc/init.d/xenomai-latencyPaste the following content, replacing 825 with your measured latency value.
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: xenomai-latency
# Required-Start: xenomai
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Set /proc/xenomai/latency value
### END INIT INFO
FILENAME=/proc/xenomai/latency
# Replace with your measured max latency in nanoseconds (value * 1000)
LATENCY=8250
test -e $FILENAME || exit 0
case "$1" in
start)
echo "Setting Xenomai latency to $LATENCY"
echo "$LATENCY" > $FILENAME
;;
stop)
;;
restart|force-reload)
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload}"
exit 1
;;
esac
exit 0Make the script executable and enable it.
sudo chmod +x /etc/init.d/xenomai-latency
sudo update-rc.d xenomai-latency defaultsAdd your user to the xenomai and kmem groups.
sudo usermod -aG xenomai,kmem koppi # replace 'koppi' with your user idLog out and log back in. Then run the Machinekit latency test.
latency-testWe will use the ec-debianize tool to build a Debian package for the IgH EtherCAT Master.
sudo apt-get -y install git debhelper gettext autoconf automake libtool dpatch libxenomai-dev
git clone https://github.com/sittner/ec-debianize
cd ec-debianize
./debian/configure -r xenomai # Specify xenomai build
dpkg-checkbuilddeps
dpkg-buildpackage -b -uc
cd ..
sudo dpkg -i etherlabmaster_*.deb
sudo cp ec-debianize/debian/etherlabmaster/etc/init.d/ethercat /etc/init.d/ethercatIn /etc/init.d/ethercat, you may need to change the config file path from /etc/sysconfig/ethercat to /etc/default/ethercat.
Enable the service:
sudo update-rc.d ethercat defaultsConfigure the master to use your Ethernet interface (eth0). Edit /etc/default/ethercat:
# Find your device with 'ifconfig' or 'ip a'
MASTER0_DEVICE="eth0"
# The driver for the NIC, e.g., e1000e for Intel gigabit
DEVICE_MODULES="e1000e"Install NTP for time synchronization.
sudo apt-get -y install ntpAdd your user to the ethercat group.
sudo usermod -aG ethercat koppi # replace 'koppi' with your user idLog out, log back in, and test the EtherCAT master.
sudo /etc/init.d/ethercat start
ethercat slaves
0 0:0 PREOP + EK1100 EtherCAT-Koppler (2A E-Bus)
1 0:1 PREOP + EL2004 4K. Dig. Ausgang 24V, 0.5A
2 0:2 PREOP + EL2004 4K. Dig. Ausgang 24V, 0.5A
3 0:3 PREOP + EL1004 4K. Dig. Eingang 24V, 3ms
4 0:4 PREOP + EL7041-1000 1K. Schrittmotor-Endstufe (50V, 5A, standard)
5 0:5 PREOP + EL7041-1000 1K. Schrittmotor-Endstufe (50V, 5A, standard)
6 0:6 PREOP + EL7041-1000 1Ch. Stepper motor output stage (50V, 5A, standard)
7 0:7 PREOP + EL2622 2K. Relais Ausgang, Schlie\u00df"er (230V AC / 30V DC)Install the lcec HAL driver for Machinekit.
sudo apt-get -y install machinekit-dev
git clone https://github.com/sittner/linuxcnc-ethercat
cd linuxcnc-ethercat
dpkg-checkbuilddeps
dpkg-buildpackage -b -uc
cd ..
sudo dpkg -i linuxcnc-ethercat*.debClone the configuration repository and link it.
cd ~
git clone https://github.com/koppi/mk
ln -s ~/mk/linuxcnc ~/linuxcnc
ln -s ~/mk/linuxcnc ~/machinekitlinuxcnc ~/linuxcnc/configs/koppi-cnc/koppi-cnc.iniln -s ~/linuxcnc/configs/koppi-cnc/koppi-cnc.desktop ~/Desktop/koppi-cnc.desktopThis setup uses a component to compensate for non-flat surfaces.
- Mount a touch probe.

- In the AXIS UI, under the MDI tab, run the
scan_surfaceO-code to probe the work area.o<scan_surface> call [0][0][220][220][10][100][10][1.5][-3]
- Activate the new measurements and create a plot.
cd ~/linuxcnc/configs/koppi-cnc/ cp engrcomp.txt koppi-cnc-engraving-comp.txt sudo apt-get -y install gnuplot-x11 ./koppi-cnc-engraving-comp-plot.sh

This script displays real-time parameters from the stepper motor terminals.
watch -n 0.1 ~/linuxcnc/configs/koppi-cnc/koppi-cnc-info.shGenerate a graph of the HAL connections.
sudo apt-get -y install python-pydot graphviz
~/linuxcnc/configs/koppi-cnc/hal-graph.py- Machinekit: Website, Google Group, GitHub
- LinuxCNC: Website, Forum
- EtherCAT: LinuxCNC EtherCAT Driver, sittner/linuxcnc-ethercat
- Xenomai Tuning: Estimate Clock Latency








