Arduino Uno giving weird feedback

Greetings, I have weird problems with my serial monitor result, I am developing a hexapod robot with embedded kinematics calculation in it

at first, I only embed inverse kinematics in it, there are no problems at all

here is the output from the working program's serial monitor :

if I input the data needed the result will comes out

but after I upgrade my program by adding differential kinematics calculation, it gives weird output

here is the output from the problem program's serial monitor :

if I input the data needed it takes me back to the setup again

I am using an arduino Uno

the difference between the program is the problem program have differential kinematics, therefore there are more variables and numbers in the loop, but I don't change the setup at all

the working program's Binary sketch size: 19356 bytes (of a 32256 byte maximum)
the problem program's Binary sketch size: 26740 bytes (of a 32256 byte maximum)

I put the programs in the attachments

I'm having my thesis defense in two days, so if anyone can help me it will be very very great

thanks,
Heggi

working program.txt (25 KB)

problem program.txt (34.7 KB)

if I input the data needed it takes me back to the setup again

I am using an arduino Uno

You are running out of memory, causing the processor to reset.

I'm having my thesis defense in two days, so if anyone can help me it will be very very great

No, sorry, my way-back machine is not working at the moment. Waiting for parts.

but after I upgrade my program by adding differential kinematics calculation, it gives weird output

I wonder why?

double t2LF, t2aLF, t2bLF, ct2LF, ct2aLF, ct2bLF, st2aLF, st2bLF, st2LF;
double l1LF, l2LF, l3LF, pxLF, pyLF, pzLF, r11LF, r21LF, k1LF, k2LF, k3LF, k4LF;
double t1LF, tt1LF, t1aLF, t1bLF, st1aLF, st1bLF, ct1aLF, ct1bLF, t3LF;
double ceilt1LF, ceilt2LF, ceilt3LF;
double pos1LF, pos2LF, pos3LF; 
double sp1LF, sp2LF, sp3LF, sp1LF2, sp2LF2, sp3LF2, spaLF, spbLF, spcLF, spdLF, speLF;
double t2LM, t2aLM, t2bLM, ct2LM, ct2aLM, ct2bLM, st2aLM, st2bLM, st2LM;
double l1LM, l2LM, l3LM, pxLM, pyLM, pzLM, r11LM, r21LM, k1LM, k2LM, k3LM, k4LM;
double t1LM, tt1LM, t1aLM, t1bLM, st1aLM, st1bLM, ct1aLM, ct1bLM, t3LM;
double ceilt1LM, ceilt2LM, ceilt3LM;
double pos1LM, pos2LM, pos3LM; 
double sp1LM, sp2LM, sp3LM, sp1LM2, sp2LM2, sp3LM2, spaLM, spbLM, spcLM, spdLM, speLM;
double t2LB, t2aLB, t2bLB, ct2LB, ct2aLB, ct2bLB, st2aLB, st2bLB, st2LB;
double l1LB, l2LB, l3LB, pxLB, pyLB, pzLB, r11LB, r21LB, k1LB, k2LB, k3LB, k4LB;
double t1LB, tt1LB, t1aLB, t1bLB, st1aLB, st1bLB, ct1aLB, ct1bLB, t3LB;
double ceilt1LB, ceilt2LB, ceilt3LB;
double pos1LB, pos2LB, pos3LB; 
double sp1LB, sp2LB, sp3LB, sp1LB2, sp2LB2, sp3LB2, spaLB, spbLB, spcLB, spdLB, speLB;
double t2RF, t2aRF, t2bRF, ct2RF, ct2aRF, ct2bRF, st2aRF, st2bRF, st2RF;
double l1RF, l2RF, l3RF, pxRF, pyRF, pzRF, r11RF, r21RF, k1RF, k2RF, k3RF, k4RF;
double t1RF, tt1RF, t1aRF, t1bRF, st1aRF, st1bRF, ct1aRF, ct1bRF, t3RF;
double ceilt1RF, ceilt2RF, ceilt3RF;
double pos1RF, pos2RF, pos3RF; 
double sp1RF, sp2RF, sp3RF, sp1RF2, sp2RF2, sp3RF2, spaRF, spbRF, spcRF, spdRF, speRF;
double t2RM, t2aRM, t2bRM, ct2RM, ct2aRM, ct2bRM, st2aRM, st2bRM, st2RM;
double l1RM, l2RM, l3RM, pxRM, pyRM, pzRM, r11RM, r21RM, k1RM, k2RM, k3RM, k4RM;
double t1RM, tt1RM, t1aRM, t1bRM, st1aRM, st1bRM, ct1aRM, ct1bRM, t3RM;
double ceilt1RM, ceilt2RM, ceilt3RM;
double pos1RM, pos2RM, pos3RM; 
double sp1RM, sp2RM, sp3RM, sp1RM2, sp2RM2, sp3RM2, spaRM, spbRM, spcRM, spdRM, speRM;
double t2RB, t2aRB, t2bRB, ct2RB, ct2aRB, ct2bRB, st2aRB, st2bRB, st2RB;
double l1RB, l2RB, l3RB, pxRB, pyRB, pzRB, r11RB, r21RB, k1RB, k2RB, k3RB, k4RB;
double t1RB, tt1RB, t1aRB, t1bRB, st1aRB, st1bRB, ct1aRB, ct1bRB, t3RB;
double ceilt1RB, ceilt2RB, ceilt3RB;
double pos1RB, pos2RB, pos3RB; 
double sp1RB, sp2RB, sp3RB, sp1RB2, sp2RB2, sp3RB2, spaRB, spbRB, spcRB, spdRB, speRB;

Now, I didn't count all of them, but, at 4 bytes apiece, that doesn't look like a reasonable number of variables to be trying to allocate in the 2 KB of SRAM that you have, when all the strings in the Serial.print() statements are also using that same 2 KB of SRAM.

For interest*, there are 282 doubles, at 4 bytes each, giving 1,128 bytes.

There are 1,806 characters in the Serial.prints. Total of 2,934 bytes, not including other variables.

If you are using IDE 1.0, consider the new F() thing for your Serial.printing.

* Yes, I find strange things like that interesting.

Ok I didn't read the code, but two words come to mind after reading that many doubles:

  • arrays
  • functions

Ok I didn't read the code, but two words come to mind after reading that many doubles:

An array of 282 doubles takes just as much space as 282 doubles. So, arrays won't help.

Organizing the code into functions makes it more readable, but generally does not reduce size or increase speed. So, functions won't help.

Don't get me wrong. Neither would hurt. But, they wouldn't help.

PaulS:

Ok I didn't read the code, but two words come to mind after reading that many doubles:

An array of 282 doubles takes just as much space as 282 doubles. So, arrays won't help.

Organizing the code into functions makes it more readable, but generally does not reduce size or increase speed. So, functions won't help.

Don't get me wrong. Neither would hurt. But, they wouldn't help.

You are totally right.

My reasoning was that (re)organizing all those variables into arrays and encapsulating pieces of code into functions might be helpful in identifying temp variables, de-duplicating code, etc. After all, if you run out of space you have (as always) two options: brute force, i.e. a bigger uP, or more clever ways of using your resources.
All this in abstract terms, since I haven't (still) read the code. It's entirely possible that the program just needs more space :slight_smile:

No, sorry, my way-back machine is not working at the moment. Waiting for parts.

LOL :slight_smile:

thanks a lot guys !
after doing some rearrangements and delete some redundant calculation, it works....

No, sorry, my way-back machine is not working at the moment. Waiting for parts.

you should tell me when it works, lol