Fixes MotorSafetyHelper locking and race conditions (#762)

Closes #760
This commit is contained in:
Thad House
2017-11-23 00:36:57 -08:00
committed by Peter Johnson
parent 614093c0c4
commit d36d72bd4f
4 changed files with 63 additions and 23 deletions

View File

@@ -738,14 +738,16 @@ void DriverStation::ReportJoystickUnpluggedWarning(llvm::StringRef message) {
void DriverStation::Run() {
m_isRunning = true;
int period = 0;
int safetyCounter = 0;
while (m_isRunning) {
HAL_WaitForDSData();
GetData();
if (++period >= 4) {
if (IsDisabled()) safetyCounter = 0;
if (++safetyCounter >= 4) {
MotorSafetyHelper::CheckMotors();
period = 0;
safetyCounter = 0;
}
if (m_userInDisabled) HAL_ObserveUserProgramDisabled();
if (m_userInAutonomous) HAL_ObserveUserProgramAutonomous();

View File

@@ -96,11 +96,19 @@ bool MotorSafetyHelper::IsAlive() const {
* shut down until its value is updated again.
*/
void MotorSafetyHelper::Check() {
DriverStation& ds = DriverStation::GetInstance();
if (!m_enabled || ds.IsDisabled() || ds.IsTest()) return;
bool enabled;
double stopTime;
std::lock_guard<wpi::mutex> lock(m_thisMutex);
if (m_stopTime < Timer::GetFPGATimestamp()) {
{
std::lock_guard<wpi::mutex> lock(m_thisMutex);
enabled = m_enabled;
stopTime = m_stopTime;
}
DriverStation& ds = DriverStation::GetInstance();
if (!enabled || ds.IsDisabled() || ds.IsTest()) return;
if (stopTime < Timer::GetFPGATimestamp()) {
llvm::SmallString<128> buf;
llvm::raw_svector_ostream desc(buf);
m_safeObject->GetDescription(desc);