WPILibC++  unspecified
MotorSafetyHelper.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <set>
11 
12 #include <wpi/mutex.h>
13 
14 #include "ErrorBase.h"
15 
16 namespace frc {
17 
18 class MotorSafety;
19 
20 class MotorSafetyHelper : public ErrorBase {
21  public:
34  explicit MotorSafetyHelper(MotorSafety* safeObject);
35 
37 
43  void Feed();
44 
50  void SetExpiration(double expirationTime);
51 
57  double GetExpiration() const;
58 
65  bool IsAlive() const;
66 
74  void Check();
75 
83  void SetSafetyEnabled(bool enabled);
84 
92  bool IsSafetyEnabled() const;
93 
100  static void CheckMotors();
101 
102  private:
103  // The expiration time for this object
104  double m_expiration;
105 
106  // True if motor safety is enabled for this motor
107  bool m_enabled;
108 
109  // The FPGA clock value when this motor has expired
110  double m_stopTime;
111 
112  // Protect accesses to the state for this object
113  mutable wpi::mutex m_thisMutex;
114 
115  // The object that is using the helper
116  MotorSafety* m_safeObject;
117 
118  // List of all existing MotorSafetyHelper objects.
119  static std::set<MotorSafetyHelper*> m_helperList;
120 
121  // Protect accesses to the list of helpers
122  static wpi::mutex m_listMutex;
123 };
124 
125 } // namespace frc
Definition: Utility.cpp:119
void SetSafetyEnabled(bool enabled)
Enable/disable motor safety for this device.
Definition: MotorSafetyHelper.cpp:81
void Feed()
Feed the motor safety object.
Definition: MotorSafetyHelper.cpp:38
Definition: MotorSafety.h:16
bool IsSafetyEnabled() const
Return the state of the motor safety enabled flag.
Definition: MotorSafetyHelper.cpp:86
Definition: MotorSafetyHelper.h:20
double GetExpiration() const
Retrieve the timeout value for the corresponding motor safety object.
Definition: MotorSafetyHelper.cpp:48
void Check()
Check if this motor has exceeded its timeout.
Definition: MotorSafetyHelper.cpp:58
bool IsAlive() const
Determine if the motor is still operating or has timed out.
Definition: MotorSafetyHelper.cpp:53
void SetExpiration(double expirationTime)
Set the expiration time for the corresponding motor safety object.
Definition: MotorSafetyHelper.cpp:43
static void CheckMotors()
Check the motors to see if any have timed out.
Definition: MotorSafetyHelper.cpp:91
Base class for most objects.
Definition: ErrorBase.h:74
MotorSafetyHelper(MotorSafety *safeObject)
The constructor for a MotorSafetyHelper object.
Definition: MotorSafetyHelper.cpp:23