Editing gcode subroutine in gmoccappy locks up program
- george4657
- Offline
- New Member
- 
				  
		Less
		More
		
			
	
		- Posts: 9
- Thank you received: 0
			
	
						21 Oct 2016 16:32				#81919
		by george4657
	
	
		
			
	
			
			 		
													
	
				Editing gcode subroutine in gmoccappy locks up program was created by george4657			
			
				I am trying to learn how to use  o g-codes to generate subroutines.
Using linuxcnc 2.8.0 gmoccapy 2.1.0
I am an experienced C programmer trying to learn the syntax for g-code.
When testing while loops I make errors that causes an infinite loop and when I save file I think the program tests for errors and gets in the loop and never comes out.
I then have to crash out of linuxcnc and restart it. I then have to zero xy an z axis before I can try edit again.
My X and Y home are fast but my Z is slow as it has a fine thread drive and an offset for zero.
I there anyway to crash out of the editor without closing cnc program.
Thanks
George
					Using linuxcnc 2.8.0 gmoccapy 2.1.0
I am an experienced C programmer trying to learn the syntax for g-code.
When testing while loops I make errors that causes an infinite loop and when I save file I think the program tests for errors and gets in the loop and never comes out.
I then have to crash out of linuxcnc and restart it. I then have to zero xy an z axis before I can try edit again.
My X and Y home are fast but my Z is slow as it has a fine thread drive and an offset for zero.
I there anyway to crash out of the editor without closing cnc program.
Thanks
George
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- 
				  
- Offline
- Platinum Member
- 
				  
		Less
		More
		
			
	
		- Posts: 4686
- Thank you received: 1433
			
	
						21 Oct 2016 17:07				#81922
		by Todd Zuercher
	
	
		
			
	
			
			 		
													
	
				Replied by Todd Zuercher on topic Editing gcode subroutine in gmoccappy locks up program			
			
				Try it with a different ui like axis which uses a separate text editor and see what happens.			
					Please Log in or Create an account to join the conversation.
- george4657
- Offline
- New Member
- 
				  
		Less
		More
		
			
	
		- Posts: 9
- Thank you received: 0
			
	
						21 Oct 2016 18:04				#81924
		by george4657
	
	
		
			
	
			
			 		
													
	
				Replied by george4657 on topic Editing gcode subroutine in gmoccappy locks up program			
			
				I set up a new format with axis.
