HAL Contents

1 Hardware abstraction 1 1.1 Overview ...... 1 1.2 In Operating Systems ...... 2 1.2.1 Microsoft Windows ...... 2 1.2.2 AS/400 ...... 2 1.3 References ...... 2

2 LinuxCNC 3 2.1 Purpose ...... 3 2.2 History ...... 3 2.3 Platforms ...... 4 2.4 Design ...... 4 2.5 Configuration ...... 4 2.6 References ...... 4 2.7 External links ...... 5 2.8 Text and image sources, contributors, and licenses ...... 6 2.8.1 Text ...... 6 2.8.2 Images ...... 6 2.8.3 Content license ...... 6

i Chapter 1

Hardware abstraction

“Hardware Abstraction Layer” redirects here. For An example of this might be a “Joystick” abstraction. the UNIX-like operating system subsystem, see HAL The joystick device, there are many physical implemen- (software). tations, is readable / writable through an API which many joystick-like devices might share. Most joystick-devices Hardware abstractions are sets of routines in software might report movement directions. Many joystick- that emulate some platform-specific details, giving pro- devices might have sensitivity-settings that can be con- grams direct access to the hardware resources. figured by an outside application. A Joystick abstraction hides details (e.g., register formats, I2C address) of the They often allow programmers to write device- hardware so that a programmer using the abstracted API independent, high performance applications by providing needn't understand the details of the device’s physical in- standard Operating System (OS) calls to hardware. The terface. This also allows code reuse since the same code process of abstracting pieces of hardware is often done can process standardized messages from any kind of im- from the perspective of a CPU. Each type of CPU plementation which supplies the “joystick” abstraction. A has a specific instruction set architecture or ISA. The “nudge forward” can be from a potentiometer or from a ISA represents the primitive operations of the machine capacitive touch sensor that recognises “swipe” gestures, that are available for use by assembly programmers as long as they both provide a signal related to “move- and compiler writers. One of the main functions of a ment”. compiler is to allow a programmer to write an algorithm in a high-level language without having to care about As physical limitations (e.g. resolution of sensor, tem- CPU-specific instructions. Then it is the job of the com- poral update frequency) may vary with hardware, an API can do little to hide that, other than by assuming a “least piler to generate a CPU-specific executable. The same type of abstraction is made in operating systems, but common denominator” model. Thus, certain deep archi- tectural decisions from the implementation may become OS APIs now represent the primitive operations of the machine, rather than an ISA. This allows a programmer relevant to users of a particular instantiation of an ab- straction. to use OS-level operations (i.e. task creation/deletion) in their programs while still remaining portable over a A good metaphor is the abstraction of transportation. variety of different platforms. Both bicycling and driving a car are transportation. They both have commonalities (e.g., you must steer) and physi- cal differences (e.g., use of feet). One can always specify 1.1 Overview the abstraction “drive to” and let the implementor decide whether bicycling or driving a car is best. The “wheeled terrestrial transport” function is abstracted and the details Many early computer systems did not have any form of of “how to drive” are encapsulated. hardware abstraction. This meant that anyone writing a program for such a system would have to know how each Examples of “abstractions” on a PC include video input, hardware device communicated with the rest of the sys- printers, audio input and output, block devices (e.g. hard tem. This was a significant challenge to software devel- disk drives or USB flash drive), etc. opers since they then had to know how every hardware In certain computer science domains, such as Operat- device in a system worked to ensure the software’s com- ing Systems or Embedded Systems, the abstractions have patibility. With hardware abstraction, rather than the pro- slightly different appearances (for instance, OSes tend to gram communicating directly with the hardware device, have more standardized interfaces), but the concept of it communicates to the operating system what the device abstraction and encapsulation of complexity are common, should do, which then generates a hardware-dependent and deep. instruction to the device. This meant programmers didn't Hardware abstraction layers are of an even lower level in need to know how specific devices worked, making their computer languages than application programming inter- programs compatible with any device.

1 2 CHAPTER 1. HARDWARE ABSTRACTION

