PLC Programming Question - Not Using the Wizard - (Problem Solved)

All things ecat Hickory CNC controller

Moderator: cnckeith

Post Reply
glbreil
Posts: 114
Joined: Sun Jan 07, 2024 10:55 am
Acorn CNC Controller: No
Plasma CNC Controller: No
AcornSix CNC Controller: No
Allin1DC CNC Controller: No
Hickory CNC Controller: Yes
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: Yes

PLC Programming Question - Not Using the Wizard - (Problem Solved)

Post by glbreil »

Hello I have added a motorized tool probe arm and set it up so that INP16 is ProbeTrip, INP15 is ProbeDetect, and INP14 is ProbeArmMachineReady. The arm is raised and lowered with OUT19 & OUT20 using Auxillary buttons Aux3 & Aux4. That all works great, the arm goes up and down and activates the appropriate inputs. What I wanted to do was use INP14 to prevent the machine from executing a G-Code program when the arm was down in the tool measuring position. The problem is the code I have used not only keeps the machine from executing a G-Code program it keeps it from executing an auto tool measure command. It Seems SV_Program_Running is not the right command to use, but I am at a loss for what else would work. For now I have just commented it out and the rest works fine. I was hoping some of you could point me toward the right command to accomplish what I am trying to do. Here is the section of Code and the part in red is my problem. Thanks In Advance.

;---------------------------------------------------------------------
; NEW: Tool Setter Arm Control (Simplified for "Push and Hold" operation)
;---------------------------------------------------------------------

; Check if Tool Setter Machine Ready (INP14) is active
; This sets ToolSetterReady_M if INP14 is active, otherwise, it will be RST by default below
IF TRUE THEN RST ToolSetterReady_M ; Default to OFF
IF INP14 THEN SET ToolSetterReady_M

; Prevent G-code program from running if ToolSetterMachineReadyInput is not active
;IF SV_PROGRAM_RUNNING && !ToolSetterReady_M
; THEN ErrorMsg_W = TOOLSETTER_NOT_READY_MSG,
; SET ErrorFlag_M,
; SET SV_STOP


; Control ToolSetterArmDown (OUT19) with Aux3Key_M (push and hold)
; Default to OFF for ToolSetterArmDown and its active flag
IF TRUE THEN RST ToolSetterArmDown
IF TRUE THEN RST ToolSetterArmDownActive_M
IF TRUE THEN RST Aux3LED

; Condition to SET ToolSetterArmDown and its active flag
IF Aux3Key_M && !ToolSetterArmUpActive_M
THEN SET ToolSetterArmDown, SET ToolSetterArmDownActive_M, SET Aux3LED

; Control ToolSetterArmUp (OUT20) with Aux4Key_M (push and hold)
; Default to OFF for ToolSetterArmUp and its active flag
IF TRUE THEN RST ToolSetterArmUp
IF TRUE THEN RST ToolSetterArmUpActive_M
IF TRUE THEN RST Aux4LED

; Condition to SET ToolSetterArmUp and its active flag
IF Aux4Key_M && !ToolSetterArmDownActive_M
THEN SET ToolSetterArmUp, SET ToolSetterArmUpActive_M, SET Aux4LED

; Turn off both arms if E-Stop is active (Safety Interlock - highest priority)
; These will override any SET commands above if SV_STOP is true.
IF SV_STOP
THEN RST ToolSetterArmDown, RST ToolSetterArmUp,
RST ToolSetterArmDownActive_M, RST ToolSetterArmUpActive_M

;---------------------------------------------------------------------
; END NEW: Tool Setter Arm Control and G-code Program Interlock
;---------------------------------------------------------------------

Thanks Gary
Last edited by glbreil on Sat Jun 28, 2025 7:53 pm, edited 1 time in total.


glbreil
Posts: 114
Joined: Sun Jan 07, 2024 10:55 am
Acorn CNC Controller: No
Plasma CNC Controller: No
AcornSix CNC Controller: No
Allin1DC CNC Controller: No
Hickory CNC Controller: Yes
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: Yes

Re: PLC Programming Question - Not Using the Wizard

Post by glbreil »

