Design and develop both a multi-threaded PC GUI application as well as an XMC RTOS application using uCOS-III to control a MakeBlock XY plotter as shown below. In either case you can select a file format (G-Code, Excellon, HPGL or SVG — see below) to determine the content that shall be drawn using the machine. As an alternative you could devise a simple drawing application to do the same. The stepper motors and the servo motor are controlled by the XMC4500 via an IO expander board and several driver boards.
Here is the subset of SVG parameters supported and recognised when opening, importing or saving:
width |
|
height |
|
viewbox |
|
rect |
|
ellipse |
|
circle |
|
polyline |
|
polygone |
|
path |
|
text |
|
transform |
|
Note
|
Colors not supported! |
Here is the subset of G-CODE currently supported
G28 |
|
G90 |
|
G91 |
|
G01 |
|
G02 |
|
Possible commands:
-
#G28$ : Plotter will move to its (0, 0) position and stop there.
-
#G90$ : Plotter will interprete all subsequent commands as absolute movements.
-
#G91$ : Plotter will interprete all subsequent commands as relative to the current position.
-
#G01:XA:YB$ : Plotter will move linearly to the point (A, B) - relative or absolute.
-
#G01:ZK$ : Plotter’s pen will be dropped (K = 1) or lifted up (K = 0).
-
#G02:XA:YB:IC:JD$ : Plotter will move in a circular way to the point (A, B), taking as reference the center at (A+C, B+D) - relative or absolute.
Using baudrate of 75000 for the spi, the following mesurements were found for the various step mode:
HW-Adjustment | Mode | x, y-Dimension |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The ratio of steps measured is ~1,1633, i.e. HEIGHT_STEP = ~0,86*WIDTH_STEP. The canvas where the user can draw something has the dimension: 555px X 477px, accounting for a ratio of ~1,1635.
In effect, every point (x, y) in canvas, will be scaled as follows:
-
x_to_plot = x . (WIDTH_STEP/CANVAS_WIDTH)
-
y_to_plot = y . (WIDTH_STEP/CANVAS_WIDTH)
so that for the point (0, 0) in GUI, the plotter will receive (0, 0) and for the point (555, 477), the plotter will receive (WIDTH_STEP, ~0,86*WIDTH_STEP).
Ctrl+N |
|
Ctrl+O |
|
Ctrl+S |
|
Ctrl+Shift+S |
|
Ctrl+? |
|
Ctrl+Z |
|
Del |
|
-
File
-
New: clean canvas and start new project.
-
Open: opens a svg file.
-
Save: saves canvas to already saved file or calls save as if still not saved.
-
Save As: saves canvas with a new name.
-
Quit: closes app.
-
-
Settings
-
Svg Directory: define the directory to import the svg’s from when using the import tool.
-
Step Motor: define the step resolution, according to section 'Scaling & Resolution'.
-
-
Help
-
About: basic info about this app.
-
Eraser |
|
Freehand |
|
Line |
|
Square |
|
Rectangle |
|
Polygone |
|
Select |
|
Magnifier |
|
Text |
|
Circle |
|
Ellipse |
|
Import |
|
Manual & Auto |
|
PromptEdit |
|
Mini Terminal |
|
Directional Buttons |
|
Pen Button |
|
Clear Terminal |
|
- Mode
-
- Manual
-
In this mode one can use the directional and pen buttons to control the plotter.
- Auto
-
In this mode one can generate g-code automatically when pressing the play button. A progress bar will show the progress of the plotting. Using the pause button, the user can always pause the current plotting and use the flow control buttons to step through the g-code commands and plot the next or previous commands.
Any time the XMC4500 receives something through its UART channel, it gets interrupted. The message is then read and forwarded onto the 'AppTaskCom' task. This task will check the message for protocol compliance and interpret the content. The 'AppTaskCom' task will finally send the interpreted message (now in the form of a structure) to the 'AppTaskPlot' task, that will execute the command received. When the 'AppTaksPlot' is done with the g-code command it will send an acknowledge message. If a '#GX:…$' is sent, then the microcontroller will send at completion the string: '#GX:DONE$'.
The communication between GUI and the XMC4500 happens through UART, using the following scheme as protocol.
Where:
-
#: Beginn of message;
-
G COMMAND: One of the supported G-Code commands [vide following section];
-
ARG{1}: a apropriate argument to the G command;
-
ARG{2}: another apropriate argument to the G command;
-
$: End of message;
Note
|
The number of arguments in a message should conform to the G command |
The software comprising this project was built and tested using the following environment:
- Hardware
-
- Plotter
-
-
MakeBlock XY_Plotter
-
- Microcontroller
-
-
Infineon XMC4500
-
- Interface
-
-
UART TTL
-
USB
-
- Operating Systems
-
- Linux
-
-
Ubuntu 16.04
-
Desktop
-
-
Ubuntu 17.04
-
Desktop
-
-
Ubuntu 18.04
-
Desktop
-
-
Fedora 28
-
Desktop
-
-
- Framework & Tools
-
- GUI
-
-
PyQt5 + Qt
-
Qt Designer
-
pyuic5
-
-
- Firmware
-
-
Micrium
-
uCOS III
-
-
Infineon
-
XMCLIB
-
-
- Documentation
-
-
Asciidoctor
-
asciidoctor-pdf
-
-
- Python3
-
-
PyQt5
-
pyudev
-
- arm-none-eabi
- SEGGER J-Link
sudo -H pip3 install pyqt5 sudo -H pip3 install pyudev
If you’re using Fedora, maybe you’ll need:
dnf install python3-pyudev-qt5