Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2011-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 | #include "frc971/wpilib/ahal/ControllerPower.h" |
| 9 | |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame^] | 10 | #include <cstdint> |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 11 | |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame^] | 12 | #include "frc971/wpilib/ahal/ErrorBase.h" |
Austin Schuh | f6b9463 | 2019-02-02 22:11:27 -0800 | [diff] [blame] | 13 | #include "hal/HAL.h" |
| 14 | #include "hal/Power.h" |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 15 | |
| 16 | using namespace frc; |
| 17 | |
| 18 | /** |
| 19 | * Get the input voltage to the robot controller. |
| 20 | * |
| 21 | * @return The controller input voltage value in Volts |
| 22 | */ |
| 23 | double ControllerPower::GetInputVoltage() { |
| 24 | int32_t status = 0; |
| 25 | double retVal = HAL_GetVinVoltage(&status); |
| 26 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 27 | return retVal; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Get the input current to the robot controller. |
| 32 | * |
| 33 | * @return The controller input current value in Amps |
| 34 | */ |
| 35 | double ControllerPower::GetInputCurrent() { |
| 36 | int32_t status = 0; |
| 37 | double retVal = HAL_GetVinCurrent(&status); |
| 38 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 39 | return retVal; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get the voltage of the 6V rail. |
| 44 | * |
| 45 | * @return The controller 6V rail voltage value in Volts |
| 46 | */ |
| 47 | double ControllerPower::GetVoltage6V() { |
| 48 | int32_t status = 0; |
| 49 | double retVal = HAL_GetUserVoltage6V(&status); |
| 50 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 51 | return retVal; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Get the current output of the 6V rail. |
| 56 | * |
| 57 | * @return The controller 6V rail output current value in Amps |
| 58 | */ |
| 59 | double ControllerPower::GetCurrent6V() { |
| 60 | int32_t status = 0; |
| 61 | double retVal = HAL_GetUserCurrent6V(&status); |
| 62 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 63 | return retVal; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Get the enabled state of the 6V rail. The rail may be disabled due to a |
| 68 | * controller brownout, a short circuit on the rail, or controller over-voltage. |
| 69 | * |
| 70 | * @return The controller 6V rail enabled value. True for enabled. |
| 71 | */ |
| 72 | bool ControllerPower::GetEnabled6V() { |
| 73 | int32_t status = 0; |
| 74 | bool retVal = HAL_GetUserActive6V(&status); |
| 75 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 76 | return retVal; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Get the count of the total current faults on the 6V rail since the controller |
| 81 | * has booted. |
| 82 | * |
| 83 | * @return The number of faults. |
| 84 | */ |
| 85 | int ControllerPower::GetFaultCount6V() { |
| 86 | int32_t status = 0; |
| 87 | int retVal = HAL_GetUserCurrentFaults6V(&status); |
| 88 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 89 | return retVal; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Get the voltage of the 5V rail. |
| 94 | * |
| 95 | * @return The controller 5V rail voltage value in Volts |
| 96 | */ |
| 97 | double ControllerPower::GetVoltage5V() { |
| 98 | int32_t status = 0; |
| 99 | double retVal = HAL_GetUserVoltage5V(&status); |
| 100 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 101 | return retVal; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Get the current output of the 5V rail. |
| 106 | * |
| 107 | * @return The controller 5V rail output current value in Amps |
| 108 | */ |
| 109 | double ControllerPower::GetCurrent5V() { |
| 110 | int32_t status = 0; |
| 111 | double retVal = HAL_GetUserCurrent5V(&status); |
| 112 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 113 | return retVal; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Get the enabled state of the 5V rail. The rail may be disabled due to a |
| 118 | * controller brownout, a short circuit on the rail, or controller over-voltage. |
| 119 | * |
| 120 | * @return The controller 5V rail enabled value. True for enabled. |
| 121 | */ |
| 122 | bool ControllerPower::GetEnabled5V() { |
| 123 | int32_t status = 0; |
| 124 | bool retVal = HAL_GetUserActive5V(&status); |
| 125 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 126 | return retVal; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Get the count of the total current faults on the 5V rail since the controller |
| 131 | * has booted. |
| 132 | * |
| 133 | * @return The number of faults |
| 134 | */ |
| 135 | int ControllerPower::GetFaultCount5V() { |
| 136 | int32_t status = 0; |
| 137 | int retVal = HAL_GetUserCurrentFaults5V(&status); |
| 138 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 139 | return retVal; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Get the voltage of the 3.3V rail. |
| 144 | * |
| 145 | * @return The controller 3.3V rail voltage value in Volts |
| 146 | */ |
| 147 | double ControllerPower::GetVoltage3V3() { |
| 148 | int32_t status = 0; |
| 149 | double retVal = HAL_GetUserVoltage3V3(&status); |
| 150 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 151 | return retVal; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Get the current output of the 3.3V rail. |
| 156 | * |
| 157 | * @return The controller 3.3V rail output current value in Amps |
| 158 | */ |
| 159 | double ControllerPower::GetCurrent3V3() { |
| 160 | int32_t status = 0; |
| 161 | double retVal = HAL_GetUserCurrent3V3(&status); |
| 162 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 163 | return retVal; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Get the enabled state of the 3.3V rail. The rail may be disabled due to a |
| 168 | * controller brownout, a short circuit on the rail, or controller over-voltage. |
| 169 | * |
| 170 | * @return The controller 3.3V rail enabled value. True for enabled. |
| 171 | */ |
| 172 | bool ControllerPower::GetEnabled3V3() { |
| 173 | int32_t status = 0; |
| 174 | bool retVal = HAL_GetUserActive3V3(&status); |
| 175 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 176 | return retVal; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Get the count of the total current faults on the 3.3V rail since the |
| 181 | * controller has booted. |
| 182 | * |
| 183 | * @return The number of faults |
| 184 | */ |
| 185 | int ControllerPower::GetFaultCount3V3() { |
| 186 | int32_t status = 0; |
| 187 | int retVal = HAL_GetUserCurrentFaults3V3(&status); |
| 188 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 189 | return retVal; |
| 190 | } |