Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */ |
| 5 | /*----------------------------------------------------------------------------*/ |
| 6 | #pragma once |
| 7 | |
| 8 | #include "MotorSafety.h" |
| 9 | #include "PWM.h" |
| 10 | #include "MotorSafetyHelper.h" |
| 11 | #include <memory> |
| 12 | |
| 13 | /** |
| 14 | * A safe version of the PWM class. |
| 15 | * It is safe because it implements the MotorSafety interface that provides timeouts |
| 16 | * in the event that the motor value is not updated before the expiration time. |
| 17 | * This delegates the actual work to a MotorSafetyHelper object that is used for all |
| 18 | * objects that implement MotorSafety. |
| 19 | */ |
| 20 | class SafePWM : public PWM, public MotorSafety |
| 21 | { |
| 22 | public: |
| 23 | explicit SafePWM(uint32_t channel); |
| 24 | virtual ~SafePWM() = default; |
| 25 | |
| 26 | void SetExpiration(float timeout); |
| 27 | float GetExpiration() const; |
| 28 | bool IsAlive() const; |
| 29 | void StopMotor(); |
| 30 | bool IsSafetyEnabled() const; |
| 31 | void SetSafetyEnabled(bool enabled); |
| 32 | void GetDescription(std::ostringstream& desc) const; |
| 33 | |
| 34 | virtual void SetSpeed(float speed); |
| 35 | private: |
| 36 | std::unique_ptr<MotorSafetyHelper> m_safetyHelper; |
| 37 | }; |