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

Go to the source code of this file.

Functions

GearShaperScreenV02 MachineScreenStartupScript ()
 Initialize the Gear Shaper screen on startup.
GearShaperScreenV02 MachineScreenPLCScript ()
 PLC-rate callback that executes core Gear Shaper screen update tasks.
GearShaperScreenV02 MachineScreenLowPriorityLoop ()
 PLC-rate screen update loop for the Gear Shaper screen.
GearShaperScreenV02 MachineScreenLoadScript ()
 Initialize screen objects and register commands when the Gear Shaper screen is loaded.
GearShaperScreenV02 CompensateXAxis ()
 Apply an X-axis tool length compensation adjustment from the CompXAxisDRO input field.
GearShaperScreenV02 GoToLoadPosition ()
 Move the machine to the configured Z load position.
GearShaperScreenV02 CheckEndOfProgram ()
 Detect end-of-program condition and record the cycle time to the machine profile.
GearShaperScreenV02 UpdateCycleProgresBar ()
 Update the cycle progress bar gauge based on elapsed versus last known cycle time.
GearShaperScreenV02 UpdateCurrentTime ()
 Update the current date and time display label on the Gear Shaper screen.
GearShaperScreenV02 EnableCutSections ()
 Show or hide cut data panels based on the configured number of cuts per piece.
GearShaperScreenV02 ResetTotalAxisComp (AxisID)
 Reset the total compensation accumulator for a specific axis to zero.
GearShaperScreenV02 ResetTotalComp ()
 Reset the global total compensation accumulator to zero.
GearShaperScreenV02 CheckCompAmount (Amount)
 Validate that a compensation amount does not exceed the configured maximum increment.
GearShaperScreenV02 Comp (AxisID, Direction, AmountName, Type)
 Apply a compensation offset to a specified axis using fixture or tool offsets.
GearShaperScreenV02 MachineCreatePreCannedCommands ()
 Register all pre-canned compensation and reset commands for the Gear Shaper screen.

Function Documentation

◆ CheckCompAmount()

GearShaperScreenV02 CheckCompAmount ( Amount )

Validate that a compensation amount does not exceed the configured maximum increment.

Reads the 'MaxCompIncrement' OEM parameter and compares it against the absolute value of the provided amount. If the amount exceeds the maximum, a warning dialog is displayed via m.SetWarningMessage() and an error is returned. Otherwise, the original amount is returned unchanged.

Parameters
Amount(number) The compensation amount to validate
Returns
(number|number) The original Amount if valid, or 0 if the amount exceeds the maximum
(boolean) Success flag - true if the amount is within limits, false if it exceeds MaxCompIncrement
(string) Status message from w.FunctionCompleted() or w.FunctionError()
Note
Documentation generated by AI on 2026-03-03

◆ CheckEndOfProgram()

GearShaperScreenV02 CheckEndOfProgram ( )

Detect end-of-program condition and record the cycle time to the machine profile.

Reads the 'EndOfProgram' OEM register. If it equals 1, the function clears the register back to 0, reads the current program run time via mc.mcCntlGetRunTime(), and writes that value to the MachMotion profile as 'LastProgramCycleTime' for use by the cycle progress bar. It also sets the 'CycleProgressBarGauge' to 100% to indicate program completion.

Returns
(nil) No meaningful primary return value on error paths
(boolean) Success flag - false on API or register error
(string) Status message from w.FunctionError() on error
Note
This function is called every PLC cycle from MachineScreenPLCScript
Documentation generated by AI on 2026-03-03

◆ Comp()

GearShaperScreenV02 Comp ( AxisID ,
Direction ,
AmountName ,
Type  )

Apply a compensation offset to a specified axis using fixture or tool offsets.