faces (API) because they interact directly with hardware 1.2.2 AS/400 instead of a system kernel, therefore HALs require less processing time than APIs. Higher level languages of- An “extreme” example of a HAL can be found in the ten use HALs and APIs to communicate with lower level System/38 and AS/400 architecture. Most compilers for components. those systems generate an abstract machine code; the Li- censed Internal Code, or LIC, translates this virtual ma- chine code into native code for the processor on which it is running and executes the resulting native code.[4] 1.2 In Operating Systems (The exceptions are compilers that generate the LIC it- self; those compilers are not available outside IBM.) This A hardware abstraction layer (HAL) is an abstraction was so successful that application software and operating layer, implemented in software, between the physical system software above the LIC layer that were compiled hardware of a computer and the software that runs on that on the original S/38 run without modification and with- computer. Its function is to hide differences in hardware out recompilation on the latest AS/400 systems, despite from most of the operating system kernel, so that most of the fact that the underlying hardware has been changed the kernel-mode code does not need to be changed to run dramatically; at least three different types of processors on systems with different hardware. On a PC, HAL can have been in use.[4] basically be considered to be the driver for the mother- board and allows instructions from higher level computer languages to communicate with lower level components, 1.3 References but prevents direct access to the hardware. BSD, Mac OS X, , CP/M, DOS, Solaris, and some [1] “Windows NT Hardware Abstraction Layer (HAL)". Mi- other portable operating systems also have a HAL, even crosoft. October 31, 2006. Retrieved 2007-08-25. if it is not explicitly designated as such. Some operat- [2] Helen Custer (1993), Inside Windows NT, Microsoft Press ing systems, such as Linux, have the ability to insert one while running, like Adeos. The NetBSD operating system [3] Russinovich, Mark. E.; Solomon, David A.; Ionescu, Alex is widely known as having a clean hardware abstraction (2008). Windows Internals: Including Windows Server layer which allows it to be highly portable. As part of this 2008 and Windows Vista. (5th ed.). Redmond, Wash.: system are uvm(9)/pmap(9), bus_space(9), bus_dma(9) Microsoft Press. p. 65. ISBN 978-0-7356-2530-3. and other subsystems. Popular buses which are used on [4] Soltis, Frank G. (1997). Inside the AS/400: Featuring the more than one architecture are also abstracted, such as AS/400e Series (2nd ed.). Loveland, Colo.: Duke Press. ISA, EISA, PCI, PCI-E, etc., allowing drivers to also be ISBN 978-1-882419-66-1. highly portable with a minimum of code modification. Operating systems having a defined HAL are easily portable across different hardware. This is especially im- portant for embedded systems that run on dozens of dif- ferent platforms.

1.2.1 Microsoft Windows

The Windows NT operating system has a HAL in the kernel space between hardware and the Windows NT executive services that are contained in the file NTOSKRNL.EXE.[1][2] This allows portability of the Windows NT kernel-mode code to a variety of proces- sors, with different memory management unit architec- tures, and a variety of systems with different I/O bus ar- chitectures; most of that code runs without change on those systems, when compiled for the instruction set ap- plicable to those systems. For example, the SGI Intel x86-based workstations were not IBM PC compatible workstations, but due to the HAL, Windows NT was able to run on them. Windows Vista and later (Windows Server 2008 and later for servers) automatically detect which hardware abstrac- tion layer (HAL) should be used at boot time.[3] Chapter 2

LinuxCNC

