Upgraded the rest of Time.
Change-Id: I0ee083837e51d8f74a798b7ba14a3b6bb3859f35
diff --git a/frc971/wpilib/ADIS16448.cc b/frc971/wpilib/ADIS16448.cc
index cf1a6f8..ec219cc 100644
--- a/frc971/wpilib/ADIS16448.cc
+++ b/frc971/wpilib/ADIS16448.cc
@@ -5,18 +5,21 @@
#include <inttypes.h>
#include <math.h>
+#include <chrono>
#include "aos/common/logging/queue_logging.h"
#include "aos/common/messages/robot_state.q.h"
#include "aos/common/time.h"
#include "aos/linux_code/init.h"
-
#include "frc971/wpilib/imu.q.h"
#include "frc971/zeroing/averager.h"
namespace frc971 {
namespace wpilib {
+using ::aos::monotonic_clock;
+namespace chrono = ::std::chrono;
+
template <uint8_t size>
bool ADIS16448::DoTransaction(uint8_t to_send[size], uint8_t to_receive[size]) {
switch (spi_->Transaction(to_send, to_receive, size)) {
@@ -128,7 +131,7 @@
// Try to initialize repeatedly as long as we're supposed to be running.
while (run_ && !Initialize()) {
- ::aos::time::SleepFor(::aos::time::Time::InMS(50));
+ ::std::this_thread::sleep_for(::std::chrono::milliseconds(50));
}
LOG(INFO, "IMU initialized successfully\n");
@@ -150,7 +153,7 @@
}
}
got_an_interrupt = true;
- const ::aos::time::Time read_time = ::aos::time::Time::Now();
+ const monotonic_clock::time_point read_time = monotonic_clock::now();
uint8_t to_send[2 * 14], to_receive[2 * 14];
memset(&to_send[0], 0, sizeof(to_send));
@@ -188,7 +191,9 @@
auto message = imu_values.MakeMessage();
message->fpga_timestamp = dio1_->ReadRisingTimestamp();
- message->monotonic_timestamp_ns = read_time.ToNSec();
+ message->monotonic_timestamp_ns =
+ chrono::duration_cast<chrono::nanoseconds>(read_time.time_since_epoch())
+ .count();
message->gyro_x =
ConvertValue(&to_receive[4], kGyroLsbDegreeSecond * M_PI / 180.0);
@@ -364,7 +369,7 @@
{
uint16_t value;
do {
- ::aos::time::SleepFor(::aos::time::Time::InMS(10));
+ ::std::this_thread::sleep_for(::std::chrono::milliseconds(10));
if (!ReadRegister(kMscCtrlAddress, &value)) return false;
} while ((value & (1 << 10)) != 0);
}
diff --git a/frc971/wpilib/gyro_interface.cc b/frc971/wpilib/gyro_interface.cc
index 6b3ab40..9b7bb8b 100644
--- a/frc971/wpilib/gyro_interface.cc
+++ b/frc971/wpilib/gyro_interface.cc
@@ -1,6 +1,7 @@
#include "frc971/wpilib/gyro_interface.h"
#include <inttypes.h>
+#include <chrono>
#include "aos/common/logging/logging.h"
#include "aos/common/time.h"
@@ -35,7 +36,7 @@
}
// Wait for it to assert the fault conditions before reading them.
- ::aos::time::SleepFor(::aos::time::Time::InMS(50));
+ ::std::this_thread::sleep_for(::std::chrono::milliseconds(50));
if (!DoTransaction(0x20000000, &result)) {
LOG(WARNING, "failed to clear latched non-fault data\n");
diff --git a/frc971/wpilib/gyro_sender.cc b/frc971/wpilib/gyro_sender.cc
index 8cfdc39..9acb6fc 100644
--- a/frc971/wpilib/gyro_sender.cc
+++ b/frc971/wpilib/gyro_sender.cc
@@ -1,6 +1,11 @@
#include "frc971/wpilib/gyro_sender.h"
+#include <fcntl.h>
#include <inttypes.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <chrono>
#include "aos/common/logging/logging.h"
#include "aos/common/logging/queue_logging.h"
@@ -16,13 +21,15 @@
namespace wpilib {
GyroSender::GyroSender() {}
+namespace chrono = ::std::chrono;
+using ::aos::monotonic_clock;
void GyroSender::operator()() {
::aos::SetCurrentThreadName("Gyro");
// Try to initialize repeatedly as long as we're supposed to be running.
while (run_ && !gyro_.InitializeGyro()) {
- ::aos::time::SleepFor(::aos::time::Time::InMS(50));
+ ::std::this_thread::sleep_for(::std::chrono::milliseconds(50));
}
LOG(INFO, "gyro initialized successfully\n");
diff --git a/frc971/wpilib/interrupt_edge_counting.cc b/frc971/wpilib/interrupt_edge_counting.cc
index 4bdb2d2..5c10b89 100644
--- a/frc971/wpilib/interrupt_edge_counting.cc
+++ b/frc971/wpilib/interrupt_edge_counting.cc
@@ -1,5 +1,7 @@
#include "frc971/wpilib/interrupt_edge_counting.h"
+#include <chrono>
+
#include "aos/common/time.h"
#include "aos/linux_code/init.h"
@@ -64,7 +66,7 @@
// Wait more than the amount of time it takes for a digital input change
// to go from visible to software to having triggered an interrupt.
- ::aos::time::SleepFor(::aos::time::Time::InUS(120));
+ ::std::this_thread::sleep_for(::std::chrono::microseconds(120));
if (TryFinishingIteration()) return;
}
diff --git a/frc971/wpilib/loop_output_handler.cc b/frc971/wpilib/loop_output_handler.cc
index 310b3e3..59770be 100644
--- a/frc971/wpilib/loop_output_handler.cc
+++ b/frc971/wpilib/loop_output_handler.cc
@@ -2,8 +2,9 @@
#include <sys/timerfd.h>
-#include <thread>
+#include <chrono>
#include <functional>
+#include <thread>
#include "aos/linux_code/init.h"
#include "aos/common/messages/robot_state.q.h"
@@ -11,7 +12,9 @@
namespace frc971 {
namespace wpilib {
-LoopOutputHandler::LoopOutputHandler(const ::aos::time::Time &timeout)
+namespace chrono = ::std::chrono;
+
+LoopOutputHandler::LoopOutputHandler(::std::chrono::nanoseconds timeout)
: watchdog_(this, timeout) {}
void LoopOutputHandler::operator()() {
@@ -44,12 +47,12 @@
}
LoopOutputHandler::Watchdog::Watchdog(LoopOutputHandler *handler,
- const ::aos::time::Time &timeout)
+ ::std::chrono::nanoseconds timeout)
: handler_(handler),
timeout_(timeout),
- timerfd_(timerfd_create(::aos::time::Time::kDefaultClock, 0)) {
+ timerfd_(timerfd_create(CLOCK_MONOTONIC, 0)) {
if (timerfd_.get() == -1) {
- PLOG(FATAL, "timerfd_create(Time::kDefaultClock, 0)");
+ PLOG(FATAL, "timerfd_create(CLOCK_MONOTONIC, 0)");
}
}
@@ -65,7 +68,11 @@
void LoopOutputHandler::Watchdog::Reset() {
itimerspec value = itimerspec();
- value.it_value = timeout_.ToTimespec();
+ value.it_value.tv_sec = chrono::duration_cast<chrono::seconds>(timeout_).count();
+ value.it_value.tv_nsec =
+ chrono::duration_cast<chrono::nanoseconds>(
+ timeout_ - chrono::seconds(value.it_value.tv_sec))
+ .count();
PCHECK(timerfd_settime(timerfd_.get(), 0, &value, nullptr));
}
diff --git a/frc971/wpilib/loop_output_handler.h b/frc971/wpilib/loop_output_handler.h
index 144093d..14a5cc5 100644
--- a/frc971/wpilib/loop_output_handler.h
+++ b/frc971/wpilib/loop_output_handler.h
@@ -22,7 +22,7 @@
class LoopOutputHandler {
public:
LoopOutputHandler(
- const ::aos::time::Time &timeout = ::aos::time::Time::InSeconds(0.10));
+ ::std::chrono::nanoseconds timeout = ::std::chrono::milliseconds(100));
void Quit() { run_ = false; }
@@ -54,7 +54,7 @@
// LoopOutputHandler whenever the timerfd expires.
class Watchdog {
public:
- Watchdog(LoopOutputHandler *handler, const ::aos::time::Time &timeout);
+ Watchdog(LoopOutputHandler *handler, ::std::chrono::nanoseconds timeout);
void operator()();
@@ -65,7 +65,7 @@
private:
LoopOutputHandler *const handler_;
- const ::aos::time::Time timeout_;
+ const ::std::chrono::nanoseconds timeout_;
::aos::ScopedFD timerfd_;