Techniek

Inhoudsopgave
1 Distributed motion system
2 Controller Area Network (CAN)
3 Processing G-code
4 Visualisatie
5 Breakpoints
6 Tools and libraries
7 Technische opmerkingen
8 Referenties, datasheets en links

1 - Distributed motion system
    De besturing bestaat uit een desktop applicatie en een aantal hardware modules. De desktop applicatie heeft de volgende functionaliteiten :
1 - Interpretie van G-code's
2 - Interactieve optimalisatie van G-code's
3 - Bediening van CNC maschine
4 - Bewaken en visualiseren van de CNC voortgang
    Module CONV002-CAN-USB fungeert als een soort van master en is via USB verbonden met de desktop computer. Ook is de deze mastermodule met alle andere slavemodules verbonden via het CAN serieel bussysteem. De module is uitgerust met niet vluchtig geheugen waarin een G-code bestand (afkomstig van de desktop) word opgeslagen. Gedurende een CNC sessie worden doorlopend G-code commando's in gesplitste vorm verstuurd naar de slave modules.
    Slavemodule STEPPER002-CAN-USB verzorgt de aansturing van een stappenmotor. Gesplitste G-code opdrachten worden gebufferd in een serieel geheugen. Een asynchroon proces leest de commando's en vertaald deze naar pulstreinen. Een ander proces stuurt de pulstreinen daadwerkelijk naar de stappenmotor. Daarnaast kunnen op deze module 2 eindschakelaars worden aangesloten. De eindschakelaars signaleren de uitersten van de bewegingsas. Deze en andere slave modules zijn uitgerust met een USB poort. Deze poort is gebruikt tijdens ontwikkeling maar is verder niet van belang voor de eindgebruiker.
    Slavemodule AUX001-CAN-USB heeft aansluitingen voor probe, koelvloeistof en spindelmotor toerental. G-code commando's zoals G38, M7, M8, M9, S worden door deze modules verwerkt.

2 - Controller Area Network CAN
    Vanwege databetrouwbaarheid en snelheid is de CAN bus een zeer geschikte kandidaat voor uitwisseling van gegevens tusen modules onderling. Communicatie vind plaats d.m.v. een 2-draadse verbinding. CAN heeft een multimaster architectuur. Dit betekent dat elke module op willekeurige momenten een bericht naar buiten mag sturen. Alle modules luisteren naar alle CAN berichten. Elk CAN bericht heeft een adres. Een module verwerkt enkel die berichten die voor hem bedoeld zijn.

3 - Processing G-code
During G-code processing a number of passes will be performed. In the final application one or more passes will be combined.
pass #1 : Tokens are specified by a lexer-grammar. Lexing converts the input file to tokens. A parser-grammar defines the syntax of the G-code language. Tokens and parser-grammar are input for the parser which then generates a parsetree. A parsetree is a n-ary tree representation of the G-code source program.
pass #2 : All blocks are checked on validity. Blocks like "G0 Z2 Y3" are converted to the more logic format "G0 Y3 Z2". Blocks like "X1 Y2 Z3" will be prepended with modal commands like G0 or G1. "F100 G0 X1 Y1" is better then "X1 F100 G0 Y1". A modified source file is generated.
pass #3 : Generation of a scopetree by walking the parsetree. The scopetree contains all information about variable names, types and scopes. Parsetree and scopetree are closely linked.
pass #4 : By walking parsetree and scopetree typechecking is performed.
pass #5 - Loops, functions and conditional statements will be converted to a series of G-code's. Everything will be converted to absolute positions in metric (mm) units
pass #6 - If Tool Radius Compensation (TRC) is active (G40 or G41) successive movement G-code's will be converted or extra movements will be inserted.
pass #7 - For path optimalisation, arc- or line-segments will be inserted
pass #8 - All movement commands will be split in separate axis movements
After pass #8 the G-code's are ready to be sent to mastermodule CONV002-CAN-USB through USB. After a start command from the desktop G-code lines will be sent to the right slavemodule. The machine starts working.

4 - Visualisation
Linenumbers in the original sourcode are also passed to the slavemodules. So if a line is executing or has been executed the slave module can signal this to the mastermodule and ultimately to the desktop. This information combined with the source code can be used for visualisation on the desktop. A currently activ line can be highlighted in the source code. In a 3D view the toolpath can be shown.

5 - Breakpoints
- Het frees- of draaiproces kan op ieder moment worden onderbroken door de "pauzeknop".
- In een G-code source file kunnen, door aanvinken van de betreffende regel(s), breakpoints worden ingegeven. Tijdens frezen of draaien stuurt mastermodule CONV002-CAN-USB continu G-code commando's naar de verschillende slave modules. Zodra een regel met breakpoint word gedetecteer word dit proces gestopt. Het CNC proces kan worden hervat door drukken van een inmiddels knipperende continue-knop.
- Ook is het mogelijk om vanaf een bepaald punt een aantal regels uit te voeren waarna met uitvoering word gestopt. Na het indrukken van de knipperende continue-knop word een vooraf ingesteld aantal regels uitgevoerd.

