diff --git a/examples/stage1/stage1a/solutions/ctre/AdvantageScopeLayout.json b/examples/stage1/stage1a/solutions/ctre/AdvantageScopeLayout.json index 9884e272..faf791fc 100644 --- a/examples/stage1/stage1a/solutions/ctre/AdvantageScopeLayout.json +++ b/examples/stage1/stage1a/solutions/ctre/AdvantageScopeLayout.json @@ -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" } diff --git a/examples/stage1/stage1a/solutions/ctre/src/main/java/first/robot/Robot.java b/examples/stage1/stage1a/solutions/ctre/src/main/java/first/robot/Robot.java index 8625e5c8..f0aa2e1c 100644 --- a/examples/stage1/stage1a/solutions/ctre/src/main/java/first/robot/Robot.java +++ b/examples/stage1/stage1a/solutions/ctre/src/main/java/first/robot/Robot.java @@ -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 diff --git a/examples/stage1/stage1a/solutions/ctre/src/main/java/first/robot/simulation/DrivetrainSim.java b/examples/stage1/stage1a/solutions/ctre/src/main/java/first/robot/simulation/DrivetrainSim.java index 15ff3e39..c4f935dd 100644 --- a/examples/stage1/stage1a/solutions/ctre/src/main/java/first/robot/simulation/DrivetrainSim.java +++ b/examples/stage1/stage1a/solutions/ctre/src/main/java/first/robot/simulation/DrivetrainSim.java @@ -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( @@ -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 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(); /** @@ -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()); diff --git a/examples/stage1/stage1a/solutions/ctre/src/main/java/first/robot/simulation/SingleFlywheelSim.java b/examples/stage1/stage1a/solutions/ctre/src/main/java/first/robot/simulation/SingleFlywheelSim.java index 17ab22fb..2d34f674 100644 --- a/examples/stage1/stage1a/solutions/ctre/src/main/java/first/robot/simulation/SingleFlywheelSim.java +++ b/examples/stage1/stage1a/solutions/ctre/src/main/java/first/robot/simulation/SingleFlywheelSim.java @@ -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; @@ -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()); diff --git a/examples/stage1/stage1a/solutions/rev/AdvantageScopeLayout.json b/examples/stage1/stage1a/solutions/rev/AdvantageScopeLayout.json new file mode 100644 index 00000000..faf791fc --- /dev/null +++ b/examples/stage1/stage1a/solutions/rev/AdvantageScopeLayout.json @@ -0,0 +1,126 @@ +{ + "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 + }, + "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-5" +} diff --git a/examples/stage1/stage1a/solutions/rev/src/main/java/first/robot/simulation/SingleFlywheelSim.java b/examples/stage1/stage1a/solutions/rev/src/main/java/first/robot/simulation/SingleFlywheelSim.java index 8d312fe1..67ffc1ed 100644 --- a/examples/stage1/stage1a/solutions/rev/src/main/java/first/robot/simulation/SingleFlywheelSim.java +++ b/examples/stage1/stage1a/solutions/rev/src/main/java/first/robot/simulation/SingleFlywheelSim.java @@ -19,9 +19,9 @@ public class SingleFlywheelSim { private final FlywheelSim m_flywheelSim; private final DoublePublisher motorVoltagePub; - private final DoublePublisher rotorVelocityPub; + private final DoublePublisher motorVelocityPub; private final DoublePublisher currentPub; - private final DoublePublisher rotorPositionPub; + private final DoublePublisher motorPositionPub; private double rotorPositionRad; private static final double kBusVoltage = 12.0; @@ -37,9 +37,13 @@ public SingleFlywheelSim(SparkMax motor, String name) { var table = NetworkTableInstance.getDefault().getTable(this.name); this.motorVoltagePub = table.getDoubleTopic("MotorVoltage").publish(); - this.rotorVelocityPub = table.getDoubleTopic("RotorVelocity").publish(); + this.motorVelocityPub = table.getDoubleTopic("MotorVelocity").publish(); this.currentPub = table.getDoubleTopic("Current").publish(); - this.rotorPositionPub = table.getDoubleTopic("RotorPosition").publish(); + this.motorPositionPub = table.getDoubleTopic("MotorPosition").publish(); + + // Voltage and current properties aren't included since they default to volts and amps already + this.motorVelocityPub.getTopic().setProperty("unit", "\"RadiansPerSecond\""); + this.motorPositionPub.getTopic().setProperty("unit", "\"Radians\""); } public void periodic() { @@ -52,8 +56,8 @@ public void periodic() { rotorPositionRad += radPerSec * 0.02; motorVoltagePub.set(motorVoltage); - rotorVelocityPub.set(radPerSec); + motorVelocityPub.set(radPerSec); currentPub.set(m_flywheelSim.getCurrentDraw()); - rotorPositionPub.set(rotorPositionRad); + motorPositionPub.set(rotorPositionRad); } }