package org.usfirst.frc2832.Robot_2016;

import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.Timer;

public class CANTalonCurrentSafety extends CANTalon {

	private class MonitorThread extends Thread {
		@Override
		public void run() {
			while (true) {
				if (getOutputCurrent() > 25) {
					disableControl();
				}else{
					enableControl();
				}
				Timer.delay(0.1);
			}
		}
	}
	public CANTalonCurrentSafety(int deviceNumber) {
		super(deviceNumber);
		(new MonitorThread()).start();
	}

	@Override
	public String getSmartDashboardType() {
		return null;
	}

}

@@ -119,198 +119,766 @@
 %0D%0A%0D%0A
-public class CANTalonCurrentSafety extends CANTalon %7B%0D%0A%0D%0A%09private class MonitorThread extends Thread %7B%0D%0A%09%09@Override%0D%0A%09%09public void run() %7B%0D%0A%09%09%09while (true) %7B%0D%0A%09%09%09%09if (getOutputCurrent() %3E 25
+/**%0D%0A * This class adds new behavior to CANTalon to give better safety%0D%0A * If you use this instead of CANTalon, the motor %3Cb%3Eshouldn't catch on fire.%3C/b%3E%0D%0A * @author Brendan%0D%0A *%0D%0A */%0D%0Apublic class CANTalonCurrentSafety extends CANTalon %7B%0D%0A%0D%0A%09/**%0D%0A%09 * A thread that monitors this motor's current.%0D%0A%09 * It disables the motor temporarily if the current goes too high.%0D%0A%09 * @author Brendan%0D%0A%09 *%0D%0A%09 */%0D%0A%09private class MonitorThread extends Thread %7B%0D%0A%09%09@Override%0D%0A%09%09public void run() %7B%0D%0A%09%09%09double current = 0;%0D%0A%09%09%09final double filter = 0.1666667;%0D%0A%09%09%09final double max = 30; // 30 Amps should not be violated in most cases%0D%0A%09%09%09%0D%0A%09%09%09while (true) %7B%0D%0A%09%09%09%09// Rolling Avg.%0D%0A%09%09%09%09current = filter * getOutputCurrent() + current * (1 - filter);%0D%0A%09%09%09%09if (current %3E max * 0.9
 ) %7B%0D
@@ -911,16 +911,42 @@
 %09%09%09%7Delse
+ if (current %3C max * 0.80)
 %7B%0D%0A%09%09%09%09%09

Improve rolling average