First problem I loaded my test program and it loaded.
I clicked file->edit and bottom of screen filled up with program but I could not edit it. Do I have to setup editor in ini file.
Second problem I loaded a test file I know did not work in gmoccapy and it locked up the axis program also.
This in fact locked up the whole computer so I had to use power button to reboot computer.
I can't see how to add an attachment so i will paste file.
o100 while [#3 LT .1]
; 1 = center X
; 2 = center Y
; 3 = radius
#3 = [#3-1]
M5
g01 x[#1-#3] y[#2] f200
M3
g02 x[#1 +#3] y[#2] i[#3] j[0]
g02 x[#1-#3] y[#2] i[-#3] j[0]
#3 = [#3-1]
m5
o100 endwhile
g21
g90
g01 x0y0 f200
o100 call [0][10][10]
o100 call [0][20][9]
o100 call [10][10][8]
o100 call [10][20][7]
m2.
					First problem I loaded my test program and it loaded.
I clicked file->edit and bottom of screen filled up with program but I could not edit it. Do I have to setup editor in ini file.
Second problem I loaded a test file I know did not work in gmoccapy and it locked up the axis program also.
This in fact locked up the whole computer so I had to use power button to reboot computer.
I can't see how to add an attachment so i will paste file.
o100 while [#3 LT .1]
; 1 = center X
; 2 = center Y
; 3 = radius
#3 = [#3-1]
M5
g01 x[#1-#3] y[#2] f200
M3
g02 x[#1 +#3] y[#2] i[#3] j[0]
g02 x[#1-#3] y[#2] i[-#3] j[0]
#3 = [#3-1]
m5
o100 endwhile
g21
g90
g01 x0y0 f200
o100 call [0][10][10]
o100 call [0][20][9]
o100 call [10][10][8]
o100 call [10][20][7]
m2.
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- 
				  
- Offline
- Platinum Member
- 
				  
		Less
		More
		
			
	
		- Posts: 4686
- Thank you received: 1433
			
	
						21 Oct 2016 18:31		 -  21 Oct 2016 18:44		#81925
		by Todd Zuercher
	
	
		
			
	
	
			 		
													
	
				Replied by Todd Zuercher on topic Editing gcode subroutine in gmoccappy locks up program			
			
				I think axis is still set up to use gedit as the default editor.  You'll either have to install gedit or edit your ini to choose a different editor.
Now to look at your code. To start with, I don't think you can call your while loop code as a sub program, I think you may need to set up a sub program to contain your while loop, then call that.
Next I'm not sure what this is supposed to doAre they comments? if so they should be in () as far as I know G-code doesn't use : for anything.
G-code is much simpler than C. The while/endwhile loop, just first performs the test and if true executes the g-code within and repeats.
So as I see it I think you are aiming more for something like this			
					Now to look at your code. To start with, I don't think you can call your while loop code as a sub program, I think you may need to set up a sub program to contain your while loop, then call that.
Next I'm not sure what this is supposed to do
; 1 = center X
; 2 = center Y
; 3 = radiusG-code is much simpler than C. The while/endwhile loop, just first performs the test and if true executes the g-code within and repeats.
So as I see it I think you are aiming more for something like this
o200 sub
o100 while [#3 GT .1] 
(#1 = center X)
(#2 = center Y)
(#3 = radius)
g01 x[#1-#3] y[#2] f200
M3
g02 x[#1 +#3] y[#2] i[#3] j[0]
g02 x[#1-#3] y[#2] i[-#3] j[0]
#3 = [#3-1]
m5
o100 endwhile
M5
g01 x[#1-#3] y[#2] f200
o200 endsub
g21
g90
g01 x0y0 f200
o200 call [0][10][10]
o200 call [0][20][9]
o200 call [10][10][8]
o200 call [10][20][7]
m2. 
		Last edit: 21 Oct 2016 18:44  by Todd Zuercher.			
			Please Log in or Create an account to join the conversation.
- george4657
- Offline
- New Member
- 
				  
		Less
		More
		
			
	
		- Posts: 9
- Thank you received: 0
			
	
						21 Oct 2016 20:12				#81927
		by george4657
	
	
		
			
	
			
			 		
													
	
				Replied by george4657 on topic Editing gcode subroutine in gmoccappy locks up program			
			
				From doc's ; ok
" Comments can be embedded in a line using parentheses () or for the remainder of a line using a semi-colon"
Doc's for while loop do not show it embedded in an other routine but this explains error "no file <o100> found" when calling while loop o100
Tested below code
-- crash from infinite loop ----
o200 sub
o100 while [#3 GT .1]
G01 x 40
o100 endwhile (would never be below .1 if all with value > .1)
o200 call[10]
---- same code loop fails test so no infinite loop so no crash ----
o200 sub
o100 while [#3 LT .1] (have to remember LT is Less than not Larger than)
G01 x 40
o100 endwhile (would never run as first loop < .1 so no error)
o200 call[10]
It is good that editor catches this error as you would not want an infinite loop to run on your cnc machine but I wish there was a way to exit editor or have editor time out.
Is there a simulator program I can use for code visualization rather than use actual linuxcnc?
					" Comments can be embedded in a line using parentheses () or for the remainder of a line using a semi-colon"
Doc's for while loop do not show it embedded in an other routine but this explains error "no file <o100> found" when calling while loop o100
Tested below code
-- crash from infinite loop ----
o200 sub
o100 while [#3 GT .1]
G01 x 40
o100 endwhile (would never be below .1 if all with value > .1)
o200 call[10]
---- same code loop fails test so no infinite loop so no crash ----
o200 sub
o100 while [#3 LT .1] (have to remember LT is Less than not Larger than)
G01 x 40
o100 endwhile (would never run as first loop < .1 so no error)
o200 call[10]
It is good that editor catches this error as you would not want an infinite loop to run on your cnc machine but I wish there was a way to exit editor or have editor time out.
Is there a simulator program I can use for code visualization rather than use actual linuxcnc?
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- 
				  
- Offline
- Platinum Member
- 
				  
		Less
		More
		
			
	
		- Posts: 4686
- Thank you received: 1433
			
	
						21 Oct 2016 20:34		 -  21 Oct 2016 20:38		#81928
		by Todd Zuercher
	
	
		
			
	
	
			 		
													
	
				Replied by Todd Zuercher on topic Editing gcode subroutine in gmoccappy locks up program			
			
				Huh, learn something new every day. (regarding using colon for comments)
That is because the docs are showing using a while loop, not using a while loop as a subroutine.
Most of the G-code simulators/backplots I've played with usually barf on most subprograms, loops, or parametric programing. partly because most every control manufacturer/G-code dialect handles that stuff a little different.
I think this one camotics.org/ is derived at least partially from Linuxcnc code and does a better job than most with parametric programming.
					That is because the docs are showing using a while loop, not using a while loop as a subroutine.
Most of the G-code simulators/backplots I've played with usually barf on most subprograms, loops, or parametric programing. partly because most every control manufacturer/G-code dialect handles that stuff a little different.
I think this one camotics.org/ is derived at least partially from Linuxcnc code and does a better job than most with parametric programming.
		Last edit: 21 Oct 2016 20:38  by Todd Zuercher.			
			Please Log in or Create an account to join the conversation.
- george4657
- Offline
- New Member
- 
				  
		Less
		More
		
			
	
		- Posts: 9
- Thank you received: 0
			
	
						21 Oct 2016 23:54				#81930
		by george4657
	
	
		
			
	
			
			 		
													
	
				Replied by george4657 on topic Editing gcode subroutine in gmoccappy locks up program			
			
				Its a semi-colon not a colon for comments.
Downloaded camotics and it worked good so thanks for that info.
It even works in windows which is where I do my development work as I only have linux on my shop cnc machines.
Thanks
George
					Downloaded camotics and it worked good so thanks for that info.
It even works in windows which is where I do my development work as I only have linux on my shop cnc machines.
Thanks
George
Please Log in or Create an account to join the conversation.
- newbynobi
- 
				  
- Offline
- Moderator
- 
				  
		Less
		More
		
			
	
		- Posts: 1928
- Thank you received: 393
			
	
						22 Oct 2016 10:07				#81934
		by newbynobi
	
	
		
			
	
			
			 		
													
	
				Replied by newbynobi on topic Editing gcode subroutine in gmoccappy locks up program			
			
				Hallo,
sorry you had problems with gmoccapy. Unfortunately the editor is incorporated in gmoccapy, I do not see a way to check if the code will run or not, as "my" editor only passes the code to the interpreter and that one will hang in the infinite loop. I you know C++, you might be able to add such a very recommended feature into that component.
Norbert
					sorry you had problems with gmoccapy. Unfortunately the editor is incorporated in gmoccapy, I do not see a way to check if the code will run or not, as "my" editor only passes the code to the interpreter and that one will hang in the infinite loop. I you know C++, you might be able to add such a very recommended feature into that component.
Norbert
Please Log in or Create an account to join the conversation.
- andypugh
- 
				  
- Offline
- Moderator
- 
				  
		Less
		More
		
			
	
		- Posts: 19677
- Thank you received: 4554
			
	
						24 Oct 2016 15:49				#81989
		by andypugh
	
	
		
			
				
Try "ESC"
Also, your code samples have no O200 ENDSUB to terminate the subroutine.
I think that O200 might even be calling itself recursively in your examples.
O200 CALL [10] will pass 10 in #1. Your loops are using #3, which will (probably) remain as zero throughout.
					
	
			
			 		
													
	
				Replied by andypugh on topic Editing gcode subroutine in gmoccappy locks up program			
			I there anyway to crash out of the editor without closing cnc program.
Try "ESC"
Also, your code samples have no O200 ENDSUB to terminate the subroutine.
I think that O200 might even be calling itself recursively in your examples.
O200 CALL [10] will pass 10 in #1. Your loops are using #3, which will (probably) remain as zero throughout.
Please Log in or Create an account to join the conversation.
- george4657
- Offline
- New Member
- 
				  
		Less
		More
		
			
	
		- Posts: 9
- Thank you received: 0
			
	
						25 Oct 2016 18:11				#82049
		by george4657
	
	
		
			
	
			
			 		
													
	
				Replied by george4657 on topic Editing gcode subroutine in gmoccappy locks up program			
			
				I tried esc as well as other keys with no success.
Sub problems as shown are from cut and paste of example. Could not figure how to attach actual file.
I no longer have a problem because I now know that LT is "Lesser than" not "Larger than" and while loops can not be called by themselves but must be called within a sub
I now develop using program camotics as recommended by Todd.
This program has a simulation mode and runs in windows a well a linux and does not lock up with endless loop.
					Sub problems as shown are from cut and paste of example. Could not figure how to attach actual file.
I no longer have a problem because I now know that LT is "Lesser than" not "Larger than" and while loops can not be called by themselves but must be called within a sub
I now develop using program camotics as recommended by Todd.
This program has a simulation mode and runs in windows a well a linux and does not lock up with endless loop.
Please Log in or Create an account to join the conversation.
		Moderators: newbynobi, HansU	
		Time to create page: 0.080 seconds	
