WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
MotorSafetyHelper.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2017. 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 "ErrorBase.h"
13 #include "HAL/cpp/priority_mutex.h"
14 
15 namespace frc {
16 
17 class MotorSafety;
18 
19 class MotorSafetyHelper : public ErrorBase {
20  public:
21  explicit MotorSafetyHelper(MotorSafety* safeObject);
23  void Feed();
24  void SetExpiration(double expirationTime);
25  double GetExpiration() const;
26  bool IsAlive() const;
27  void Check();
28  void SetSafetyEnabled(bool enabled);
29  bool IsSafetyEnabled() const;
30  static void CheckMotors();
31 
32  private:
33  // the expiration time for this object
34  double m_expiration;
35  // true if motor safety is enabled for this motor
36  bool m_enabled;
37  // the FPGA clock value when this motor has expired
38  double m_stopTime;
39  // protect accesses to the state for this object
40  mutable hal::priority_recursive_mutex m_syncMutex;
41  // the object that is using the helper
42  MotorSafety* m_safeObject;
43  // List of all existing MotorSafetyHelper objects.
44  static std::set<MotorSafetyHelper*> m_helperList;
45  // protect accesses to the list of helpers
46  static hal::priority_recursive_mutex m_listMutex;
47 };
48 
49 } // namespace frc
void SetSafetyEnabled(bool enabled)
Enable/disable motor safety for this device Turn on and off the motor safety option for this PWM obje...
Definition: MotorSafetyHelper.cpp:111
void Feed()
Feed the motor safety object.
Definition: MotorSafetyHelper.cpp:53
Definition: MotorSafety.h:16
bool IsSafetyEnabled() const
Return the state of the motor safety enabled flag Return if the motor safety is currently enabled for...
Definition: MotorSafetyHelper.cpp:121
Definition: MotorSafetyHelper.h:19
double GetExpiration() const
Retrieve the timeout value for the corresponding motor safety object.
Definition: MotorSafetyHelper.cpp:71
void Check()
Check if this motor has exceeded its timeout.
Definition: MotorSafetyHelper.cpp:92
bool IsAlive() const
Determine if the motor is still operating or has timed out.
Definition: MotorSafetyHelper.cpp:81
void SetExpiration(double expirationTime)
Set the expiration time for the corresponding motor safety object.
Definition: MotorSafetyHelper.cpp:62
static void CheckMotors()
Check the motors to see if any have timed out.
Definition: MotorSafetyHelper.cpp:131
Base class for most objects.
Definition: ErrorBase.h:72
Definition: priority_mutex.h:26
MotorSafetyHelper(MotorSafety *safeObject)
The constructor for a MotorSafetyHelper object.
Definition: MotorSafetyHelper.cpp:34