attempt to divide by zero

More
04 Feb 2019 14:33 #125659 by jefsaro
Hello ,
  here is my problem, i made a divider with linux cnc to make slot grooves, i do not know how is called the machine in english, when i want to put the number of grooves in the interface pyvcp, it's good but i have an alarm, division by zero when i load the program, can you help me?
thank you
Attachments:

Please Log in or Create an account to join the conversation.

More
04 Feb 2019 19:47 #125677 by Todd Zuercher
If you are dividing by the value of your M66 input, you need to make sure it isn't = 0.
Do you have something connected to the hal pin "motion.analog-in-00" connected to anything or set to some value? If not it will = 0.

Adding a debug statement to your code like this will print and tell you what the value is of that when it is running.
(o<MortaiseuseDiviseur> sub)
g54g17g90
g0z0
g0y0
g0 a-10
g0 a0


M66 E0 L0
(debug,Value of M66 E0 L0 = #5399)

#2 = #5399 (_nb_division)
#3 = [360/#2] (angle 360/ nbre de rainure)
M66 E1 L0
#4 = #5399 (_Prof)
#6 = [#4/0.05] (calcul du  nbre passe)
M66 E2 L0 (longueur)
#7 = #5399
M66 E3 L0 (retour)
#8 = #5399

o100repeat[#1]
o101 repeat[#6]   (nbre de passe)
g91 g1 y0.05 f200 (profondeur de passe constante de 0.1mm)
g90 g1 z-[#7]f25000
g91y-.7
g90 g0 z0
g91g0y.7
o101 endrepeat
g0g90y0
(m0)
g0y[-#8]
g0g91a[#3]
o100endrepeat
g0z0
g0y0
g0a0
g0g90a-10
g0a0
g0 y-150
(o<MortaiseuseDiviseur> endsub)
m2

If you are giving a value to that hal pin but there is a chance that the value given could be zero, then you are going to have to add a test to your G-code that will test for such a situation and then take appropriate action if the value is =0.

Please Log in or Create an account to join the conversation.

More
05 Feb 2019 05:24 #125718 by jefsaro
Replied by jefsaro on topic attempt to divide by zero
207/5000
Hello ,
thank you for your quick answer, in halmetre, I have good motion analog 00 which changes the parameter, I put the picture, I do not understand because the other parameters functionnes.
Thanks for your help.

Please Log in or Create an account to join the conversation.

More
05 Feb 2019 05:41 #125719 by jefsaro
Replied by jefsaro on topic attempt to divide by zero
Hello ,
thank you for your quick answer, in halmetre, I have good motion analog 00 which changes the parameter, I put the picture, I do not understand because the other parameters functionnes.
I have tried your program, I have the same problem.
Thanks for your help
Attachments:

Please Log in or Create an account to join the conversation.

More
05 Feb 2019 14:09 #125730 by pl7i92
Replied by pl7i92 on topic attempt to divide by zero
you can check the Value with IF LT or LE 0
this will give you more options

Please Log in or Create an account to join the conversation.

More
05 Feb 2019 14:15 #125731 by Todd Zuercher
I'm not sure what the problem is, but I can duplicate it in a simulation.

It is looking rather like a bug.
If you acknowledge the error (click ok), and then try to run the file, I think it will still run correctly.

A possible work around might be to change your g-code to simply multiply the value of #2, then in your Glade input box for the number of divisions simply enter 1/6 instead of 6. (I believe that those input boxes can handle that.) I don't know for sure if that will work, and I didn't feel like building a Glade panel just to test it.

Please Log in or Create an account to join the conversation.

More
05 Feb 2019 14:34 #125735 by jefsaro
Replied by jefsaro on topic attempt to divide by zero
hello ,
I attach the program files.
regards
jf
Attachments:

Please Log in or Create an account to join the conversation.

More
05 Feb 2019 20:37 #125761 by rodw
Replied by rodw on topic attempt to divide by zero
It does not matter which programming language you use, divide by zero is an error that generally generates a runtime error and program halt so never do it. if its going to happen, you are far better off putting a conditional around it. eg in psuedo code
if y <> 0
  a = x/y
else
  y = some error value

if you set Y on error to be some unexpected value, (-1 or 9999), you can test you got a valid result. eg.
 if y = 9999
   do some error routine

Please Log in or Create an account to join the conversation.

More
05 Feb 2019 21:17 #125764 by Todd Zuercher
The problem is not that he is trying to divide by zero.
The problem is that there is a bug in Linuxcnc that is seeing motion.analog-in-nn's
parameter (#5399) as zero when Linuxcnc is reading the file, even though that parameter is not = 0 when the g-code program is ran. I tried it even with the pin setp-ed to some value and it still gives the error.

Please Log in or Create an account to join the conversation.

More
05 Feb 2019 22:09 #125770 by rodw
Replied by rodw on topic attempt to divide by zero
Bugs aside, this is a classic example why experienced programmers program defensively and include error checking for errors that should never happen. I'm sure the Linuxcnc code base is littered with examples of a defence approach.

Perhaps another workaround would be to not use the motion.analog.nn pins and instead directly reference the GUI pin by its corresponding Gcode variable. These variables are only set once at the start of the gcode program but that is probably not a limitation for this particular application as my guess is the number of divisions never changes after the gcode program is commenced.

Please Log in or Create an account to join the conversation.

Time to create page: 0.094 seconds
Powered by Kunena Forum