WPILibC++  2019.1.1-beta-4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
MotorSafety.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 #include <wpi/raw_ostream.h>
12 
13 #include "frc/DriverStation.h"
14 #include "frc/ErrorBase.h"
15 #include "frc/Timer.h"
16 #include "frc/Watchdog.h"
17 
18 namespace frc {
19 
26 class MotorSafety : public ErrorBase {
27  public:
28  MotorSafety() = default;
29  virtual ~MotorSafety() = default;
30 
31  MotorSafety(MotorSafety&& rhs);
32  MotorSafety& operator=(MotorSafety&& rhs);
33 
39  void Feed();
40 
46  void SetExpiration(double expirationTime);
47 
53  double GetExpiration() const;
54 
60  bool IsAlive() const;
61 
69  void SetSafetyEnabled(bool enabled);
70 
78  bool IsSafetyEnabled() const;
79 
80  virtual void StopMotor() = 0;
81  virtual void GetDescription(wpi::raw_ostream& desc) const = 0;
82 
83  private:
84  static constexpr double kDefaultSafetyExpiration = 0.1;
85 
86  Watchdog m_watchdog{kDefaultSafetyExpiration, [this] { TimeoutFunc(); }};
87 
88  // True if motor safety is enabled for this motor
89  bool m_enabled = false;
90 
91  mutable wpi::mutex m_thisMutex;
92 
93  void TimeoutFunc();
94 };
95 
96 } // namespace frc
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
bool IsAlive() const
Determine if the motor is still operating or has timed out.
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
bool IsSafetyEnabled() const
Return the state of the motor safety enabled flag.
This base class runs a watchdog timer and calls the subclass's StopMotor() function if the timeout ex...
Definition: MotorSafety.h:26
void SetExpiration(double expirationTime)
Set the expiration time for the corresponding motor safety object.
void Feed()
Feed the motor safety object.
A class that's a wrapper around a watchdog timer.
Definition: Watchdog.h:30
Base class for most objects.
Definition: ErrorBase.h:74
void SetSafetyEnabled(bool enabled)
Enable/disable motor safety for this device.
double GetExpiration() const
Retrieve the timeout value for the corresponding motor safety object.