Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import xbot.common.command.SimpleWaitForMaintainerCommand;
import xbot.common.controls.actuators.XCANMotorController;
import xbot.common.controls.actuators.XCANMotorControllerPIDProperties;
import xbot.common.properties.AngularVelocityProperty;
import xbot.common.properties.DoubleProperty;
import xbot.common.properties.PropertyFactory;
import xbot.common.resiliency.DeviceHealth;
Expand All @@ -20,8 +21,6 @@
import java.util.List;

import static edu.wpi.first.units.Units.RPM;
import static edu.wpi.first.units.Units.Rotations;
import static edu.wpi.first.units.Units.RotationsPerSecond;
import static edu.wpi.first.units.Units.Seconds;

@Singleton
Expand All @@ -40,6 +39,8 @@ public class ShooterSubsystem extends BaseSetpointSubsystem<AngularVelocity, Dou

public AngularVelocity currentTargetVelocity = RPM.of(0);

public AngularVelocityProperty lowPowerModeVelocity;

private final Subsystem trimSetpointLock = new Subsystem() {

};
Expand Down Expand Up @@ -121,6 +122,7 @@ public ShooterSubsystem(XCANMotorController.XCANMotorControllerFactory xcanMotor
this.defaultShootingVelocity = this.propertyFactory.createPersistentProperty("Default Shooter Velocity RPM", 3000);
this.trimValue = this.propertyFactory.createPersistentProperty("Shooter Trim Value", 0);
this.readinessTimeoutSeconds = this.propertyFactory.createPersistentProperty("Readiness Timeout Seconds", 2.0);
this.lowPowerModeVelocity = this.propertyFactory.createPersistentProperty("LowPowerModeVelocity", RPM.of(150));
}

public void stop() {
Expand All @@ -142,9 +144,23 @@ public void decreaseShooterOffset() {
}

public void runMotorsAtVelocity(AngularVelocity velocity) {
for (var motor : getHealthyShooterMotors()) {
var allMotors = getShooterMotors();
var healthyMotors = getHealthyShooterMotors();
for (var motor : healthyMotors) {
motor.setVelocityTarget(velocity);
}

if (isInLowPowerMode) {
// In low power mode, we want all the other motors that are NOT our
// main healthy motor, that is still healthy.
var otherMotors = allMotors.stream()
.filter(motor -> !healthyMotors.contains(motor)
&& motor.getHealth() == DeviceHealth.Healthy)
.toList();
for (var motor : otherMotors) {
motor.setVelocityTarget(lowPowerModeVelocity.get());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should set the min value between lowPowerModeVelocity and velocity, otherwise when we're seeing 0rpm in general across all 3motors, this is going to cause 2 of them to spin right?

}
}
}

public boolean isReadyToFire() {
Expand Down