Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/config/ini-config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ The maximum number of `USER_M_PATH` directories is defined at compile time (typ:
Preserve case in O-word names within comments if set, enables reading of mixed-case HAL items in structured comments like `(debug, #<_hal[MixedCaseItem])`.
* `OWORD_WARNONLY = 0` (Default: 0) +
Warn rather than error in case of errors in O-word subroutines.
* `DISABLE_G92_PERSISTENCE = 0` (bool, Default: 0)
Allow to clear the G92 offset automatically when config start-up.
* `DISABLE_G92_PERSISTENCE = 0` (bool, Default: 0) +
When set the shared G52/G92 offset is cleared at startup, by M2 and M30, and by an abort.
* `DISABLE_AUTO_G54 = 0` (bool, Default: 0) +
When set M2 and M30 will no longer automatically reset the active WCS to 'G54'.
* `RETAIN_WORK_PLANE = 0` (bool, Default: 0) +
Expand Down
14 changes: 8 additions & 6 deletions docs/src/gcode/coordinates.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,21 @@ program, the best practice is to issue a G92.1 at the end of any G
code files where you use G92 offsets.

When a program is aborted during processing that has 'G92' offsets in
effect a startup will cause them to become active again. As a
safeguard, always have your preamble to set the environment as you
expect it. Additionally, 'G92' persistence may be disabled by setting
'DISABLE_G92_PERSISTENCE = 1' in the '[RS274NGC]' section of the
INI file.
effect, they stay in effect, and a startup will cause them to become
active again. The offset kept is the one the machine had when the
program stopped, not one set by a line the interpreter had read ahead
to. As a safeguard, always have your preamble to set the environment
as you expect it. Additionally, 'G92' persistence may be disabled by
setting 'DISABLE_G92_PERSISTENCE = 1' in the '[RS274NGC]' section of
the INI file, which also clears the offsets on an abort.

[[sec:g92-g52-interaction-cautions]]
=== G92 and G52 Interaction Cautions

'G52' and 'G92' share the same offset registers. Unless 'G92'
persistence is disabled in the INI file (see
<<sec:g92-commands,G92 Commands>>),
'G52' offsets will also persist after machine reset,
'G52' offsets will also persist after machine reset, an abort,
'M02' or 'M30'. Beware that a 'G52' offset in effect during a program
abort may result in unintended offsets when the next program is run.
See <<sec:g92-persistence-cautions,G92 Persistence Cautions>> above.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/gcode/overview.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ example '##2' means the value of the parameter whose index is the
'DISABLE_G92_PERSISTENCE = 1' in the '[RS274NGC]' section of the
INI file.
* '5211-5219' - Shared "G52" and "G92" offset for X, Y, Z, A, B, C, U,
V & W. Volatile by default; persistent if
V & W. Persistent by default; volatile if
'DISABLE_G92_PERSISTENCE = 1' in the '[RS274NGC]' section of the
INI file.
* '5220' - Coordinate System number 1 - 9 for G54 - G59.3. Persistent.
Expand Down
5 changes: 5 additions & 0 deletions include/nml_intf/canon.hh
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,11 @@ extern int GET_EXTERNAL_HAL_VALUE(const char *name, double *value);
interpreter has, -1 when there is no machine to ask (sai, preview). */
extern int GET_EXTERNAL_G68_FRAME(double origin[3], double rotation[9]);

/* The G92/G52 offset the machine last executed, X Y Z A B C U V W in
program units: 1 with offset filled in, -1 when there is no machine to
ask (sai, preview). */
extern int GET_EXTERNAL_G92_OFFSET(double offset[9]);

// Returns the current motion path-following tolerance
extern double GET_EXTERNAL_MOTION_CONTROL_TOLERANCE();

Expand Down
1 change: 1 addition & 0 deletions src/emc/rs274ngc/gcodemodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ int GET_EXTERNAL_KINS_TYPE_FLAGS(int ktype) {
return kins_type_flags[ktype];
}
int GET_EXTERNAL_G68_FRAME(double * /*origin*/, double * /*rotation*/) { return -1; }
int GET_EXTERNAL_G92_OFFSET(double * /*offset*/) { return -1; }

// the kind of transform the machine runs, from a canon that watches the
// status buffer; one that cannot answer has no machine, and the joints
Expand Down
43 changes: 43 additions & 0 deletions src/emc/rs274ngc/rs274ngc_pre.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2658,6 +2658,49 @@ int Interp::on_abort(int reason, const char *message)
reset();
_setup.mdi_interrupt = false;

// the G92/G52 offset: the read ahead may have set one the machine never
// got, so the interpreter takes the one status has, as it does the
// coordinate system. DISABLE_G92_PERSISTENCE clears it, as M2 does.
// Canon is told either way, since the message that would have brought
// status level with the interpreter died with the queue. This comes
// ahead of the plane, which checks the offset under it against status.
{
double *const off[9] = {
&_setup.axis_offset_x, &_setup.axis_offset_y, &_setup.axis_offset_z,
&_setup.AA_axis_offset, &_setup.BB_axis_offset, &_setup.CC_axis_offset,
&_setup.u_axis_offset, &_setup.v_axis_offset, &_setup.w_axis_offset };
double *const cur[9] = {
&_setup.current_x, &_setup.current_y, &_setup.current_z,
&_setup.AA_current, &_setup.BB_current, &_setup.CC_current,
&_setup.u_current, &_setup.v_current, &_setup.w_current };
double want[9];
bool have = GET_EXTERNAL_G92_OFFSET(want) > 0;
bool changed = false, any = false;

if (_setup.disable_g92_persistence) {
for (int i = 0; i < 9; i++) { want[i] = 0.0; }
have = true;
}
if (have) {
for (int i = 0; i < 9; i++) {
if (*off[i] != want[i]) { changed = true; }
if (want[i] != 0.0) { any = true; }
*cur[i] += *off[i] - want[i];
*off[i] = want[i];
}
// an unchanged offset keeps its parameters, so a G92.2 still
// has the values G92.3 brings back
if (changed || _setup.disable_g92_persistence) {
_setup.parameters[5210] = any ? 1.0 : 0.0;
for (int i = 0; i < 9; i++) {
_setup.parameters[5211 + i] = PROGRAM_TO_USER_AX(i, want[i]);
}
}
}
SET_G92_OFFSET(*off[0], *off[1], *off[2], *off[3], *off[4], *off[5],
*off[6], *off[7], *off[8]);
}

// the tilted work plane goes before the abort routine runs, so that
// routine can change coordinate systems as it likes. Canon is told
// even when the read ahead had already cancelled it, since the message
Expand Down
5 changes: 5 additions & 0 deletions src/emc/sai/saicanon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ extern int GET_EXTERNAL_G68_FRAME(double * /*origin*/, double * /*rotation*/)
return -1;
}