6 - Tools and libraries
Ubuntu-noble tools :
CodeBlocks IDE, SDCC 8051, GCC arm, GCC MinGW-w64, GCC x86/x86_64, flash8051, gdb-multiarch, Black Magic Probe debugger (hw), Silabs USB debug adapter (hw), KiCad, FreeCad
Windows-10 tools :
CodeBlocks IDE, Keil C51 compiler, Silabs USB debug adapter (hw), UVision5
C++ libraries :
GNU C++ Standard Library, wxWidgets 3.2.10, ANTLR 4.13.2, hidapi 0.16.0

7 - Technische opmerkingen

1 - Two processors Printed circuit board CONV002-CAN-USB heeft 2 processoren (c8051f320 en stm32f303). Beide microcontrollers communiceren via een standaard UART poort. De firmware in de c8051f320 bestaat voor het grootste deel uit USB HID functionaliteit. De desktop PC communiceert dus met de c8051f320. Tijdens ontwikkeling bleek dat het beter is om de USB functionaliteit buiten de stm32f303 te houden.
2 - Different USB HID behaviour Ubuntu-noble and Windows-10 show different behaviour with a USB HID device. When no IN packets send to host, Windows-10 host will send SUSPEND. In Ubuntu-noble this doesn't happen.
3 - Typical steppermotor frquency sherline 1 mm per rotation, stepper motor 200 full steps, reduction ratio 1, feed rates : plastic 2000-4000 mm/min, alu 1000-2500 mm/min, ss 300-800 mm/min.
Step frequency : 4000 mm/min = 66.7 mm/s -> 13340 steps/s = 13kHz. Pulse period : 75 us --> reaction on start command fast enough
4 - Hardware development Schematic and pcb CONV002-CAN-USB (KiCad)
Schematic and pcb STEPPER002-CAN-USB (KiCad)
Schematic and pcb AUX001-CAN-USB with (KiCad)
Simulate mounting pcb's in Hammond enclosures (FreeCad)
5 - Embedded software development Interfacing SPI winbond W25Q128FV (F320 master)
USB functionality (F320 master)
Interfacing SPI sgs L6480 (STM32 master)
Interfacing SPI microchip 23LC1024 (STM32 slave)
CAN functionality (STM32 master, slave)
G-code's USB to W25Q128FV (F320 master)
G-code's W25Q128FV to UART (F320 master)
G-code's UART buffer to 23LC1024 (STM32 master)
G-code's 23LC1024 to CAN (STM32 master)
G-code's from CAN to 23LC1024 (STM32 slave)
G-code's from 23LC1024 to stepper sequences in RAM (STM32 slave)
Stepper sequences via DMA to L6480 (STM32 slave)
6 - Desktop software development GUI development
Configuration
G-code interpretation
Path control and optimalisation
Setting breakpoints
Start, stop, pause, continue machine
Monitor CNC proces
Visualise toolpath
7 - Absolute or relativ coordinates, metric or imperial units In a G-code source file G90 en G91 determine if positions are absolute or relativ. G20 and G21 determine imperial or metric. After interpretation all positions are converted to absolute and metric. So after interpretation on the desktop G90, G91, G20, G21 are implicitly present in the generated data. Commands sent to axismodules include distance, cruise speed, accelleration and deceleration. The mastermodule keeps track of the absolute current position and stores it somewhere for later reference like visualisation.
8 - Plane select In a G-code source file G17-G19.1 (plane select) determine in which plane successiv arc movements will happen. So these commands are not visible anymore in the commands to axismodules.
9 - Tool table The tool table is stored and maintained on the desktop computer. Tool radius is already an implicit part of the slave module commands.
10 - G-code interpreter : data types and scopes During one pass a scopetree is generated. The scopetree is linked to the parsetree. This scopetree contains all symbols like variable names, variable types, variable scopes and function names. The scopetree is structured as a tree of (scope)nodes. Each node contains a hashmap of symbol objects. During runtime, values of program variables are read from or written to the scopetree.

8 - Referenties, datasheets en links
    Voor het realiseren van deze CNC besturing zijn meerdere bronnen geraadpleegd. Hierbij de meest relevante :

1 Future of G-code
referentie
2 The NIST RS274NGC Interpreter - Version 3
referentie
3 Mill series programming workbook (Haas)
referentie
4 Theory and design of CNC systems
referentie
5 Language implementation patterns (Terence Parr)
referentie
6 Definitive ANTLR4 reference (Terence Parr)
referentie
7 CNC programming handbook edition 3 referentie
8 CNC programming handbook second edition referentie
9 Crafting interpreters (Robert Nystrom)
referentie
10 Cross-Platform GUI Programming with wxWidgets (Bruce Perens)
referentie
11 LinuxCNC website
12 LinuxCNC : G-Code Quick Reference Table website
13 C8051F320 microcontroller
datasheet
14 STM32F303 microcontroller
datasheet
15 L6480 stepper controller
datasheet
16 1 Mbit spi serial ram
datasheet
17 128 Mbit serial flash
datasheet