Mach Modules Documentation
Lua Module API Documentation
Loading...
Searching...
No Matches
TurnGUIModule.lua File Reference

Go to the source code of this file.

Functions

TurnGUIModule ScreenLoadScript ()
 Screen load script callback executed when the turning screen is first loaded.
TurnGUIModule StartUpScript ()
 Startup script callback executed once after the screen has loaded.
TurnGUIModule PLCScript ()
 PLC script callback executed on every Mach4 PLC cycle for the turning screen.
TurnGUIModule SetSpindleSpeedDRO (Speed,...)
 Set the spindle speed DRO and execute the appropriate G96 or G97 MDI command.
TurnGUIModule SetToolOffsetData_Screen (value, offset,...)
 Screen-level adapter to set tool offset data, remapping argument order for screen callbacks.
TurnGUIModule SetToolOffsetData (OffsetNumber, Val)
 Set a tool offset data value for the current tool by offset number.
TurnGUIModule GetToolOffsetData (OffsetNumber)
 Retrieve a tool offset data value for the current tool by offset number.
TurnGUIModule ChuckToggleBtn ()
 Toggle the chuck between open and closed states via PLC sequence calls.
TurnGUIModule TailstockToggleBtn ()
 Toggle the tailstock between extended and retracted states via PLC sequence calls.
TurnGUIModule ZeroDROBtn (Axis)
 Zero a single axis DRO by computing and storing its machine position offset.
TurnGUIModule ZeroAllDROBtn ()
 Zero all axis DROs by computing and storing machine position offsets.
TurnGUIModule CalculateXToolOffset (MeasureValue)
 Calculate and set the X-axis tool offset based on a measured diameter value.
TurnGUIModule CalculateZToolOffset (MeasureValue)
 Calculate and set the Z-axis tool length offset based on a measured value.

Function Documentation

◆ CalculateXToolOffset()

TurnGUIModule CalculateXToolOffset ( MeasureValue )

Calculate and set the X-axis tool offset based on a measured diameter value.

Computes a new X-axis tool offset using the current machine position, work offset, tool slide direction, and the provided measurement value. If diameter mode is active, the measured value is halved before use. The tool slide direction is determined by the sign of the MTOOL_LATHE_TOOLSLIDE value - negative values invert the direction. After computing the new offset, the X wear offset is cleared and the tool offsets are re-activated via an MDI T-code command.

Parameters
MeasureValue(number) The measured diameter or radius value used to calculate the new X tool offset
Returns
(nil) No return value on success
(boolean) False if the MDI command fails; no explicit return on success
(string) Error message from w.FunctionError() if the MDI command fails
Note
Documentation generated by AI on 2026-03-03

◆ CalculateZToolOffset()

TurnGUIModule CalculateZToolOffset ( MeasureValue )

Calculate and set the Z-axis tool length offset based on a measured value.

Computes a new Z-axis tool length offset by comparing the current axis position, the existing offset amount, and the provided measurement value. The formula used is: NewOffset = AxisPosition + CurrentOffsetAmount - MeasureValue. After computing the new offset, it clears the Z wear offset and re-activates the tool offsets via an MDI T-code command.

Parameters
MeasureValue(number) The measured Z position value used to calculate the new tool length offset
Returns
(nil) No return value on success
(boolean) False if the MDI command fails; no explicit return on success
(string) Error message from w.FunctionError() if the MDI command fails
Note
Documentation generated by AI on 2026-03-03

◆ ChuckToggleBtn()

TurnGUIModule ChuckToggleBtn ( )

Toggle the chuck between open and closed states via PLC sequence calls.

Reads the current chuck state using the M10_PLCSequenceNum PLC sequence bit. If the chuck is currently closed (bit is true), it triggers the M11 sequence to open it. If the chuck is currently open (bit is false), it triggers the M10 sequence to close it. This function requires the mb (ModBus) module to be available. OEM parameters M10_PLCSequenceNum and M11_PLCSequenceNum are read to determine the correct PLC sequence numbers.

Returns
(nil) Always nil as the primary return value
(boolean) Success flag - true if operation completed successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
Note
Documentation generated by AI on 2026-03-03

◆ GetToolOffsetData()

TurnGUIModule GetToolOffsetData ( OffsetNumber )

Retrieve a tool offset data value for the current tool by offset number.

Gets the current tool number using w.GetCurrentTool() and then retrieves the specified offset data field using mc.mcToolGetData(). Returns the offset value along with a success flag and status message following the standard triple return pattern.

Parameters
OffsetNumber(number) The tool offset data field identifier (e.g., mc.MTOOL_LATHE_X, mc.MTOOL_LATHE_Z)
Returns
(number|nil) The tool offset data value, or nil on error
(boolean) Success flag - true if operation completed successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
Note
Documentation generated by AI on 2026-03-03

◆ PLCScript()

TurnGUIModule PLCScript ( )

PLC script callback executed on every Mach4 PLC cycle for the turning screen.

Called periodically by the Mach4 PLC cycle. Updates the feedrate DRO labels via the screen module and calculates the CSS (Constant Surface Speed) to RPM conversion based on the current X-axis machine position. The CSS-to-RPM calculation accounts for the current machine units (metric or imperial).

Note
This function is called automatically by the Mach4 PLC cycle - do not call manually
Documentation generated by AI on 2026-03-03

◆ ScreenLoadScript()

TurnGUIModule ScreenLoadScript ( )

Screen load script callback executed when the turning screen is first loaded.

Called during screen initialization. Sets the version strings for the TurnGUIModule using SVN URL and revision information. Initializes global variables including TIP_DIRECTION_LAST, CURRENT_DIAMETER_MODE, and sets the SV_CUR_LENGTH_INDEX pound variable to the current tool number if available.