extern int GET_EXTERNAL_G92_OFFSET(double * /*offset*/)
{
return -1;
}

extern bool GET_EXTERNAL_KINEMATICS_IDENTITY()
{
return true;
Expand Down
10 changes: 10 additions & 0 deletions src/emc/task/emccanon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4329,6 +4329,16 @@ int GET_EXTERNAL_G68_FRAME(double origin[3], double rotation[9])
return 1;
}

int GET_EXTERNAL_G92_OFFSET(double offset[9])
{
// status follows the executed commands, canon the read ahead
const EmcPose &p = emcStatus->task.g92_offset;
const double ext[9] = { p.tran.x, p.tran.y, p.tran.z, p.a, p.b, p.c, p.u, p.v, p.w };

for (int i = 0; i < 9; i++) { offset[i] = TO_PROG_AX(i, FROM_EXT_AX(i, ext[i])); }
return 1;
}

bool GET_EXTERNAL_KINEMATICS_IDENTITY()
{
return emcStatus->motion.traj.kinematics_type == KINEMATICS_IDENTITY;
Expand Down
1 change: 1 addition & 0 deletions tests/interp/compile/use-rs274.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ void *GET_EXTERNAL_KINEMATICS(const struct KinematicsUserOps **ops, const char *
}
int GET_EXTERNAL_HAL_VALUE(const char *name, double *value) { return -ENOENT; }
int GET_EXTERNAL_G68_FRAME(double origin[3], double rotation[9]) { return -1; }
int GET_EXTERNAL_G92_OFFSET(double offset[9]) { return -1; }
void SET_G68_FRAME(double x, double y, double z, const double rotation[9], int active) {}
void HOME_CYCLE(void) {}
void HOME_CYCLE_JOINT(int joint) {}
Expand Down
117 changes: 117 additions & 0 deletions tests/statbuffer-g5x-abort/nopersist.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# This config file was created 2016-06-17 10:27:05.976381 by the update_ini script
# The original config files may be found in the /data/s/linuxcnc-dev/tests/statbuffer-g5x-abort/test.old directory

[EMC]
# The version string for this INI file.
VERSION = 1.1

DEBUG = 0x0

[DISPLAY]
DISPLAY = ./test-ui.py

[FILTER]
#No Content

[RS274NGC]
PARAMETER_FILE = sim.var
DISABLE_G92_PERSISTENCE = 1
USER_M_PATH = ./subs

[EMCMOT]
EMCMOT = motmod
COMM_TIMEOUT = 4.0
BASE_PERIOD = 0
SERVO_PERIOD = 1000000

[TASK]
TASK = milltask
CYCLE_TIME = 0.001

[HAL]
HALUI = halui
HALFILE = core_sim.hal

[HALUI]
#No Content

[TRAJ]
NO_FORCE_HOMING=1
AXES = 3
COORDINATES = X Y Z
HOME = 0 0 0
LINEAR_UNITS = inch
ANGULAR_UNITS = degree
DEFAULT_LINEAR_VELOCITY = 1.2
MAX_LINEAR_VELOCITY = 4

[EMCIO]
TOOL_TABLE = simpockets.tbl
TOOL_CHANGE_QUILL_UP = 1
RANDOM_TOOLCHANGER = 0


[KINS]
KINEMATICS = trivkins
#This is a best-guess at the number of joints, it should be checked
JOINTS = 3

[AXIS_X]
MIN_LIMIT = -40.0
MAX_LIMIT = 40.0
MAX_VELOCITY = 4
MAX_ACCELERATION = 1000.0

[JOINT_0]

TYPE = LINEAR
HOME = 0.000
MAX_VELOCITY = 4
MAX_ACCELERATION = 1000.0
BACKLASH = 0.000
INPUT_SCALE = 4000
OUTPUT_SCALE = 1.000
MIN_LIMIT = -40.0
MAX_LIMIT = 40.0
FERROR = 0.050
MIN_FERROR = 0.010

[AXIS_Y]
MIN_LIMIT = -40.0
MAX_LIMIT = 40.0
MAX_VELOCITY = 4
MAX_ACCELERATION = 1000.0

[JOINT_1]

TYPE = LINEAR
HOME = 0.000
MAX_VELOCITY = 4
MAX_ACCELERATION = 1000.0
BACKLASH = 0.000
INPUT_SCALE = 4000
OUTPUT_SCALE = 1.000
MIN_LIMIT = -40.0
MAX_LIMIT = 40.0
FERROR = 0.050
MIN_FERROR = 0.010

[AXIS_Z]
MIN_LIMIT = -40.0
MAX_LIMIT = 40.0
MAX_VELOCITY = 4
MAX_ACCELERATION = 1000.0

[JOINT_2]

TYPE = LINEAR
HOME = 0.0
MAX_VELOCITY = 4
MAX_ACCELERATION = 1000.0
BACKLASH = 0.000
INPUT_SCALE = 4000
OUTPUT_SCALE = 1.000
MIN_LIMIT = -40.0
MAX_LIMIT = 40.0
FERROR = 0.050
MIN_FERROR = 0.010
44 changes: 37 additions & 7 deletions tests/statbuffer-g5x-abort/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@

retval = 0

# the G52 set from MDI below survives the abort unless the INI clears it
ini = linuxcnc.ini(os.environ['INI_FILE_NAME'])
persist = int(ini.find('RS274NGC', 'DISABLE_G92_PERSISTENCE') or 0) == 0
g52 = 7.0 if persist else 0.0
print("DISABLE_G92_PERSISTENCE = %d" % (0 if persist else 1))

def wait_for(cond, what, timeout=30):
end = time.time() + timeout
while time.time() < end:
s.poll()
if cond():
return
time.sleep(0.01)
print("timed out waiting for %s: motion_line %d read_line %d" % (what, s.motion_line, s.read_line))
sys.exit(1)


c = linuxcnc.command()
s = linuxcnc.stat()
Expand All @@ -32,16 +48,18 @@
c.mdi('G10 L2 P3 X0 Y0 Z-6 (Set G56)')
c.mdi('G54 (Use G54)')
c.mdi('G0 X0 Y0 Z0 (Move to 0,0,0)')
c.mdi('G52 X7 (the offset the machine has when the program runs)')
c.wait_complete()

# FIXME: this is lame
time.sleep(1)

c.mode(linuxcnc.MODE_AUTO)
c.auto(linuxcnc.AUTO_RUN, 0)

# FIXME: this is lame
time.sleep(1)
# abort in the slow move, once the read ahead has passed the G52 X3;
# status counts lines from 0
lines = open('test.ngc').read().splitlines()
slow = [i for i, l in enumerate(lines) if l.startswith('G1 ')][0]
buster = [i for i, l in enumerate(lines) if l.startswith('M66')][0]
wait_for(lambda: s.motion_line == slow and s.read_line >= buster, "the slow move")

c.abort()

Expand All @@ -62,8 +80,8 @@
c.wait_complete()
s.poll()

if math.fabs(s.position[0]) > 0.000001:
print("'G0 X0 Y0 Z0' took us to X=%.6f, should be 0" % s.position[0])
if math.fabs(s.position[0] - g52) > 0.000001:
print("'G0 X0 Y0 Z0' took us to X=%.6f, should be %g" % (s.position[0], g52))
retval = 1

if math.fabs(s.position[1]) > 0.000001:
Expand Down Expand Up @@ -98,6 +116,18 @@
print("g5x_offset.z is %.6f, should be -5" % s.g5x_offset[2])
retval = 1

# the G52 X3 the read ahead reached never ran
if math.fabs(s.g92_offset[0] - g52) > 0.000001:
print("g92_offset.x is %.6f, should be %g" % (s.g92_offset[0], g52))
retval = 1

c.mdi('(debug,#5211)')
c.wait_complete()
err = e.poll()
if not err or math.fabs(float(err[1]) - g52) > 0.000001:
print("#5211 is %s, should be %g" % (err and err[1], g52))
retval = 1

if retval == 0:
print("Everything ok!")

Expand Down
1 change: 1 addition & 0 deletions tests/statbuffer-g5x-abort/test.ngc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ G1 X5 Y-5 F1
; 3. Interp will read ahead: set G56 offset and throw a queue buster;
; execution will never reach this point
G56
G52 X3
M66 P0 L0 (queue buster)

%
Expand Down
6 changes: 4 additions & 2 deletions tests/statbuffer-g5x-abort/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash

set -e
rm -f sim.var sim.var.bak
linuxcnc -r test.ini

linuxcnc -r nopersist.ini
rm -f sim.var sim.var.bak