LinuxCNC (formerly “Enhanced Machine Controller” reference implementation of the industry standard lan- or “EMC2”) is a free, open-source GNU/Linux software guage for of machining operations, RS- system that implements numerical control capability us- 274D (G-code). ing general purpose computers to control CNC machines. The software included the RS274 interpreter driving Designed by various volunteer developers at linuxcnc.org, the motion trajectory planner, real-time motor/actuator it is typically bundled as an ISO file with a modified ver- drivers and a user interface. It demonstrated the feasi- sion of 32-bit Linux which provides the required bility of an advanced numerical control system using off real-time kernel. the shelf PC hardware running FreeBSD or Linux, inter- Due to the tight real-time operating system integration, a facing to various hardware motion control systems. Addi- standard Ubuntu Linux desktop PC without the real-time tional development continues using current and additional kernel will only run the package in demo mode. architectures (i.e. ARM architecture devices). The demonstration project was very successful and cre- ated a community of users and volunteer contributors. 2.1 Purpose Around June 2000, NIST relocated the source code to sourceforge.net under the Public Domain license in order LinuxCNC is a software system for numerical control of to allow external contributors to make changes. In 2003, machines such as machines, , plasma cut- the community rewrote some parts of it, reorganized and ters, routers, cutting machines, robots and hexapods. It simplified other parts, then gave it the new name, EMC2. can control up to 9 axes or joints of a CNC machine us- EMC2 is still being actively developed. Licensing is now ing G-code (RS-274NGC) as input. It has several GUIs under the GNU General Public License. suited to specific kinds of usage (touch screen, interactive The adoption of the new name EMC2 was prompted by development). several major changes. Primarily, a new layer known Currently it is almost exclusively used on x86 PC plat- as HAL (Hardware Abstraction layer) was introduced to forms, but has been ported to other architectures.. It interconnect functions easily without altering C code or makes extensive use of a real time-modified kernel, and recompiling. This split trajectory and motion planning supports both stepper- and servo-type drives. from motion hardware, making it easier to generate con- trol programs to support gantry machine, thread- It does not provide drawing (CAD - Computer Aided ing and rigid tapping, SCARA robot arms and a variety Design) or G-code generation from the drawing (CAM of other adaptations. HAL comes with some interactive - Computer Automated Manufacturing) functions. tools to examine signals and connect and remove links. It also includes a virtual oscilloscope to examine signals in real time. Another change with EMC2 is Classic Ladder, 2.2 History (an open-source ladder logic implementation) adapted for the real time environment to configure complex auxiliary The EMC Public Domain software system was originally devices like automatic tool changers. developed by NIST, as the next step beyond the National Around 2011, the name was changed officially from Center for Manufacturing Sciences / Air Force sponsored EMC2 to LinuxCNC. This was done at the insistence Next Generation Controller Program[NGC 1989] /Spec- of EMC Corporation and the agreement of the project ification for an Open Systems Architecture[SOSAS]. It leadership. Internally some refer to LinuxCNC by EMC was called the EMC [Enhanced Machine Controller Ar- or EMC2 as it was historically known. EMC Corpora- chitecture 1993]. Government sponsored Public Domain tion proposed that the LinuxCNC project, as previously software systems for the control of milling machines were named, would be confusing for customers or potential among the very first projects developed with the digital customers with their (mainly) storage related products. computer in the 1950s. It was to be a “vendor-neutral”

3 4 CHAPTER 2. LINUXCNC

2.3 Platforms motors, solenoids and other actuators. LinuxCNC also includes a software programmable logic Due to the need of fine grained, precise real time control controller (PLC) which is usually used in extensive con- of machines in motion, EMC requires a platform with figurations (such as complex machining centres). The real-time computing capabilities. It uses Linux kernel software PLC is based on the open source project with real time extensions (RTAI) or with RT-PREEMPT Classicladder,[6] and runs within the real-time environ- kernel using linuxcnc’s 'uspace' flavour of RTAPI. In- ment. stalling EMC2 (and the underlying real time extension) is a daunting task, therefore prebuilt binary packages have been built and are being distributed. The policy for 2.6 References EMC2 is to build packages and offer support on Ubuntu LTS (long-term support) releases.[1] Notes

[1] “Installing EMC2 ... and supported platforms”. Linux- 2.4 Design cnc Board of Directors. September 18, 2010. Retrieved 2010-09-29.

