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

Go to the source code of this file.

Functions

GrinderSurfaceGUIModuleV01 ScreenLoadScript ()
 Initialize screen-level globals, signal library entries, and the GrindDressCycleStart input handler.
GrinderSurfaceGUIModuleV01 StartUpScript ()
 Initialize machine axis configuration and write axis type pound variables on screen startup.
GrinderSurfaceGUIModuleV01 GetWheelAttributes ()
 Return the list of wheel attribute definitions mapping tool table field names to pound variable numbers.
GrinderSurfaceGUIModuleV01 UpdateGrinderWheelAttributes ()
 Update grinding wheel tool table attributes from the current tool's extended data to pound variables.
GrinderSurfaceGUIModuleV01 ResetTotalCompBtn (AxisID)
 Reset the accumulated total compensation value for a specified axis to zero.
GrinderSurfaceGUIModuleV01 CompMainGrindAxis (Direction, Amount)
 Apply a compensation move to the main vertical grinding axis.
GrinderSurfaceGUIModuleV01 Comp (AxisID, Type, Direction, Amount)
 Apply a compensation move to a specified axis by adjusting the work offset and optionally moving to zero.
GrinderSurfaceGUIModuleV01 StartHydraulics ()
 Start the hydraulics system by activating the HydraulicsOutput OEM parameter signal.
GrinderSurfaceGUIModuleV01 StopHydraulics ()
 Stop the hydraulics system by stopping the grinding wheel and deactivating the hydraulics output.
GrinderSurfaceGUIModuleV01 HydraulicsToggleBtn ()
 Toggle hydraulics on or off based on the current HydraulicsOutput signal state.
GrinderSurfaceGUIModuleV01 StartGrindingWheel ()
 Start the grinding wheel after verifying no alarms or warnings are active.
GrinderSurfaceGUIModuleV01 StopGrindingWheel ()
 Stop the grinding wheel by turning off the output signal and setting spindle direction to off.
GrinderSurfaceGUIModuleV01 GrindingWheelToggleBtn ()
 Toggle the grinding wheel on or off based on its current output signal state.
GrinderSurfaceGUIModuleV01 UpdateGrinderControls ()
 Update high-priority grinder UI controls including the total comp DRO and end-of-program handling.
GrinderSurfaceGUIModuleV01 UpdateLowPriorityGrinderControls ()
 Update low-priority grinder UI elements including hydraulics, grinding wheel, coolant, and comp buttons.
GrinderSurfaceGUIModuleV01 PLCScript ()
 Execute high-priority PLC script updates for the surface grinder screen.
GrinderSurfaceGUIModuleV01 LowPriorityLoop ()
 Execute low-priority periodic updates for grinder UI controls and wheel attributes.
GrinderSurfaceGUIModuleV01 ToggleMDI ()
 Toggle the MDI input group visibility, switching between the G-code view and the MDI line.
GrinderSurfaceGUIModuleV01 CycleStop ()
 Stop the current grind cycle, retract the grinding wheel, reset alarms, and turn off all outputs.
GrinderSurfaceGUIModuleV01 MachineCycleStartFinal ()
 Finalize cycle start by setting the current tab pound variable and triggering toolpath regeneration.
GrinderSurfaceGUIModuleV01 UpdatePoundVars ()
 Refresh pound variables #500-#550 by reading and re-writing each value to force screen DRO updates.
GrinderSurfaceGUIModuleV01 TeachDresser (fieldName)
 Teach the dresser position for a given tool table field by reading current machine position.

Function Documentation

◆ Comp()

GrinderSurfaceGUIModuleV01 Comp ( AxisID ,
Type ,
Direction ,
Amount  )

Apply a compensation move to a specified axis by adjusting the work offset and optionally moving to zero.

