Welcome to SiviCNCDriver’s documentation!¶
What is SiviCNCDriver ?¶
SiviCNCDriver, as its name lets you guess, is designed to drive a CNC. What does it do ?
- Provides a basic tool to view and edit G-Codes files. You can see which G-Code line draws which path and perform some basic edits with the preprocessor, such as finding an origin to the coordinate system which minimize the bounding box of the drawing.
- Allows you to control manually your CNC, by :
- Sending your own G-Codes;
- Sending custom G-Codes so the machine performs continuous movements, or step-by-step movements;
- Sending automatic commands so the machine performs some goings and comings and you can measure the play or the steps/mm.
- Sends as custom G-Codes and store as JSON configuration files for your machine.
Screenshots¶
Installation¶
Using pip¶
On any operating system with a python and pip installated, use pip (you may need superuser privilege)
pip install sivicncdriver
Then you should be able to run the program with a simple:
sivicnc
You can get the development version using pip, although it is not recommended.
pip install git+git://github.com/Klafyvel/SiviCNCDriver
Contribute¶
The project has its own Git repository on GitHub.
You nill need virtualenv
pip install --user virtualenv
Create a directory in which we will work.
mkdir SiviCNCDriver
cd SiviCNCDriver
Clone the project
git clone https://github.com/Klafyvel/SiviCNCDriver.git
Then create the virtual environment
virtualenv ENV
Activate it
source ENV/bin/activate
Download the dependencies
cd SiviCNCDriver
pip install -r requirements.txt
You can code ! To test the code, run the application as package
python -m sivicncdriver
If you need to re-create the ui after editing it with QtCreator, you can use make_ui.sh or directly pyuic5.
Custom G-Codes¶
SiviCNCDriver uses several custom G-Codes, they may change in the future.
Command | Explanation |
---|---|
S0 Xnnn Ynnn Znnn |
Perform a straight line with nnn in steps on the given axes. A negative number make the axis go backward. |
S1 X Y Z |
Trigger continuous advancement forward on the given axes. |
S2 X Y Z |
Trigger continuous advancement backward on the given axes. |
S3 X Y Z |
Stop continuous advancement (if exists) on the given axes. |
S5 X Y Z |
Set driving mode to normal on the given axes. |
S6 X Y Z |
Set driving mode to max torque on the given axes. |
S7 X Y Z |
Set driving mode to half steps on the given axes. |
S8 Xnnn Ynnn Znnn |
Set the play of the given axes, with nnn in millimeters. |
S9 X Y Z |
Set the given axes sense to reverse. |
S10 X Y Z |
Set the given axes sense to normal. |
S11 Xnnn Ynnn Znnn |
Set the minimal duration between two pulses for the given axes. |
License¶
SiviCNCDriver Copyright (C) 2017 Hugo LEVY-FALK
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
sivicncdriver¶
sivicncdriver package¶
Subpackages¶
sivicncdriver.gcode package¶
Submodules¶
sivicncdriver.gcode.arc_calculator module¶
It creates small segments from an arc given with G-codes parameters : origin, end, path to center and sense of rotation.
Example: |
---|
>>> from arc_calculator import arc_to_segments
>>> a = arc_to_segments((0,0),(5,0),(10,0))
>>> for x,y in a:
... print((x,y))
...
(0.0, 6.12323e-16)
(0.09966, -0.993334)
(0.39469, -1.94708)
(0.87331, -2.8232)
(1.51646, -3.58677)
(2.29848, -4.20735)
(3.1882, -4.66019)
(4.15015, -4.92725)
(5.14598, -4.99787)
(6.136, -4.86924)
(7.08072, -4.54649)
(7.94249, -4.04249)
(8.68696, -3.37733)
(9.28444, -2.57752)
(9.71111, -1.67495)
(10, 0)
-
sivicncdriver.gcode.arc_calculator.
arc_to_segments
(start, vect_to_center, end, clockwise=False, length=1)[source]¶ Creates small segments from an arc.
Uses Decimal for better precision. It yields the vertices.
Parameters: - start (A float tuple) – The starting position
- vect_to_center (A float tuple) – A vector to go to the center of the arc from the starting position
- end (A float tuple) – The ending position
- clockwise (bool) – Should it go clockwise ?
- length (float) – length of the segments
Returns: None, it yields vertices.
sivicncdriver.gcode.gcode module¶
A module to parse G-codes.
sivicncdriver.gcode.gcode_maker module¶
A bunch of command to easily create G-Codes.
-
sivicncdriver.gcode.gcode_maker.
config_as_gcode
(**kwargs)[source]¶ Make a set of commands to save the configuration.
Parameters: - x_ratio (float) – The X axis ratio (mm/step)
- y_ratio (float) – The Y axis ratio (mm/step)
- z_ratio (float) – The Z axis ratio (mm/step)
- x_drive (int) – X axis drive mode (0:normal, 1:full torque, 2:half step)
- y_drive (int) – Y axis drive mode (0:normal, 1:full torque, 2:half step)
- z_drive (int) – Z axis drive mode (0:normal, 1:full torque, 2:half step)
- x_play (float) – X axis play
- y_play (float) – Y axis play
- z_play (float) – Z axis play
- x_reverse (bool) – Should the X axis be reversed ?
- y_reverse (bool) – Should the Y axis be reversed ?
- z_reverse (bool) – Should the Z axis be reversed ?
- x_min_time (int) – The minimal duration between 2 pulse for the x axis in milliseconds.
- y_min_time (int) – The minimal duration between 2 pulse for the y axis in milliseconds.
- z_min_time (int) – The minimal duration between 2 pulse for the z axis in milliseconds.
-
sivicncdriver.gcode.gcode_maker.
start_continuous
(axis, direction='forward')[source]¶ Start a continuous movement in the given direction. :param axis: The axis which is to move. :param direction: The direction. :type axis: str :type direction: str
-
sivicncdriver.gcode.gcode_maker.
start_continuous_x_backward
()[source]¶ Start a continuous movement on X axis backward
-
sivicncdriver.gcode.gcode_maker.
start_continuous_x_forward
()[source]¶ Start a continuous movement on X axis forward.
-
sivicncdriver.gcode.gcode_maker.
start_continuous_y_backward
()[source]¶ Start a continuous movement on Y axis backward
-
sivicncdriver.gcode.gcode_maker.
start_continuous_y_forward
()[source]¶ Start a continuous movement on Y axis forward.
-
sivicncdriver.gcode.gcode_maker.
start_continuous_z_backward
()[source]¶ Start a continuous movement on Z axis backward
-
sivicncdriver.gcode.gcode_maker.
start_continuous_z_forward
()[source]¶ Start a continuous movement on Z axis forward.
-
sivicncdriver.gcode.gcode_maker.
step
(axis, n)[source]¶ Moves the given axis of n steps.
Parameters: - axis (str) – The axis
- n (int) – number of steps
-
sivicncdriver.gcode.gcode_maker.
step_x
(n)[source]¶ Moves the X axis oh n steps. :param n: The number of steps :type n: int
-
sivicncdriver.gcode.gcode_maker.
step_y
(n)[source]¶ Moves the Y axis oh n steps. :param n: The number of steps :type n: int
Module contents¶
sivicncdriver.serial package¶
Submodules¶
sivicncdriver.serial.serial_list module¶
sivicncdriver.serial.serial_manager module¶
Provides a class to handle the CNC machine through a serial object.
-
class
sivicncdriver.serial.serial_manager.
SerialManager
(serial, fake_mode=False)[source]¶ Bases:
PyQt5.QtCore.QObject
A class to manage the serial port.
It will try to send what it receive and send via the send_print signal. When it receive a ‘ok’ from the serial it will send the send_confirm signal.
-
open
(baudrate, serial_port, timeout)[source]¶ Opens the serial port with the given parameters.
Parameters: - baudrate – The baudrate.
- serial_port – The port to be used.
- timeout – Timeout for reading and writing.
-
readMsg
()[source]¶ Reads a line from the serial port. And emit the send_print or send_confirm signals if necessary.
-
sendMsg
(msg)[source]¶ Sends a message using the serial port if fake_mode is False.
Parameters: msg – The message to be sent. Returns: True if no error occurred, else False.
-
send_confirm
¶
-
send_print
¶
-
serial_fatal_error
¶
-
sivicncdriver.serial.thread_read module¶
sivicncdriver.serial.thread_send module¶
-
class
sivicncdriver.serial.thread_send.
SendThread
(serial_manager, gcode)[source]¶ Bases:
PyQt5.QtCore.QThread
A thread to send a list of instructions without blocking the main thread.
-
run
()[source]¶ Runs the thread.
The commands are sent using the serial manager. If an error occurs or if the thread is stopped by the user, then it quits.
-
read_allowed
¶
-
update_progress
¶
-
Module contents¶
sivicncdriver.ui package¶
Submodules¶
sivicncdriver.ui.interface module¶
Provides the MainWindow class.
-
class
sivicncdriver.ui.interface.
MainWindow
[source]¶ Bases:
PyQt5.QtWidgets.QMainWindow
,sivicncdriver.ui.main_window.Ui_MainWindow
The main window of the application.
-
config_as_dict
()[source]¶ Get the configuration as a dict.
Returns: The configuration as a dict. Return type: dict
-
draw_file
(gcode=None)[source]¶ Draws a gcode file.
Parameters: gcode – gcode to use in place of the one form code_edit.
-
highlight_selected_path
()[source]¶ Looks for selected line in the code_edit, then updates the drawing to highlight the corresponding path.
-
parse_error
(line)[source]¶ Handles parsing errors.
Parameters: line – The line where the error occurred.
-
print
(txt, msg_type='operator')[source]¶ Prints a message on the application console.
Parameters: - txt (str) – The message
- msg_type (str) – The type of the message. Can be “operator”, “machine”, “error” or “info”
-
run_thread
(gcode, n=None, disable=True, allow_waiting=True)[source]¶ Run a thread to send the given gcode.
Parameters: - gcode (list) – The gcode as a list of commands.
- n (int) – A length for the sending_process progress bar.
- disable (bool) – Disable ui elements which trigger sending.
- allow_waiting (bool) – Adds the command to the waiting queue.
-
save_config
(filename=None)[source]¶ Saves a configuration.
Parameters: filename (str) – The name of the file.
-
sending_end
()[source]¶ Manages the end of upload. If some commands are waiting, run them at the end.
-
set_serial_mode
(mode)[source]¶ Change serial mode.
Parameters: mode (str) – can be “manual” or “file”
-
sivicncdriver.ui.main_window module¶
sivicncdriver.ui.preprocessor module¶
Provides the PreprocessorDialog class.
-
class
sivicncdriver.ui.preprocessor.
PreprocessorDialog
(gcode, parent=None)[source]¶ Bases:
PyQt5.QtWidgets.QDialog
,sivicncdriver.ui.preprocessor_window.Ui_dialog
The preprocessor dialog.
sivicncdriver.ui.preprocessor_window module¶
sivicncdriver.ui.ressources_rc module¶
sivicncdriver.ui.view3d module¶
-
class
sivicncdriver.ui.view3d.
View3D
(parent=None, width=5, height=4, dpi=100)[source]¶ Bases:
matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg
Prints G-Codes in 3D.
-
compute_data
(gcode)[source]¶ Computes the paths generated by a gcode file.
Parameters: gcode (str) – The gcode.
-
draw
(**kwargs)[source]¶ Parameters: - reverse_x (bool) – Should the x axis be reversed ? (default : False)
- reverse_y (bool) – Should the y axis be reversed ? (default : False)
- reverse_z (bool) – Should the z axis be reversed ? (default : False)
- highlight_line (int) – A line which is to be highlighted. (default : None)
-
parse_error
¶
-
Module contents¶
Submodules¶
sivicncdriver.app module¶
sivicncdriver.settings module¶
Module contents¶
The SiviCNCDriver Package¶
This is the SiviCNCDriver package. To run the application directly you should
use the sivicnc
command in a shell. Alternately you can use the main
function of the package which doesn’t take any parameter.
Example: |
---|
>>> from sivicncdriver.app import main
>>> main()