WPILibC++  unspecified
Servo.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2017 FIRST. 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 #include "networktables/NetworkTableEntry.h"
16 
17 namespace frc {
18 
26 class Servo : public SafePWM {
27  public:
28  explicit Servo(int channel);
29  virtual ~Servo();
30  void Set(double value);
31  void SetOffline();
32  double Get() const;
33  void SetAngle(double angle);
34  double GetAngle() const;
35  static double GetMaxAngle() { return kMaxServoAngle; }
36  static double GetMinAngle() { return kMinServoAngle; }
37 
38  void UpdateTable() override;
39  void StartLiveWindowMode() override;
40  void StopLiveWindowMode() override;
41  std::string GetSmartDashboardType() const override;
42  void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
43 
44  protected:
45  nt::NetworkTableEntry m_valueEntry;
46  NT_EntryListener m_valueListener = 0;
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:26
Definition: Timer.cpp:18
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:103
std::string GetSmartDashboardType() const override
Definition: Servo.cpp:125
void InitTable(std::shared_ptr< nt::NetworkTable > subTable) override
Initializes a table for this sendable object.
Definition: Servo.cpp:127
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:118
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: Servo.cpp:107
A safe version of the PWM class.
Definition: SafePWM.h:27
NetworkTables Entry.
Definition: NetworkTableEntry.h:30
void SetOffline()
Set the servo to offline.
Definition: Servo.cpp:55
Servo(int channel)
Definition: Servo.cpp:26