jueves, 10 de septiembre de 2015

Instalación machinekit con kernel xenomai en PC

LinuxCNC se puede instalar en Debian y Ubuntu pero Machinekit solo se puede instalar en Debian Wheezy. Yo he logrado instalar LinuxCNC en Ubuntu 12.04 LTS (Precise) pero solo sirve en Sistemas Linux con arquitectura x86 (i686).

La ventaja que se tiene de instalar LinuxCNC en Ubuntu es que en este sistema la versión de glade-gtk2 (Glade 3.8) es estable y no tiene los bugs que se presentan en Glade con Debian, estos bugs se pueden corregir con algunos trucos que se explicarán en un tutorial donde inidique como crear GUI's.
Para instalar LinuxCNC en Ubuntu hay que instalar el kernel RTAI agregando los siguientes repositorios.

Ubuntu 12.04 LTS (Precise)

sudo nano /etc/apt/sources.list
deb     http://buildbot.linuxcnc.org/ precise master-rt
deb-src http://buildbot.linuxcnc.org/ precise master-rt
sudo apt-get update
sudo apt-get install linuxcnc

Para simulación

sudo nano /etc/apt/sources.list
deb     http://buildbot.linuxcnc.org/ precise master-sim
deb-src http://buildbot.linuxcnc.org/ precise master-sim
sudo apt-get update
sudo apt-get install linuxcnc-sim

Para seleccionar kernel con el que se quiere iniciar, instalar lo siguiente:

sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer
grub-customizer &

Por último instalar Glade 3.8.

sudo apt-get install glade-gtk2

Para realizar modificaciones en linuxcnc, recomiendo clonar de este repositorio link:

sudo apt-get install git
sudo apt-get install dpkg-dev
mkdir linuxcnc-dev
cd linuxcnc-dev
git clone git://git.linuxcnc.org/git/linuxcnc.git linuxcnc
cd linuxcnc/debian
./configure sim
cd ..
dpkg-checkbuilddeps
sudo apt-get install libpth-dev dvipng tcl-dev tk-dev tcl8.4-dev tk8.4-dev \
bwidget libxaw7-dev libncurses-dev libreadline-dev asciidoc source-highlight \
dblatex groff python-dev python-tk python-lxml libglu1-mesa-dev libgl1-mesa-swx11-dev \
libgtk2.0-dev libgnomeprintui2.2-dev autoconf libboost-python-dev texlive-lang-cyrillic \
texlive-lang-french texlive-lang-german texlive-lang-spanish texlive-lang-polish \
libmodbus-dev python-support libudev-dev libusb-1.0-0-dev 
sudo apt-get install tclx
sudo apt-get purge tcl8.4-dev tk8.4-dev
cd src
./autogen.sh
./configure --with-realtime=uspace
make
cd ..
. ./scripts/rip-environment
linuxcnc
#opcional para ejecutar directamente linuxcnc desde /scripts/rip-environment en la terminal
#crear respaldo de .bashrc
cd 
cp .bashrc .bashrc.bk
sh -c "echo 'if [ -f ~/linuxcnc-dev/linuxcnc/scripts/rip-environment ]; then\n\
    source ~/linuxcnc-dev/linuxcnc/scripts/rip-environment\n\
    echo \"Environment set up for running LinuxCNC-dev\"\n\
fi\n' >> ~/.bashrc"
linuxcnc

A continuación se va explicar como instalar Machinekit en el Sistema Debian Wheezy que se encuentra en la sección de descargas de LinuxCNC. Este se va instalar en modo simulador por usarse en una máquina virtual (VMware Workstation) y servirá para poder crear interfáz gráficas que se integrarán a la GUI gmoccapy_lcd7, utilizando glade con las librerías gtk2.

Para poder usar todas las funciones de VMware se necesita instalar "VMware Tools Installation" que se encuentra en la pestaña VM.


cd /media/cdrom0
sudo cp VMwareTools-10.0.0-2977863.tar.gz ~/Documents/
cd ~/Documents/
tar -xvf VMwareTools-10.0.0-2977863.tar.gz
cd vmware-tools-distrib/
sudo ./vmware-install.pl
sudo reboot

Escribir yes y luego seguir los pasos que van saliendo cuando diga [yes] poner yes y cuando diga [no] poner no, cuando no salga nada darle a la tecla Enter. Con eso ya se puede copiar archivos entre el sistema primario y la máquina virtual, se expande la ventana de la máquina para acomadarse al tamaño de la pantalla, se puede compartir archivos entre sistemas y muchos más.

