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