Society of Robots - Robot Forum
Software => Software => Topic started by: Admin on August 31, 2009, 07:50:24 AM
-
I'm trying to get the timer to work properly with WebbotLib and having a few probs.
First, this code:
TICK_COUNT start = clockGetus();
do_something();
for(i=0;i<10;i++)
{
do_stuff();
TICK_COUNT end = clockGetus();
TICK_COUNT duration = end - start;
rprintf("%d",duration);
TICK_COUNT start = clockGetus();//restart clock
}
gives me this warning:
../code.h:287: warning: unused variable 'start'
Line 287 is referring to the 'start' in the for loop. The position of it doesn't seem to matter.
Next, I think a clockGetms(); function could be useful (for ms, not us).
Also, what is the best way to print out the timer? I tried this:
rprintf("%d",duration);
But it only prints the timer as a signed long int - meaning it is giving me values from +/-32768 (and overflowing way too fast for what I'm measuring).
Then I tried this:
rprintfu16(duration);
But it just gives me strange values like 'B5C0'.
I also tried:
rprintf("%ld",duration);
but it just does:
ldldldldldldldldld
-
I fixed the warning.
This:
TICK_COUNT start = clockGetus();//restart clock
should be:
start = clockGetus();//restart clock
-
Also, what is the best way to print out the timer? I tried this:
rprintf("%d",duration);
But it only prints the timer as a signed long int - meaning it is giving me values from +/-32768 (and overflowing way too fast for what I'm measuring).
The TICK_COUNT data type is an 'uint_32' so you cant print it out with %d - see later
Then I tried this:
rprintfu16(duration);
But it just gives me strange values like 'B5C0'.
That prints out a 16 bit number in hexadecimal. But since its a 32 bit number you should use rprintfu32 instead - but that will still output hexadecimal
I also tried:
rprintf("%ld",duration);
but it just does:
ldldldldldldldldld
To turn on this extended syntax for rprintf you need to put:
#define RPRINTF_COMPLEX
At the top of your program - before your #includes
This links in a larger rprintf library
The other alternative is to use the rprintfNum function described in the manual
-
thanks!
To turn on this extended syntax for rprintf you need to put:
Code:
#define RPRINTF_COMPLEX
At the top of your program - before your #includes
Your manual says:
If you have declared PRINTF_COMPLEX then it will include some additional code which
allows: %d, %u, %o, %x, %c and %s as well as the width, precision and padding modifiers
Did you mean to say %ld? (typo?)
-
The manual is correct, but incomplete, I need to '%ld' to the list as well - thanks.
Done in 1.5 release