This code appears to be part of an industrial automation...

August 25, 2025 at 08:09 PM

local debug = not My.Config.IsSiteServer local feeder = PF341 local motor1 = FM343_1 local motor2 = FM343_2 local gate1 = VE344 local gate2 = VE345 local pump = HP336 local flakerRolls = V343 local flakerVir = FM343_vir local equipmentAlarms = (pump.AlarmedOutput.Value) or motor1.AlarmedOutput.Value or motor2.AlarmedOutput.Value or flakerRolls.AlarmedOutput.Value or FlakingStop.InAnAlarmState.Value local motor1Running = Me.iRollMotor1Running.Value local motor2Running = Me.iRollMotor2Running.Value local rollsClosed = Me.iHMIRollsClose.Value local rollsOpened = Me.iRollsOpened.Value local runMotor1 = false local runMotor2 = false local runPump = false local closeRollsCMD = false local OKStartMotors = pump.RampComplete.Value local OKCloseRolls = motor1.RampComplete.Value and motor2.RampComplete.Value and pump.RampComplete.Value local statusMsg = "" if flakerRolls and (not flakerRolls.GateType == flakerRolls.GateType.SingleActing) then flakerRolls.GateType = flakerRolls.GateType.SingleActing end -------------------------------------------------------------------------------------------------------------------------------------------------- --HMI imputs -------------------------------------------------------------------------------------------------------------------------------------------------- local HMIenableFlaker = Me.iHMIEnableFlaker.InputValue local HMIstartMotors = Me.iHMIRollMotorsStart.InputValue and motor1.InAutoMode.Value and motor2.InAutoMode.Value local HMIcloseRolls = Me.iHMIRollsClose.InputValue local HMIMasterEnable = true --Me.iHMIMasterEnable.Value --.Value deliberate if not HMIenableFlaker or not HMIMasterEnable then if Me.iHMIEnableFlaker.InputValue then Me.iHMIEnableFlaker.InputValue = false end if Me.iHMIRollMotorsStart.InputValue then Me.iHMIRollMotorsStart.InputValue = false end if Me.iHMIRollsClose.InputValue then Me.iHMIRollsClose.InputValue = false end HMIenableFlaker = false HMIstartMotors = false HMIcloseRolls = false end -------------------------------------------------------------------------------------------------------------------------------------------------- if pump.IdleTimer.PresetSeconds ~= Me.pCfgHydaulicPumpStopDelay then pump.IdleTimer.PresetSeconds = Me.pCfgHydaulicPumpStopDelay end if Me.iRollsOpened.DebounceOnSeconds ~= Me.pCfgRollOpenTime then Me.iRollsOpened.DebounceOnSeconds = Me.pCfgRollOpenTime end if Me.iRollsClosed.DebounceOnSeconds ~= Me.pCfgRollCloseTime then Me.iRollsClosed.DebounceOnSeconds = Me.pCfgRollCloseTime end if Me.tPumpDelayStop.PresetSeconds ~= Me.pCfgHydaulicPumpStopDelay then Me.tPumpDelayStop.PresetSeconds = Me.pCfgHydaulicPumpStopDelay end if Me.tRollMotor2StartDelay.PresetSeconds ~= Me.pCfgRollMotor2StartDelay then Me.tRollMotor2StartDelay.PresetSeconds = Me.pCfgRollMotor2StartDelay end if not flakerRolls.InAutoMode.Value then flakerRolls.AutoPB.OneShot = true end -------------------------------------------------------------------------------------------------------------------------------------------------- --Functions -------------------------------------------------------------------------------------------------------------------------------------------------- local function debugPrint(s) if (debug) then helmprint(tostring(os.date()).. ": " .. Me.Name..".BStC: " .. tostring(s)) end end local function openRolls() closeRollsCMD = false end local function closeRolls() if feeder.RampComplete.Value and motor1.RampComplete.Value and motor2.RampComplete.Value then closeRollsCMD = true else closeRollsCMD = false if Me.iHMIRollsClose.InputValue then Me.iHMIRollsClose.InputValue = false end end end local function startPump() runPump = true end local function stopPump() runPump = false end local function startMotors() runMotor1 = true --Once motor1 is running start a timer before starting motor2 if motor1Running then if not Me.tRollMotor2StartDelay.Enabled then Me.tRollMotor2StartDelay.Enabled = true end else if Me.tRollMotor2StartDelay.Enabled then Me.tRollMotor2StartDelay:Reset() Me.tRollMotor2StartDelay.Enabled = false end end --Start motor2 once timer is done if motor1Running and Me.tRollMotor2StartDelay.TimerDone or Me.tRollMotor2StartDelay.PresetSeconds == 0 then runMotor2 = true else runMotor2 = false end end local function stopMotors() runMotor1 = false runMotor2 = false if Me.tRollMotor2StartDelay.Enabled then Me.tRollMotor2StartDelay:Reset() Me.tRollMotor2StartDelay.Enabled = false end end local function clearOutputs() Me.oRunFeeder.Value = false end local function clearUserInputs() if Me.iHMIRollMotorsStart.InputValue then Me.iHMIRollMotorsStart.InputValue = false end if Me.iHMIRollsClose.InputValue then Me.iHMIRollsClose.InputValue = false end if not HMIMasterEnable then if Me.iHMIEnableFlaker.InputValue then Me.iHMIEnableFlaker.InputValue = false end end end -------------------------------------------------------------------------------------------------------------------------------------------------- --State functions -------------------------------------------------------------------------------------------------------------------------------------------------- local function stateIdle() --0 if HMIenableFlaker then startPump() else stopPump() end stopMotors() openRolls() if HMIenableFlaker and not equipmentAlarms then Me.pState = states.run end if not HMIMasterEnable then clearUserInputs() end end local function stateRun() --10 startPump() if (not motor1.InAutoMode.Value or not motor2.InAutoMode.Value) and Me.iHMIRollMotorsStart.InputValue then Me.iHMIRollMotorsStart.InputValue = false end if HMIcloseRolls then closeRolls() else openRolls() end if HMIstartMotors then startMotors() else stopMotors() end if not HMIenableFlaker or not HMIMasterEnable or equipmentAlarms then clearUserInputs() Me.pState = states.idle end end -------------------------------------------------------------------------------------------------------------------------------------------------- --Execute state functions -------------------------------------------------------------------------------------------------------------------------------------------------- if not HMIenableFlaker then --clearUserInputs() --Me.pState = states.idle end if Me.pState == states.run then stateRun() else Me.pState = states.idle stateIdle() end if Me.pStatus ~= statusMsg then Me.pStatus = statusMsg end --Set outputs to run equipment Me.oPumpRun.Value = runMotor1 or runMotor2 or Me.iHMIEnableFlaker.Value --runPump Me.oRollsMotor1Run.Value = runMotor1 Me.oRollsMotor2Run.Value = runMotor2 Me.oRollsClose.Value = closeRollsCMD if Me.pStatus ~= statusMsg then Me.pStatus = statusMsg end -------------------------------------------------------------------------------------------------------------------------------------------------- --Downstream gates positioning and loaded flags -------------------------------------------------------------------------------------------------------------------------------------------------- if flakerVir.Loaded then gate1.InhibitClean.InputValue = true gate2.InhibitClean.InputValue = true gate1.LoadMe = true gate2.LoadMe = true else gate1.InhibitClean.InputValue = false gate2.InhibitClean.InputValue = false end if Me.iDownstreamFillRequest.Value and VE375.AtPositionTwo.Value and CD370_DRAG.RampComplete.Value and CD401_DRAG.RampComplete.Value and motor1.RampComplete.Value and motor2.RampComplete.Value and feeder.RampComplete.Value and flakerRolls.AtOpenPosition.Value then Me.oGatesReqPos1.Value = 1 Me.oGatesReqPos2.Value = 1 else Me.oGatesReqPos1.Value = 2 Me.oGatesReqPos2.Value = 2 end

