Tuesday, December 2, 2014

YetAnotherGCodeSender, a C++ software for TinyG and ShapeOko2.

Hi. I’m working on a C++ program that connects to the TinyG and configures it for the ShapeOko2 machine. It will, soon, also be able to deliver the gcode files to the machine, line by line.

If you are interested, the sources can be found here. They include a Makefile so you should be able to compile them in a linux machine just by typing ‘make’ and <ENTER>. The only required library is libxml2, which is available on most linux distributions and can be installed by conventional package managers:

- apt-get install libxml2 on RaspberryPi, Debian, etc;

- port install libxml2 on Mac OS;

- yum install libxml2 on Fedora, etc;

- cd /usr/ports/textproc/libxml2; make; make install on FreeBSD.

The chances that you have it already installed in your system are very big. Please read your linux distribution manual to learn how to install it if it is not your case.

To download the code you can access the link I gave or checkout it using Mercurial, which is a version control system available on almost all systems (including Raspberry Pi). You can learn how to use Mercurial here or, if you already have it installed in your linux (or MacOS) system, type this in a terminal:

$ mkdir YetAnotherGCodeSender

$ cd YetAnotherGCodeSender

$ hg init

$ hg pull -U https://xp-dev.com/hg/YetAnotherGCodeSender

The Mercurial version control system can also be installed using available package managers (yum, apt-get, ports, macports etc) or via an excellent software called SourceTree which is available for Mac and Windows systems. This software handles all the checkouts and updates graphically and can make your life easier if you do not like the command line interface.

For my program (YetAnotherGCodeSender), all the machine configuration parameters are written inside a XML file that is easy to be changed. The parameters include the communications port. The file looks like this:

<config>

<attribute key="serial_port_device">/dev/tty.usbserial-DA00XWU7</attribute>

<attribute key="serial_port_data_bits">8</attribute>

<attribute key="serial_port_parity">0</attribute>

<attribute key="serial_port_stop_bits">1</attribute>

<attribute key="serial_port_baud_rate">115200</attribute>

<attribute key="serial_port_flow_control">XONXOFF</attribute>

<!-- Global system settings -->

<!-- Junction acceleration: Global cornering acceleration value -->

<setup key="JUNCTION_ACCELERATION" command="$ja">2000000</setup>

<!-- Chordal tolerance: Sets precision of arc drawing. Trades off precision for max arc draw rate-->

<setup key="CHORDAL_TOLERANCE" command="$ct"></setup>

<!-- Switch type: 0=NO, 1=NC -->

<setup key="SWITCH_TYPE" command="$st">1</setup>

<!-- Motor disable timeout: Number of seconds before motor power is automatically released. Maximum value is 40 million. -->

<setup key="MOTOR_DISABLE_TIMEOUT" command="$mt">10</setup>

<!-- Communications settings -->

<!-- Enable JSON mode: 0=text mode, 1=JSON mode -->

<setup key="ENABLE_JSON_MODE" command="$ej">0</setup>

<!-- JSON verbosity: 0=silent ... 5=verbose (see details) -->

<setup key="JSON_VERBOSITY" command="$jv">3</setup>

<!-- JSON syntax: 0=relaxed, 1=strict -->

<setup key="JSON_SYNTAX" command="$js">0</setup>

...

<!-- Status report interval: in milliseconds (50 ms minimum interval) -->

<setup key="STATUS_REPORT_INTERVAL_MS" command="$si">50</setup>

<!-- Enable CR on TX: 0=send LF line termination on TX, 1= send both LF and CR termination -->

<setup key="ENABLE_CR_ON_TX" command="$ec">0</setup>

<!-- Enable character echo: 0=off, 1=enabled -->

<setup key="ENABLE_CHARACTER_ECHO" command="$ee">0</setup>

<!-- Enable flow control: 0=off, 1=XON/XOFF enabled, 2=RTS/CTS enabled -->

<setup key="ENABLE_FLOW_CONTROL" command="$ex">1</setup>

<!-- Baud rate: 1=9600, 2=19200, 3=38400, 4=57600, 5=115200, 6=230400. 115200 is default-->

<setup key="BAUD_RATE" command="$baud">5</setup>

...

<!-- Motor 1 settings --

<!-- Motor mapping to axis: Configures the axis to which this motor is connected (for Cartesian machines) Typically: $1ma=0, $2ma=1, $3ma=2, $4ma=3 to map motors 1-4 to X,Y,Z,A, respectively-->

<setup key="M1_MOTOR_MAP" command="$1ma">0</setup>

<!-- Step angle: Motor parameter indicating the angle traveled per whole step. Typical setting is $1sa=1.8 for 1.8 degrees per step (200 steps per revolution) -->

<setup key="M1_STEP_ANGLE" command="$1sa">1.8</setup>

...

</config>

In principle you just need to run the main program and it will read the XML file, send it to TinyG and configure your machine. More advanced functions will include spindle warm up and other tasks which are not available now.

The current code is able to send the configuration parameters to TinyG with success. I’m working on the functions that read the GCode file and send them line-by-line to the controller, so if an emergency happens (crash, break etc) you can stop the task by killing the program.

I almost forgot this: the program outputs a log file with details of the communication between it and the TinyG. You can find there all the commands and the answers from the controller.

 

 

The files are licensed as follows:

/************************************************************************

*

* This file is part of YetAnotherGCodeSender

* Copyright (C) 2014 Eduardo Novaes Hering

*

* YetAnotherGCodeSender 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/>

*

************************************************************************/

This code is still immature. If you decide to use it, take all the necessary safety precautions before trying. As written in the license, 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.

 

No comments:

Post a Comment