Reads the compensation amount from pound variable #508 (Coarse Comp) or #509 (Fine Comp) based on the Amount parameter. Negates the amount if Direction is not 1. Warns if Feed Override or Rapid Override is less than 1%. Supports two compensation types:

  • Type 1: Adjusts the G54 work offset only (G91 G10 L2 P1).
  • Type 2: Adjusts the G54 work offset and moves the axis to position 0. Accumulates the total compensation in the TOTAL_COMP global table and logs the operation.
    Parameters
    AxisID(number) The Mach4 axis ID constant (e.g., mc.X_AXIS, mc.Y_AXIS, mc.Z_AXIS)
    Type(number) Compensation type: 1 = adjust offset only, 2 = adjust offset and move to zero
    Direction(number) Movement direction: 1 = positive, any other value = negative
    Amount(string) Compensation amount selector: "Coarse" reads #508, any other value reads #509 (Fine)
    Returns
    (nil) No meaningful primary return value
    (boolean) Success flag - true if compensation was applied successfully
    (string) Status message from w.FunctionCompleted() or w.FunctionError()
    Note
    Documentation generated by AI on 2026-03-03

◆ CompMainGrindAxis()

GrinderSurfaceGUIModuleV01 CompMainGrindAxis ( Direction ,
Amount  )

Apply a compensation move to the main vertical grinding axis.

Delegates to Comp() using the global VERTICAL_AXIS_ID and Type 1 (offset adjust only).

Parameters
Direction(number) Movement direction: 1 = positive, any other value = negative
Amount(string) Compensation amount selector: "Coarse" reads pound var #508, otherwise reads #509 (Fine)
Returns
(nil) No meaningful primary return value
(boolean) Success flag - true if compensation was applied successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
See also
GrinderSurfaceGUIModuleV01.Comp() for the full compensation implementation
Note
Documentation generated by AI on 2026-03-03

◆ CycleStop()

GrinderSurfaceGUIModuleV01 CycleStop ( )

Stop the current grind cycle, retract the grinding wheel, reset alarms, and turn off all outputs.

Performs a full cycle stop sequence for the surface grinder:

  1. If the machine is homing, disables the machine and raises a warning instead of stopping.
  2. Issues mc.mcCntlCycleStop() to halt motion.
  3. Calculates the retract position from pound variables #506 (Retract Amount) and #534 (Start Depth), and moves the vertical axis to the retract position if needed.
  4. Resets the controller with mc.mcCntlReset().
  5. Calls user.UserCycleStop() if defined.
  6. Turns off mist and coolant output signals.
  7. Executes MachineStop.mcs private script.
  8. Turns off all active output signals, respecting IgnoreOutputsOnStop and IgnoreAuxButtonsOnStop OEM parameters and AUX button configurations.
  9. Restores the G-code line number and updates pound variables.
    Returns
    (nil) No meaningful primary return value
    (boolean) Success flag - true if cycle stop completed successfully
    (string) Status message from w.FunctionCompleted() or w.FunctionError()
    Warning
    This function modifies machine state, turns off output signals, and executes a private M-code script. Ensure the machine is in a safe state before calling.
    Note
    Documentation generated by AI on 2026-03-03

◆ GetWheelAttributes()

GrinderSurfaceGUIModuleV01 GetWheelAttributes ( )

Return the list of wheel attribute definitions mapping tool table field names to pound variable numbers.

Returns a two-dimensional table where each entry contains a tool table field name string and a corresponding pound variable number. This table is also used inside the t.mcs tool change macro and must be kept in sync with that file.

Returns
(table) Array of {fieldName, poundVarNumber} pairs defining wheel attributes. Currently includes: {"Z1DressPosition", 655}
Note
Documentation generated by AI on 2026-03-03

◆ GrindingWheelToggleBtn()

GrinderSurfaceGUIModuleV01 GrindingWheelToggleBtn ( )

Toggle the grinding wheel on or off based on its current output signal state.

Reads the current state of the GrindingWheelOutput OEM parameter signal. If the output is currently active, calls StopGrindingWheel(); otherwise calls StartGrindingWheel().

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

◆ HydraulicsToggleBtn()

GrinderSurfaceGUIModuleV01 HydraulicsToggleBtn ( )

Toggle hydraulics on or off based on the current HydraulicsOutput signal state.

