This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for CANcoder to MaroonFramework (#21)
* start adding support for CANcoder in MaroonFramework * remove CANcoderEncoder.get() * add support for CANcoders * responding to PR comments
- Loading branch information
Showing
8 changed files
with
118 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.team766.hal.wpilib; | ||
|
||
import com.ctre.phoenix6.StatusSignal; | ||
import com.ctre.phoenix6.hardware.CANcoder; | ||
import com.team766.hal.EncoderReader; | ||
import com.team766.logging.Category; | ||
import com.team766.logging.Logger; | ||
import com.team766.logging.Severity; | ||
|
||
public class CANcoderEncoder implements EncoderReader { | ||
|
||
private final CANcoder cancoder; | ||
private double distancePerPulse = 1; | ||
|
||
public CANcoderEncoder(int deviceId) { | ||
cancoder = new CANcoder(deviceId); | ||
} | ||
|
||
public CANcoderEncoder(int deviceId, String canBus) { | ||
cancoder = new CANcoder(deviceId, canBus); | ||
} | ||
|
||
@Override | ||
public double getDistance() { | ||
StatusSignal<Double> position = cancoder.getPosition(); | ||
if (!position.getStatus().isOK()) { | ||
Logger.get(Category.HAL) | ||
.logData( | ||
Severity.ERROR, | ||
"Unable to get position: %s", | ||
position.getStatus().toString()); | ||
return 0; | ||
} | ||
return distancePerPulse * position.getValueAsDouble(); | ||
} | ||
|
||
@Override | ||
public double getRate() { | ||
StatusSignal<Double> velocity = cancoder.getVelocity(); | ||
if (!velocity.getStatus().isOK()) { | ||
Logger.get(Category.HAL) | ||
.logData( | ||
Severity.ERROR, | ||
"Unable to get rate: %s", | ||
velocity.getStatus().toString()); | ||
return 0; | ||
} | ||
return distancePerPulse * velocity.getValueAsDouble(); | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
cancoder.setPosition(0); | ||
} | ||
|
||
@Override | ||
public void setDistancePerPulse(double distancePerPulse) { | ||
// each "pulse" is a rotation | ||
this.distancePerPulse = distancePerPulse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters