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 <support/mutex.h>
13 
14 #include "ErrorBase.h"
15 
16 namespace frc {
17 
18 class MotorSafety;
19 
20 class MotorSafetyHelper : public ErrorBase {
21  public:
22  explicit MotorSafetyHelper(MotorSafety* safeObject);
24  void Feed();
25  void SetExpiration(double expirationTime);
26  double GetExpiration() const;
27  bool IsAlive() const;
28  void Check();
29  void SetSafetyEnabled(bool enabled);
30  bool IsSafetyEnabled() const;
31  static void CheckMotors();
32 
33  private:
34  // The expiration time for this object
35  double m_expiration;
36 
37  // True if motor safety is enabled for this motor
38  bool m_enabled;
39 
40  // The FPGA clock value when this motor has expired
41  double m_stopTime;
42 
43  // Protect accesses to the state for this object
44  mutable wpi::mutex m_thisMutex;
45 
46  // The object that is using the helper
47  MotorSafety* m_safeObject;
48 
49  // List of all existing MotorSafetyHelper objects.
50  static std::set<MotorSafetyHelper*> m_helperList;
51 
52  // Protect accesses to the list of helpers
53  static wpi::mutex m_listMutex;
54 };
55 
56 } // namespace frc
Definition: RobotController.cpp:14
void SetSafetyEnabled(bool enabled)
Enable/disable motor safety for this device.
Definition: MotorSafetyHelper.cpp:128
void Feed()
Feed the motor safety object.
Definition: MotorSafetyHelper.cpp:55
Definition: MotorSafety.h:16
bool IsSafetyEnabled() const
Return the state of the motor safety enabled flag.
Definition: MotorSafetyHelper.cpp:140
Definition: MotorSafetyHelper.h:20
double GetExpiration() const
Retrieve the timeout value for the corresponding motor safety object.
Definition: MotorSafetyHelper.cpp:75
void Check()
Check if this motor has exceeded its timeout.
Definition: MotorSafetyHelper.cpp:98
bool IsAlive() const
Determine if the motor is still operating or has timed out.
Definition: MotorSafetyHelper.cpp:86
void SetExpiration(double expirationTime)
Set the expiration time for the corresponding motor safety object.
Definition: MotorSafetyHelper.cpp:65
static void CheckMotors()
Check the motors to see if any have timed out.
Definition: MotorSafetyHelper.cpp:151
Base class for most objects.
Definition: ErrorBase.h:74
MotorSafetyHelper(MotorSafety *safeObject)
The constructor for a MotorSafetyHelper object.
Definition: MotorSafetyHelper.cpp:35