001package com.ctre.phoenix.motorcontrol; 002 003/** 004 * All the faults available to motor controllers 005 */ 006public class Faults { 007 /** 008 * Motor Controller is under 6.5V 009 */ 010 public boolean UnderVoltage; 011 /** 012 * Forward limit switch is tripped and device is trying to go forward 013 * Only trips when the device is limited 014 */ 015 public boolean ForwardLimitSwitch; 016 /** 017 * Reverse limit switch is tripped and device is trying to go reverse 018 * Only trips when the device is limited 019 */ 020 public boolean ReverseLimitSwitch; 021 /** 022 * Sensor is beyond forward soft limit and device is trying to go forward 023 * Only trips when the device is limited 024 */ 025 public boolean ForwardSoftLimit; 026 /** 027 * Sensor is beyond reverse soft limit and device is trying to go reverse 028 * Only trips when the device is limited 029 */ 030 public boolean ReverseSoftLimit; 031 /** 032 * Device detects hardware failure 033 */ 034 public boolean HardwareFailure; 035 /** 036 * Device was powered-on or reset while robot is enabled. 037 * Check your breakers and wiring. 038 */ 039 public boolean ResetDuringEn; 040 /** 041 * Device's sensor overflowed 042 */ 043 public boolean SensorOverflow; 044 /** 045 * Device detects its sensor is out of phase 046 */ 047 public boolean SensorOutOfPhase; 048 /** 049 * Not used, @see ResetDuringEn 050 */ 051 public boolean HardwareESDReset; 052 /** 053 * Remote Sensor is no longer detected on bus 054 */ 055 public boolean RemoteLossOfSignal; 056 /** 057 * API error detected. Make sure API and firmware versions are compatible. 058 */ 059 public boolean APIError; 060 /** 061 * Supply is well above the rated voltage of the hardware. This fault is specific to Brushless. 062 */ 063 public boolean SupplyOverV; 064 /** 065 * Supply is rapidly fluctuating and unstable. This fault is specific to Brushless. 066 */ 067 public boolean SupplyUnstable; 068 069 /** 070 * @return true if any faults are tripped 071 */ 072 public boolean hasAnyFault() { 073 return UnderVoltage | 074 ForwardLimitSwitch | 075 ReverseLimitSwitch | 076 ForwardSoftLimit | 077 ReverseSoftLimit | 078 HardwareFailure | 079 ResetDuringEn | 080 SensorOverflow | 081 SensorOutOfPhase | 082 HardwareESDReset | 083 RemoteLossOfSignal | 084 APIError | 085 SupplyOverV | 086 SupplyUnstable; 087 } 088 /** 089 * @return Current fault list as a bit field 090 */ 091 public int toBitfield() { 092 int retval = 0; 093 int mask = 1; 094 retval |= UnderVoltage ? mask : 0; mask <<= 1; 095 retval |= ForwardLimitSwitch ? mask : 0; mask <<= 1; 096 retval |= ReverseLimitSwitch ? mask : 0; mask <<= 1; 097 retval |= ForwardSoftLimit ? mask : 0; mask <<= 1; 098 retval |= ReverseSoftLimit ? mask : 0; mask <<= 1; 099 retval |= HardwareFailure ? mask : 0; mask <<= 1; 100 retval |= ResetDuringEn ? mask : 0; mask <<= 1; 101 retval |= SensorOverflow ? mask : 0; mask <<= 1; 102 retval |= SensorOutOfPhase ? mask : 0; mask <<= 1; 103 retval |= HardwareESDReset ? mask : 0; mask <<= 1; 104 retval |= RemoteLossOfSignal ? mask : 0; mask <<= 1; 105 retval |= APIError ? mask : 0; mask <<= 1; 106 retval |= SupplyOverV ? mask : 0; mask <<= 1; 107 retval |= SupplyUnstable ? mask : 0; mask <<= 1; 108 return retval; 109 } 110 /** 111 * Updates current fault list with specified bit field of faults 112 * 113 * @param bits bit field of faults to update with 114 */ 115 public void update(int bits) { 116 int mask = 1; 117 UnderVoltage = ((bits & mask)!=0) ? true : false; mask <<= 1; 118 ForwardLimitSwitch = ((bits & mask)!=0) ? true : false; mask <<= 1; 119 ReverseLimitSwitch = ((bits & mask)!=0) ? true : false; mask <<= 1; 120 ForwardSoftLimit = ((bits & mask)!=0) ? true : false; mask <<= 1; 121 ReverseSoftLimit = ((bits & mask)!=0) ? true : false; mask <<= 1; 122 HardwareFailure = ((bits & mask)!=0) ? true : false; mask <<= 1; 123 ResetDuringEn = ((bits & mask)!=0) ? true : false; mask <<= 1; 124 SensorOverflow = ((bits & mask)!=0) ? true : false; mask <<= 1; 125 SensorOutOfPhase = ((bits & mask)!=0) ? true : false; mask <<= 1; 126 HardwareESDReset = ((bits & mask)!=0) ? true : false; mask <<= 1; 127 RemoteLossOfSignal = ((bits & mask)!=0) ? true : false; mask <<= 1; 128 APIError = ((bits & mask)!=0) ? true : false; mask <<= 1; 129 SupplyOverV = ((bits & mask)!=0) ? true : false; mask <<= 1; 130 SupplyUnstable = ((bits & mask)!=0) ? true : false; mask <<= 1; 131 } 132 public Faults() { 133 UnderVoltage = false; 134 ForwardLimitSwitch = false; 135 ReverseLimitSwitch = false; 136 ForwardSoftLimit = false; 137 ReverseSoftLimit = false; 138 HardwareFailure =false; 139 ResetDuringEn = false; 140 SensorOverflow = false; 141 SensorOutOfPhase = false; 142 HardwareESDReset = false; 143 RemoteLossOfSignal = false; 144 APIError = false; 145 SupplyOverV = false; 146 SupplyUnstable = false; 147 } 148 /** 149 * @return string representation of current faults tripped 150 */ 151 public String toString() { 152 StringBuilder work = new StringBuilder(); 153 work.append(" UnderVoltage:"); work.append(UnderVoltage ? "1" : "0"); 154 work.append( " ForwardLimitSwitch:"); work.append(ForwardLimitSwitch ? "1" : "0"); 155 work.append( " ReverseLimitSwitch:"); work.append(ReverseLimitSwitch ? "1" : "0"); 156 work.append( " ForwardSoftLimit:"); work.append(ForwardSoftLimit ? "1" : "0"); 157 work.append( " ReverseSoftLimit:"); work.append(ReverseSoftLimit ? "1" : "0"); 158 work.append( " HardwareFailure:"); work.append(HardwareFailure ? "1" : "0"); 159 work.append( " ResetDuringEn:"); work.append(ResetDuringEn ? "1" : "0"); 160 work.append( " SensorOverflow:"); work.append(SensorOverflow ? "1" : "0"); 161 work.append( " SensorOutOfPhase:"); work.append(SensorOutOfPhase ? "1" : "0"); 162 work.append( " HardwareESDReset:"); work.append(HardwareESDReset ? "1" : "0"); 163 work.append( " RemoteLossOfSignal:"); work.append(RemoteLossOfSignal ? "1" : "0"); 164 work.append( " APIError:"); work.append(APIError ? "1" : "0"); 165 work.append( " SupplyOverV:"); work.append(SupplyOverV ? "1" : "0"); 166 work.append( " SupplyUnstable:"); work.append(SupplyUnstable ? "1" : "0"); 167 return work.toString(); 168 } 169}; 170