WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
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 /*----------------------------------------------------------------------------*/
8 #pragma once
10 #include <memory>
11 #include <string>
13 #include "HAL/Types.h"
14 #include "LiveWindow/LiveWindowSendable.h"
15 #include "SensorBase.h"
16 #include "tables/ITableListener.h"
18 namespace frc {
37 class PWM : public SensorBase,
38  public ITableListener,
39  public LiveWindowSendable {
40  public:
41  enum PeriodMultiplier {
42  kPeriodMultiplier_1X = 1,
43  kPeriodMultiplier_2X = 2,
44  kPeriodMultiplier_4X = 4
45  };
47  explicit PWM(int channel);
48  virtual ~PWM();
49  virtual void SetRaw(uint16_t value);
50  virtual uint16_t GetRaw() const;
51  virtual void SetPosition(double pos);
52  virtual double GetPosition() const;
53  virtual void SetSpeed(double speed);
54  virtual double GetSpeed() const;
55  virtual void SetDisabled();
56  void SetPeriodMultiplier(PeriodMultiplier mult);
57  void SetZeroLatch();
58  void EnableDeadbandElimination(bool eliminateDeadband);
59  void SetBounds(double max, double deadbandMax, double center,
60  double deadbandMin, double min);
61  void SetRawBounds(int max, int deadbandMax, int center, int deadbandMin,
62  int min);
63  void GetRawBounds(int32_t* max, int32_t* deadbandMax, int32_t* center,
64  int32_t* deadbandMin, int32_t* min);
65  int GetChannel() const { return m_channel; }
67  protected:
68  void ValueChanged(ITable* source, llvm::StringRef key,
69  std::shared_ptr<nt::Value> value, bool isNew) override;
70  void UpdateTable() override;
71  void StartLiveWindowMode() override;
72  void StopLiveWindowMode() override;
73  std::string GetSmartDashboardType() const override;
74  void InitTable(std::shared_ptr<ITable> subTable) override;
75  std::shared_ptr<ITable> GetTable() const override;
77  std::shared_ptr<ITable> m_table;
79  private:
80  int m_channel;
81  HAL_DigitalHandle m_handle;
82 };
84 } // namespace frc
virtual ~PWM()
Free the PWM channel.
Definition: PWM.cpp:65
A table whose values can be read and written to.
Definition: ITable.h:22
void SetBounds(double max, double deadbandMax, double center, double deadbandMin, double min)
Set the bounds on the PWM pulse widths.
Definition: PWM.cpp:105
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:17
Base class for all sensors.
Definition: SensorBase.h:22
void InitTable(std::shared_ptr< ITable > subTable) override
Initializes a table for this sendable object.
Definition: PWM.cpp:343
void GetRawBounds(int32_t *max, int32_t *deadbandMax, int32_t *center, int32_t *deadbandMin, int32_t *min)
Get the bounds on the PWM values.
Definition: PWM.cpp:149
virtual void SetSpeed(double speed)
Set the PWM value based on a speed.
Definition: PWM.cpp:205
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: PWM.cpp:321
virtual double GetSpeed() const
Get the PWM value in terms of speed.
Definition: PWM.cpp:224
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: PWM.cpp:334
PWM(int channel)
Allocate a PWM given a channel number.
Definition: PWM.cpp:30
void SetRawBounds(int max, int deadbandMax, int center, int deadbandMin, int min)
Set the bounds on the PWM values.
Definition: PWM.cpp:127
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: PWM.cpp:315
void EnableDeadbandElimination(bool eliminateDeadband)
Optionally eliminate the deadband from a speed controller.
Definition: PWM.cpp:85
virtual uint16_t GetRaw() const
Get the PWM value directly from the hardware.
Definition: PWM.cpp:254
A listener that listens to changes in values in a ITable.
Definition: ITableListener.h:18
std::shared_ptr< ITable > GetTable() const override
Definition: PWM.cpp:348
void SetPeriodMultiplier(PeriodMultiplier mult)
Slow down the PWM signal for old devices.
Definition: PWM.cpp:269
virtual double GetPosition() const
Get the PWM value in terms of a position.
Definition: PWM.cpp:184
virtual void SetRaw(uint16_t value)
Set the PWM value directly to the hardware.
Definition: PWM.cpp:239
virtual void SetPosition(double pos)
Set the PWM value based on a position.
Definition: PWM.cpp:167
Class implements the PWM generation in the FPGA.
Definition: PWM.h:37
std::string GetSmartDashboardType() const override
Definition: PWM.cpp:341
virtual void SetDisabled()
Temporarily disables the PWM output.
Definition: PWM.cpp:297
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: PWM.cpp:327