Remove obsolete timer functions and replace with std::chrono (#64)

Removed delayTicks(), delayMillis(), delaySeconds(), HAL_NO_WAIT, HAL_WAIT_FOREVER,
niTimestamp32(), and niTimestamp64().

Replaced clock_gettime() and usleep() with std::chrono.
This commit is contained in:
Tyler Veness
2016-05-26 20:19:23 -07:00
committed by Peter Johnson
parent 4af0bbddee
commit fa8bb3fa91
14 changed files with 37 additions and 119 deletions

View File

@@ -7,9 +7,9 @@
#include "CANTalon.h"
#include <unistd.h> // usleep
#include <chrono>
#include <sstream>
#include <thread>
#include "HAL/HAL.h"
#include "LiveWindow/LiveWindow.h"
@@ -31,6 +31,8 @@ const double kNativePwdUnitsPerRotation = 4096.0;
*/
const double kMinutesPer100msUnit = 1.0 / 600.0;
constexpr unsigned int CANTalon::kDelayForSolicitedSignalsUs;
/**
* Constructor for the CANTalon device.
*
@@ -386,7 +388,9 @@ double CANTalon::GetP() const {
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */
// small yield for getting response
std::this_thread::sleep_for(
std::chrono::microseconds(kDelayForSolicitedSignalsUs));
double p;
status = m_impl->GetPgain(m_profile, p);
if (status != CTR_OKAY) {
@@ -407,7 +411,9 @@ double CANTalon::GetI() const {
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */
// small yield for getting response
std::this_thread::sleep_for(
std::chrono::microseconds(kDelayForSolicitedSignalsUs));
double i;
status = m_impl->GetIgain(m_profile, i);
@@ -429,8 +435,9 @@ double CANTalon::GetD() const {
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */
// small yield for getting response
std::this_thread::sleep_for(
std::chrono::microseconds(kDelayForSolicitedSignalsUs));
double d;
status = m_impl->GetDgain(m_profile, d);
if (status != CTR_OKAY) {
@@ -452,7 +459,9 @@ double CANTalon::GetF() const {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */
// small yield for getting response
std::this_thread::sleep_for(
std::chrono::microseconds(kDelayForSolicitedSignalsUs));
double f;
status = m_impl->GetFgain(m_profile, f);
if (status != CTR_OKAY) {
@@ -473,7 +482,8 @@ int CANTalon::GetIzone() const {
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(kDelayForSolicitedSignalsUs);
std::this_thread::sleep_for(
std::chrono::microseconds(kDelayForSolicitedSignalsUs));
int iz;
status = m_impl->GetIzone(m_profile, iz);
@@ -1117,7 +1127,8 @@ uint32_t CANTalon::GetFirmwareVersion() const {
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(kDelayForSolicitedSignalsUs);
std::this_thread::sleep_for(
std::chrono::microseconds(kDelayForSolicitedSignalsUs));
status =
m_impl->GetParamResponseInt32(CanTalonSRX::eFirmVers, firmwareVersion);
if (status != CTR_OKAY) {
@@ -1141,7 +1152,9 @@ int CANTalon::GetIaccum() const {
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */
// small yield for getting response
std::this_thread::sleep_for(
std::chrono::microseconds(kDelayForSolicitedSignalsUs));
int iaccum;
status = m_impl->GetParamResponseInt32(CanTalonSRX::ePidIaccum, iaccum);
if (status != CTR_OKAY) {
@@ -1519,7 +1532,8 @@ bool CANTalon::GetParameter(uint32_t paramEnum, double& dvalue) const {
retval = false;
}
/* small yield for getting response */
usleep(kDelayForSolicitedSignalsUs);
std::this_thread::sleep_for(
std::chrono::microseconds(kDelayForSolicitedSignalsUs));
/* get the last received update */
status = m_impl->GetParamResponse((CanTalonSRX::param_t)paramEnum, dvalue);
if (status != CTR_OKAY) {

View File

@@ -172,7 +172,6 @@ void IterativeRobot::DisabledPeriodic() {
printf("Default %s() method... Overload me!\n", __FUNCTION__);
firstRun = false;
}
delayTicks(1);
}
/**
@@ -187,7 +186,6 @@ void IterativeRobot::AutonomousPeriodic() {
printf("Default %s() method... Overload me!\n", __FUNCTION__);
firstRun = false;
}
delayTicks(1);
}
/**
@@ -202,7 +200,6 @@ void IterativeRobot::TeleopPeriodic() {
printf("Default %s() method... Overload me!\n", __FUNCTION__);
firstRun = false;
}
delayTicks(1);
}
/**
@@ -217,5 +214,4 @@ void IterativeRobot::TestPeriodic() {
printf("Default %s() method... Overload me!\n", __FUNCTION__);
firstRun = false;
}
delayTicks(1);
}

View File

@@ -7,9 +7,9 @@
#include "Timer.h"
#include <time.h>
#include <chrono>
#include <iostream>
#include <thread>
#include "HAL/HAL.h"
#include "Utility.h"
@@ -25,7 +25,7 @@
*/
void Wait(double seconds) {
if (seconds < 0.0) return;
delaySeconds(seconds);
std::this_thread::sleep_for(std::chrono::duration<double>(seconds));
}
/**
@@ -41,12 +41,9 @@ double GetClock() { return Timer::GetFPGATimestamp(); }
* on Saturday.
*/
double GetTime() {
struct timespec tp;
clock_gettime(CLOCK_REALTIME, &tp);
double realTime = (double)tp.tv_sec + (double)((double)tp.tv_nsec * 1e-9);
return (realTime);
using namespace std::chrono;
return duration_cast<duration<double>>(system_clock::now().time_since_epoch())
.count();
}
// for compatibility with msvc12--see C2864
@@ -167,9 +164,3 @@ double Timer::GetFPGATimestamp() {
// Call the helper GetFPGATime() in Utility.cpp
return GetFPGATime() * 1.0e-6;
}
// Internal function that reads the PPC timestamp counter.
extern "C" {
uint32_t niTimestamp32(void);
uint64_t niTimestamp64(void);
}