|
Mach Modules Documentation
Lua Module API Documentation
|
Go to the source code of this file.
Functions | |
| VFD | Cleanup () |
| Clean up all resources associated with this VFD instance. | |
| VFD | CleanupCommonControls () |
| Remove all auxiliary spindle control registers and I/O points for the VFD device. | |
| VFD VFDCollection | Create () |
| Create and return an empty VFD collection object. | |
| VFD VFDCollection | Add () |
| Add a VFD object to the collection. | |
| VFD VFDCollection | Update () |
| Update all VFD instances in the collection. | |
| VFD VFDCollection | StopMotor () |
| Stop the motor on all VFD instances in the collection. | |
| VFD VFDCollection | ResetAlarms () |
| Reset alarms on all VFD instances in the collection. | |
| VFD VFDCollection | DoAll (...) |
| Call a named member function on every VFD in the collection. | |
| VFD | CreateVFDs () |
| Instantiate and return all enabled VFD objects for the current machine configuration. | |
| VFD | GetSpindleControlObjects () |
| Return the table defining all spindle control register and I/O point names. | |
| VFD | CreateSpindleControls () |
| Create spindle control registers and I/O outputs for the VFD device. | |
| VFD | GetMaxMotorRPM () |
| Get the maximum motor RPM from Mach4 spindle settings or auxiliary OEM parameter. | |
| VFD | SetMotorRPM () |
| Set the commanded motor frequency/percentage on the Delta VFD drive. | |
| VFD | GetCommandedMotorRPM () |
| Get the commanded motor RPM from Mach4 or auxiliary control register. | |
| VFD | GetCommandedMotorDirection () |
| Get the commanded motor direction from Mach4 or auxiliary I/O. | |
| VFD | SetActualMotorRPMFeedback () |
| Set the actual motor RPM feedback from VFD sensor data. | |
| VFD | SetActualMotorLoadFeedbackPercentage () |
| Set the actual motor load feedback percentage in the standard feedback register. | |
| VFD | GetActualMotorLoadFeedbackPercentage () |
| Get the actual motor load feedback percentage (base VFD implementation). | |
| VFD | GetSSVRPM () |
| Compute the commanded spindle RPM with Spindle Speed Variation (SSV) applied. | |
| Delta | Create (vfd_instance, vfd_cleanup) |
| Create and initialize a Delta MS3000 VFD object. | |
| Delta | StartMotorForward () |
| Start the Delta MS3000 VFD motor in the forward direction. | |
| Delta | StartMotorReverse () |
| Start the Delta MS3000 VFD motor in the reverse direction. | |
| Delta | GetActualMotorRPMFeedback () |
| Get the actual motor RPM feedback from the Delta MS3000 VFD. | |
| Delta | ReadAlarmCode () |
| Read the current alarm code from the Delta MS3000 VFD Warning_Alarm register. | |
| Delta | ReadWarningCode () |
| Read the current warning code from the Delta MS3000 VFD Warning_Alarm register. | |
| Delta | IsAlarmActive () |
| Check whether a Delta MS3000 VFD alarm is currently active. | |
| Delta | CheckForAlarms () |
| Check for active alarms on the Delta MS3000 VFD and create GMS alarm notifications. | |
| Delta | ReadWarnings () |
| Read and process warning codes from the Delta MS3000 VFD (stub). | |
| Delta | AutoTune () |
| Stop Delta VFD auto-tune if it is currently active. | |
| VFD VFDCollection Add | ( | ) |
Add a VFD object to the collection.
Appends the provided VFD instance to the internal vfds array using table.insert(). The added VFD will be included in all subsequent collection-wide operations such as Update(), StopMotor(), ResetAlarms(), and DoAll().
| vfd | (table) The VFD object to add to the collection |
| Delta AutoTune | ( | ) |
Stop Delta VFD auto-tune if it is currently active.
Checks whether the Delta-05-00_0 OEM parameter is non-zero (indicating auto-tune is active). If so, waits 150 ms for the spindle to start, then writes 0 to both the OEM parameter and the modbus register "05-00" to disable auto-tune. Raises an error via w.Error() if either register write fails.
| Hitachi CheckForAlarms | ( | ) |
Check for active alarms on the Delta MS3000 VFD and create GMS alarm notifications.
Check for active alarms on the Hitachi VFD and create GMS alarm notifications.
Check for active alarms on the Yaskawa VFD and create GMS alarm notifications.
Reads the alarm code via ReadAlarmCode() and compares it to the last known error code. If a new alarm is detected (and it is not the ignored "Safety torque off (STo)" alarm code 76), looks up the description in the ErrorCodes table and creates a GMS Alarm notification with instructions for clearing the fault. The motor is stopped when an alarm is detected. The LastErrorCode field is updated after each check regardless of alarm state.
Performs two independent checks. First, if the motor is marked as running, it verifies the Drive_Ready signal is still asserted; if not, creates a GMS Alarm for lost ready signal and stops the motor. Second, reads the alarm code via ReadAlarmCode(). If a new alarm is detected, looks up the description in the ErrorCodes table and creates a GMS Alarm notification, then stops the motor and records the alarm code in LastErrorCode.
Performs several checks in sequence: first verifies control is enabled, then checks for a base frequency error on the modbus function5 channel (restarting it if needed), then checks if an alarm is currently active via IsAlarmActive(). If a new alarm is detected and not already acknowledged, it reads the alarm code, looks up the description in the ErrorCodes table, collects trip diagnostic data (output frequency, current, voltage, LAD state, trip count), and creates a GMS Alarm notification. The motor is stopped when an alarm is detected.
| VFD Cleanup | ( | ) |
Clean up all resources associated with this VFD instance.
Calls CleanupCommonControls() to remove any auxiliary spindle control registers and I/O points that were created for this VFD device. Intended to be called when a VFD instance is being torn down or when the VFD is found to be disabled during initialization.
| VFD CleanupCommonControls | ( | ) |
Remove all auxiliary spindle control registers and I/O points for the VFD device.
If ControlSource is "Auxiliary", retrieves the spindle control object list via GetSpindleControlObjects() and then removes each register and each I/O point from the VFD auxiliary device using w.RemoveRegister() and w.RemoveIO(). Logs each removal operation. Does nothing if ControlSource is not "Auxiliary".
| VFD VFDCollection Create | ( | ) |
Create and return an empty VFD collection object.
Instantiates a new VFDCollection object using Lua metatables and initializes its internal vfds array to an empty table. The returned collection can be populated using Add() and then operated on using Update(), StopMotor(), ResetAlarms(), and DoAll().
| Hitachi Create | ( | vfd_instance | , |
| vfd_cleanup | ) |
Create and initialize a Delta MS3000 VFD object.
Create and initialize a Hitachi P1 VFD object.
Create and initialize a Yaskawa V1000 VFD object.
Instantiates a new Delta VFD object using Lua metatables. Reads all Mach-configurable string parameters (control enable, modbus names, control source, etc.) from OEM parameters using the instance suffix. If vfd_cleanup is true, returns immediately after reading basic parameters for cleanup purposes without creating spindle controls or writing to the drive.
When fully initializing, the function:
| mach_instance | (number) The Mach4 instance handle |
| vfd_instance | (number) The VFD instance index (0-based, used to suffix OEM parameter names) |
| vfd_cleanup | (boolean|nil) If true, perform minimal initialization for cleanup only |
When fully initializing, the function:
| mach_instance | (number) The Mach4 instance handle |
| vfd_instance | (number) The VFD instance index (0-based, used to suffix OEM parameter names) |
| vfd_cleanup | (boolean|nil) If true, perform minimal initialization for cleanup only |
When fully initializing, the function:
| mach_instance | (number) The Mach4 instance handle |
| vfd_instance | (number) The VFD instance index (0-based, used to suffix OEM parameter names) |
| vfd_cleanup | (boolean|nil) If true, perform minimal initialization for cleanup only |
| VFD CreateSpindleControls | ( | ) |
Create spindle control registers and I/O outputs for the VFD device.
Creates all registers and I/O points needed for spindle control by iterating over the SpindleControls table populated by GetSpindleControlObjects(). Always creates Standard_Registers (e.g., Feedback_Load) as permanent registers. If ControlSource is "Auxiliary", additionally creates Registers (Command_RPM, Feedback_RPM) and I/O outputs (FWD, REV) as permanent objects on the VFD auxiliary device. Raises an error via w.Error() if any register or I/O creation fails.
| VFD CreateVFDs | ( | ) |
Instantiate and return all enabled VFD objects for the current machine configuration.
Reads OEM parameters to determine which VFD types and instances are enabled, then creates and collects the appropriate VFD subclass objects. Iterates instances 0-2 for each supported VFD type (DeltaMS3000, YaskawaV1000, Hitachi). For each instance, if the corresponding ControlEnabled OEM parameter is "Yes", the VFD is created and added to the collection. If not enabled, a temporary object is created and immediately cleaned up to remove any stale registers or I/O. Stops iteration for a given type as soon as a missing OEM parameter is detected.
| mach_instance | (number) The Mach4 instance handle passed to each VFD constructor |
| VFD VFDCollection DoAll | ( | ... | ) |
Call a named member function on every VFD in the collection.
Iterates over all VFD objects in the collection and calls the method identified by fn_name on each one, forwarding all additional arguments via varargs. Useful for broadcasting any arbitrary operation to all managed VFD instances without requiring a dedicated forwarding method on VFDCollection.
| fn_name | (string) The name of the method to call on each VFD object |
| ... | (any) Additional arguments forwarded to each VFD method call |
| Hitachi GetActualMotorLoadFeedbackPercentage | ( | ) |
Get the actual motor load feedback percentage (base VFD implementation).
Get the actual motor load feedback as a percentage for the Hitachi VFD.
Get the actual motor load feedback as a percentage for the Yaskawa VFD.
Base class implementation that always returns 0. Subclasses (Delta, Yaskawa, Hitachi) override this method to return actual load data read from the VFD monitoring registers.
Reads the Output_Current register from the monitoring modbus device. The rated current reference (Yaskawa-E2-01) is halved for Small drive capacity to match the register scaling. The actual current is then scaled from [0, max_load] to [0, 100] to produce a load percentage. Returns the absolute value to handle any sign issues.
Reads the Output_Current_Monitor register from the monitoring modbus device and scales it from 0 to the motor rated current (Hitachi-Hb108 parameter) to produce a load percentage from 0 to 100. Returns the absolute value to handle any sign issues.
| Hitachi GetActualMotorRPMFeedback | ( | ) |
Get the actual motor RPM feedback from the Delta MS3000 VFD.
Get the actual motor RPM feedback from the Hitachi VFD output frequency.
Get the actual motor RPM feedback from the Yaskawa VFD output frequency.
Reads the Motor_Speed_In_RPM_Estimated register from the monitoring modbus device (ModbusName_MON). Returns the absolute value of the register reading to handle reverse rotation.
Reads the Output_Frequencey (sic) register from the monitoring modbus device. Scales the output frequency to RPM using either the CommandTypeMaxValue (for Percentage command type) or motor_max_frequency (for Frequency command type) as the input range, mapping to [0, max_rpm]. Returns the absolute value to handle reverse rotation.
Reads the Output_Frequency_Monitor register from the monitoring modbus device, then scales it from the range [0, motor_max_frequency] to [0, max_rpm] to compute the estimated motor RPM. Returns the absolute value to handle reverse rotation.
| VFD GetCommandedMotorDirection | ( | ) |
Get the commanded motor direction from Mach4 or auxiliary I/O.
Determines the commanded spindle direction from one of two sources depending on the configured ControlSource. If ControlSource is "Mach", reads the spindle direction via mc.mcSpindleGetDirection() and applies the pulley reverse flag from mc.mcSpindleGetReverse() to invert the direction if needed. If ControlSource is "Auxiliary", reads the FWD and REV I/O states from the VFD device to determine direction. Raises an error via w.Error() if any API call or I/O read fails.
| VFD GetCommandedMotorRPM | ( | ) |
Get the commanded motor RPM from Mach4 or auxiliary control register.
Retrieves the commanded spindle RPM from one of two sources depending on the configured ControlSource. If ControlSource is "Mach", reads the motor RPM via mc.mcSpindleGetMotorRPM() and applies Spindle Speed Variation (SSV) via GetSSVRPM(). If ControlSource is "Auxiliary", reads the Command_RPM register from the VFD device; if the ControlSourceCommandType is "Percentage", scales the percentage value to RPM using GetMaxMotorRPM() as the upper bound. Raises an error via w.Error() if any API call or register read or scale operation fails.
| VFD GetMaxMotorRPM | ( | ) |
Get the maximum motor RPM from Mach4 spindle settings or auxiliary OEM parameter.
Retrieves the maximum motor RPM from one of two sources depending on the configured ControlSource. If ControlSource is "Mach", reads the motor max RPM via mc.mcSpindleGetMotorMaxRPM(). If ControlSource is "Auxiliary", reads the AuxiliaryControlMaxRPM OEM parameter value directly. Raises an error via w.Error() if the Mach4 API call fails.
| VFD GetSpindleControlObjects | ( | ) |
Return the table defining all spindle control register and I/O point names.
Constructs and returns a table with three subtables describing the objects used for spindle control:
| VFD GetSSVRPM | ( | ) |
Compute the commanded spindle RPM with Spindle Speed Variation (SSV) applied.
Reads OEM parameters 1940 (SSV enable), 1941 (SSV amplitude in RPM), and 1942 (SSV interval/frequency) to determine whether SSV mode should be active. If SSV is enabled and the spindle is running (CommandedDirection != 0) with valid amplitude and interval values, activates SSV mode and applies a sinusoidal variation to the commanded speed: new_rpm = amplitude * sin(period * elapsed_time) + cmd_speed The result is clamped to the current range's [min_speed, max_speed] limits. If SSV conditions are no longer met, deactivates SSV mode and returns the original cmd_speed.
| cmd_speed | (number) The base commanded spindle speed in RPM before SSV is applied |
| Hitachi IsAlarmActive | ( | ) |
Check whether a Delta MS3000 VFD alarm is currently active.
Check whether a Hitachi VFD alarm is currently active.
Check whether a Yaskawa VFD alarm is currently active.
Calls ReadAlarmCode() and returns true if the alarm code is greater than zero and is not equal to 76 (the "Safety torque off (STo)" alarm, which is intentionally ignored). Returns early without a meaningful value if control is not enabled.
Calls ReadAlarmCode() and returns true if any alarm code is present (non-nil). Returns early without a meaningful value if control is not enabled.
Reads the Output_Terminal_AL I/O state from the VFD modbus device to determine if an alarm (fault) condition is present. Returns early without a meaningful value if control is not enabled.
| Hitachi ReadAlarmCode | ( | ) |
Read the current alarm code from the Delta MS3000 VFD Warning_Alarm register.
Read the current alarm code from the Hitachi VFD trip monitor.
Read the current alarm code from the Yaskawa VFD error signal registers.
Reads the combined Warning_Alarm register from the monitoring modbus device. The lower 8 bits (masked with 0xFF) contain the alarm code and the upper bits contain the warning code. Extracts and returns only the alarm code (lower byte).
Reads three error signal registers (Error_Signal_1, Error_Signal_2, Error_Signal_3) from the monitoring modbus device. For each non-zero word, scans bits 0-15 to find the first set bit and returns a formatted key string in the form '<signal_number>.<hex_bit>' (e.g., '1.5', '2.A') that indexes into the Yaskawa.ErrorCodes table. Returns nil if all three error signal registers are zero (no alarm).
Starts the modbus function1 polling cycle, reads the Trip_Monitor_1_Factor register from the monitoring modbus device to obtain the active fault code, then stops the function1 polling cycle. The returned code is a numeric key into the Hitachi.ErrorCodes table. Returns nil if no alarm is present.
| Delta ReadWarningCode | ( | ) |
Read the current warning code from the Delta MS3000 VFD Warning_Alarm register.
Reads the combined Warning_Alarm register from the monitoring modbus device. The lower 8 bits contain the alarm code and the upper bits contain the warning code. Extracts and returns only the warning code (upper byte, shifted right by 8 bits).
| Hitachi ReadWarnings | ( | ) |
Read and process warning codes from the Delta MS3000 VFD (stub).
Read and log warning codes from the Hitachi VFD (currently disabled).
Read and process warning codes from the Yaskawa VFD.
This function is currently a stub. It checks the DeltaControlEnabled_0 OEM parameter and returns immediately if control is not enabled. No warning data is read or processed. Intended to be expanded in a future implementation.
Reads the Operation_Error I/O state from the VFD modbus device. If a new warning is detected (different from LastWarningCode), creates a GMS Warning notification with corrective action text explaining the oPE error and steps to identify the conflicting parameter. The LastWarningCode is updated after each call regardless of whether a warning was active.
This function is currently disabled via an early return and performs no action. When enabled, it reads the Operation_Error I/O state from the VFD modbus device and, if a new warning is detected, creates a Global Message System (GMS) warning with corrective action information. The LastWarningCode is updated after each call.
| VFD VFDCollection ResetAlarms | ( | ) |
Reset alarms on all VFD instances in the collection.
Reset active alarms on the Hitachi VFD.
Reset active alarms on the Yaskawa VFD.
Reset active alarms on the Delta MS3000 VFD.
Iterates over all VFD objects in the collection and calls ResetAlarms() on each one. Each VFD subclass implements its own alarm reset sequence, which may include pulsing reset registers or I/O outputs and displaying a blocking please-wait dialog.
Checks whether an alarm is active via IsAlarmActive(). If so, clears the internal LastErrorCode state, pulses the Reset modbus register to value 2 and then back to 0, with a 6-second please-wait dialog in between to allow the drive time to reset.
Checks both IsAlarmActive() and the hardware Fault I/O signal. If either indicates a fault, pulses the Multi-Function_Input_4 I/O output true and then false, with a 6-second please-wait dialog in between to allow the drive time to reset. Clears the internal LastErrorCode state after the reset attempt.
First checks for a base frequency error on the modbus function5 channel and issues a Stop command to the modbus controller if found. If an alarm is active (via IsAlarmActive()), it pulses the Fault_Reset I/O output true and then false, with a 6-second please-wait dialog in between to allow the drive time to reset. Clears the internal LastErrorCode and AlarmActive state after the reset attempt.
| VFD SetActualMotorLoadFeedbackPercentage | ( | ) |
Set the actual motor load feedback percentage in the standard feedback register.
Writes the provided load percentage value to the Standard_Registers Feedback_Load register on the VFD device. Only writes if the value is a non-nil number. Raises an error via w.Error() if the register write fails.
| load_pct | (number) The motor load percentage to write (typically 0-100) |
| VFD SetActualMotorRPMFeedback | ( | ) |
Set the actual motor RPM feedback from VFD sensor data.
Writes the provided RPM value to the appropriate feedback destination depending on the configured ControlSource. If ControlSource is "Mach", calls mc.mcSpindleSetSensorRPM() to update the Mach4 spindle sensor RPM. Otherwise, writes the RPM value to the Feedback_RPM register on the VFD auxiliary device. Only writes if RPM is a non-nil number. Raises an error via w.Error() if the API call or register write fails.
| RPM | (number) The actual motor RPM value to set as feedback |
| VFD SetMotorRPM | ( | ) |
Set the commanded motor frequency/percentage on the Delta VFD drive.
Updates the commanded motor speed only if the new RPM differs from the last commanded RPM. Converts the RPM value to either a percentage (scaled to CommandTypeMaxValue) or a frequency (scaled to motor_max_frequency) depending on the CommandType parameter. The computed frequency is clamped to [motor_min_frequency, motor_max_frequency] when using Frequency mode. Writes the resulting value to the "Frequency" modbus register on the VFD device. Raises an error via w.Error() if any scale or register write operation fails.
| RPM | (number) The commanded motor speed in RPM to convert and write to the drive |
| Hitachi StartMotorForward | ( | ) |
Start the Delta MS3000 VFD motor in the forward direction.
Start the Hitachi VFD motor in the forward direction.
Start the Yaskawa VFD motor in the forward direction.
Clears the Stop and Reverse I/O outputs, then sets Forward and Run I/O outputs to true on the VFD modbus device to command forward rotation. Also calls AutoTune() after issuing the run command. Raises an error via w.Error() if any I/O write fails.
Clears the Reverse I/O output and sets the Forward I/O output to true on the VFD modbus device to command forward rotation, then sets the motor_running flag to true. Raises an error via w.Error() if either I/O write fails.
Clears the Reverse I/O output and sets Run_Stop to true on the VFD modbus device to command forward rotation. Raises an error via w.Error() if either I/O write fails.
| Hitachi StartMotorReverse | ( | ) |
Start the Delta MS3000 VFD motor in the reverse direction.
Start the Hitachi VFD motor in the reverse direction.
Start the Yaskawa VFD motor in the reverse direction.
Clears the Stop and Forward I/O outputs, then sets Reverse and Run I/O outputs to true on the VFD modbus device to command reverse rotation. Also calls AutoTune() after issuing the run command. Raises an error via w.Error() if any I/O write fails.
Clears the Forward I/O output and sets the Reverse I/O output to true on the VFD modbus device to command reverse rotation, then sets the motor_running flag to true. Raises an error via w.Error() if either I/O write fails.
Sets the Reverse I/O output to true and Run_Stop to true on the VFD modbus device to command reverse rotation. Raises an error via w.Error() if either I/O write fails.
| Hitachi StopMotor | ( | ) |
Stop the motor on all VFD instances in the collection.
Stop the Hitachi VFD motor.
Stop the Yaskawa VFD motor.
Stop the Delta MS3000 VFD motor.
Iterates over all VFD objects in the collection and calls StopMotor() on each one. Each VFD subclass implements its own motor stop sequence by writing the appropriate I/O outputs on the VFD modbus device.
Sets the Run I/O output to false and the Stop I/O output to true on the VFD modbus device to command the motor to stop. Raises an error via w.Error() if either I/O write fails.
Sets both Forward and Reverse I/O outputs to false on the VFD modbus device to command the motor to stop, then sets the motor_running flag to false. Raises an error via w.Error() if either I/O write fails.
Sets the Run_Stop I/O output to false on the VFD modbus device to command the motor to stop. Raises an error via w.Error() if the I/O write fails.
| VFD Update | ( | ) |
Update all VFD instances in the collection.
Perform a full periodic update cycle for the VFD.
Iterates over all VFD objects in the collection and calls Update() on each one. Each VFD subclass Update() synchronizes commanded RPM, direction, RPM feedback, load feedback, alarms, and warnings with the current Mach4 or auxiliary control state.
Called repeatedly to synchronize the VFD drive state with the commanded state from Mach4 or auxiliary controls. Performs the following steps in order: