Fixed a few more small TODOs

Timer::Get now compensates for the FPGA time rolling over after 71 minutes

UltraSonic::Ping doesn't bother disabling automatic mode, since it asserts
that it's not in automatic mode on the line before.

Change-Id: I6b0f45327c453abd8a846ec8da0f9676e210d909
This commit is contained in:
Thomas Clark
2014-08-04 15:25:41 -04:00
parent d521eb79b9
commit e73c8d06eb
2 changed files with 21 additions and 14 deletions

View File

@@ -11,6 +11,10 @@
#include "HAL/HAL.hpp" #include "HAL/HAL.hpp"
#include "HAL/cpp/Synchronized.hpp" #include "HAL/cpp/Synchronized.hpp"
#include "Utility.h" #include "Utility.h"
#include <iostream>
// The time, in seconds, at which the 32-bit FPGA timestamp rolls over to 0
static const double kRolloverTime = (1ll << 32) / 1e6;
/** /**
* Pause the task for a specified time. * Pause the task for a specified time.
@@ -89,8 +93,13 @@ double Timer::Get()
Synchronized sync(m_semaphore); Synchronized sync(m_semaphore);
if(m_running) if(m_running)
{ {
// This math won't work if the timer rolled over (71 minutes after boot). // If the current time is before the start time, then the FPGA clock
// TODO: Check for it and compensate. // rolled over. Compensate by adding the ~71 minutes that it takes
// to roll over to the current time.
if(currentTime < m_startTime) {
currentTime += kRolloverTime;
}
result = (currentTime - m_startTime) + m_accumulatedTime; result = (currentTime - m_startTime) + m_accumulatedTime;
} }
else else

View File

@@ -230,9 +230,7 @@ void Ultrasonic::SetAutomaticMode(bool enabling)
*/ */
void Ultrasonic::Ping() void Ultrasonic::Ping()
{ {
// TODO: Either assert or disable, not both.
wpi_assert(!m_automaticEnabled); wpi_assert(!m_automaticEnabled);
SetAutomaticMode(false); // turn off automatic round robin if pinging single sensor
m_counter->Reset(); // reset the counter to zero (invalid data now) m_counter->Reset(); // reset the counter to zero (invalid data now)
m_pingChannel->Pulse(kPingTime); // do the ping to start getting a single range m_pingChannel->Pulse(kPingTime); // do the ping to start getting a single range
} }