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