blob: 16a64c1045f774f600ccfe6a1f508b8f31a4914f [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
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 <memory>
11#include <sstream>
12
13#include "MotorSafety.h"
14#include "MotorSafetyHelper.h"
15#include "PWM.h"
16
17namespace frc {
18
19/**
20 * A safe version of the PWM class.
21 * It is safe because it implements the MotorSafety interface that provides
22 * timeouts in the event that the motor value is not updated before the
23 * expiration time. This delegates the actual work to a MotorSafetyHelper
24 * object that is used for all objects that implement MotorSafety.
25 */
26class SafePWM : public PWM, public MotorSafety {
27 public:
28 explicit SafePWM(int channel);
29 virtual ~SafePWM() = default;
30
31 void SetExpiration(double timeout);
32 double GetExpiration() const;
33 bool IsAlive() const;
34 void StopMotor();
35 bool IsSafetyEnabled() const;
36 void SetSafetyEnabled(bool enabled);
37 void GetDescription(std::ostringstream& desc) const;
38
39 virtual void SetSpeed(double speed);
40
41 private:
42 std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
43};
44
45} // namespace frc