LinuxCNC uses the model of 'sense, plan, act' in its inter- [2] “Linuxcnc hardware design requirements”. actions with hardware.[2] For instance, it reads the current [3] “Simple Tp Notes”. axis position, calculates a new target position/voltage, and then writes that to the hardware. There is no buffer- [4] “EMC2’s Hardware Abstraction Layer”. Linuxcnc Board ing of commands nor are externally initiated reads or of Directors. Retrieved 2010-09-30. writes allowed. This no-buffering approach gives the [5] “A couple case studies”. Retrieved 2010-09-30. most freedom to adding or changing capabilities of Lin- uxCNC. By using relatively “dumb” external hardware [6] “ClassicLadder”. sites.google.com. Retrieved 2014-03- and programming the capabilities in the host computer, 06. LinuxCNC is not locked to any one piece of hardware. It also allows an interested user to easily change be- Bibliography haviour/capabilities/hardware. • This model tends to lend itself to specific types of ex- Proctor, F. M., and Michaloski, J., “Enhanced Ma- ternal interfaces---PCI, PCIE, (in SPP or chine Controller Architecture Overview,” NIST In- EPP mode), ISA, and Ethernet have been used for motor ternal Report 5331, December 1993. Available on- control. USB and RS232 serial are not good candidates; line at ftp://129.6.13.104/pub/NISTIR_5331.pdf USB having bad realtime capabilities and RS232 being • Albus, J.S., Lumia, R., “The Enhanced Machine too slow for motor control. Controller (EMC): An Open Architecture Con- LinuxCNC has basic “realtime” requirements because of troller for Machine Tools,” Journal of Manufactur- this model. The interval between reading and writing ing Review, Vol. 7, No. 3, pp. 278–280, September must be consistent and reasonably fast. A typical machine 1994. does realtime calculations in a 1 millisecond repeating • Lumia, “The Enhanced Machine Controller Archi- thread. The reading and writing to hardware must be a tecture”, 5th International Symposium on Robotics small part of this time, e.g. 200 microseconds, otherwise and Manufacturing, Maui, HI, August 14–18, the phase shift makes tuning more difficult and there is 1994, http://www.nist.gov/customcf/get_pdf.cfm? less time available for the non-realtime programs, which pub_id=820483 may make the screen controls less responsive. • LinuxCNC “employs a trapezoidal velocity profile Fred Proctor et al., “Simulation and Implementa- generator.”[3] tion of an Open Architecture Controller”, Simu- lation, and Control Technologies for Manufactur- ing, Volume 2596, Proceedings of the SPIE, Octo- ber 1995, http://www.isd.mel.nist.gov/documents/ 2.5 Configuration proctor/sim/sim.html • Fred Proctor, John Michaloski, Will Shackleford, LinuxCNC uses a software layer called HAL (Hardware [4] and Sandor Szabo, “Validation of Standard Inter- Abstraction Layer). faces for Machine Control”, Intelligent Automation HAL allows a multitude of configurations to be built [5] and Soft Computing: Trends in Research, Devel- while being flexible: one can mix & match various hard- opment, and Applications, Volume 2, TSI Press, ware control boards, output control signals through the Albuquerque, NM, 1996, http://www.isd.mel.nist. parallel port or serial port - while driving stepper or servo gov/documents/proctor/isram96/isram96.html 2.7. EXTERNAL LINKS 5

• Shackleford and Proctor, “Use of open source (Volumes 102 - 104): Digital Design and Man- distribution for a Machine tool Controller”, ufacturing Technology, 2010, http://dx.doi.org/10. Sensors and controls for intelligent manufac- 4028/www.scientific.net/AMR.102-104.363 turing. Conference, Boston MA, 2001, vol. • 4191, pp. 19–30, http://www.isd.mel.nist. Klancnik et al., “Computer-Based Workpiece De- gov/documents/shackleford/4191_05.pdf or tection on CNC Milling Machine Tools Using Op- http://dx.doi.org/10.1117/12.417244 tical Camera and Neural Networks”, Advances in Production Engineering & Management 5 • Morar et al., “ON THE POSSIBILITY OF IM- (2010) 1, 59-68, http://maja.uni-mb.si/files/apem/ PROVING THE WIND GENERATORS”, In- APEM5-1-view.pdf ternational Conference on Economic Engineering • Milutinovic et al., “Reconfigurable robotic machin- and Manufacturing Systems, Brasov, 25–26 Octo- ing system controlled and programmed in a ma- ber 2007, http://www.recentonline.ro/021/Morar_ chine tool manner”, The International Journal of L_01a.pdf Advanced Manufacturing Technology, 2010, http: • Zhang et al., “Development of EMC2 CNC //dx.doi.org/10.1007/s00170-010-2888-8 Based on Qt”, Manufacturing Technology & Ma- chine Tool, 2008, http://en.cnki.com.cn/Article_ en/CJFDTOTAL-ZJYC200802046.htm 2.7 External links

