Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Fix Sporadic Temperature Reporting#41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
c325948909eaf3c04759f6977fd9b2db845aa746bd37861e4c1eee3c47e4d79325297b354d6b2498afcf32510fd1b2d90161c8c45a3eac27ec19e3bc6ef41aFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.carlmontrobotics.lib199; | ||
| public class MotorConfig { | ||
| public static final MotorConfig NEO = new MotorConfig(70, 40); | ||
| public static final MotorConfig NEO_550 = new MotorConfig(40, 20); | ||
| public final int temperatureLimitCelsius, currentLimitAmps; | ||
| public MotorConfig(int temperatureLimitCelsius, int currentLimitAmps) { | ||
| this.temperatureLimitCelsius = temperatureLimitCelsius; | ||
| this.currentLimitAmps = currentLimitAmps; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,7 +2,6 @@ | ||
| import java.util.Arrays; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.CopyOnWriteArrayList; | ||
| import com.ctre.phoenix.ErrorCode; | ||
| import com.revrobotics.CANSparkMax; | ||
| @@ -15,12 +14,15 @@ public final class MotorErrors { | ||
| private static final ConcurrentHashMap<Integer, CANSparkMax> temperatureSparks = new ConcurrentHashMap<>(); | ||
| private static final ConcurrentHashMap<Integer, Integer> sparkTemperatureLimits = new ConcurrentHashMap<>(); | ||
| private static final CopyOnWriteArrayList<Integer> overheatedSparks = new CopyOnWriteArrayList<>(); | ||
| private static final ConcurrentHashMap<Integer, Integer> overheatedSparks = new ConcurrentHashMap<>(); | ||
| private static final ConcurrentHashMap<CANSparkMax, Short> flags = new ConcurrentHashMap<>(); | ||
| private static final ConcurrentHashMap<CANSparkMax, Short> stickyFlags = new ConcurrentHashMap<>(); | ||
| public static final int kOverheatTripCount = 5; | ||
ProfessorAtomicManiac marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| static { | ||
| Lib199Subsystem.registerAsyncPeriodic(MotorErrors::doReportSparkMaxTemp); | ||
| Lib199Subsystem.registerAsyncPeriodic(MotorErrors::printSparkMaxErrorMessages); | ||
| } | ||
| public static void reportError(ErrorCode error) { | ||
| @@ -108,16 +110,30 @@ public static void reportSparkMaxTemp(CANSparkMax spark, int temperatureLimit) { | ||
| int id = spark.getDeviceId(); | ||
| temperatureSparks.put(id, spark); | ||
| sparkTemperatureLimits.put(id, temperatureLimit); | ||
| overheatedSparks.put(id, 0); | ||
| } | ||
| public static void doReportSparkMaxTemp() { | ||
| temperatureSparks.forEach((port, spark) -> { | ||
| double temp = spark.getMotorTemperature(); | ||
| double limit = sparkTemperatureLimits.get(port); | ||
| int numTrips = overheatedSparks.get(port); | ||
| SmartDashboard.putNumber("Port " + port + " Spark Max Temp", temp); | ||
| if(numTrips < kOverheatTripCount) { | ||
| if(temp > limit) { | ||
| overheatedSparks.put(port, ++numTrips); | ||
| } else { | ||
| overheatedSparks.put(port, 0); | ||
| } | ||
| } | ||
| // Check if temperature exceeds the setpoint or if the controller has already overheated to prevent other code from resetting the current limit after the controller has cooled | ||
| if(temp >= sparkTemperatureLimits.get(port) || overheatedSparks.contains(port)) { | ||
| if(!overheatedSparks.contains(port)) { | ||
| overheatedSparks.add(port); | ||
| if(numTrips >= kOverheatTripCount) { | ||
| if(numTrips < kOverheatTripCount + 1) { | ||
| // Set trip count to kOverheatTripCount + 1 to flag that an error message has already been printed | ||
| // This prevents the error message from being re-printed every time the periodic method is run | ||
| overheatedSparks.put(port, kOverheatTripCount + 1); | ||
CoolSpy3 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| System.err.println("Port " + port + " spark max is operating at " + temp + " degrees Celsius! It will be disabled until the robot code is restarted."); | ||
CoolSpy3 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| spark.setSmartCurrentLimit(1); | ||
ProfessorAtomicManiac marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
Uh oh!
There was an error while loading. Please reload this page.