Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 2 | /* Copyright (c) FIRST 2008-2016. All Rights Reserved. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 6 | /*----------------------------------------------------------------------------*/ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 7 | |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 8 | #pragma once |
| 9 | |
| 10 | #include "ErrorBase.h" |
| 11 | #include "HAL/cpp/priority_mutex.h" |
| 12 | |
| 13 | #include <set> |
| 14 | |
| 15 | class MotorSafety; |
| 16 | |
| 17 | class 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 | }; |