Reads the current state of the HydraulicsOutput OEM parameter signal. If the output is currently active, calls StopHydraulics(); otherwise calls StartHydraulics().

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

◆ LowPriorityLoop()

GrinderSurfaceGUIModuleV01 LowPriorityLoop ( )

Execute low-priority periodic updates for grinder UI controls and wheel attributes.

Called on a low-priority timer loop. Delegates to UpdateLowPriorityGrinderControls() for UI updates (button labels, colors, signal states) and to UpdateGrinderWheelAttributes() to sync tool table dress position data to pound variables.

Note
Documentation generated by AI on 2026-03-03

◆ MachineCycleStartFinal()

GrinderSurfaceGUIModuleV01 MachineCycleStartFinal ( )

Finalize cycle start by setting the current tab pound variable and triggering toolpath regeneration.

Reads the currently active tab from the MainWindowTabs UI control, writes it to pound variable #514, and returns early if the active tab is not a grinder tab (3, 4, or 5). For grinder tabs, if the machine is IDLE and no M00 is active, it triggers a toolpath regeneration dialog.

Returns
(boolean|nil) True if cycle start should proceed, nil if aborted early
(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()

GrinderSurfaceGUIModuleV01 PLCScript ( )

Execute high-priority PLC script updates for the surface grinder screen.

Called on every PLC cycle. Performs the following updates in order:

  1. Updates the tool verify DRO via UpdateToolVerifyDRO().
  2. Updates feedrate text and DROs via screen.UpdateFeedrateDROLabels().
  3. Updates DRO axis positions via screen.UpdateDROPostions().
  4. Updates grinder-specific controls (comp DRO, end-of-program register) via UpdateGrinderControls().
    Note
    Documentation generated by AI on 2026-03-03

◆ ResetTotalCompBtn()

GrinderSurfaceGUIModuleV01 ResetTotalCompBtn ( AxisID )

Reset the accumulated total compensation value for a specified axis to zero.

Parameters
AxisID(number) The Mach4 axis ID constant. Used as a 0-based index into the TOTAL_COMP table
Returns
(nil) No meaningful primary return value
(boolean) Success flag - always true
(string) Status message from w.FunctionCompleted()
Note
Documentation generated by AI on 2026-03-03

◆ ScreenLoadScript()

GrinderSurfaceGUIModuleV01 ScreenLoadScript ( )

Initialize screen-level globals, signal library entries, and the GrindDressCycleStart input handler.

Performs the following setup on screen load:

  1. Initializes button color stage constants (BTN_COLOR_STAGE_1, BTN_COLOR_STAGE_2, BTN_COLOR_STAGE_3).
  2. Resets the TOTAL_COMP accumulator table to {0,0,0,0,0,0} and sets VERTICAL_AXIS_ID to -1.
  3. Defines the local helper _GetSigId() to retrieve signal IDs from OEM parameter I/O signal objects.
  4. For each Mach4 instance, populates MACHINE_TYPE_SIG_LIBRARY_INST with output signal handlers:
    • OSIG_OUTPUT30: Sets CoarseLed GREEN
    • OSIG_OUTPUT31: Sets MediumLed GREEN
    • OSIG_OUTPUT32: Sets FineLed GREEN
    • OSIG_OUTPUT33: Sets DwellLed YELLOW
  5. If the GrindDressCycleStart OEM parameter maps to a valid input signal (>= mc.MC_ISIGS_START), registers a handler that calls GrindDressCycleStartBtn() when the signal goes high.
    Note
    Documentation generated by AI on 2026-03-03

◆ StartGrindingWheel()

GrinderSurfaceGUIModuleV01 StartGrindingWheel ( )

Start the grinding wheel after verifying no alarms or warnings are active.

Performs the following sequence:

  1. Checks for active GMS alarms and warnings via w.GetGMSAlarms() and w.GetGMSWarnings(). If any are active, displays a warning message and returns without starting.
  2. Activates the GrindingWheelOutput OEM parameter signal.
  3. Reads the commanded spindle RPM from pound variable #511 (Grinding Wheel RPM).
  4. Sets the spindle command RPM via mc.mcSpindleSetCommandRPM().
  5. Sets spindle direction to forward via mc.mcSpindleSetDirection() with mc.MC_SPINDLE_FWD.
    Returns
    (nil) No meaningful primary return value
    (boolean) Success flag - true if the grinding wheel was started successfully
    (string) Status message from w.FunctionCompleted() or w.FunctionError()
    Warning
    The machine must have no active GMS alarms or warnings before the grinding wheel can start.
    Note
    Documentation generated by AI on 2026-03-03

◆ StartHydraulics()

GrinderSurfaceGUIModuleV01 StartHydraulics ( )

Start the hydraulics system by activating the HydraulicsOutput OEM parameter signal.

Returns
(nil) No meaningful primary return value
(boolean) Success flag - true if hydraulics were started successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
Note
Documentation generated by AI on 2026-03-03

◆ StartUpScript()

GrinderSurfaceGUIModuleV01 StartUpScript ( )

Initialize machine axis configuration and write axis type pound variables on screen startup.

Performs the following initialization sequence:

  1. Writes the grinder tab index (3) to pound variable #514 (Current Screen Tab).
  2. Reads the VerticalAxisConfiguration OEM parameter and sets the global VERTICAL_AXIS_ID to mc.Y_AXIS or mc.Z_AXIS accordingly, then writes it to pound variable #500.
  3. Reads the LongitudinalAxisType OEM parameter ("Servo" = 0, otherwise 1) and writes it to pound variable #501.
  4. Reads the LatitudinalAxisType OEM parameter ("Servo" = 0, otherwise 1) and writes it to pound variable #502. If any pound variable write fails, returns an error immediately.
    Returns
    (nil) No meaningful primary return value
    (boolean) Success flag - true if all axis configuration values were written successfully
    (string) Status message from w.FunctionCompleted() or w.FunctionError()
    Warning
    If VerticalAxisConfiguration is not "Y" or "Z", displays a message box but continues execution.
    Note
    Documentation generated by AI on 2026-03-03

◆ StopGrindingWheel()

GrinderSurfaceGUIModuleV01 StopGrindingWheel ( )

Stop the grinding wheel by turning off the output signal and setting spindle direction to off.

Deactivates the GrindingWheelOutput OEM parameter signal and then calls mc.mcSpindleSetDirection() with mc.MC_SPINDLE_OFF to stop the spindle.

Returns
(nil) No meaningful primary return value
(boolean) Success flag - true if the grinding wheel was stopped successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
Note
Documentation generated by AI on 2026-03-03

◆ StopHydraulics()

GrinderSurfaceGUIModuleV01 StopHydraulics ( )

Stop the hydraulics system by stopping the grinding wheel and deactivating the hydraulics output.

First calls StopGrindingWheel() to ensure the grinding wheel is stopped before hydraulics are disabled, then deactivates the HydraulicsOutput OEM parameter signal.

Returns
(nil) No meaningful primary return value
(boolean) Success flag - true if hydraulics were stopped successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
Warning
Always stops the grinding wheel before cutting hydraulic power to prevent equipment damage.
Note
Documentation generated by AI on 2026-03-03

◆ TeachDresser()

GrinderSurfaceGUIModuleV01 TeachDresser ( fieldName )

Teach the dresser position for a given tool table field by reading current machine position.

Determines the axis (X, Y, or Z) based on the field name provided, reads the current machine position for that axis, and stores it in the tool table under the given field name. Supports up to three dress positions per axis (e.g., X1DressPosition, X2DressPosition, X3DressPosition). After updating the tool table, the tool file is saved to disk.

Parameters
fieldName(string) The tool table field name identifying the dress position to teach. Valid values include: "X1DressPosition", "X2DressPosition", "X3DressPosition", "Y1DressPosition", "Y2DressPosition", "Y3DressPosition", "Z1DressPosition", "Z2DressPosition", "Z3DressPosition"
Returns
(nil) No meaningful 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

◆ ToggleMDI()

GrinderSurfaceGUIModuleV01 ToggleMDI ( )

Toggle the MDI input group visibility, switching between the G-code view and the MDI line.

Requires password protection level 1 before toggling. Reads the current Left position of the MDIGroup panel to determine whether it is visible (Left == "105") or hidden (Left == "10000"). Swaps the MDI and GCode group positions accordingly and updates the MdiBtn label and background color.

Returns
(nil) No meaningful primary return value
(boolean) Success flag - false if password check fails, true otherwise
(string) Status message from w.FunctionError() on failure
Note
Documentation generated by AI on 2026-03-03

◆ UpdateGrinderControls()

GrinderSurfaceGUIModuleV01 UpdateGrinderControls ( )

Update high-priority grinder UI controls including the total comp DRO and end-of-program handling.

Performs two updates on each PLC cycle:

  1. If TOTAL_COMP for the vertical axis is not nil, writes the accumulated compensation value to the TotalCompDRO screen object.
  2. Reads the EndOfProgram OEM register; if it equals 1, calls UpdatePoundVars() to refresh pound variables and then resets the EndOfProgram register to 0.
    Returns
    (nil) No meaningful primary return value
    (boolean) Success flag - true if all updates completed successfully
    (string) Status message from w.FunctionCompleted() or w.FunctionError()
    Note
    Documentation generated by AI on 2026-03-03

◆ UpdateGrinderWheelAttributes()

GrinderSurfaceGUIModuleV01 UpdateGrinderWheelAttributes ( )

Update grinding wheel tool table attributes from the current tool's extended data to pound variables.

Retrieves the current tool number and iterates through the wheel attribute definitions returned by GetWheelAttributes(). For each attribute, reads the value from the tool table using mc.mcToolGetDataExDbl(). If the machine is IDLE and the current tool is greater than 0, writes the tool data value to the corresponding pound variable. If the tool is 0, writes 0 to the pound variable instead. Only updates pound variables when the machine is in MC_STATE_IDLE.

Returns
(nil) No meaningful primary return value
(boolean) Success flag - true if all attributes were updated successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
Note
Documentation generated by AI on 2026-03-03

◆ UpdateLowPriorityGrinderControls()

GrinderSurfaceGUIModuleV01 UpdateLowPriorityGrinderControls ( )

Update low-priority grinder UI elements including hydraulics, grinding wheel, coolant, and comp buttons.

Refreshes the following UI controls:

  • JobFileNameText label with the current job file name.
  • HydraulicsBtn color (yellow = on/pressure low, green = on/pressure OK, off = stopped) and label.
  • GrindingWheelBtn color (yellow = output on/input low, green = output on/input OK, off) and label.
  • GrindingWheelLED color based on grinding wheel input state.
  • CoolantBtn label based on OSIG_COOLANTON signal state.
  • FineCompDownBtn, CoarseCompDownBtn, FineCompUpBtn, CoarseCompUpBtn labels with current comp amounts from pound variables #508 (Coarse Comp) and #509 (Fine Comp).
  • ASideGrindText and BSideGrindText background colors based on pound variable #556 (A Side Grinding).
    Returns
    (nil) No meaningful primary return value
    (boolean) Success flag - true if all updates completed successfully
    (string) Status message from w.FunctionCompleted() or w.FunctionError()
    Note
    Documentation generated by AI on 2026-03-03

◆ UpdatePoundVars()

GrinderSurfaceGUIModuleV01 UpdatePoundVars ( )

Refresh pound variables #500-#550 by reading and re-writing each value to force screen DRO updates.

Waits for the machine to reach IDLE state via w.PleaseWaitDialog(), then iterates through pound variables #500 through #550, reading each value with mc.mcCntlGetPoundVar() and immediately writing it back with mc.mcCntlSetPoundVar(). This forces the screen to refresh any DROs bound to these variables. The function blocks until the machine is idle before proceeding.

Returns
(nil) No meaningful primary return value
(boolean) Success flag - true if all variables were refreshed successfully
(string) Status message from w.FunctionCompleted() or w.FunctionError()
Note
Documentation generated by AI on 2026-03-03