Skip to content

Commit

Permalink
experimental can optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
JayK445 committed Apr 2, 2024
1 parent cd54fe0 commit d9c1617
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/frc/robot/subsystems/DrivebaseSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import static frc.robot.Constants.Drive.*;

import com.ctre.phoenix6.BaseStatusSignal;
import com.ctre.phoenix6.hardware.ParentDevice;
import com.ctre.phoenix6.mechanisms.swerve.SwerveDrivetrain;
import com.ctre.phoenix6.mechanisms.swerve.SwerveDrivetrainConstants;
import com.ctre.phoenix6.mechanisms.swerve.SwerveModule;
Expand Down Expand Up @@ -208,6 +210,10 @@ public DrivebaseSubsystem(VisionSubsystem visionSubsystem) {
swerveDrivetrain.getModule(2),
swerveDrivetrain.getModule(3)
};

for(SwerveModule swerveModule : swerveModules) {
// disables all unspecified CAN signals, OK because api does for us
ParentDevice.optimizeBusUtilizationForAll(swerveModule.getDriveMotor(), swerveModule.getSteerMotor(), swerveModule.getCANcoder()); }
} else {
swerveDrivetrain = null;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/frc/robot/subsystems/PivotSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public PivotSubsystem() {
pivotMotor.setInverted(true);
pivotMotor.clearStickyFaults();
pivotMotor.set(0);
pivotMotor.optimizeBusUtilization(); // disable all CAN signals, OK because relies on encoder anyways

pivotMotor.setNeutralMode(NeutralModeValue.Brake);

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/frc/robot/subsystems/ShooterSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

package frc.robot.subsystems;

import com.ctre.phoenix6.BaseStatusSignal;
import com.ctre.phoenix6.controls.Follower;
import com.ctre.phoenix6.controls.VelocityVoltage;
import com.ctre.phoenix6.hardware.ParentDevice;
import com.ctre.phoenix6.hardware.TalonFX;
import com.ctre.phoenix6.signals.NeutralModeValue;
import edu.wpi.first.networktables.GenericEntry;
Expand Down Expand Up @@ -87,6 +89,9 @@ public ShooterSubsystem() {
acceleratorMotor.clearStickyFaults();
rollerMotorBottom.clearStickyFaults();

ParentDevice.optimizeBusUtilizationForAll(rollerMotorTop, rollerMotorBottom); // disables all CAN status signals
BaseStatusSignal.setUpdateFrequencyForAll(100, rollerMotorTop.getVelocity(), rollerMotorBottom.getVelocity()); // specifies which CAN signal to enable

rollerMotorBottom.setControl(new Follower(rollerMotorTop.getDeviceID(), false));

acceleratorMotor.setInverted(true);
Expand Down

0 comments on commit d9c1617

Please sign in to comment.