I think I might have found a solution to my problem when studying other system variables in the PLC Programming Manual, but I haven't made it to the machine yet. Do you think this could work to all the machine to go ahead and auto measure when INP14 is not active? The key change is in red.

; Prevent G-code program from running if ToolSetterMachineReadyInput is not active
IF SV_PROGRAM_RUNNING && !ToolSetterReady_M && !SV_DOING_AUTO_TOOL_MEASURE
THEN ErrorMsg_W = TOOLSETTER_NOT_READY_MSG,
SET ErrorFlag_M,
SET SV_STOP
Last edited by glbreil on Sat Jun 28, 2025 7:54 pm, edited 1 time in total.


glbreil
Posts: 114
Joined: Sun Jan 07, 2024 10:55 am
Acorn CNC Controller: No
Plasma CNC Controller: No
AcornSix CNC Controller: No
Allin1DC CNC Controller: No
Hickory CNC Controller: Yes
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: Yes

Re: PLC Programming Question - Not Using the Wizard

Post by glbreil »

Problem Solved!


cncsnw
Community Expert
Posts: 4553
Joined: Wed Mar 24, 2010 5:48 pm

Re: PLC Programming Question - Not Using the Wizard - (Problem Solved)

Post by cncsnw »

A couple of style and convention comments:

Code: Select all

; Check if Tool Setter Machine Ready (INP14) is active
; This sets ToolSetterReady_M if INP14 is active, otherwise, it will be RST by default below
IF TRUE THEN RST ToolSetterReady_M ; Default to OFF
IF INP14 THEN SET ToolSetterReady_M
Supposing that you have previously named INP14 as "ProbeArmMachineReady", it would be better to use that assigned name rather than the raw input name.

The above code (but using an assigned name) is exactly the same as:

Code: Select all

IF ProbeArmMachineReady THEN (ToolSetterReady_M)
... except that this version takes one line instead of two, probably runs a little faster, and is less prone to editing errors.

