|
Mach Modules Documentation
Lua Module API Documentation
|
Go to the source code of this file.
Functions | |
| ReciprocatingAxis | Create (axis, pos_a, pos_b) |
| Create a new ReciprocatingAxis instance for a specific axis and instance. | |
| ReciprocatingAxis | CreateAll () |
| Create ReciprocatingAxis objects for all enabled axes in the given instance. | |
| ReciprocatingAxis | GetParameter (default_value) |
| Retrieve a named OEM parameter value for this axis, with a default fallback. | |
| ReciprocatingAxis | IsRunning () |
| Check if the reciprocating axis cycle is currently active. | |
| ReciprocatingAxis | IsStopping () |
| Check if the axis is currently running and a stop has been requested. | |
| ReciprocatingAxis | SetPosA () |
| Set the target position for PosA (endpoint 0). | |
| ReciprocatingAxis | SetPosB () |
| Set the target position for PosB (endpoint 1). | |
| ReciprocatingAxis | SetPosADwell () |
| Set the dwell time in milliseconds after arriving at PosA. | |
| ReciprocatingAxis | SetPosBDwell () |
| Set the dwell time in milliseconds after arriving at PosB. | |
| ReciprocatingAxis | SetPosAFeedrate () |
| Set the feedrate for reciprocating motion toward PosA. | |
| ReciprocatingAxis | SetPosBFeedrate () |
| Set the feedrate for reciprocating motion toward PosB. | |
| ReciprocatingAxis | SetFeedrate () |
| Set the feedrate for reciprocating motion in both directions. | |
| ReciprocatingAxis | SetPositionThreshold () |
| Set the in-position threshold distance used to detect endpoint arrival. | |
| ReciprocatingAxis | Start () |
| Start the reciprocating axis cycle, optionally setting a new feedrate. | |
| ReciprocatingAxis | StartCannedCycle (all_axes, axis_id, position_a, position_b, dwell, feedrate) |
| Configure and start a reciprocating axis canned cycle with a single call. | |
| ReciprocatingAxis | StopAxis (all_axes, axis_id, stop_type) |
| Stop a specific axis in the collection using a named stop type. | |
| ReciprocatingAxis | Stop () |
| Request the axis to stop at the next reciprocating endpoint. | |
| ReciprocatingAxis | StopAll (all_axes) |
| Stop all jogging reciprocating axes in the collection. | |
| ReciprocatingAxis | StopAtA () |
| Request the axis to stop after it next arrives at PosA. | |
| ReciprocatingAxis | StopAtB () |
| Request the axis to stop after it next arrives at PosB. | |
| ReciprocatingAxis | StopMidCycle () |
| Immediately halt axis motion at the current position without waiting for an endpoint. | |
| ReciprocatingAxis | StopMidCycleAll (all_axes) |
| Immediately stop all jogging axes in the collection mid-cycle. | |
| ReciprocatingAxis | IsDwelling () |
| Check if the axis is currently in a dwell (pause) state. | |
| ReciprocatingAxis | IsAtPosA () |
| Check if the axis is currently within the in-position threshold of PosA. | |
| ReciprocatingAxis | IsAtPosB () |
| Check if the axis is currently within the in-position threshold of PosB. | |
| ReciprocatingAxis | IsMovingTowardsA () |
| Check if the axis was last commanded to move toward PosA. | |
| ReciprocatingAxis | IsMovingTowardsB () |
| Check if the axis was last commanded to move toward PosB. | |
| ReciprocatingAxis | IsStopRequested () |
| Check if any stop condition has been requested for this axis. | |
| ReciprocatingAxis | Process () |
| Main update function for the reciprocating axis; must be called regularly. | |
| ReciprocatingAxis | ProcessAll (all_axes) |
| Process all reciprocating axes with error protection. | |
| ReciprocatingAxis | Dwell () |
| Handle dwell timing at the current endpoint before the next jog stroke. | |
| ReciprocatingAxis | ProcessStop () |
| Evaluate stop conditions and either halt or continue the reciprocating cycle. | |
| ReciprocatingAxis Create | ( | axis | , |
| pos_a | , | ||
| pos_b | ) |
Create a new ReciprocatingAxis instance for a specific axis and instance.
Constructs and initializes a ReciprocatingAxis object with the given axis and instance. Initial positions pos_a and pos_b are stored as pos0 and pos1 respectively. Configuration values are loaded from OEM parameters using GetParameter() with the following defaults if parameters are missing:
| instance | (number) The Mach4 instance handle to use for all motion and API calls |
| axis | (number) The axis number to reciprocate (e.g., mc.X_AXIS) |
| pos_a | (number) The machine coordinate for endpoint A (pos0) |
| pos_b | (number) The machine coordinate for endpoint B (pos1) |
| ReciprocatingAxis CreateAll | ( | ) |
Create ReciprocatingAxis objects for all enabled axes in the given instance.
Iterates from mc.X_AXIS to mc.MC_MAX_AXES - 1 and calls mc.mcAxisIsEnabled() for each axis. For every enabled axis, creates a ReciprocatingAxis object via Create() with pos_a and pos_b both initialized to 0. Returns a sparse table indexed by axis number containing only the enabled axes.
| instance | (number) The Mach4 instance handle to query axis enable state and use for motion |
| ReciprocatingAxis Dwell | ( | ) |
Handle dwell timing at the current endpoint before the next jog stroke.
Manages the dwell (pause) period after arriving at an endpoint. On the first call after arrival, records the start time via os.clock(). Subsequent calls check elapsed time against the configured dwell duration (dwell_0 for pos0, dwell_1 for pos1). Returns true when the dwell period has elapsed or no dwell is needed. Dwell is skipped on the initial start (commanded_position_idx == -1) and when a stop has been requested.
| ReciprocatingAxis GetParameter | ( | default_value | ) |
Retrieve a named OEM parameter value for this axis, with a default fallback.
Constructs the parameter name by combining the axis number (zero-padded to two digits) with the provided parameter name in the format "ReciprocatingAxis##<param>". Looks up the value via w.GetOEMParamValue(). If the value is nil or non-positive and differs from the default, logs a warning and returns the default value instead.
| param | (string) The parameter name suffix (e.g., "DefaultPosADwell", "InPositionThreshold") |
| default_value | (number) The fallback value to use if the parameter is missing or invalid |
| ReciprocatingAxis IsAtPosA | ( | ) |
Check if the axis is currently within the in-position threshold of PosA.
| ReciprocatingAxis IsAtPosB | ( | ) |
Check if the axis is currently within the in-position threshold of PosB.
| (none) |
| ReciprocatingAxis IsDwelling | ( | ) |
Check if the axis is currently in a dwell (pause) state.
| ReciprocatingAxis IsMovingTowardsA | ( | ) |
Check if the axis was last commanded to move toward PosA.
| ReciprocatingAxis IsMovingTowardsB | ( | ) |
Check if the axis was last commanded to move toward PosB.
| ReciprocatingAxis IsRunning | ( | ) |
Check if the reciprocating axis cycle is currently active.
| ReciprocatingAxis IsStopping | ( | ) |
Check if the axis is currently running and a stop has been requested.
Returns true only when the axis is both actively reciprocating (IsRunning() is true) and at least one stop condition has been flagged (IsStopRequested() is true). This indicates the axis is in the process of completing its final stroke before halting.
| ReciprocatingAxis IsStopRequested | ( | ) |
Check if any stop condition has been requested for this axis.
| ReciprocatingAxis Process | ( | ) |
Main update function for the reciprocating axis; must be called regularly.
Drives the reciprocating axis state machine. Should be called on every screen update cycle or timer tick. Performs the following steps in order:
| ReciprocatingAxis ProcessAll | ( | all_axes | ) |
Process all reciprocating axes with error protection.
Calls _ProcessAll() inside a w.pcall() protected call. If an error occurs and the machine is still enabled, the error is reported via w.AlarmMessage(). This prevents a single axis error from crashing the calling script.
| all_axes | (table) Table of ReciprocatingAxis objects indexed by axis ID |
| ReciprocatingAxis ProcessStop | ( | ) |
Evaluate stop conditions and either halt or continue the reciprocating cycle.
Called when the axis has arrived at an endpoint and a stop has been requested. Determines whether to stop immediately or run one more stroke based on which endpoint was just reached versus which endpoint the stop was requested at:
| ReciprocatingAxis SetFeedrate | ( | ) |
Set the feedrate for reciprocating motion in both directions.
Calls SetPosAFeedrate() and SetPosBFeedrate() with the same rate value, applying it to both the PosA and PosB strokes simultaneously.
| rate | (number) Feedrate in machine units per minute for both directions |
| ReciprocatingAxis SetPosA | ( | ) |
Set the target position for PosA (endpoint 0).
Updates the stored PosA coordinate. The new value takes effect on the next stroke commanded toward PosA; any in-progress stroke is not affected.
| pos | (number) The target machine coordinate for PosA in machine units |
| ReciprocatingAxis SetPosADwell | ( | ) |
Set the dwell time in milliseconds after arriving at PosA.
Converts dwell_ms to a number via tonumber(). If conversion fails, defaults to 0. The dwell value is clamped to a minimum of 0 via math.max(). The dwell is applied on each arrival at PosA before the axis reverses direction toward PosB.
| dwell_ms | (number) Dwell duration in milliseconds. Negative values are clamped to 0 |
| ReciprocatingAxis SetPosAFeedrate | ( | ) |
Set the feedrate for reciprocating motion toward PosA.
Converts the rate to a number via tonumber(). If conversion fails, defaults to 10. This feedrate is applied when the axis is commanded to move toward PosA (index 0).
| rate | (number) Feedrate in machine units per minute for the PosA direction |
| ReciprocatingAxis SetPosB | ( | ) |
Set the target position for PosB (endpoint 1).
Updates the stored PosB coordinate. The new value takes effect on the next stroke commanded toward PosB; any in-progress stroke is not affected.
| pos | (number) The target machine coordinate for PosB in machine units |
| ReciprocatingAxis SetPosBDwell | ( | ) |
Set the dwell time in milliseconds after arriving at PosB.
Converts dwell_ms to a number via tonumber(). If conversion fails, defaults to 0. The dwell value is clamped to a minimum of 0 via math.max(). The dwell is applied on each arrival at PosB before the axis reverses direction toward PosA.
| dwell_ms | (number) Dwell duration in milliseconds. Negative values are clamped to 0 |
| ReciprocatingAxis SetPosBFeedrate | ( | ) |
Set the feedrate for reciprocating motion toward PosB.
Converts the rate to a number via tonumber(). If conversion fails, defaults to 10. This feedrate is applied when the axis is commanded to move toward PosB (index 1).
| rate | (number) Feedrate in machine units per minute for the PosB direction |
| ReciprocatingAxis SetPositionThreshold | ( | ) |
Set the in-position threshold distance used to detect endpoint arrival.
The threshold is used by IsAtPosA() and IsAtPosB() to determine whether the axis has arrived at an endpoint. A smaller value requires more precise positioning before a dwell or direction reversal is triggered.
| thresh | (number) The in-position threshold in machine units |
| ReciprocatingAxis Start | ( | ) |
Start the reciprocating axis cycle, optionally setting a new feedrate.
Validates that both feedrates are positive before starting. If an optional rate is provided, SetFeedrate() is called to apply it to both directions before starting. Resets all stop flags (stop, stop_at_0, stop_at_1) and sets the running flag to true. Raises a Lua error via w.Error() if either feedrate is nil or non-positive.
| rate | (number|nil) Optional feedrate to apply to both directions before starting. If nil, the previously configured feedrates are used |
| ReciprocatingAxis StartCannedCycle | ( | all_axes | , |
| axis_id | , | ||
| position_a | , | ||
| position_b | , | ||
| dwell | , | ||
| feedrate | ) |
Configure and start a reciprocating axis canned cycle with a single call.
Convenience function that sets PosA, PosB, dwell at both endpoints, and feedrate for both directions on the specified axis, then starts the reciprocating cycle. Any parameter that is nil is left at its previously configured value. Dwell is applied equally to both PosA and PosB; feedrate is applied equally to both directions.
| all_axes | (table) Table of ReciprocatingAxis objects indexed by axis ID |
| axis_id | (number) The axis ID key used to look up the axis in all_axes |
| position_a | (number|nil) Target position for PosA, or nil to keep current value |
| position_b | (number|nil) Target position for PosB, or nil to keep current value |
| dwell | (number|nil) Dwell time in milliseconds at each endpoint, or nil to keep current value |
| feedrate | (number|nil) Feedrate for both directions, or nil to keep current value |
| ReciprocatingAxis Stop | ( | ) |
Request the axis to stop at the next reciprocating endpoint.
Sets the stop flag, which causes the axis to cease reciprocating after it arrives at whichever endpoint it reaches next. Does not halt motion immediately; the axis will complete its current stroke before stopping.
| ReciprocatingAxis StopAll | ( | all_axes | ) |
Stop all jogging reciprocating axes in the collection.
Iterates over all axes in the provided table and calls Stop() on each one that is currently jogging. Axes that are not jogging are left unaffected. This requests a stop at the next endpoint rather than halting motion immediately mid-stroke.
| all_axes | (table) Table of ReciprocatingAxis objects indexed by axis ID |
| ReciprocatingAxis StopAtA | ( | ) |
Request the axis to stop after it next arrives at PosA.
Sets the stop_at_0 flag. The axis will complete its current stroke and, once it arrives at PosA (within pos_threshold), will cease reciprocating. Has no effect if the axis is not currently running.
| ReciprocatingAxis StopAtB | ( | ) |
Request the axis to stop after it next arrives at PosB.
Sets the stop_at_1 flag. The axis will complete its current stroke and, once it arrives at PosB (within pos_threshold), will cease reciprocating. Has no effect if the axis is not currently running.
| ReciprocatingAxis StopAxis | ( | all_axes | , |
| axis_id | , | ||
| stop_type | ) |
Stop a specific axis in the collection using a named stop type.
Dispatches a stop command to the specified axis based on the numeric stop_type:
| all_axes | (table) Table of ReciprocatingAxis objects indexed by axis ID |
| axis_id | (number) The axis ID key used to look up the axis in all_axes |
| stop_type | (number) Numeric stop type (0=mid-cycle, 1=at A, 2=at B, 3=any end) |
| ReciprocatingAxis StopMidCycle | ( | ) |
Immediately halt axis motion at the current position without waiting for an endpoint.
Requests a stop via Stop(), then checks if the axis is still jogging. If jogging and not already decelerating (mcJogIsStopping != 1), issues mcJogVelocityStop to halt motion immediately. Updates commanded_position to the current machine position so the state machine does not attempt to resume the interrupted stroke.
| ReciprocatingAxis StopMidCycleAll | ( | all_axes | ) |
Immediately stop all jogging axes in the collection mid-cycle.
Iterates over all axes in the provided table and calls StopMidCycle() on each one that is currently jogging. Axes that are not jogging are left unaffected.
| all_axes | (table) Table of ReciprocatingAxis objects indexed by axis ID |