blob: 4787cee74f954b4068f68d69b6842b198b03089a [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* Open Source Software - may be modified and shared by FRC teams. The code */
Brian Silverman1a675112016-02-20 20:42:49 -05004/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
Brian Silverman26e4e522015-12-17 01:56:40 -05006/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05007
Brian Silverman26e4e522015-12-17 01:56:40 -05008#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 */
22class SafePWM : public PWM, public MotorSafety
23{
24public:
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);
37private:
38 std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
39};