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 "SafePWM.h"
11 #include "SpeedController.h"
12 
13 #include <memory>
14 
22 class Servo : public SafePWM {
23  public:
24  explicit Servo(uint32_t channel);
25  virtual ~Servo();
26  void Set(float value);
27  void SetOffline();
28  float Get() const;
29  void SetAngle(float angle);
30  float GetAngle() const;
31  static float GetMaxAngle() { return kMaxServoAngle; }
32  static float GetMinAngle() { return kMinServoAngle; }
33 
34  void ValueChanged(ITable* source, llvm::StringRef key,
35  std::shared_ptr<nt::Value> value, bool isNew) override;
36  void UpdateTable() override;
37  void StartLiveWindowMode() override;
38  void StopLiveWindowMode() override;
39  std::string GetSmartDashboardType() const override;
40  void InitTable(std::shared_ptr<ITable> subTable) override;
41  std::shared_ptr<ITable> GetTable() const override;
42 
43  std::shared_ptr<ITable> m_table;
44 
45  private:
46  float GetServoAngleRange() const { return kMaxServoAngle - kMinServoAngle; }
47 
48  static constexpr float kMaxServoAngle = 180.0;
49  static constexpr float kMinServoAngle = 0.0;
50 
51  static constexpr float kDefaultMaxServoPWM = 2.4;
52  static constexpr float kDefaultMinServoPWM = .6;
53 };
void SetOffline()
Set the servo to offline.
Definition: Servo.cpp:53
A table whose values can be read and written to.
Definition: ITable.h:43
void InitTable(std::shared_ptr< ITable > subTable) override
Initializes a table for this sendable object.
Definition: Servo.cpp:127
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: Servo.cpp:113
A safe version of the PWM class.
Definition: SafePWM.h:25
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: Servo.cpp:107
float Get() const
Get the servo position.
Definition: Servo.cpp:63
float GetAngle() const
Get the servo angle.
Definition: Servo.cpp:97
Servo(uint32_t channel)
Definition: Servo.cpp:22
void SetAngle(float angle)
Set the servo angle.
Definition: Servo.cpp:80
void Set(float value)
Set the servo position.
Definition: Servo.cpp:46
std::shared_ptr< ITable > GetTable() const override
Definition: Servo.cpp:132
std::string GetSmartDashboardType() const override
Definition: Servo.cpp:125
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: Servo.cpp:119
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:39
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:101
Standard hobby style servo.
Definition: Servo.h:22