Skip to content
Open
Show file tree
Hide file tree
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
236 changes: 121 additions & 115 deletions examples/stage1/stage1a/solutions/ctre/AdvantageScopeLayout.json
Original file line number Diff line number Diff line change
@@ -1,120 +1,126 @@
{
"hubs": [
{
"x": 328,
"y": 194,
"width": 1101,
"height": 652,
"state": {
"sidebar": {
"width": 300,
"expanded": ["/DrivetrainSim"]
"hubs": [
{
"x": 328,
"y": 194,
"width": 1101,
"height": 652,
"state": {
"sidebar": {
"width": 300,
"expanded": [
"/DrivetrainSim",
"/IntakeLauncher",
"/Feeder",
"/Drivetrain"
]
},
"tabs": {
"selected": 2,
"tabs": [
{
"type": 0,
"title": "",
"controller": null,
"controllerUUID": "vlfwq7pm9tlj70qdvvq45nifwex34k2g",
"renderer": "",
"controlsHeight": 0
},
{
"type": 1,
"title": "",
"controller": {
"leftSources": [
{
"type": "stepped",
"logKey": "NT:/IntakeLauncher/MotorVoltage",
"logType": "Number",
"visible": true,
"options": {
"color": "#2b66a2",
"size": "normal"
}
},
{
"type": "stepped",
"logKey": "NT:/Feeder/MotorVoltage",
"logType": "Number",
"visible": true,
"options": {
"color": "#e5b31b",
"size": "normal"
}
}
],
"rightSources": [
{
"type": "stepped",
"logKey": "NT:/IntakeLauncher/MotorVelocity",
"logType": "Number",
"visible": true,
"options": {
"color": "#af2437",
"size": "normal"
}
},
{
"type": "stepped",
"logKey": "NT:/Feeder/MotorVelocity",
"logType": "Number",
"visible": true,
"options": {
"color": "#80588e",
"size": "normal"
}
}
],
"discreteSources": [],
"leftLockedRange": null,
"rightLockedRange": null,
"leftUnitConversion": {
"autoTarget": null,
"preset": null
},
"tabs": {
"selected": 1,
"tabs": [
{
"type": 0,
"title": "",
"controller": null,
"controllerUUID": "vlfwq7pm9tlj70qdvvq45nifwex34k2g",
"renderer": "",
"controlsHeight": 0
},
{
"type": 1,
"title": "Line Graph",
"controller": {
"leftSources": [
{
"type": "stepped",
"logKey": "NT:/intake/MotorVoltage",
"logType": "Number",
"visible": true,
"options": {
"color": "#2b66a2",
"size": "normal"
}
},
{
"type": "stepped",
"logKey": "NT:/shooter/MotorVoltage",
"logType": "Number",
"visible": true,
"options": {
"color": "#e5b31b",
"size": "normal"
}
}
],
"rightSources": [
{
"type": "stepped",
"logKey": "NT:/intake/MotorVelocity",
"logType": "Number",
"visible": true,
"options": {
"color": "#af2437",
"size": "normal"
}
},
{
"type": "stepped",
"logKey": "NT:/shooter/MotorVelocity",
"logType": "Number",
"visible": true,
"options": {
"color": "#80588e",
"size": "normal"
}
}
],
"discreteSources": [],
"leftLockedRange": null,
"rightLockedRange": null,
"leftUnitConversion": {
"autoTarget": null,
"preset": null
},
"rightUnitConversion": {
"autoTarget": null,
"preset": null
},
"leftFilter": 0,
"rightFilter": 0
},
"controllerUUID": "2htqlla9hnswdie42z4tmy5c6xlm59sh",
"renderer": null,
"controlsHeight": 200
},
{
"type": 2,
"title": "2D Field",
"controller": {
"sources": [
{
"type": "robot",
"logKey": "NT:SimPose",
"logType": "Pose2d",
"visible": true,
"options": {
"bumpers": ""
}
}
],
"field": "FRC:2026 Field",
"orientation": 3,
"size": "large"
},
"controllerUUID": "9ukgi1echibr7o0wodpgms6ajn3yic95",
"renderer": null,
"controlsHeight": 200
}
]
}
"rightUnitConversion": {
"autoTarget": null,
"preset": null
},
"leftFilter": 0,
"rightFilter": 0,
"showRobotMode": false
},
"controllerUUID": "2htqlla9hnswdie42z4tmy5c6xlm59sh",
"renderer": null,
"controlsHeight": 200
},
{
"type": 2,
"title": "",
"controller": {
"sources": [
{
"type": "robot",
"logKey": "NT:/Drivetrain/Pose",
"logType": "Pose2d",
"visible": true,
"options": {
"bumpers": ""
}
}
],
"field": "FRC:2026 Field",
"orientation": 3,
"size": "large"
},
"controllerUUID": "9ukgi1echibr7o0wodpgms6ajn3yic95",
"renderer": null,
"controlsHeight": 200
}
]
}
],
"satellites": [],
"version": "27.0.0-alpha-4"
}
}
],
"satellites": [],
"version": "27.0.0-alpha-5"
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class Robot extends OpModeRobot {

private DrivetrainSim drivetrainSim = new DrivetrainSim(leftLeader, rightLeader);
private SingleFlywheelSim intakeLauncherSim =
new SingleFlywheelSim(intakeLauncher, "intakeLauncher");
private SingleFlywheelSim feederSim = new SingleFlywheelSim(feeder, "feeder");
new SingleFlywheelSim(intakeLauncher, "IntakeLauncher");
private SingleFlywheelSim feederSim = new SingleFlywheelSim(feeder, "Feeder");

/**
* This function is run when the robot is first started up and should be used for any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class DrivetrainSim {
private final double kGearRatio = 10.71;
private final double kWheelRadiusMeters = Inches.of(3.0).in(Meters);
private final double linearToMotorRatio = (1.0 / kWheelRadiusMeters) * kGearRatio;
private static final double kBusVoltage = 12.0;

private final DifferentialDrivetrainSim driveSim =
new DifferentialDrivetrainSim(
Expand All @@ -46,49 +45,51 @@ public class DrivetrainSim {
Inches.of(21.5).in(Meters), // Distance between the left and right wheels
null);

// we add front slashes here so that the keys show up consistently between the CTRE and REV
// examples.
private final StructPublisher<Pose2d> simPosePublisher =
NetworkTableInstance.getDefault().getStructTopic("Drivetrain/Pose", Pose2d.struct).publish();
NetworkTableInstance.getDefault().getStructTopic("/Drivetrain/Pose", Pose2d.struct).publish();

private final DoublePublisher leftPositionPub =
NetworkTableInstance.getDefault().getDoubleTopic("Drivetrain/LeftPositionMeters").publish();
NetworkTableInstance.getDefault().getDoubleTopic("/Drivetrain/LeftPositionMeters").publish();

private final DoublePublisher rightPositionPub =
NetworkTableInstance.getDefault().getDoubleTopic("Drivetrain/RightPositionMeters").publish();
NetworkTableInstance.getDefault().getDoubleTopic("/Drivetrain/RightPositionMeters").publish();

private final DoublePublisher leftVelocityPub =
NetworkTableInstance.getDefault().getDoubleTopic("Drivetrain/LeftVelocityMPS").publish();
NetworkTableInstance.getDefault().getDoubleTopic("/Drivetrain/LeftVelocityMPS").publish();

private final DoublePublisher rightVelocityPub =
NetworkTableInstance.getDefault().getDoubleTopic("Drivetrain/RightVelocityMPS").publish();
NetworkTableInstance.getDefault().getDoubleTopic("/Drivetrain/RightVelocityMPS").publish();

private final DoublePublisher leftMotorVelocityPub =
NetworkTableInstance.getDefault()
.getDoubleTopic("Drivetrain/LeftMotor/MotorVelocityRPS")
.getDoubleTopic("/Drivetrain/LeftMotor/MotorVelocityRPS")
.publish();

private final DoublePublisher rightMotorVelocityPub =
NetworkTableInstance.getDefault()
.getDoubleTopic("Drivetrain/RightMotor/MotorVelocityRPS")
.getDoubleTopic("/Drivetrain/RightMotor/MotorVelocityRPS")
.publish();

private final DoublePublisher leftMotorVoltagePub =
NetworkTableInstance.getDefault()
.getDoubleTopic("Drivetrain/LeftMotor/MotorVoltage")
.getDoubleTopic("/Drivetrain/LeftMotor/MotorVoltage")
.publish();

private final DoublePublisher rightMotorVoltagePub =
NetworkTableInstance.getDefault()
.getDoubleTopic("Drivetrain/RightMotor/MotorVoltage")
.getDoubleTopic("/Drivetrain/RightMotor/MotorVoltage")
.publish();

private final DoublePublisher leftMotorSupplyCurrentPub =
NetworkTableInstance.getDefault()
.getDoubleTopic("Drivetrain/LeftMotor/MotorSupplyCurrent")
.getDoubleTopic("/Drivetrain/LeftMotor/MotorSupplyCurrent")
.publish();

private final DoublePublisher rightMotorSupplyCurrentPub =
NetworkTableInstance.getDefault()
.getDoubleTopic("Drivetrain/RightMotor/MotorSupplyCurrent")
.getDoubleTopic("/Drivetrain/RightMotor/MotorSupplyCurrent")
.publish();

/**
Expand All @@ -97,19 +98,16 @@ public class DrivetrainSim {
*/
public DrivetrainSim(TalonFX leftTalon, TalonFX rightTalon) {
this.leftTalon = leftTalon;
leftTalonSim = new TalonFXSimState(leftTalon, ChassisReference.CounterClockwise_Positive);
leftTalonSim = new TalonFXSimState(leftTalon, ChassisReference.Clockwise_Positive);
leftTalonSim.setMotorType(MotorType.KrakenX60);

this.rightTalon = rightTalon;
rightTalonSim = new TalonFXSimState(rightTalon, ChassisReference.Clockwise_Positive);
rightTalonSim = new TalonFXSimState(rightTalon, ChassisReference.CounterClockwise_Positive);
rightTalonSim.setMotorType(MotorType.KrakenX60);
}

public void periodic() {
double leftMotorVoltage = leftTalon.getThrottle() * kBusVoltage;
double rightMotorVoltage = rightTalon.getThrottle() * kBusVoltage;

driveSim.setInputs(leftMotorVoltage, rightMotorVoltage);
driveSim.setInputs(leftTalonSim.getMotorVoltage(), rightTalonSim.getMotorVoltage());
driveSim.update(0.02);

OnboardIMUSim.setYaw(driveSim.getHeading().getRadians());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ public SingleFlywheelSim(TalonFX talonMotor, String name) {
motorVelocityPub = table.getDoubleTopic("MotorVelocity").publish();
motorCurrentPub = table.getDoubleTopic("MotorStatorCurrent").publish();
motorPositionPub = table.getDoubleTopic("MotorPosition").publish();

// Voltage and current properties aren't included since they default to volts and amps already
motorVelocityPub.getTopic().setProperty("unit", "\"RotationsPerSecond\"");
motorPositionPub.getTopic().setProperty("unit", "\"Rotations\"");
}

public void periodic() {
double motorVoltage = talonMotor.getThrottle() * kBusVoltage;

flywheelSim.setInputVoltage(motorVoltage);
flywheelSim.setInputVoltage(talonMotorSim.getMotorVoltage());
flywheelSim.update(0.02);

double motorVelo = flywheelSim.getAngularVelocity() * gearRatio;
Expand All @@ -63,7 +65,7 @@ public void periodic() {
talonMotorSim.setRawRotorPosition(Radians.of(motorPosition));
talonMotorSim.setRotorVelocity(RadiansPerSecond.of(motorVelo));

motorVoltagePub.set(motorVoltage);
motorVoltagePub.set(talonMotor.getMotorVoltage().getValueAsDouble());
motorVelocityPub.set(talonMotor.getVelocity().getValueAsDouble());
motorCurrentPub.set(talonMotor.getStatorCurrent().getValueAsDouble());
motorPositionPub.set(talonMotor.getPosition().getValueAsDouble());
Expand Down
Loading