Brian Silverman | 890a32a | 2018-03-11 15:41:56 -0700 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #ifndef CTR_EXCLUDE_WPILIB_CLASSES |
| 4 | |
| 5 | #include <cstdint> |
| 6 | #include "ctre/phoenix/LowLevel/CANBusAddressable.h" |
| 7 | #include "ctre/phoenix/ErrorCode.h" |
| 8 | #include "ctre/phoenix/paramEnum.h" |
| 9 | #include "ctre/phoenix/CANifierControlFrame.h" |
| 10 | #include "ctre/phoenix/CANifierStatusFrame.h" |
| 11 | #include "ctre/phoenix/CANifierStickyFaults.h" |
| 12 | #include "ctre/phoenix/CANifierFaults.h" |
| 13 | #include "ctre/phoenix/CANifierVelocityMeasPeriod.h" |
| 14 | |
| 15 | namespace ctre {namespace phoenix { |
| 16 | /** |
| 17 | * CTRE CANifier |
| 18 | * |
| 19 | * Device for interfacing common devices to the CAN bus. |
| 20 | */ |
| 21 | class CANifier: public CANBusAddressable { |
| 22 | public: |
| 23 | /** |
| 24 | * Enum for the LED Output Channels |
| 25 | */ |
| 26 | enum LEDChannel { |
| 27 | LEDChannelA = 0, LEDChannelB = 1, LEDChannelC = 2, |
| 28 | }; |
| 29 | |
| 30 | /** |
| 31 | * Enum for the PWM Input Channels |
| 32 | */ |
| 33 | enum PWMChannel { |
| 34 | PWMChannel0 = 0, PWMChannel1 = 1, PWMChannel2 = 2, PWMChannel3 = 3, |
| 35 | }; |
| 36 | const int PWMChannelCount = 4; |
| 37 | |
| 38 | /** |
| 39 | * General IO Pins on the CANifier |
| 40 | */ |
| 41 | enum GeneralPin { |
| 42 | QUAD_IDX = 0, //----- Must match CANifier_CCI enums -----// |
| 43 | QUAD_B = 1, |
| 44 | QUAD_A = 2, |
| 45 | LIMR = 3, |
| 46 | LIMF = 4, |
| 47 | SDA = 5, |
| 48 | SCL = 6, |
| 49 | SPI_CS = 7, |
| 50 | SPI_MISO_PWM2P = 8, |
| 51 | SPI_MOSI_PWM1P = 9, |
| 52 | SPI_CLK_PWM0P = 10, |
| 53 | }; |
| 54 | |
| 55 | /** |
| 56 | * Structure to hold the pin values. |
| 57 | */ |
| 58 | struct PinValues { |
| 59 | bool QUAD_IDX; |
| 60 | bool QUAD_B; |
| 61 | bool QUAD_A; |
| 62 | bool LIMR; |
| 63 | bool LIMF; |
| 64 | bool SDA; |
| 65 | bool SCL; |
| 66 | bool SPI_CS_PWM3; |
| 67 | bool SPI_MISO_PWM2; |
| 68 | bool SPI_MOSI_PWM1; |
| 69 | bool SPI_CLK_PWM0; |
| 70 | }; |
| 71 | |
| 72 | CANifier(int deviceNumber); |
| 73 | ErrorCode SetLEDOutput(double percentOutput, LEDChannel ledChannel); |
| 74 | ErrorCode SetGeneralOutput(GeneralPin outputPin, bool outputValue, bool outputEnable); |
| 75 | ErrorCode SetGeneralOutputs(int outputBits, int isOutputBits); |
| 76 | ErrorCode GetGeneralInputs(PinValues &allPins); |
| 77 | bool GetGeneralInput(GeneralPin inputPin); |
| 78 | int GetQuadraturePosition(); |
| 79 | int GetQuadratureVelocity(); |
| 80 | ErrorCode SetQuadraturePosition(int newPosition, int timeoutMs); |
| 81 | ErrorCode ConfigVelocityMeasurementPeriod( |
| 82 | CANifierVelocityMeasPeriod period, int timeoutMs); |
| 83 | ErrorCode ConfigVelocityMeasurementWindow(int windowSize, int timeoutMs); |
| 84 | /** |
| 85 | * Gets the bus voltage seen by the motor controller. |
| 86 | * |
| 87 | * @return The bus voltage value (in volts). |
| 88 | */ |
| 89 | double GetBusVoltage(); |
| 90 | ErrorCode GetLastError(); |
| 91 | ErrorCode SetPWMOutput(int pwmChannel, double dutyCycle); |
| 92 | ErrorCode EnablePWMOutput(int pwmChannel, bool bEnable); |
| 93 | ErrorCode GetPWMInput(PWMChannel pwmChannel, double dutyCycleAndPeriod[]); |
| 94 | |
| 95 | //------ Custom Persistent Params ----------// |
| 96 | ErrorCode ConfigSetCustomParam(int newValue, int paramIndex, |
| 97 | int timeoutMs); |
| 98 | int ConfigGetCustomParam(int paramIndex, |
| 99 | int timeoutMs); |
| 100 | //------ Generic Param API, typically not used ----------// |
| 101 | ErrorCode ConfigSetParameter(ParamEnum param, double value, |
| 102 | uint8_t subValue, int ordinal, int timeoutMs); |
| 103 | double ConfigGetParameter(ParamEnum param, int ordinal, int timeoutMs); |
| 104 | |
| 105 | |
| 106 | ErrorCode SetStatusFramePeriod(CANifierStatusFrame statusFrame, |
| 107 | int periodMs, int timeoutMs); |
| 108 | /** |
| 109 | * Gets the period of the given status frame. |
| 110 | * |
| 111 | * @param frame |
| 112 | * Frame to get the period of. |
| 113 | * @param timeoutMs |
| 114 | * Timeout value in ms. @see #ConfigOpenLoopRamp |
| 115 | * @return Period of the given status frame. |
| 116 | */ |
| 117 | int GetStatusFramePeriod(CANifierStatusFrame frame, int timeoutMs); |
| 118 | ErrorCode SetControlFramePeriod(CANifierControlFrame frame, int periodMs); |
| 119 | /** |
| 120 | * Gets the firmware version of the device. |
| 121 | * |
| 122 | * @return Firmware version of device. |
| 123 | */ |
| 124 | int GetFirmwareVersion(); |
| 125 | /** |
| 126 | * Returns true if the device has reset since last call. |
| 127 | * |
| 128 | * @return Has a Device Reset Occurred? |
| 129 | */ |
| 130 | bool HasResetOccurred(); |
| 131 | ErrorCode GetFaults(CANifierFaults & toFill); |
| 132 | ErrorCode GetStickyFaults(CANifierStickyFaults & toFill); |
| 133 | ErrorCode ClearStickyFaults(int timeoutMs); |
| 134 | |
| 135 | private: |
| 136 | void* m_handle; |
| 137 | bool _tempPins[11]; |
| 138 | }; |
| 139 | }} |
| 140 | #endif // CTR_EXCLUDE_WPILIB_CLASSES |