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

G-Codes viewer Machine configuration Commands sending

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

Binary distribution (Windows)

If, for some reasons, you can’t or don’t want to use pip, a binary is available here .

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.ui package
Submodules
sivicncdriver.ui.interface module
The 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.

about_license()[source]

Displays informations about the license.

about_qt()[source]

Displays informations about Qt.

auto_cmd()[source]

Sends auto commands using a thread if they are too long.

choose_file()[source]

Sets the gcode file.

close_file()[source]

Close the current file.

config_as_dict()[source]

Get the configuration as a dict.

Returns:The configuration as a dict.
Return type:dict
connectUi()[source]

Connects The UI signals and slots.

draw_file(gcode=None)[source]

Draws a gcode file.

Parameters:gcode – gcode to use in place of the one form code_edit.
emergency_stop()[source]
end_preprocessor()[source]

Manages the end of the preprocessing interface.

goto_origin()[source]
highlight_selected_path()[source]
list_configs()[source]

Lists available configurations.

list_serials()[source]

Lists available serials ports.

load_file()[source]

Loads a gcode file.

manage_auto_cmd_number(n)[source]

Enable the widgets for auto commands

manage_connection()[source]

Manages the connection widgets.

manage_emulate_serial_port(s)[source]

Enable widgets for serial port emulation.

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”
reset_config()[source]

Resets the configuration.

run_custom_cmd()[source]

Sends a custom command using a thread.

run_preprocessor()[source]

Runs the preprocessor dialog.

run_thread(gcode, n=None, disable=True, allow_waiting=True)[source]

Run a thread to send the diven gcode. :param gcode: The gcode as a list of commands. :param n: a length for the sending_process. :param disable: Should the ui elements which trigger sending be

disabled ?
Parameters:allow_waiting (bool) – If True and a thread is already running, wait for it to end before sending the command. Else stop the current thread.
save_config(filename=None)[source]

Saves a configuration. :param filename: The name of the file. :type filename: str

save_config_as()[source]

Saves a configuration in a new file.

save_file()[source]

Saves a gcode file.

save_file_as()[source]

Saves a gcode file in a nex file.

send_cmd()[source]

Sends an user command using a thread.

send_config()[source]

Send a configuration to the machine.

send_file()[source]

Send a file using a different thread.

sending_end()[source]

Manages the end of upload. If some commands are waiting, run them at the end.

set_origin()[source]
set_serial_mode(mode)[source]

Change serial mode.

Parameters:mode (str) – can be “manual” or “file”
start_continuous_x_backward()[source]
start_continuous_x_forward()[source]
start_continuous_y_backward()[source]
start_continuous_y_forward()[source]
start_continuous_z_backward()[source]
start_continuous_z_forward()[source]
stop_x()[source]
stop_y()[source]
stop_z()[source]
update_config(i)[source]

Updates the configuration widgets.

update_drawing(highlight_line=None)[source]

Updates the drawing.

Parameters:highlight_line (int) – A line which is to be highlighted.
update_progress(s)[source]

Updates the progress bar.

sivicncdriver.ui.main_window module
class sivicncdriver.ui.main_window.Ui_MainWindow[source]

Bases: object

retranslateUi(MainWindow)[source]
setupUi(MainWindow)[source]
sivicncdriver.ui.preprocessor module
The 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.

accept()[source]
cancel()[source]
get_minimize_bounding_box()[source]

Computes a new origin for the drawing.

remove_useless()[source]

Remove useless things in the code according to the UI options.

run_preprocessor()[source]

Runs the preprocessor on the G-Code.

sivicncdriver.ui.preprocessor_window module
class sivicncdriver.ui.preprocessor_window.Ui_dialog[source]

Bases: object

retranslateUi(dialog)[source]
setupUi(dialog)[source]
sivicncdriver.ui.ressources_rc module
sivicncdriver.ui.ressources_rc.qCleanupResources()[source]
sivicncdriver.ui.ressources_rc.qInitResources()[source]
Module contents

Submodules

sivicncdriver.app module
sivicncdriver.app.main()[source]

The main function of the application.

It will create a QApplication and a main window then run the application and exit.

sivicncdriver.arc_calculator module
The 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.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 module

A module to parse G-codes.

sivicncdriver.gcode.parse(gcode)[source]

Parse gcode.

It yields a dict for each line with :

name
name of the code (G, M)
value
an integer
args
a dict with the code arguments, ex : {‘Y’:3.0}
Parameters:gcode (str) – The gcode which is to be parsed.
sivicncdriver.gcode_maker module

A bunch of command to easily create G-Codes.

sivicncdriver.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_maker.emergency_stop()[source]

Stop every axis.

sivicncdriver.gcode_maker.goto_origin()[source]

Go to the origin.

sivicncdriver.gcode_maker.set_origin()[source]

Register the current position as the origin.

sivicncdriver.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_maker.start_continuous_x_backward()[source]

Start a continuous movement on X axis backward

sivicncdriver.gcode_maker.start_continuous_x_forward()[source]

Start a continuous movement on X axis forward.

sivicncdriver.gcode_maker.start_continuous_y_backward()[source]

Start a continuous movement on Y axis backward

sivicncdriver.gcode_maker.start_continuous_y_forward()[source]

Start a continuous movement on Y axis forward.

sivicncdriver.gcode_maker.start_continuous_z_backward()[source]

Start a continuous movement on Z axis backward

sivicncdriver.gcode_maker.start_continuous_z_forward()[source]

Start a continuous movement on Z axis forward.

sivicncdriver.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_maker.step_x(n)[source]

Moves the X axis oh n steps. :param n: The number of steps :type n: int

sivicncdriver.gcode_maker.step_y(n)[source]

Moves the Y axis oh n steps. :param n: The number of steps :type n: int

sivicncdriver.gcode_maker.step_z(n)[source]

Moves the Z axis oh n steps. :param n: The number of steps :type n: int

sivicncdriver.gcode_maker.stop(axis)[source]

Stop any movement on the given axis.

sivicncdriver.gcode_maker.stop_x()[source]

Stop any movement on the X axis.

sivicncdriver.gcode_maker.stop_y()[source]

Stop any movement on the Y axis.

sivicncdriver.gcode_maker.stop_z()[source]

Stop any movement on the Z axis.

sivicncdriver.serial_list module
sivicncdriver.serial_list.serial_ports()[source]

Lists serial ports

Raises:EnvironmentError – On unsupported or unknown platforms
Returns:A list of available serial ports
sivicncdriver.serial_manager module
The serial_manager module

Provides a class to handle the CNC machine through a serial object.

class sivicncdriver.serial_manager.SerialManager(serial, fake_mode=False)[source]

Bases: PyQt5.QtCore.QObject

close()[source]
open(baudrate, serial_port, timeout)[source]
readMsg()[source]
sendMsg(msg)[source]
send_confirm
send_print
sivicncdriver.settings module
sivicncdriver.thread_send module
class sivicncdriver.thread_send.SendThread(serial_manager, gcode)[source]

Bases: PyQt5.QtCore.QThread

A thread to send a list of instructions without blocking the main thread.

confirm(st)[source]

Receive confirmation from the readThread.

Parameters:st – Everything ok ?
read_allowed
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.

stop()[source]

A simple slot to tell the thread to stop.

update_progress

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()

Indices and tables