Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 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 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | #include <memory> |
| 11 | #include <string> |
| 12 | |
Austin Schuh | f6b9463 | 2019-02-02 22:11:27 -0800 | [diff] [blame] | 13 | #include "hal/Types.h" |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 14 | #include "frc971/wpilib/ahal/SensorBase.h" |
| 15 | |
| 16 | namespace frc { |
| 17 | |
| 18 | /** |
| 19 | * Class implements the PWM generation in the FPGA. |
| 20 | * |
| 21 | * The values supplied as arguments for PWM outputs range from -1.0 to 1.0. They |
| 22 | * are mapped to the hardware dependent values, in this case 0-2000 for the |
| 23 | * FPGA. Changes are immediately sent to the FPGA, and the update occurs at the |
| 24 | * next FPGA cycle. There is no delay. |
| 25 | * |
| 26 | * As of revision 0.1.10 of the FPGA, the FPGA interprets the 0-2000 values as |
| 27 | * follows: |
| 28 | * - 2000 = maximum pulse width |
| 29 | * - 1999 to 1001 = linear scaling from "full forward" to "center" |
| 30 | * - 1000 = center value |
| 31 | * - 999 to 2 = linear scaling from "center" to "full reverse" |
| 32 | * - 1 = minimum pulse width (currently .5ms) |
| 33 | * - 0 = disabled (i.e. PWM output is held low) |
| 34 | */ |
| 35 | class PWM { |
| 36 | public: |
| 37 | enum PeriodMultiplier { |
| 38 | kPeriodMultiplier_1X = 1, |
| 39 | kPeriodMultiplier_2X = 2, |
| 40 | kPeriodMultiplier_4X = 4 |
| 41 | }; |
| 42 | |
| 43 | explicit PWM(int channel); |
| 44 | virtual ~PWM(); |
| 45 | virtual void SetRaw(uint16_t value); |
| 46 | virtual uint16_t GetRaw() const; |
| 47 | virtual void SetPosition(double pos); |
| 48 | virtual double GetPosition() const; |
| 49 | virtual void SetSpeed(double speed); |
| 50 | virtual double GetSpeed() const; |
| 51 | virtual void SetDisabled(); |
| 52 | void SetPeriodMultiplier(PeriodMultiplier mult); |
| 53 | void SetZeroLatch(); |
| 54 | void EnableDeadbandElimination(bool eliminateDeadband); |
| 55 | void SetBounds(double max, double deadbandMax, double center, |
| 56 | double deadbandMin, double min); |
| 57 | void SetRawBounds(int max, int deadbandMax, int center, int deadbandMin, |
| 58 | int min); |
| 59 | void GetRawBounds(int32_t *max, int32_t *deadbandMax, int32_t *center, |
| 60 | int32_t *deadbandMin, int32_t *min); |
| 61 | int GetChannel() const { return m_channel; } |
| 62 | |
| 63 | protected: |
| 64 | private: |
| 65 | int m_channel; |
| 66 | HAL_DigitalHandle m_handle; |
| 67 | }; |
| 68 | |
| 69 | } // namespace frc |