blob: f364626d21251c8f87894548642fa67a4ed53fe0 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. All Rights Reserved.
3 */
4/* Open Source Software - may be modified and shared by FRC teams. The code */
5/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
6/*----------------------------------------------------------------------------*/
7#pragma once
8
9#include "MotorSafety.h"
10#include "PWM.h"
11#include "MotorSafetyHelper.h"
12#include <memory>
13#include <sstream>
14
15/**
16 * A safe version of the PWM class.
17 * It is safe because it implements the MotorSafety interface that provides
18 * timeouts
19 * in the event that the motor value is not updated before the expiration time.
20 * This delegates the actual work to a MotorSafetyHelper object that is used for
21 * all
22 * objects that implement MotorSafety.
23 */
24class SafePWM : public PWM, public MotorSafety {
25 public:
26 explicit SafePWM(uint32_t channel);
27 virtual ~SafePWM() = default;
28
29 void SetExpiration(float timeout);
30 float GetExpiration() const;
31 bool IsAlive() const;
32 void StopMotor();
33 bool IsSafetyEnabled() const;
34 void SetSafetyEnabled(bool enabled);
35 void GetDescription(std::ostringstream& desc) const;
36
37 virtual void SetSpeed(float speed);
38
39 private:
40 std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
41};