Author Topic: timer problems with WebbotLib  (Read 968 times)

0 Members and 1 Guest are viewing this topic.

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
timer problems with WebbotLib
« 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:
Code: [Select]
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:
Quote
../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

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: timer problems with WebbotLib
« Reply #1 on: August 31, 2009, 08:30:03 AM »
I fixed the warning.

This:
TICK_COUNT start = clockGetus();//restart clock

should be:
start = clockGetus();//restart clock

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,121
  • Helpful? 108
Re: timer problems with WebbotLib
« Reply #2 on: August 31, 2009, 09:34:09 AM »
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:
Code: [Select]
#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
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: timer problems with WebbotLib
« Reply #3 on: August 31, 2009, 09:52:50 AM »
thanks!

Quote
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:
Quote
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?)

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,121
  • Helpful? 108
SOLVED timer problems with WebbotLib
« Reply #4 on: August 31, 2009, 09:59:53 AM »
The manual is correct, but incomplete, I need to '%ld' to the list as well - thanks.
Done in 1.5 release
« Last Edit: September 02, 2009, 12:42:55 AM by Webbot »
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here

data_list