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