WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Servo.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2016. 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 
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
Standard hobby style servo.
Definition: Servo.h:25
A table whose values can be read and written to.
Definition: ITable.h:22
double GetAngle() const
Get the servo angle.
Definition: Servo.cpp:99
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: Servo.cpp:109
std::string GetSmartDashboardType() const override
Definition: Servo.cpp:127
std::shared_ptr< ITable > GetTable() const override
Definition: Servo.cpp:134
void InitTable(std::shared_ptr< ITable > subTable) override
Initializes a table for this sendable object.
Definition: Servo.cpp:129
double Get() const
Get the servo position.
Definition: Servo.cpp:65
void SetAngle(double angle)
Set the servo angle.
Definition: Servo.cpp:81
void Set(double value)
Set the servo position.
Definition: Servo.cpp:48
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: Servo.cpp:121
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: Servo.cpp:115
A safe version of the PWM class.
Definition: SafePWM.h:26
void SetOffline()
Set the servo to offline.
Definition: Servo.cpp:55
Servo(int channel)
Definition: Servo.cpp:24
void ValueChanged(ITable *source, llvm::StringRef key, std::shared_ptr< nt::Value > value, bool isNew) override
Called when a key-value pair is changed in a ITable.
Definition: Servo.cpp:103