Applies a coarse or fine compensation amount to the specified axis in the given direction. Supports four compensation types:

  • Type 1: Adjust fixture offset only
  • Type 2: Adjust fixture offset and move axis to zero
  • Type 3: Adjust tool offset only
  • Type 4: Adjust tool offset and move axis to zero The compensation amount is read from the OEM parameter 'CoarseCompAmount' or 'FineCompAmount' depending on AmountName. The function validates the direction, axis ID, and amount before applying. After applying, it updates both the per-axis OEM register (TotalCompAmount_<Axis>) and the global TotalCompAmount register. Issues a warning if Feed Override or Rapid Override is below 1%. Behavior differs between Mill and Turn machine types in the G-code generated.
    Parameters
    AxisID(number) The axis index to compensate (mc.X_AXIS through mc.MC_MAX_COORD_AXES)
    Direction(number) Compensation direction: 1 for positive, -1 for negative (defaults to 1 if invalid)
    AmountName(string) The compensation step size: "Coarse" or "Fine"
    Type(number) Compensation type: 1 (fixture offset), 2 (fixture offset + move), 3 (tool offset), 4 (tool offset + move)
    Returns
    (nil) No meaningful primary return value
    (boolean) Success flag - true if operation completed successfully
    (string) Status message from w.FunctionCompleted() or w.FunctionError()
    Warning
    Feed Override or Rapid Override below 1% will trigger a warning message but will not abort the operation
    See also
    GearShaperScreenV02.CheckCompAmount() for amount validation
    GearShaperScreenV02.ResetTotalAxisComp() to reset the accumulated compensation
    Note
    Documentation generated by AI on 2026-03-03

◆ CompensateXAxis()

GearShaperScreenV02 CompensateXAxis ( )

Apply an X-axis tool length compensation adjustment from the CompXAxisDRO input field.

Reads the value from the 'CompXAxisDRO' screen object, divides it by 2, and adds it to the current tool's height offset (MTOOL_MILL_HEIGHT) using the active tool number from pound variable SV_CUR_LENGTH_INDEX. Calls m.SetToolLengthDRO() to apply the updated offset, then resets the 'CompXAxisDRO' field to "0".

Returns
(nil) No meaningful primary return value on error paths
(boolean) Success flag - false on API error
(string) Status message from w.FunctionError() on error
Note
Documentation generated by AI on 2026-03-03

◆ EnableCutSections()

GearShaperScreenV02 EnableCutSections ( )

Show or hide cut data panels based on the configured number of cuts per piece.

Reads pound variable #511 (CutsPerPiece) to determine how many cut sections should be visible. Panels named 'CutData0Panel' through 'CutData<count-1>Panel' are shown (Hidden = 0), and panels from index cut_count through 9 are hidden (Hidden = 1). Each visibility change is logged via w.Log(). Only panels that exist (verified with h.IsObject()) are modified.

Note
This function does not return a value; it calls w.FunctionCompleted() for side-effect logging only
Documentation generated by AI on 2026-03-03

◆ GoToLoadPosition()

GearShaperScreenV02 GoToLoadPosition ( )

Move the machine to the configured Z load position.

Reads the unit mode (Imperial or Metric) from pound variable #614 and the Z load position from pound variable #514. Converts the load position from its stored units to the current machine units (dividing by 25.4 if Imperial mode is active). Issues an MDI command "M19 G90 G00 Z<pos>" to orient the spindle and move to the load position.

Returns
(boolean|nil) True on success, or nil on error
(boolean) Success flag - true if the move completed successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
Warning
This function initiates machine motion; the machine must be in an appropriate state to accept MDI commands
Note
Documentation generated by AI on 2026-03-03

◆ MachineCreatePreCannedCommands()

GearShaperScreenV02 MachineCreatePreCannedCommands ( )

Register all pre-canned compensation and reset commands for the Gear Shaper screen.

Iterates over all enabled axes and registers coarse/fine compensation commands for both fixture offsets (Types 1/2) and tool offsets (Types 3/4), in both positive and negative directions. For each enabled axis, eight compensation commands are created (Fixture Coarse In/Out, Fixture Fine In/Out, Tool Coarse In/Out, Tool Fine In/Out). Additionally, per-axis total comp reset commands and a global total comp reset command are registered. All commands are created via w.CreateCommandActionOption(), w.CreateSimpleCommand(), and w.SetCommandButtonLabels().

Note
This function is registered with the CommandRegistrar during MachineScreenLoadScript and is called automatically by the Mach4 command framework
Documentation generated by AI on 2026-03-03

◆ MachineScreenLoadScript()

GearShaperScreenV02 MachineScreenLoadScript ( )

Initialize screen objects and register commands when the Gear Shaper screen is loaded.

Creates a new job file (m.JobFile) associated with the current screen, configured to manage pound variables in the range 502, 506, 508, 510-516, and 520-589, with overwrite enabled and notes shown on open. Resets the 'CycleProgressBarGauge' to 0. Initializes enabled axes via m.InitializeEnabledAxes(1902). Registers the MachineCreatePreCannedCommands function with the CommandRegistrar so compensation commands are available.

