From 76a4fb72f750e6b4b8e5420223a8a6fd7a3d2aeb Mon Sep 17 00:00:00 2001 From: ErikCald Date: Fri, 15 Apr 2022 23:42:48 -0400 Subject: [PATCH] Prevent color sensor calls when not needed. This small change means the color sensor will only be called when the code asks instead of always. The code happens to always call the color sensor UNLESS the switch closest to the shooter is pressed. Hopefully this break in color sensor calls can fix the issue. In match 105 at DCMP, ColorSensorSubsystem.periodic was reported at taking 0.35s. Here is my detailed notes on what I found reading the driverstation logs: Loop overrun message, displays time of each subsystem/command: Match 68 -> All ColorSensorSubsystem.periodic were below 0.0025s Match 95 -> All ColorSensorSubsystem.periodic were below 0.0025s Match 105 Auto Period -> All ColorSensorSubsystem.periodic were below 0.0025s Match 105 Tele Period -> ALL ColorSensorSubsystem.periodic were ABOVE 0.35s The moment teleoperated started, ColorSensorSubsystem.periodic() was taking way too long to run. Motor safety was saying "hey, I haven't gotten a new percent output for the drivetrain motors in awhile I'm going to stop the motors from moving." Battery Voltage reported from the driver station, voltage was a flat line for over 20 seconds : Beginning of the match = 12.7 V End of the match = 12.3 V Number of reported brownouts = 7 --- .../frc/robot/subsystems/ColorSensorSubsystem.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/ColorSensorSubsystem.java b/src/main/java/frc/robot/subsystems/ColorSensorSubsystem.java index 4320269..8f11f0f 100644 --- a/src/main/java/frc/robot/subsystems/ColorSensorSubsystem.java +++ b/src/main/java/frc/robot/subsystems/ColorSensorSubsystem.java @@ -126,12 +126,11 @@ public RawColor getRawColor() { return colorSensor.getRawColor(); } - public boolean isDetected() { - return bDetectedCargo; - } + // public boolean isDetected() { + // return bDetectedCargo; + // } - @Override - public void periodic() { + public boolean isDetected() { //proximity sensor range: 1cm to 10cm @@ -168,5 +167,6 @@ else if(blue > BLUE_THRESHOLD && proximity > BLUE_PROXIMITY_THRESHOLD) detectBlue.setBoolean(isBlue); bDetectedCargo = isRed || isBlue; + return bDetectedCargo; } } \ No newline at end of file