If there is no other condition that sets or resets ToolSetterReady_M, then you could just as well leave it out and reference ProbeArmMachineReady directly instead. The only reason to copy an input to a memory bit is so that M function macros and the cncxmsg.txt file can refer to a memory bit address (#70xxx / MEMxxx) which does not change even if the sensor gets moved to a different PLC input.

Regarding error reporting: fault conditions are not the same as error conditions.
See http://www.cncsnw.com/PLCApplicationsMPU11.htm

Code: Select all

IF SV_PROGRAM_RUNNING && !ToolSetterReady_M && !SV_DOING_AUTO_TOOL_MEASURE
THEN ErrorMsg_W = TOOLSETTER_NOT_READY_MSG,
SET ErrorFlag_M,
SET SV_STOP
Since you apparently intend this to be an error condition (one that stops the program cycle but does not remove power from the servos), you should not set SV_STOP.

If you wanted it to be a fault, you would assign the message code to FaultMsg_W instead of ErrorMsg_W, and you would not set ErrorFlag_M. Also, it would be better to set "OtherFault_M" rather than setting SV_STOP directly, so that the fault-detect and fault-reset code in MainStage can work properly.


glbreil
Posts: 114
Joined: Sun Jan 07, 2024 10:55 am
Acorn CNC Controller: No
Plasma CNC Controller: No
AcornSix CNC Controller: No
Allin1DC CNC Controller: No
Hickory CNC Controller: Yes
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: Yes

Re: PLC Programming Question - Not Using the Wizard - (Problem Solved)

Post by glbreil »

Thanks Marc, it took me a long time to get all that to work. I will have to study your comments some more to understand the error vs fault message. I am trying to get a little better understanding of what is going on in the PLC, it is slow going. Gary


glbreil
Posts: 114
Joined: Sun Jan 07, 2024 10:55 am
Acorn CNC Controller: No
Plasma CNC Controller: No
AcornSix CNC Controller: No
Allin1DC CNC Controller: No
Hickory CNC Controller: Yes
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: Yes

Re: PLC Programming Question - Not Using the Wizard - (Problem Solved)

Post by glbreil »

cncsnw wrote: Tue Jul 01, 2025 1:15 pm A couple of style and convention comments:

Code: Select all

; Check if Tool Setter Machine Ready (INP14) is active
; This sets ToolSetterReady_M if INP14 is active, otherwise, it will be RST by default below
IF TRUE THEN RST ToolSetterReady_M ; Default to OFF
IF INP14 THEN SET ToolSetterReady_M
Supposing that you have previously named INP14 as "ProbeArmMachineReady", it would be better to use that assigned name rather than the raw input name.

The above code (but using an assigned name) is exactly the same as:

Code: Select all

IF ProbeArmMachineReady THEN (ToolSetterReady_M)
... except that this version takes one line instead of two, probably runs a little faster, and is less prone to editing errors.

If there is no other condition that sets or resets ToolSetterReady_M, then you could just as well leave it out and reference ProbeArmMachineReady directly instead. The only reason to copy an input to a memory bit is so that M function macros and the cncxmsg.txt file can refer to a memory bit address (#70xxx / MEMxxx) which does not change even if the sensor gets moved to a different PLC input.

Regarding error reporting: fault conditions are not the same as error conditions.
See http://www.cncsnw.com/PLCApplicationsMPU11.htm

Code: Select all

IF SV_PROGRAM_RUNNING && !ToolSetterReady_M && !SV_DOING_AUTO_TOOL_MEASURE
THEN ErrorMsg_W = TOOLSETTER_NOT_READY_MSG,
SET ErrorFlag_M,
SET SV_STOP
Since you apparently intend this to be an error condition (one that stops the program cycle but does not remove power from the servos), you should not set SV_STOP.

If you wanted it to be a fault, you would assign the message code to FaultMsg_W instead of ErrorMsg_W, and you would not set ErrorFlag_M. Also, it would be better to set "OtherFault_M" rather than setting SV_STOP directly, so that the fault-detect and fault-reset code in MainStage can work properly.
Thanks for the information on the difference between errors and faults. I did indeed want to keep the machine from running a program if the arm is down and it is not specifically doing a tool measurement just to prevent being able to crash into the tool arm. So I set it up as a fault and set the OtherFault_M rather than the SV_Stop as you suggested. I also got rid of ToolSetterReady_M.

I am curious why it is better to set OtherFault_M rather than set SV_Stop directly? I also removed the ToolSetterReady_M. It does seem to work as intended, but is there anything in the rest of it that would be better done differently?

Thanks Gary

;---------------------------------------------------------------------
; NEW: Tool Setter Arm Control ("Push and Hold" operation)
;---------------------------------------------------------------------

; Prevent G-code program from running if ToolSetterMachineReadyInput is not active
IF SV_PROGRAM_RUNNING && !ToolSetterMachineReadyInput && !SV_DOING_AUTO_TOOL_MEASURE
THEN FaultMsg_W = TOOLSETTER_NOT_READY_MSG,
SET OtherFault_M

; Control ToolSetterArmDown (OUT19) with Aux3Key_M (push and hold)
; At the start of every check ensure ToolSetterArmDown is deactivated and reset.
IF TRUE THEN RST ToolSetterArmDown
IF TRUE THEN RST ToolSetterArmDownActive_M
IF TRUE THEN RST Aux3LED

; Make sure up and down can't be active at the same time.
IF Aux3Key_M && !ToolSetterArmUpActive_M
THEN SET ToolSetterArmDown, SET ToolSetterArmDownActive_M, SET Aux3LED

; Control ToolSetterArmUp (OUT20) with Aux4Key_M (push and hold)
; At the start of every check ensure ToolSetterArmUp is deactivated and reset.
IF TRUE THEN RST ToolSetterArmUp
IF TRUE THEN RST ToolSetterArmUpActive_M
IF TRUE THEN RST Aux4LED

; Make sure up and down can't be active at the same time.
IF Aux4Key_M && !ToolSetterArmDownActive_M
THEN SET ToolSetterArmUp, SET ToolSetterArmUpActive_M, SET Aux4LED

; If E-Stop is active then the tool arm won't move.
; Override any SET commands above if SV_STOP is active.
IF SV_STOP
THEN RST ToolSetterArmDown, RST ToolSetterArmUp,
RST ToolSetterArmDownActive_M, RST ToolSetterArmUpActive_M

;---------------------------------------------------------------------
; END NEW: Tool Setter Arm Control and G-code Program Interlock
;---------------------------------------------------------------------


Post Reply