blob: f124605df414dc712b14baf5dea9eb1d2d39ac22 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* Open Source Software - may be modified and shared by FRC teams. The code */
Brian Silverman1a675112016-02-20 20:42:49 -05004/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
Brian Silverman26e4e522015-12-17 01:56:40 -05006/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05007
Brian Silverman26e4e522015-12-17 01:56:40 -05008#pragma once
9
10#include "ErrorBase.h"
11#include "HAL/cpp/priority_mutex.h"
12
13#include <set>
14
15class MotorSafety;
16
17class MotorSafetyHelper : public ErrorBase {
18 public:
19 MotorSafetyHelper(MotorSafety *safeObject);
20 ~MotorSafetyHelper();
21 void Feed();
22 void SetExpiration(float expirationTime);
23 float GetExpiration() const;
24 bool IsAlive() const;
25 void Check();
26 void SetSafetyEnabled(bool enabled);
27 bool IsSafetyEnabled() const;
28 static void CheckMotors();
29
30 private:
31 double m_expiration; // the expiration time for this object
32 bool m_enabled; // true if motor safety is enabled for this motor
33 double m_stopTime; // the FPGA clock value when this motor has expired
34 mutable priority_recursive_mutex
35 m_syncMutex; // protect accesses to the state for this object
36 MotorSafety *m_safeObject; // the object that is using the helper
37 // List of all existing MotorSafetyHelper objects.
38 static std::set<MotorSafetyHelper*> m_helperList;
39 static priority_recursive_mutex
40 m_listMutex; // protect accesses to the list of helpers
41};