WPILibC++  unspecified
PWM.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 <stdint.h>
11 
12 #include <memory>
13 #include <string>
14 
15 #include <HAL/Types.h>
16 
17 #include "LiveWindow/LiveWindowSendable.h"
18 #include "SensorBase.h"
19 #include "networktables/NetworkTableEntry.h"
20 
21 namespace frc {
22 
40 class PWM : public SensorBase, public LiveWindowSendable {
41  public:
58  };
59 
60  explicit PWM(int channel);
61  virtual ~PWM();
62  virtual void SetRaw(uint16_t value);
63  virtual uint16_t GetRaw() const;
64  virtual void SetPosition(double pos);
65  virtual double GetPosition() const;
66  virtual void SetSpeed(double speed);
67  virtual double GetSpeed() const;
68  virtual void SetDisabled();
70  void SetZeroLatch();
71  void EnableDeadbandElimination(bool eliminateDeadband);
72  void SetBounds(double max, double deadbandMax, double center,
73  double deadbandMin, double min);
74  void SetRawBounds(int max, int deadbandMax, int center, int deadbandMin,
75  int min);
76  void GetRawBounds(int32_t* max, int32_t* deadbandMax, int32_t* center,
77  int32_t* deadbandMin, int32_t* min);
78  int GetChannel() const { return m_channel; }
79 
80  protected:
81  void UpdateTable() override;
82  void StartLiveWindowMode() override;
83  void StopLiveWindowMode() override;
84  std::string GetSmartDashboardType() const override;
85  void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
86 
87  nt::NetworkTableEntry m_valueEntry;
88  NT_EntryListener m_valueListener = 0;
89 
90  private:
91  int m_channel;
92  HAL_DigitalHandle m_handle;
93 };
94 
95 } // namespace frc
virtual ~PWM()
Free the PWM channel.
Definition: PWM.cpp:67
Definition: Timer.cpp:18
void SetBounds(double max, double deadbandMax, double center, double deadbandMin, double min)
Set the bounds on the PWM pulse widths.
Definition: PWM.cpp:107
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:20
PeriodMultiplier
Represents the amount to multiply the minimum servo-pulse pwm period by.
Definition: PWM.h:45
void InitTable(std::shared_ptr< nt::NetworkTable > subTable) override
Initializes a table for this sendable object.
Definition: PWM.cpp:343
Skip every other pulse.
Definition: PWM.h:53
Skip three out of four pulses.
Definition: PWM.h:57
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:151
virtual void SetSpeed(double speed)
Set the PWM value based on a speed.
Definition: PWM.cpp:207
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: PWM.cpp:317
virtual double GetSpeed() const
Get the PWM value in terms of speed.
Definition: PWM.cpp:226
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: PWM.cpp:333
Don&#39;t skip pulses.
Definition: PWM.h:49
PWM(int channel)
Allocate a PWM given a channel number.
Definition: PWM.cpp:31
void SetRawBounds(int max, int deadbandMax, int center, int deadbandMin, int min)
Set the bounds on the PWM values.
Definition: PWM.cpp:129
void EnableDeadbandElimination(bool eliminateDeadband)
Optionally eliminate the deadband from a speed controller.
Definition: PWM.cpp:87
virtual uint16_t GetRaw() const
Get the PWM value directly from the hardware.
Definition: PWM.cpp:256
void SetPeriodMultiplier(PeriodMultiplier mult)
Slow down the PWM signal for old devices.
Definition: PWM.cpp:271
virtual double GetPosition() const
Get the PWM value in terms of a position.
Definition: PWM.cpp:186
virtual void SetRaw(uint16_t value)
Set the PWM value directly to the hardware.
Definition: PWM.cpp:241
NetworkTables Entry.
Definition: NetworkTableEntry.h:30
virtual void SetPosition(double pos)
Set the PWM value based on a position.
Definition: PWM.cpp:169
Class implements the PWM generation in the FPGA.
Definition: PWM.h:40
std::string GetSmartDashboardType() const override
Definition: PWM.cpp:341
virtual void SetDisabled()
Temporarily disables the PWM output.
Definition: PWM.cpp:299
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: PWM.cpp:321