Program freezing (or getting stuck?)Possiby asked to calculate large numbers?

Hi Guys! Ive done buckets of trouble shooting on this, and i THINK i have identified where the problem is, but i cannt work out how to correct it. In short i am programming my CNC router (converting GCode into CNC movements)

I am working on circular interpolation. Because of the problems i have been having i have stripped back the code as far as i reasonably can. This sketch below parses out GCode instructions, interpolates 10 points between each GCode position and sends them to the Serial port in CSV format. This way i can quickly paste them into excel and live-update a scatter chart. I should be plotting a circle. Linerar interpolation works great, i am ending up with a (12 sided? Dodecagon?) circle.

circular interpolation is still causing me issues. I am using basic pythagarous to calculate the positions, and have put my calculations though a simple sketch that only does the pythagarous part and had the same result

If my reworking of the sketch on the link above is anything to go by, the problem is using pythagarous with large numbers.

If i run the sketch and leave the line as an INT, it runs through, but the math result is all wrong (repeatable on the super simple sketch)

if i make it a double, i get the correct result on the super simple sketch, but on the CNC sketch it freezes the program.

Why is the highlighted line freezing the sketch? Overflowing perhaps? How can i change the math to ensure the correct result (i think it would work if it was a double) without freezing the sketch up.

Hope this makes sense. Cheers. Olly. My sketch is attached, Line 339

     int Xside = (Xmove+readI); // length of XSide

              double Yside = sqrt (sq(h) - sq(Xside)); // <<<<<< Curves??

incidentally, h = 3000, XSide = approx 3000

plotpointsforexcel2.ino (15.5 KB)

incidentally, h = 3000, XSide = approx 3000

So, what is 3000 * 3000? Does that have a ghost of a chance of fitting in an int?

OllyR: This sketch below parses out GCode instructions, interpolates 10 points between each GCode position and sends them to the Serial port in CSV format.

To my mind it would make a lot more sense to parse the GCode on the PC and just send the numbers for the stepper motor movements to the Arduino.

...R

PaulS: So, what is 3000 * 3000? Does that have a ghost of a chance of fitting in an int?

  1. I realise that this is the reason i am not getting correct results. The question i have is that if i change it to a double, or a float or a long, the program stalls at the point it should spit out the answer. I do not know if there is something i am doing fundamentally wrong with regards to asking the arduino to perform the sums.

If i run the same calculation on a cut back sketch (where by it ONLY does the calculation) it produces the correct answer.

The question i have is that if i change it to a double, or a float or a long, the program stalls at the point it should spit out the answer.

That hardly looks like a question. It looks more like a problem statement. We can hardly be expected to help you when the code you posted uses the wrong types, and the code that uses the correct types is kept from us. We do NOT operate under the assumption that that is all that you changed or that you made all the necessary changes. We need to see that for ourselves, and we often need to actually run the code for ourselves.

If i run the same calculation on a cut back sketch (where by it ONLY does the calculation) it produces the correct answer.

Then, clearly the calculation is not the problem. So, why are you assuming that it is?

I'd hazard a guess, without seeing the code, that the real problem is elsewhere. I'd also hazard a guess that the real problem is that you are out of memory.

The code uses Strings. With a capital S.