Oops, I was wrong about vision: it uses a double storing seconds.<div>I&#39;ve been using uint64 on the client side and in log files (to allow exact comparisons), which is why I thought it was also in the vision detection message.<div>
<div><br></div><div><div class="gmail_quote">On Fri, Nov 9, 2012 at 3:18 PM, Christopher Head <span dir="ltr">&lt;<a href="mailto:chead@chead.ca" target="_blank">chead@chead.ca</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Well, technically the OS gives it as nanoseconds. I didn’t want to go<br>
with uint64 nanoseconds because it would only be a few bits away from a<br>
32-bit time_t which suffers from the 2038 bug (admittedly it would be a<br>
few orders of binary magnitude, but still). Then Joydeep implied he<br>
thought milliseconds were not as fine as they could be. I like the<br>
tradeoff of using microseconds though! Joydeep, what do you think? (or<br>
anyone else)<br>
<br>
Chris<br>
<div class="HOEnZb"><div class="h5"><br>
On Fri, 9 Nov 2012 13:55:44 -0800<br>
Ben Johnson &lt;<a href="mailto:circuitben@gmail.com">circuitben@gmail.com</a>&gt; wrote:<br>
<br>
&gt; I am in favor of using integers for time.<br>
&gt; If we use floating-point seconds, we have a potential rounding error<br>
&gt; because we need so much dynamic range.  Because 1e-6 can&#39;t be<br>
&gt; represented exactly in a float64, adding one microsecond to a time<br>
&gt; produces an incorrect result (see the demonstration code below).<br>
&gt;<br>
&gt; If we use floating-point microseconds, that is no better than integer<br>
&gt; microseconds, but with a less elegant implementation.  Vision uses<br>
&gt; integer microseconds in a uint64, and timing matters much more for<br>
&gt; vision than for referee messages.<br>
&gt;<br>
&gt; A double doesn&#39;t give significantly better resolution than one<br>
&gt; microsecond (less than two bits), and since it can&#39;t actually<br>
&gt; represent one microsecond exactly, I would argue that it&#39;s worse.  It<br>
&gt; introduces rounding error without any advantage.<br>
&gt; Referee messages except for time remaining are inherently<br>
&gt; high-latency, because they pass through two humans before they reach<br>
&gt; the computer. Extremely high precision is not necessary.<br>
&gt; If for some reason we actually need better resolution, I would suggest<br>
&gt; adding more bits as another field.  The purpose of floating-point<br>
&gt; formats is to provide a variable exponent, which we don&#39;t need here.<br>
&gt;<br>
&gt; It&#39;s easy to convert to a double on the receiving side, but it&#39;s hard<br>
&gt; to fix rounding errors after the fact.  I would rather see the time<br>
&gt; exactly as the OS originally gave it.<br>
&gt;<br>
&gt; Rounding demonstration:<br>
&gt; #include &lt;stdio.h&gt;<br>
&gt; #include &lt;sys/time.h&gt;<br>
&gt;<br>
&gt; int main()<br>
&gt; {<br>
&gt;     struct timeval tv;<br>
&gt;     gettimeofday(&amp;tv, 0);<br>
&gt;<br>
&gt;     double t0 = tv.tv_sec + tv.tv_usec * 1.0e-6;<br>
&gt;     double t1 = t0 + 1.0e-6;<br>
&gt;     printf(&quot;%g\n&quot;, t1 - t0);<br>
&gt;<br>
&gt;     return 0;<br>
&gt; }<br>
</div></div><div class="HOEnZb"><div class="h5">_______________________________________________<br>
robocup-small mailing list<br>
<a href="mailto:robocup-small@cc.gatech.edu">robocup-small@cc.gatech.edu</a><br>
<a href="https://mailman.cc.gatech.edu/mailman/listinfo/robocup-small" target="_blank">https://mailman.cc.gatech.edu/mailman/listinfo/robocup-small</a><br>
</div></div></blockquote></div><br></div></div></div>