Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 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 <string> |
| 12 | |
| 13 | #include "SafePWM.h" |
| 14 | #include "SpeedController.h" |
| 15 | |
| 16 | namespace frc { |
| 17 | |
| 18 | /** |
| 19 | * Standard hobby style servo. |
| 20 | * |
| 21 | * The range parameters default to the appropriate values for the Hitec HS-322HD |
| 22 | * servo provided |
| 23 | * in the FIRST Kit of Parts in 2008. |
| 24 | */ |
| 25 | class Servo : public SafePWM { |
| 26 | public: |
| 27 | explicit Servo(int channel); |
| 28 | virtual ~Servo(); |
| 29 | void Set(double value); |
| 30 | void SetOffline(); |
| 31 | double Get() const; |
| 32 | void SetAngle(double angle); |
| 33 | double GetAngle() const; |
| 34 | static double GetMaxAngle() { return kMaxServoAngle; } |
| 35 | static double GetMinAngle() { return kMinServoAngle; } |
| 36 | |
| 37 | void ValueChanged(ITable* source, llvm::StringRef key, |
| 38 | std::shared_ptr<nt::Value> value, bool isNew) override; |
| 39 | void UpdateTable() override; |
| 40 | void StartLiveWindowMode() override; |
| 41 | void StopLiveWindowMode() override; |
| 42 | std::string GetSmartDashboardType() const override; |
| 43 | void InitTable(std::shared_ptr<ITable> subTable) override; |
| 44 | std::shared_ptr<ITable> GetTable() const override; |
| 45 | |
| 46 | std::shared_ptr<ITable> m_table; |
| 47 | |
| 48 | private: |
| 49 | double GetServoAngleRange() const { return kMaxServoAngle - kMinServoAngle; } |
| 50 | |
| 51 | static constexpr double kMaxServoAngle = 180.0; |
| 52 | static constexpr double kMinServoAngle = 0.0; |
| 53 | |
| 54 | static constexpr double kDefaultMaxServoPWM = 2.4; |
| 55 | static constexpr double kDefaultMinServoPWM = .6; |
| 56 | }; |
| 57 | |
| 58 | } // namespace frc |