Note
This function is called automatically during screen load - do not call manually
TIP_DIRECTION_LAST is initialized to nil; CURRENT_DIAMETER_MODE reflects the current diameter mode at load time
Documentation generated by AI on 2026-03-03

◆ SetSpindleSpeedDRO()

TurnGUIModule SetSpindleSpeedDRO ( Speed ,
... )

Set the spindle speed DRO and execute the appropriate G96 or G97 MDI command.

When the machine is in IDLE state, reads the current spindle modal group (G96 or G97) and executes an MDI command to set the spindle speed to the specified value. If the machine is not in IDLE state, the function returns without executing any command. Any additional arguments passed via varargs are accepted but not used.

Parameters
Speed(number) The spindle speed value to set (in RPM for G97, or surface speed for G96)
...(any) Additional arguments accepted but not used
Returns
(number|nil) The speed value that was set, or nil if machine was not idle or on error
(boolean) Success flag - true if operation completed successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
Note
Only executes when the machine is in MC_STATE_IDLE; silently succeeds in all other states
Documentation generated by AI on 2026-03-03

◆ SetToolOffsetData()

TurnGUIModule SetToolOffsetData ( OffsetNumber ,
Val  )

Set a tool offset data value for the current tool by offset number.

Sets the specified tool offset data field for the current tool using mc.mcToolSetData(). The machine must be in IDLE state, Feed Hold (FRUN_FH), or Manual Feed Hold (MRUN_FH) state to modify offsets. If the machine is in any other state, a warning message is displayed and the function returns without modifying the offset.

Parameters
OffsetNumber(number) The tool offset data field identifier (e.g., mc.MTOOL_LATHE_X, mc.MTOOL_LATHE_Z)
Val(number) The value to set for the specified tool offset field
Returns
(number|nil) The value that was set, or nil if the machine state did not allow modification
(boolean) Success flag - true if operation completed or machine was not in a valid state
(string) Status message from w.FunctionCompleted() or w.FunctionError()
Warning
Machine must be in IDLE, FRUN_FH, or MRUN_FH state to modify tool offsets
Note
Documentation generated by AI on 2026-03-03

◆ SetToolOffsetData_Screen()

TurnGUIModule SetToolOffsetData_Screen ( value ,
offset ,
... )

Screen-level adapter to set tool offset data, remapping argument order for screen callbacks.

Acts as a thin adapter between the screen DRO callback convention (value first, offset second) and the m.SetToolOffsetData() function. Screen DRO modify callbacks receive the new value as the first argument and the offset identifier as the second argument, which is the reverse of the direct API. Any additional arguments passed via varargs are forwarded.

Parameters
value(number) The new value to set for the tool offset field
offset(number) The tool offset data field identifier (e.g., mc.MTOOL_LATHE_X, mc.MTOOL_LATHE_Z)
...(any) Additional arguments passed through from the screen callback
Returns
(number|nil) The value that was set, or nil on error
(boolean) Success flag - true if operation completed successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
Note
Documentation generated by AI on 2026-03-03

◆ StartUpScript()

TurnGUIModule StartUpScript ( )

Startup script callback executed once after the screen has loaded.

Called once during screen startup after ScreenLoadScript. Initializes screen objects to their default values (CommandedSpindleSpeedDRO set to "0"), runs the spindle speed check, and configures the conversational (Alexsys) button if the screen module provides a ConfigureConversationalButton function.

Note
This function is called automatically during screen startup - do not call manually
Documentation generated by AI on 2026-03-03

◆ TailstockToggleBtn()

TurnGUIModule TailstockToggleBtn ( )

Toggle the tailstock between extended and retracted states via PLC sequence calls.

Reads the current tailstock state using the M25_PLCSequenceNum PLC sequence bit. If the tailstock is currently extended (bit is true), it triggers the M26 sequence to retract it. If the tailstock is currently retracted (bit is false), it triggers the M25 sequence to extend it. This function requires the mb (ModBus) module to be available. OEM parameters M25_PLCSequenceNum and M26_PLCSequenceNum are read to determine the correct PLC sequence numbers.

Returns
(nil) Always nil as the primary return value
(boolean) Success flag - true if operation completed successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
Note
Documentation generated by AI on 2026-03-03

◆ ZeroAllDROBtn()

TurnGUIModule ZeroAllDROBtn ( )

Zero all axis DROs by computing and storing machine position offsets.

Iterates over all coordinate axes from X_AXIS to MC_MAX_COORD_AXES-1 and computes a DRO offset for each axis such that the displayed position reads zero. For the X axis, diameter mode is taken into account by doubling the machine position. Unit conversion between inches and millimeters is also applied based on MACHINE_DEFAULT_UNITS and MACHINE_CURRENT_UNITS. The computed offsets are stored in DRO_MODE_OFFSET_ARRAY. The operation is logged to the operator log.

Note
Does not modify machine coordinates - only updates the DRO display offset array
Documentation generated by AI on 2026-03-03

◆ ZeroDROBtn()

TurnGUIModule ZeroDROBtn ( Axis )

Zero a single axis DRO by computing and storing its machine position offset.

Computes a DRO offset for the specified axis such that the displayed position reads zero at the current machine position. For the X axis, diameter mode is taken into account by doubling the machine position. Unit conversion between inches and millimeters is applied based on MACHINE_DEFAULT_UNITS and MACHINE_CURRENT_UNITS. The computed offset is stored in DRO_MODE_OFFSET_ARRAY at the index corresponding to the given axis. The operation is logged to the operator log.

Parameters
Axis(number) The axis index to zero (e.g., mc.X_AXIS, mc.Z_AXIS)
Note
Does not modify machine coordinates - only updates the DRO display offset array
Documentation generated by AI on 2026-03-03