WPILibC++  2019.1.1-beta-1-11-g761933a
 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 
37  MotorSafetyHelper& operator=(MotorSafetyHelper&&) = default;
38 
44  void Feed();
45 
51  void SetExpiration(double expirationTime);
52 
58  double GetExpiration() const;
59 
66  bool IsAlive() const;
67 
75  void Check();
76 
84  void SetSafetyEnabled(bool enabled);
85 
93  bool IsSafetyEnabled() const;
94 
101  static void CheckMotors();
102 
103  private:
104  // The expiration time for this object
105  double m_expiration;
106 
107  // True if motor safety is enabled for this motor
108  bool m_enabled;
109 
110  // The FPGA clock value when this motor has expired
111  double m_stopTime;
112 
113  // Protect accesses to the state for this object
114  mutable wpi::mutex m_thisMutex;
115 
116  // The object that is using the helper
117  MotorSafety* m_safeObject;
118 };
119 
120 } // 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.