Skip to content

Commit

Permalink
Merge pull request #1 from Team3256/feat/Turret
Browse files Browse the repository at this point in the history
Feat/turret
  • Loading branch information
chaoticthegreat authored Sep 3, 2024
2 parents 46c3578 + 0d210b0 commit 09fbf66
Show file tree
Hide file tree
Showing 12 changed files with 562 additions and 9 deletions.
1 change: 1 addition & 0 deletions networktables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
92 changes: 92 additions & 0 deletions simgui-ds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"keyboardJoysticks": [
{
"axisConfig": [
{
"decKey": 65,
"incKey": 68
},
{
"decKey": 87,
"incKey": 83
},
{
"decKey": 69,
"decayRate": 0.0,
"incKey": 82,
"keyRate": 0.009999999776482582
}
],
"axisCount": 3,
"buttonCount": 4,
"buttonKeys": [
90,
88,
67,
86
],
"povConfig": [
{
"key0": 328,
"key135": 323,
"key180": 322,
"key225": 321,
"key270": 324,
"key315": 327,
"key45": 329,
"key90": 326
}
],
"povCount": 1
},
{
"axisConfig": [
{
"decKey": 74,
"incKey": 76
},
{
"decKey": 73,
"incKey": 75
}
],
"axisCount": 2,
"buttonCount": 4,
"buttonKeys": [
77,
44,
46,
47
],
"povCount": 0
},
{
"axisConfig": [
{
"decKey": 263,
"incKey": 262
},
{
"decKey": 265,
"incKey": 264
}
],
"axisCount": 2,
"buttonCount": 6,
"buttonKeys": [
260,
268,
266,
261,
269,
267
],
"povCount": 0
},
{
"axisCount": 0,
"buttonCount": 0,
"povCount": 0
}
]
}
5 changes: 5 additions & 0 deletions simgui.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"NetworkTables Info": {
"visible": true
}
}
5 changes: 5 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public static class FeatureFlags {

public static final boolean shooterRegenBraking = true;
public static final boolean kSwerveEnabled = true;
public static final boolean kClimbEnabled = true;
public static final boolean kIntakeEnabled = true;
public static final boolean kShooterEnabled = true;
public static final boolean kPivotShooterEnabled = true;
public static final boolean kTurretEnabled = true;
}

// Defaults from Monologue docs
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
import frc.robot.utils.NT4PublisherNoFMS;
import monologue.Logged;
import monologue.Monologue;
import org.littletonrobotics.junction.LogFileUtil;
import org.littletonrobotics.junction.LoggedRobot;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.wpilog.WPILOGReader;
import org.littletonrobotics.junction.networktables.NT4Publisher;
import org.littletonrobotics.junction.wpilog.WPILOGWriter;

/**
Expand Down Expand Up @@ -47,13 +46,16 @@ public void robotInit() {
1, ModuleType.kRev); // Ignore this "resource leak"; it was the example code from docs
} else {
setUseTiming(false); // Run as fast as possible
String logPath =
LogFileUtil
.findReplayLog(); // Pull the replay log from AdvantageScope (or prompt the user)
Logger.setReplaySource(new WPILOGReader(logPath)); // Read replay log
Logger.addDataReceiver(
new WPILOGWriter(
LogFileUtil.addPathSuffix(logPath, "_sim"))); // Save outputs to a new log
// String logPath =
// LogFileUtil
// .findReplayLog(); // Pull the replay log from AdvantageScope (or prompt the
// user)
// Logger.setReplaySource(new WPILOGReader(logPath)); // Read replay log
// Logger.addDataReceiver(
// new WPILOGWriter(
// LogFileUtil.addPathSuffix(logPath, "_sim"))); // Save outputs to a new log
Logger.addDataReceiver(new WPILOGWriter(""));
Logger.addDataReceiver(new NT4Publisher());
}

// Logger.disableDeterministicTimestamps() // See "Deterministic Timestamps" in
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import frc.robot.commands.Autos;
import frc.robot.commands.ExampleCommand;
import frc.robot.subsystems.ExampleSubsystem;
import frc.robot.subsystems.turret.*;

/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
Expand All @@ -25,6 +26,13 @@ public class RobotContainer {
// The robot's subsystems and commands are defined here...
private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem();

private final Turret turret =
new Turret(
Constants.FeatureFlags.kTurretEnabled,
new TurretIOTalonFX(),
new EncoderIOCancoder(TurretConstants.kCanCoderID1),
new EncoderIOCancoder(TurretConstants.kCanCoderID2));

// Replace with CommandPS4Controller or CommandJoystick if needed
private final CommandXboxController m_driverController =
new CommandXboxController(OperatorConstants.kDriverControllerPort);
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/frc/robot/subsystems/turret/EncoderIO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2024 FRC 3256
// https://github.com/Team3256
//
// Use of this source code is governed by a
// license that can be found in the LICENSE file at
// the root directory of this project.

package frc.robot.subsystems.turret;

import edu.wpi.first.math.geometry.Rotation2d;
import org.littletonrobotics.junction.AutoLog;

public interface EncoderIO {

@AutoLog
public static class EncoderIOInputs {
public double encoderPositionDegrees = 0.0;
public double encoderVelocity = 0.0;

public Rotation2d turretMotorAbsolutePosition = new Rotation2d();
}

public default void updateInputs(EncoderIOInputs inputs) {}

public default void zero() {}
}
50 changes: 50 additions & 0 deletions src/main/java/frc/robot/subsystems/turret/EncoderIOCancoder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2024 FRC 3256
// https://github.com/Team3256
//
// Use of this source code is governed by a
// license that can be found in the LICENSE file at
// the root directory of this project.

package frc.robot.subsystems.turret;

import com.ctre.phoenix6.BaseStatusSignal;
import com.ctre.phoenix6.StatusSignal;
import com.ctre.phoenix6.hardware.CANcoder;
import edu.wpi.first.math.util.Units;

public class EncoderIOCancoder implements EncoderIO {

private final CANcoder encoder;

private final StatusSignal<Double> encoderPosition;
private final StatusSignal<Double> encoderVelocity;

public EncoderIOCancoder(int canCoderID) {
encoder = new CANcoder(canCoderID, "mani");
var response = encoder.getConfigurator().apply(TurretConstants.canCoderConfig);

if (!response.isOK()) {
System.out.println(
"CANcoder ID " + canCoderID + " failed config with error " + response.getDescription());
}

encoderPosition = encoder.getAbsolutePosition();
encoderVelocity = encoder.getVelocity();

BaseStatusSignal.setUpdateFrequencyForAll(
TurretConstants.updateFrequency, encoderPosition, encoderVelocity);
encoder.optimizeBusUtilization();
}

@Override
public void updateInputs(EncoderIOInputs inputs) {
BaseStatusSignal.refreshAll(encoderPosition, encoderVelocity);
inputs.encoderPositionDegrees = Units.rotationsToDegrees(encoderPosition.getValueAsDouble());
inputs.encoderVelocity = encoderVelocity.getValueAsDouble();
}

@Override
public void zero() {
encoder.setPosition(0.0);
}
}
Loading

0 comments on commit 09fbf66

Please sign in to comment.