Debug() float conversion?
Up to Development Discussion
I'm trying to write some floating-point values, but calling Debug like this:
Debug( 0, "angle %f", 1.234);
Seems to crash things. Is this known to work?
This may or may not be related, but you're not the first to have trouble with %f. However, it usually puts out garbage chars, not crashes everything. Unfortunately, my work around has been erased from the forum! So here you go. It could be written shorter but you get the idea.
char[21] strTemp;
snprintf(strTemp, 20, "%d.%02d", FloatRound(myfloat), FloatRemainder(myfloat));
int FloatRound(float VarValue)
{
int varRound = (int)VarValue;
return varRound;
}
int FloatRemainder(float VarValue)
{
int varRound = (int)VarValue;
int mask = varRound * 100; //shift two places with zeros in tens place
float ftemp = VarValue * 100; //move decimal over because floats won't print
int shifted = (int)ftemp;
int remainder = shifted - mask;
return remainder;
}
Has anyone run across the real fix to this problem??
I'm using (what I thought was the latest) GNUARM under windows.
I know how to work around it but would be nice to be able to fix it.
Thanks very much,
Newbie Rob
Sure Rob, I can point you in the right direction of the real fix. It seems stdio in the GNU Toolchain has been compiled without floating point support. Common because many embedded systems don't support floating point. It would need to be compiled with FLOATING_POINT defined. jfaller seems to know a lot about it. As he points out the article is no longer entirely accurate.
http://www.embedded.com/story/OEG20011220S0058
http://www.makingthings.com/forum/discussion/view_topic?topic_id=108
eDub
I am having this issue where I get garbage out from the float. Even when converting to a char array:
/debug/message È.V from USB (COM3)
Any help would be appreciated.
I also get this through the USB Write command.
I am using the correct format for this too.. sprintf(cpos1, "%f", test1); //convert pos value to character array
Any idea how to print floats??
Powered by
Ploneboard