Note
Documentation generated by AI on 2026-03-03

◆ MachineScreenLowPriorityLoop()

GearShaperScreenV02 MachineScreenLowPriorityLoop ( )

PLC-rate screen update loop for the Gear Shaper screen.

Called at PLC cycle rate. Updates the 'CutsLeftText' label to display the currently running cut data index. When the machine is not in FRUN or FRUN_FH state, the label is cleared to a blank space. During program execution, reads CutsLeft (#600) and CutsPerPiece (#511) from pound variables, clamps CutsLeft to CutsPerPiece if it exceeds it, and formats the label as "Currently Running 'Cut Data <N>'".

Returns
(boolean|nil) True on success, nil on pound variable read error
(boolean) Success flag - false on error
(string) Status message from w.FunctionError() on error, or completion string on success
Note
Documentation generated by AI on 2026-03-03

◆ MachineScreenPLCScript()

GearShaperScreenV02 MachineScreenPLCScript ( )

PLC-rate callback that executes core Gear Shaper screen update tasks.

Called at PLC cycle rate. Invokes end-of-program detection, cycle progress bar update, and current time display update in sequence by calling CheckEndOfProgram(), UpdateCycleProgresBar(), and UpdateCurrentTime().

Note
Documentation generated by AI on 2026-03-03

◆ MachineScreenStartupScript()

GearShaperScreenV02 MachineScreenStartupScript ( )

Initialize the Gear Shaper screen on startup.

Sets the machine type name label on the screen to the localized string "Mach Gear Shaper" using m.screen.SetMachineTypeNameLabel().

Note
Documentation generated by AI on 2026-03-03

◆ ResetTotalAxisComp()

GearShaperScreenV02 ResetTotalAxisComp ( AxisID )

Reset the total compensation accumulator for a specific axis to zero.

Sets the OEM parameter 'TotalCompAmount_<AxisLetter>' to zero for the specified axis, clearing the running total of compensation adjustments applied to that axis. The axis letter is resolved from AXIS_LETTER_ARRAY_0 using the provided AxisID.

Parameters
AxisID(number) The axis index whose total compensation should be reset (mc.X_AXIS through mc.MC_MAX_COORD_AXES)
Returns
(nil) No meaningful primary return value
(boolean) Success flag - true if the reset completed successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
See also
GearShaperScreenV02.ResetTotalComp() to reset the global total compensation
Note
Documentation generated by AI on 2026-03-03

◆ ResetTotalComp()

GearShaperScreenV02 ResetTotalComp ( )

Reset the global total compensation accumulator to zero.

Sets the OEM parameter 'TotalCompAmount' to zero, clearing the running total of all compensation adjustments that have been applied across all axes.

Returns
(nil) No meaningful primary return value
(boolean) Success flag - true if the reset completed successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
See also
GearShaperScreenV02.ResetTotalAxisComp() to reset compensation for a specific axis
Note
Documentation generated by AI on 2026-03-03

◆ UpdateCurrentTime()

GearShaperScreenV02 UpdateCurrentTime ( )

Update the current date and time display label on the Gear Shaper screen.

Reads the current system time formatted as "DayOfWeek, Month Day, HH:MM:SS" using os.date() and sets the "CurrentTimeText" screen object label to this value.

Note
Documentation generated by AI on 2026-03-03

◆ UpdateCycleProgresBar()

GearShaperScreenV02 UpdateCycleProgresBar ( )

Update the cycle progress bar gauge based on elapsed versus last known cycle time.

Only updates the progress bar when the machine is in the FRUN (program running) state. Reads the current run time via mc.mcCntlGetRunTime() and the last recorded program cycle time from the MachMotion profile ('LastProgramCycleTime'). If a valid prior cycle time exists (> 0), calculates the percentage completion and updates the 'CycleProgressBarGauge' screen object. The percentage is formatted to one decimal place.

Returns
(nil) No meaningful primary return value on error paths
(boolean) Success flag - false on API error
(string) Status message from w.FunctionError() on error
Note
The progress bar is only updated when MACH_STATE equals mc.MC_STATE_FRUN
Documentation generated by AI on 2026-03-03