Ahora hay que instalar el kernel que se va a usar para Machinekit y realizar los pasos que se encuentran en la página oficial Machinekit en Documentation -> Debian packages y Building From Source.

 Primero hay que configurar los repositorios para poder instalar todas las librerías que necesita Machinekit.

sudo sh -c \
    "echo 'deb http://deb.dovetail-automata.com wheezy main' > \
    /etc/apt/sources.list.d/machinekit.list; \
    apt-get update ; \
    apt-get install dovetail-automata-keyring"
sudo apt-get update 

Luego hay que instalar el kernel que se desee, en este caso se usara el kernel Xenomai para 32 bits.

sudo apt-get install linux-image-xenomai.x86-686-pae

Lo siguiente es instalar algunos paquetes necesarios para poder configurar y correr Machinekit.

sudo apt-get install libczmq-dev python-zmq libjansson-dev \
    libwebsockets-dev libxenomai-dev python-pyftpdlib 

otros (cython)

sudo sh -c \
    "echo 'deb http://ftp.us.debian.org/debian wheezy-backports main' > \
     /etc/apt/sources.list.d/wheezy-backports.list"
sudo apt-get update
sudo apt-get install -t wheezy-backports cython
sudo apt-get install bwidget
sudo apt-get update

Ahora hay que instalar git para clonar los archivos de Machinekit almacenados en github.

Nota: cuando se llegue a la parte de git clone elegir la ruta donde se quiere guardar la descarga. Lo mejor  es descargar en la ruta principal (cd ~/).

sudo apt-get install git dpkg-dev
sudo apt-get install --no-install-recommends devscripts equivs
git clone https://github.com/machinekit/machinekit.git
cd machinekit
debian/configure -px
sudo mk-build-deps -ir
cd src

Esta parte es muy importante, se va explicar como poder utilizar el kernel xenomai y configurar el modo simulación para utilizar en la máquina virtual.

./autogen.sh

Para elegir el modo de configuración existen los siguientes comandos.

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-remote      enable remote zeroMQ services
  --enable-examples      build included programming examples
  --enable-proto-js    build Javascript bindings based on https://github.com/dcodeIO/ProtoBuf.js/wiki
  --enable-shmdrv      use the common shared memory driver kernel module
  --enable-portable-parport      Build hal_parport using the ppdev ioctl instead of inb/outb
  --enable-emcweb      build the emcweb interface
  --enable-dev       build unstable development code
  --enable-nml      enable NML-using parts

Optional Features and Packages:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-platform-pc      Build for PC platform (default for x86 arch)
  --with-platform-beaglebone
                          Build for Beaglebone platform (default for ARM arch)
  --with-platform-raspberry
                          Build for Raspberry platform (default for ARM arch)
  --with-platform-zedboard
                          Build for Zedboard platform
  --with-rundir=<directory>  directory for IPC sockets and other transient files (default /tmp)
  --with-xenomai-kernel-sources="<ksrc_dir> <ksrc_dir>..."
                          directory paths of xenomai kernel source(s),
                          space-separated
  --with-rtai-kernel-sources="<ksrc_dir> <ksrc_dir>..."
                          directory paths of RTAI kernel source(s),
                          space-separated
  --with-shmdrv-kernel-sources="<ksrc_dir> <ksrc_dir>..."
                          directory paths of kernel source(s) to build shmdrv
                          module for
  --with-extra-kernel-sources="<dir> <dir>..."
                          list of extra kernel source directories to search
  --with-posix            build POSIX (simulator) non-realtime threads modules
                          (enabled by default)
  --with-rt-preempt       build RT_PREEMPT threads modules
  --with-xenomai          build Xenomai userland threads
  --with-xenomai-kernel   build Xenomai kernel-space realtime threads
                          (deprecated)
  --with-xeno-config=<path>
                          location of the xeno-config executable
  --with-rtai-kernel      build RTAI kernel-space realtime threads modules
  --with-rtai-config=<path>
                          location of the rtai-config executable
  --enable-drivers        Build hardware drivers
  --enable-usermode-pci   Build PCI drivers with usermode PCI support
  --with-libmodbus                        Specify whether or not to build
                                          the drivers that use libmodbus
                                          (defaults to "yes")
  --with-libusb-1.0                       Specify whether or not to build
                                          the drivers that use libusb-1.0
                                          (defaults to "yes")
  --with-lttng                       Specify whether or not to use
                                          the LTTNG tracing framework
                                          (defaults to "no")
  --disable-gtk        Disable the parts of LinuxCNC that depend on GTK
  --with-rmmod=</path/rmmod>              rmmod variant
  --with-insmod=</path/insmod>            insmod variant
  --with-python=<path>                    Specify the Python interpreter
  --enable-build-documentation=format   Build documentation.
                          Format may be "pdf" or "html" if only one format is desired.
  --with-tcl=DIR          directory containing tcl configuration
                          (tclConfig.sh)
  --with-tk=DIR           directory containing tk configuration (tkConfig.sh)
  --with-x                use the X Window System
  --disable-nls           don't use NLS
  --with-locale-dir=DIR   Location of the locale file(s)
                          DATADIR/locale
  --disable-python        Disable the parts of LinuxCNC that depend on Python
  --with-boost-python     specify the boost python shared library to use. For
                          instance, --with-boost-python=boost_python-py25.
                          Defaults to boost-python. If you use this then you
                          should probably set PYTHON too, to avoid using
                          multiple python versions.
  --with-boost[=ARG]      use Boost library from a standard location
                          (ARG=yes), from the specified location (ARG=<path>),
                          or disable it (ARG=no) [ARG=yes]
  --with-boost-libdir=LIB_DIR
                          Force given directory for boost libraries. Note that
                          this will override library path detection, so use
                          this parameter only if default library detection
                          fails and you know exactly where your boost
                          libraries are located.
  --with-boost-serialization[=special-lib]
                          use the Serialization library from boost - it is
                          possible to specify a certain library for the linker
                          e.g.
                          --with-boost-serialization=boost_serialization-gcc-mt-d-1_33_1
  --with-boost-thread[=special-lib]
                          use the Thread library from boost - it is possible
                          to specify a certain library for the linker e.g.
                          --with-boost-thread=boost_thread-gcc-mt
  --with-boost-system[=special-lib]
                          use the System library from boost - it is possible
                          to specify a certain library for the linker e.g.
                          --with-boost-system=boost_system-gcc-mt

