Go Down

Topic: Simple assignment operator not working! [SOLVED] (Read 2784 times) previous topic - next topic

Nick Gammon


However something very strange happens when i take the //comment from the line '//heading = heading + temp4'. 'heading' seems to become a null variable or something, and the 'if' comparisons that check the heading against the RC angle stop working entirely.


Yeah, it's like it's Not A Number any more. <grin>
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

AWOL

I can't believe it's Not A Number tm    :smiley-yell:
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Coding Badly


Xenophage

SOLVED!!! Step by step I backed through my math, setting variables as simple numbers, until I came across the TRUE trouble code. 'enctickL' becomes 0 when the robot isn't moving, and i was doing 1/0 which becomes NaN! I didn't think anything of it at first because it was reporting regular numbers. This was then filtering down through the math and eventually showing itself at 'heading = heading + angleinc'. I added two if statements to change them from 0 to 999999 to my main code and it worked! Thank you guys so much for the help! I'm feeling much better about bringing my robot in to class today!

Code: [Select]

enctickL = pulseIn(encpinL, HIGH, 40000);
enctickR = pulseIn(encpinR, HIGH, 40000);

temp1 = 1.0 / (float)enctickL;//temp1 = ticks per millisecond
temp2 = 1.0 / (float)enctickR;



mromani

If you feel the problem is solved, please consider adding [SOLVED] to the topic title. :-)

Nick Gammon


It would be nice. And you could change it.


Now fixed in the next release:

http://code.google.com/p/arduino/issues/detail?id=946
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Coding Badly


No F?

Code: [Select]
  if (isnan (number))
    return print ( F( "nan" ) );

Nick Gammon

They may not want the overhead of the progmem library, if a sketch was not otherwise using it.

But you could always comment on the Google Code board.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

What about this, a few lines down:

Code: [Select]
// Print the decimal point, but only if there are digits beyond
  if (digits > 0) {
    n += print(".");


That could be:

Code: [Select]
// Print the decimal point, but only if there are digits beyond
  if (digits > 0) {
    n += print(F("."));


Or perhaps better:

Code: [Select]
// Print the decimal point, but only if there are digits beyond
  if (digits > 0) {
    n += print('.');
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Coding Badly

But you could always comment on the Google Code board.


Naw.  Seems like rather low hanging fruit (especially the print(".") in your post) and was curious.

Go Up