Reading value of pin in g code

More
9 years 7 months ago #89991 by Radek
Hi, I want to make if loop and don't know how to write it properly. The task is: if state of coil1 (in classicladder) is 1 then make something. Coil1 is assigned to pin P01.

I tried with:
Code:
o100 if [M66 P01 L3 Q999999] ... o100 endif
or simple
Code:
o100 if [P01 = 1](funny creating ;) )

I got this error:

Unknown word where unary operation could be

Please Log in to join the conversation.

More
9 years 7 months ago #90122 by andypugh
There are a number of issues here.

Firstly, to check for equality in G-code you have to use "EQ"

O100 IF [#124 EQ 100]
Do Stuff
O100 ENDIF

linuxcnc.org/docs/2.7/html/gcode/overvie...ode:binary-operators

It is possible to read HAL pins in G-code, but the feature needs to be turned-on.
linuxcnc.org/docs/2.7/html/remap/remap.h...i_file_configuration

I wouldn't recommend doing that in this case, though. The problem is that the values are read at preview-time, not at run-time. This could cause unexpected results.

Much better to "net" the classicladder pin to one of the G-code digital input pins and use M66 to read it.
linuxcnc.org/docs/2.7/html/gcode/m-code.html#mcode:m66

Please Log in to join the conversation.

More
9 years 7 months ago #90173 by Radek
I knew this comands, but i can't use it properly. While loop is working well.
My unfortunately bad ideas ....
Code:
o100 if [M66 P1 L3 Q99999999]
Code:
#1 = M66 P1 L3 Q99999999 o100 if [#1 EQ 1]

also try with GOTO.. here is one of my bad codes..
Code:
M66 P01 L3 Q99999999 N100 GOTO 110 M66 P02 L3 Q99999999 N120 GOTO 130 M66 P03 L3 Q99999999 N140 GOTO 150
and there is an error:

bad character n used

Please Log in to join the conversation.

More
9 years 7 months ago #90177 by andypugh

Radek wrote: I knew this comands, but i can't use it properly.


The key is the phrase "The current value of the input is stored in parameter #5399"
Code:
M66 P1 L0 o100 if [#5399 EQ 1]

Though normally you don't need to check the value as you use it in a "wait for state" mode and just need to check for timeout.

Please Log in to join the conversation.

More
9 years 7 months ago #90179 by Radek
Ok, but now i want to back to 1st line of programme. What command should i use? GOTO ?

Ok... shit happens.. it's not working
Code:
M66 P11 L0 o100 if [#5399 EQ 1] Do stuff o100 endif M66 P12 L0 o110 if [#5399 EQ 1] Do stuff o110 endif M66 P13 L0 o120 if [#5399 EQ 1] Do stuff o120 endif

Please Log in to join the conversation.

More
9 years 7 months ago #90201 by andypugh

Radek wrote: Ok, but now i want to back to 1st line of programme. What command should i use? GOTO ?


Do you want it to run for ever?
Code:
O500 WHILE [1 EQ 1] Do Stuff O500 ENDWHILE

There is no GOTO in G-code:
linuxcnc.org/docs/2.7/html/gcode/o-code.html

Please Log in to join the conversation.

More
9 years 7 months ago #90204 by Radek
I got while loop, but i need also if but it doesn't work.. are there any mistakes in my code ?

Please Log in to join the conversation.

More
9 years 7 months ago #90206 by andypugh

Radek wrote: I got while loop, but i need also if but it doesn't work.. are there any mistakes in my code ?


Well, the command "Do Stuff" if it is literally in the code won't help.

By default there are only 4 digital input pins, so your P11, P12, P13 are likely to cause trouble.

Please Log in to join the conversation.

More
9 years 7 months ago #90209 by Radek

andypugh wrote:

Radek wrote: I got while loop, but i need also if but it doesn't work.. are there any mistakes in my code ?


Well, the command "Do Stuff" if it is literally in the code won't help.

By default there are only 4 digital input pins, so your P11, P12, P13 are likely to cause trouble.


this is my code... While is working properly, but if not. Why? I want also to back to the 1st line of programme after endif.

Attachment not found

Please Log in to join the conversation.

More
9 years 7 months ago #90210 by andypugh
What error message do you get?

Please Log in to join the conversation.

Time to create page: 0.096 seconds
Powered by Kunena Forum