En este caso hay que elegir el kernel xenomai y el modo simulación.

./configure --with-xenomai --with-posix

Ahora hay que compilar los archivos con el comando make, en caso de tener una pc con un procesador multinúcleo ejecutar "nproc" para saber el número de núcleos.

nproc
make -j#número que retorna nproc 
#o ejecutar directo
make -j`nproc`

por último ejecutar sudo make setuid y configurar lo siguiente en el caso de obtener advertencias.

sudo make setuid

Solucionar advertencias.

sudo touch /var/log/linuxcnc.log
sudo service rsyslog restart
sudo cp rtapi/rsyslogd-linuxcnc.conf /etc/rsyslog.d/linuxcnc.conf
sudo service rsyslog restart
sudo cp -i src/rtapi/shmdrv/shmdrv.rules /etc/udev/rules.d (si sale la advertencia)
sudo nano /etc/security/limits.conf
cambiar memclock de 20480 -> * - memlock 32767 #EMC2
ctrl+o y ctrl+x
sudo apt-get install avahi-daemon avahi-discover
sudo make setuid
sudo adduser <username>  xenomai -> (nombre de usuario que se haya asignado en S.O)
sudo reboot

Al reiniciar elegir el kernel xenomai, abrir terminal y escribir lo siguiente:

uname -a
sale lo siguiente -> Linux linuxcnc 3.8-1-xenomai.x86-686-pae #1 SMP Debian 3.8.13-9 i686 GNU/Linux
cd machinekit
. ./scripts/rip-environment

Con . ./scripts/rip-environment se activa la versión de Machinekit que se ha compilado, esto es muy útil para que se puedan añadir o modificar archivos, librerías, imágenes, etc; de este modo se evita dañar algún archivo del sistema de linux.

Nota: Ejecutar . ./scripts/rip-environment simpre que se quiera usar machinekit, solo es necesario volverlo a ejecutar cuando se cierra el terminal o se reinicia linux.
Si se quiere ejecutar siempre Machinekit desde la terminal de forma directa, se debe agregar una variable de entorno.

#Primero hacer un respaldo de .bashrc
cd
cp .bashrc .bashrc.bk
sh -c "echo 'if [ -f ~/machinekit/scripts/rip-environment ]; then\n\
    source ~/machinekit/scripts/rip-environment\n\
    echo \"Environment set up for running Machinekit and LinuxCNC\"\n\
fi\n' >> ~/.bashrc"

Ejecutamos linuxcnc (Machinekit)

linuxcnc

Y si todo salio bién ejecutara el programa.


1 comentario: