WPILibC++  2018.4.1-20180824021726-1174-g488ba79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 <wpi/mutex.h>
11 
12 #include "frc/ErrorBase.h"
13 
14 namespace frc {
15 
16 class MotorSafety;
17 
18 class MotorSafetyHelper : public ErrorBase {
19  public:
32  explicit MotorSafetyHelper(MotorSafety* safeObject);
33 
35 
41  void Feed();
42 
48  void SetExpiration(double expirationTime);
49 
55  double GetExpiration() const;
56 
63  bool IsAlive() const;
64 
72  void Check();
73 
81  void SetSafetyEnabled(bool enabled);
82 
90  bool IsSafetyEnabled() const;
91 
98  static void CheckMotors();
99 
100  private:
101  // The expiration time for this object
102  double m_expiration;
103 
104  // True if motor safety is enabled for this motor
105  bool m_enabled;
106 
107  // The FPGA clock value when this motor has expired
108  double m_stopTime;
109 
110  // Protect accesses to the state for this object
111  mutable wpi::mutex m_thisMutex;
112 
113  // The object that is using the helper
114  MotorSafety* m_safeObject;
115 };
116 
117 } // namespace frc
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
void SetSafetyEnabled(bool enabled)
Enable/disable motor safety for this device.
MotorSafetyHelper(MotorSafety *safeObject)
The constructor for a MotorSafetyHelper object.
double GetExpiration() const
Retrieve the timeout value for the corresponding motor safety object.
Definition: MotorSafety.h:16
Definition: MotorSafetyHelper.h:18
void Feed()
Feed the motor safety object.
bool IsSafetyEnabled() const
Return the state of the motor safety enabled flag.
Base class for most objects.
Definition: ErrorBase.h:74
bool IsAlive() const
Determine if the motor is still operating or has timed out.
static void CheckMotors()
Check the motors to see if any have timed out.
void SetExpiration(double expirationTime)
Set the expiration time for the corresponding motor safety object.
void Check()
Check if this motor has exceeded its timeout.