This code appears to be part of an industrial automation system or PLC (Programmable Logic Controller) script for a flaker machine. Here's a breakdown of what the code does:


1. System Setup and Initializations

  • Variables like debug, feeder, motor1, motor2, gate1, and other tags are initialized to reference equipment or signals in the system.
  • Configurable parameters and preset values such as IdleTimer, DebounceOnSeconds, and timers for motor events are checked and, if necessary, updated to the correct system values.
  • Alarm statuses, motor states, and conditions for equipment operation are initialized.

2. Input Handling and Validation

  • Reads and validates inputs from an HMI (Human-Machine Interface) for commands like enabling the flaker, starting motors, and closing rolls.
  • If the flaker or master enable (HMIMasterEnable) is disabled, it clears user inputs associated with the flaker’s operation.

3. Pump, Motor, and Rolls Control Logic

  • Functions are defined to:
    • Start and stop the pump: startPump() and stopPump()
    • Start and stop motors: startMotors() and stopMotors()
    • Open and close the rolls: openRolls() and closeRolls()
    • Clear outputs and user inputs when transitioning states or encountering a fault.
  • Timing and interlocking for starting and stopping motors are implemented, particularly ensuring that motor2 starts only after motor1.

4. FSM (Finite State Machine) Design

  • Implements two main states:
    • Idle State (stateIdle):
      • Operates when the flaker is disabled or alarms are present.
      • Stops pumps, motors, and opens the rolls.
      • Transitions to the Run state if the flaker is enabled and there are no alarms.
    • Run State (stateRun):
      • Operates when the flaker and motors are enabled.
      • Starts the pump and motors, and closes the rolls based on HMI commands.
      • Transitions back to Idle if the flaker is disabled, alarms are present, or a master enable is turned off.

5. Output Control

  • Outputs are set to drive the equipment:
    • Signals like Me.oPumpRun, Me.oRollsMotor1Run, Me.oRollsMotor2Run, and Me.oRollsClose control whether the pump and motors are running or whether rolls are closed.
    • Logical conditions are used to determine the appropriate state of outputs.

6. Downstream Equipment and Gate Control

  • Checks and controls the position of downstream gates (gate1 and gate2) based on the state of the system (e.g., whether the downstream flaker is loaded and ready).
  • Adjusts gate positions depending on loading conditions and downstream fill requests:
    • Gates operate between two positions (Value = 1 for position 1 or Value = 2 for position 2), synchronized with downstream equipment and other criteria.

7. Debugging and Status Updates

  • A debug utility (debugPrint) is provided to log system events if debug mode is active.
  • Updates the current status message (statusMsg) to reflect system states and conditions.

Overall Purpose

This script appears to manage the operational logic of a flaker system, which likely processes materials into flakes. It:

  1. Monitors alarms and equipment states.
  2. Responds to HMI commands for starting/stopping the system with appropriate safeguards and interlocks.
  3. Manages the coordination and sequencing of multiple components (e.g., pump, motors, rolls, and gates).
  4. Transitions between Idle and Run states based on the input conditions and system status.

This is typical control logic for an industrial automation application where operational safety, sequencing, and modularity are crucial.

Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node