• Leto et al., “CAD/CAM INTEGRATION FOR • EMC2 project homepage at www.linuxcnc.org NURBS PATH INTERPOLATION ON PC BASED REAL-TIME NUMERICAL CON- • EMC2 project wiki TROL”, 8th INTERNATIONAL CONFERENCE • The NIST RS274NGC Standard - Version 3 Aug ON ADVANCED MANUFACTURING SYS- 2000 also available as a PDF TEMS AND TECHNOLOGY JUNE 12–13, 2008 UNIVERSITY OF UDINE - ITALY, http: • The Enhanced Machine Controller homepage at //158.110.28.100/amst08/papers/art837759.pdf NIST • Xu et al., “Mechanism and Application of HAL in the EMC2”, Modern Manufacturing Technol- ogy and Equipment 2009-05, http://en.cnki.com. cn/Article_en/CJFDTOTAL-SDJI200905037.htm

• Zivanovic et al., “Methodology for Configuring Desktop 3-axis Parallel Kinematic Machine”, FME Transactions (2009) 37, 107-115,

• Glavonjic et al., “Desktop 3-axis parallel kine- matic milling machine”, The International Journal of Advanced Manufacturing Technology Volume 46, Numbers 1-4, 51-60 (2009), http://dx.doi.org/ 10.1007/s00170-009-2070-3

• Staroveski et al., “IMPLEMENTATION OF A LINUX-BASED CNC OPEN CONTROL SYS- TEM”, 12th INTERNATIONAL SCIENTIFIC CONFERENCE ON PRODUCTION ENGI- NEERING –CIM2009, Croatian Association of Production Engineering, Zagreb 2009,

• Li et al., “Control system design and simula- tion of parallel kinematic machine based on EMC2”, Machinery Design & Manufacture 2010-08, http://en.cnki.com.cn/Article_en/ CJFDTOTAL-JSYZ201008074.htm

• Li et al., “Kinematics Analysis and Control System Design of 6-DOF Parallel Kinematic Machine with Matlab and EMC2”, Advanced Materials Research 6 CHAPTER 2. LINUXCNC

2.8 Text and image sources, contributors, and licenses

2.8.1 Text

• Hardware abstraction Source: http://en.wikipedia.org/wiki/Hardware%20abstraction?oldid=623653409 Contributors: Kku, Marius, Tagishsimon, Rich Farmbrough, Neg, Danhash, Chobot, DaGizza, NTBot, SmackBot, Brianski, Bluebot, Phatom87, Alaibot, Widefox, JAnDbot, Metrax, Mr. Stradivarius, Alexbot, Arjayay, DanielPharos, Callmejosh, Addbot, Dawynn, AnomieBOT, Erik9bot, Matzi4, WikitanvirBot, ZéroBot, MajorVariola, Ego White Tray, Bomazi, Helpful Pixie Bot, Wbm1058, Tech77, Greenstruck, Monkbot and Anonymous: 13 • LinuxCNC Source: http://en.wikipedia.org/wiki/LinuxCNC?oldid=646656844 Contributors: Archivist, Bearcat, Vadmium, Ringbang, GraemeLeggett, Ichudov, Chris the speller, Chendy, Wizard191, Servant74, Hebrides, Electron9, Arch dude, 7severn7, Cirt, Sun Cre- ator, Onomou, Addbot, Grandscribe, Team4Technologies, AnomieBOT, SubtlySnide, I dream of horses, EmausBot, JonathanMElson, SWPadnos, BG19bot, Game-Guru999, Autodidaktos, K7L, Mogism, Oroszegy, Petebachant, Chester8888 and Anonymous: 13

2.8.2 Images

2.8.3 Content license

• Creative Commons Attribution-Share Alike 3.0