Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Game Piece Visualization via Maple Sim #169

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 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
2 changes: 1 addition & 1 deletion src/main/kotlin/frc/robot/RobotContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@
* calls). Instead, the structure of the robot (including subsystems, commands,
* and trigger mappings) should be declared here.
*/
object RobotContainer {
object RobotContainer {

private val driverController = CommandPS5Controller(0)
private val operatorController = CommandXboxController(1)
private val testController = CommandXboxController(2)

Check warning on line 34 in src/main/kotlin/frc/robot/RobotContainer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "testController" is never used

private val swerveDrive = frc.robot.swerveDrive
private val vision = frc.robot.vision

Check warning on line 37 in src/main/kotlin/frc/robot/RobotContainer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "vision" is never used
private val climber = frc.robot.climber

Check warning on line 38 in src/main/kotlin/frc/robot/RobotContainer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "climber" is never used
private val elevator = frc.robot.elevator
private val gripper = frc.robot.gripper
private val extender = frc.robot.extender
private val roller = frc.robot.roller

Check warning on line 42 in src/main/kotlin/frc/robot/RobotContainer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "roller" is never used
private val wrist = frc.robot.wrist

Check warning on line 43 in src/main/kotlin/frc/robot/RobotContainer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "wrist" is never used
val visualizer: Visualizer
val voltage = Units.Volts.of(1.0)

Expand All @@ -58,7 +58,7 @@
}

@AutoLogOutput(key = "MapleSimPose")
private fun getMapleSimPose(): Pose2d? =

Check warning on line 61 in src/main/kotlin/frc/robot/RobotContainer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "getMapleSimPose" is never used
driveSimulation?.simulatedDriveTrainPose

private fun getDriveCommandReal(): Command =
Expand Down Expand Up @@ -124,7 +124,7 @@
DriveCommands.wheelRadiusCharacterization(swerveDrive)

private fun registerAutoCommands() {
fun register(name: String, command: Command) =

Check warning on line 127 in src/main/kotlin/frc/robot/RobotContainer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "register" is never used
NamedCommands.registerCommand(name, command)
}
}
2 changes: 2 additions & 0 deletions src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,65 @@
import edu.wpi.first.units.measure.Distance
import frc.robot.IS_RED

fun Translation2d.getRotationToTranslation(other: Translation2d): Rotation2d =

Check warning on line 11 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "getRotationToTranslation" is never used
(this - other).angle

fun Pose2d.flip(): Pose2d = FlippingUtil.flipFieldPose(this)

Check warning on line 14 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "flip" is never used

fun Pose2d.toPose3d(): Pose3d = Pose3d(this)

Check warning on line 16 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "toPose3d" is never used

fun Pose2d.flipIfNeeded(): Pose2d = if (IS_RED) this.flip() else this

Check warning on line 18 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "flipIfNeeded" is never used

fun Pose2d.withTranslation(translation: Translation2d): Pose2d =

Check warning on line 20 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "withTranslation" is never used
Pose2d(translation, this.rotation)

fun Pose2d.withRotation(rotation: Rotation2d): Pose2d =

Check warning on line 23 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "withRotation" is never used
Pose2d(this.translation, rotation)

fun Pose3d.withRotation(rotation: Rotation3d): Pose3d =

Check warning on line 26 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "withRotation" is never used
Pose3d(this.translation, rotation)

fun Pose3d.withRotation(

Check warning on line 29 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "withRotation" is never used
roll: Double = 0.0,
pitch: Double = 0.0,
yaw: Double = 0.0
): Pose3d = Pose3d(this.translation, Rotation3d(roll, pitch, yaw))

fun Pose3d.withRotation(

Check warning on line 35 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "withRotation" is never used
roll: Angle = Rotations.zero(),
pitch: Angle = Rotations.zero(),
yaw: Angle = Rotations.zero(),
): Pose3d = Pose3d(this.translation, Rotation3d(roll, pitch, yaw))

fun Pose2d.toTransform(): Transform2d =

Check warning on line 41 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "toTransform" is never used
Transform2d(this.translation, this.rotation)

fun Pose2d.distanceFromPoint(translationMeters: Translation2d): Distance =

Check warning on line 44 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "distanceFromPoint" is never used
Units.Meters.of(this.translation.getDistance(translation))

fun Pose3d.toTransform(): Transform3d =

Check warning on line 47 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "toTransform" is never used
Transform3d(this.translation, this.rotation)

fun Translation2d.flip(): Translation2d = FlippingUtil.flipFieldPosition(this)

Check warning on line 50 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "flip" is never used

fun Translation2d.flipIfNeeded(): Translation2d =

Check warning on line 52 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "flipIfNeeded" is never used
if (IS_RED) this.flip() else this

fun Translation2d.toTransform(): Transform2d = Transform2d(this, Rotation2d())

Check warning on line 55 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "toTransform" is never used

fun Translation2d.toPose(): Pose2d = Pose2d(this, Rotation2d())

Check warning on line 57 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "toPose" is never used

fun Translation2d.rotationToPoint(targetPoint: Translation2d): Rotation2d =

Check warning on line 59 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "rotationToPoint" is never used
Rotation2d(targetPoint.x - this.x, targetPoint.y - this.y)

fun Rotation2d.flip(): Rotation2d = FlippingUtil.flipFieldRotation(this)

Check warning on line 62 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "flip" is never used

fun Rotation2d.flipIfNeeded(): Rotation2d = if (IS_RED) this.flip() else this

Check warning on line 64 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "flipIfNeeded" is never used

fun Rotation2d.toTransform(): Transform2d = Transform2d(Translation2d(), this)

Check warning on line 66 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "toTransform" is never used

fun Rotation2d.toPose(): Pose2d = Pose2d(Translation2d(), this)

Check warning on line 68 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "toPose" is never used

fun Transform2d.toPose(): Pose2d = Pose2d(this.translation, this.rotation)

Check warning on line 70 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "toPose" is never used

fun Transform3d.toPose(): Pose3d = Pose3d(this.translation, this.rotation)

Check warning on line 72 in src/main/kotlin/frc/robot/lib/GeomExtensionFunctions.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "toPose" is never used
11 changes: 7 additions & 4 deletions src/main/kotlin/frc/robot/subsystems/ReefCommands.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package frc.robot.subsystems

import edu.wpi.first.math.geometry.Rotation2d

Check warning on line 3 in src/main/kotlin/frc/robot/subsystems/ReefCommands.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import edu.wpi.first.units.Units
import edu.wpi.first.wpilibj2.command.Command
import edu.wpi.first.wpilibj2.command.Commands.*
import edu.wpi.first.wpilibj2.command.button.Trigger
import frc.robot.*
import frc.robot.lib.getRotation2d

Check warning on line 9 in src/main/kotlin/frc/robot/subsystems/ReefCommands.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import frc.robot.lib.getRotation3d

Check warning on line 10 in src/main/kotlin/frc/robot/subsystems/ReefCommands.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import frc.robot.lib.getTranslation2d
import frc.robot.subsystems.elevator.Positions
import org.ironmaple.simulation.SimulatedArena
Expand All @@ -14,13 +17,13 @@

private val CORAL_SHOOT_OFFSET =
getTranslation2d(Units.Meters.of(0.40), Units.Meters.of(0.0))
private val GRIPPER_HEIGHT = Units.Meters.of(0.50)
private val GRIPPER_HEIGHT = Units.Meters.of(0.9)
private val CORAL_SHOOT_SPEED = Units.MetersPerSecond.of(3.0)
private val CORAL_L4_SHOOT_ANGLE = Units.Degrees.of(-80.0)
private val WRIST_ANGLE_OFFSET = Units.Degrees.of(35.0)

private fun visualizeCoralOuttake(): Command =
runOnce({

Check notice on line 26 in src/main/kotlin/frc/robot/subsystems/ReefCommands.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Lambda argument inside parentheses

Lambda argument should be moved out of parentheses
if (!gripper.hasCoral.asBoolean) return@runOnce

val arena = SimulatedArena.getInstance()
Expand Down Expand Up @@ -49,15 +52,15 @@
)
})

fun visualizeCoralOuttakeIfNeeded(): Command = visualizeCoralOuttake().onlyIf { CURRENT_MODE != Mode.REAL }

private fun scoreCoral(endTrigger: Trigger): Command =
sequence(
waitUntil(endTrigger),
gripper
.outtake()
.withTimeout(CORAL_OUTTAKE_TIMEOUT)
.alongWith(
visualizeCoralOuttake().onlyIf { CURRENT_MODE != Mode.REAL }
),
.alongWith(visualizeCoralOuttakeIfNeeded()),
moveDefaultPosition()
)

Expand Down Expand Up @@ -109,4 +112,4 @@
gripper.intake().until(gripper.hasCoral).andThen(moveDefaultPosition())
)

fun retract(): Command = parallel(elevator.zero(), wrist.retract())

Check warning on line 115 in src/main/kotlin/frc/robot/subsystems/ReefCommands.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "retract" is never used
43 changes: 37 additions & 6 deletions src/main/kotlin/frc/robot/subsystems/Visualizer.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package frc.robot.subsystems

import edu.wpi.first.math.geometry.Pose3d
import edu.wpi.first.math.geometry.Translation2d
import edu.wpi.first.math.geometry.Translation3d
import edu.wpi.first.math.geometry.*
import edu.wpi.first.units.Units.*
import edu.wpi.first.units.measure.Angle
import frc.robot.lib.getPose3d
import frc.robot.lib.getRotation3d
import frc.robot.lib.getTranslation3d
import frc.robot.CURRENT_MODE
import frc.robot.Mode
import frc.robot.driveSimulation
import frc.robot.lib.*
import frc.robot.roller
import frc.robot.subsystems.drive.Drive
import kotlin.math.cos
Expand Down Expand Up @@ -53,6 +52,10 @@

private val gripper = frc.robot.gripper

private val ALGAE_OFFSET = Transform3d(0.4, 0.0, 0.35, Rotation3d())

Check notice on line 55 in src/main/kotlin/frc/robot/subsystems/Visualizer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Private property naming convention

Private property name `ALGAE_OFFSET` should not contain underscores in the middle or the end
private val CORAL_HEIGHT_OFFSET = getPose3d(z = 0.07)

Check notice on line 56 in src/main/kotlin/frc/robot/subsystems/Visualizer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Private property naming convention

Private property name `CORAL_HEIGHT_OFFSET` should not contain underscores in the middle or the end
private val CORAL_ANGLE_OFFSET = Degrees.of(25.0)

Check notice on line 57 in src/main/kotlin/frc/robot/subsystems/Visualizer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Private property naming convention

Private property name `CORAL_ANGLE_OFFSET` should not contain underscores in the middle or the end

private fun getElevatorPoses(): Pair<Pose3d, Pose3d> {

val secondStageHeight = elevator.height.invoke().`in`(Meters)
Expand All @@ -71,6 +74,34 @@
return Pair(firstStagePose, secondStagePose)
}

@AutoLogOutput(key = "Visualizer/AlgaePoseInRobot")
private fun getAlgaePose(): Pose3d? =

Check warning on line 78 in src/main/kotlin/frc/robot/subsystems/Visualizer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "getAlgaePose" is never used
if (CURRENT_MODE != Mode.REAL && roller.shouldVisualizeAlgaeInSim())
driveSimulation
?.simulatedDriveTrainPose
?.toPose3d()
?.plus(ALGAE_OFFSET)
else Pose3d()

@AutoLogOutput(key = "Visualizer/CoralPoseInRobot")
private fun getCoralPose(): Pose3d? =

Check warning on line 87 in src/main/kotlin/frc/robot/subsystems/Visualizer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "getCoralPose" is never used
if (CURRENT_MODE != Mode.REAL && gripper.hasCoral.asBoolean)
driveSimulation
?.simulatedDriveTrainPose
?.toPose3d()
?.plus(
getGripperRollerPose(
CORAL_ROLLER_UP_C2C[0],
CORAL_ROLLER_UP_C2C[1]
)
.minus(CORAL_HEIGHT_OFFSET)
)
?.withRotation(
pitch = -wrist.angle.invoke() + CORAL_ANGLE_OFFSET,
yaw = driveSimulation.simulatedDriveTrainPose.rotation.measure!! //
)
else Pose3d()

private fun getSwerveModulePoseTurn(
moduleX: Double,
moduleY: Double,
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/frc/robot/subsystems/drive/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
DriveTrainSimulationConfig.Default()
.withRobotMass(Kilograms.of(ROBOT_MASS_KG))
.withCustomModuleTranslations(getModuleTranslations())
.withBumperSize(Meters.of(0.851), Meters.of(0.851))
.withGyro(COTS.ofNav2X())
.withSwerveModule(
new SwerveModuleSimulationConfig(
Expand Down Expand Up @@ -139,7 +140,7 @@
new SwerveModulePosition(),
new SwerveModulePosition()
};
private SwerveDrivePoseEstimator poseEstimator =

Check warning on line 143 in src/main/kotlin/frc/robot/subsystems/drive/Drive.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `poseEstimator` may be 'final'
new SwerveDrivePoseEstimator(
kinematics, rawGyroRotation, lastModulePositions, new Pose2d());

Expand Down
11 changes: 7 additions & 4 deletions src/main/kotlin/frc/robot/subsystems/gripper/Gripper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import edu.wpi.first.wpilibj2.command.Command
import edu.wpi.first.wpilibj2.command.SubsystemBase
import edu.wpi.first.wpilibj2.command.button.Trigger
import frc.robot.subsystems.visualizeCoralOuttakeIfNeeded
import org.littletonrobotics.junction.AutoLogOutput
import org.littletonrobotics.junction.Logger
import org.littletonrobotics.junction.networktables.LoggedNetworkNumber

class Gripper(private val io: GripperIO) : SubsystemBase() {
private val kV = 6

Check warning on line 16 in src/main/kotlin/frc/robot/subsystems/gripper/Gripper.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "kV" is never used
var rollerAngle: Angle = Units.Rotations.zero()
private val tuningVoltage =
LoggedNetworkNumber("/Tuning/Gripper/Voltage", 0.0)
Expand All @@ -28,29 +29,31 @@
private fun setVoltage(voltage: Voltage): Command =
startEnd({ io.setVoltage(voltage) }, { io.setVoltage(STOP_VOLTAGE) })

private fun getVoltage(): Double {

Check warning on line 32 in src/main/kotlin/frc/robot/subsystems/gripper/Gripper.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "getVoltage" is never used
return io.inputs.appliedVoltage.`in`(Units.Volts)
}
fun tuningVoltage(): Command =

Check warning on line 35 in src/main/kotlin/frc/robot/subsystems/gripper/Gripper.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "tuningVoltage" is never used
setVoltage(Units.Volts.of(tuningVoltage.get()))
.withName("Gripper/Tuning")

fun intake(): Command =
setVoltage(INTAKE_VOLTAGE).withName("Gripper/Intake")

private fun outtakeCommand(voltage: Voltage): Command = setVoltage(voltage).alongWith(visualizeCoralOuttakeIfNeeded())

fun slowOuttake(): Command =

Check warning on line 44 in src/main/kotlin/frc/robot/subsystems/gripper/Gripper.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "slowOuttake" is never used
setVoltage(SLOW_OUTTAKE_VOLTAGE).withName("Gripper/SlowOuttake")
outtakeCommand(SLOW_OUTTAKE_VOLTAGE).withName("Gripper/SlowOuttake")

fun outtake(): Command =
setVoltage(OUTTAKE_VOLTAGE).withName("Gripper/Outtake")
outtakeCommand(OUTTAKE_VOLTAGE).withName("Gripper/Outtake")

fun fastOuttake(): Command = setVoltage(Units.Volts.of(-10.0))
fun fastOuttake(): Command = outtakeCommand(FAST_OUTTAKE_VOLTAGE).withName("Gripper/FastOuttake")

fun removeAlgae(): Command =
setVoltage(REMOVE_ALGAE_VOLTAGE).withName("Gripper/RemoveAlgae")

override fun periodic() {
rollerAngle += Units.Rotations.of(getVoltage() * kV * 0.02)
rollerAngle += Units.Rotations.of(getVoltage() * kV * -0.02) //
io.updateInputs()
Logger.processInputs(this::class.simpleName, io.inputs)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import edu.wpi.first.units.measure.Voltage

const val GEAR_RATIO = 1.0 // TODO: Replace with real value

val DEFAULT_SENSOR_SIMULATION_DISTANCE: Distance = Units.Centimeters.of(20.0)
val DISTANCE_THRESHOLD: Distance = Units.Centimeters.of(14.2)
val INTAKE_VOLTAGE: Voltage = Units.Volts.of(7.5)
val OUTTAKE_VOLTAGE: Voltage = Units.Volts.of(-9.0)
val SLOW_OUTTAKE_VOLTAGE: Voltage = Units.Volts.of(-1.5)
val FAST_OUTTAKE_VOLTAGE: Voltage = Units.Volts.of(-10.0)
val REMOVE_ALGAE_VOLTAGE: Voltage = Units.Volts.of(12.0) // TODO: Calibrate
val STOP_VOLTAGE: Voltage = Units.Volts.zero()
val MOMENT_OF_INERTIA: MomentOfInertia =
Expand Down
12 changes: 11 additions & 1 deletion src/main/kotlin/frc/robot/subsystems/gripper/GripperIOSim.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import org.littletonrobotics.junction.networktables.LoggedNetworkNumber
class GripperIOSim : GripperIO {
override val inputs = LoggedGripperInputs()
private var sensorDistance =
LoggedNetworkNumber("/Tuning/Gripper/SensorDistance", 20.0)
LoggedNetworkNumber(
"/Tuning/Gripper/SensorDistance",
DEFAULT_SENSOR_SIMULATION_DISTANCE.`in`(Units.Centimeters)
)

private val motor =
TalonFXSim(
Expand All @@ -32,6 +35,13 @@ class GripperIOSim : GripperIO {
inputs.sensorDistance.mut_replace(
Units.Centimeters.of(sensorDistance.get())
)

if (inputs.appliedVoltage < Units.Volts.zero()) {
sensorDistance.set(
DEFAULT_SENSOR_SIMULATION_DISTANCE.`in`(Units.Centimeters)
)
}
Comment on lines +39 to +43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is not obvious. Is that just making the sensor return true once the rollers rotate?
It's better to have a trigger that'll handle it. Also, add a small debounce (the coral isn't intake'd instantly).


inputs.appliedVoltage.mut_replace(motor.appliedVoltage)
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/frc/robot/subsystems/intake/roller/Roller.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import edu.wpi.first.units.measure.Voltage
import edu.wpi.first.wpilibj2.command.Command
import edu.wpi.first.wpilibj2.command.SubsystemBase
import org.littletonrobotics.junction.AutoLogOutput
import org.littletonrobotics.junction.Logger
import org.littletonrobotics.junction.networktables.LoggedNetworkNumber

class Roller(private val io: RollerIO) : SubsystemBase() {
private var kV = 2

Check warning on line 13 in src/main/kotlin/frc/robot/subsystems/intake/roller/Roller.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "kV" is never used
var rollerAngle: Angle = Units.Rotations.zero()
private val tuningVoltage =
LoggedNetworkNumber("Tuning/Roller/Voltage", 0.0)
Expand All @@ -21,12 +22,18 @@
)
.withName("Roller/setVoltage")

fun setTuningVoltage(): Command =

Check warning on line 25 in src/main/kotlin/frc/robot/subsystems/intake/roller/Roller.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "setTuningVoltage" is never used
setVoltage(Units.Volts.of(tuningVoltage.get()))
.withName("Roller/Voltage")
fun getVoltage(): Double {

Check warning on line 28 in src/main/kotlin/frc/robot/subsystems/intake/roller/Roller.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "getVoltage" is never used
return io.inputs.appliedVoltage.baseUnitMagnitude()
}

@AutoLogOutput(key = "VisualizeAlgaeInSim")
// THIS SHOULD ONLY BE USED IN THE SIMULATION!!
fun shouldVisualizeAlgaeInSim(): Boolean =
io.getIntakeSimulation()?.gamePiecesAmount != 0

fun intake() = setVoltage(INTAKE_VOLTAGE).withName("Roller/intake")

fun outtake() = setVoltage(OUTTAKE_VOLTAGE).withName("Roller/outtake")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ val INTAKE_VOLTAGE: Voltage = Units.Volts.of(-0.7 * 12.0)
val OUTTAKE_VOLTAGE: Voltage = Units.Volts.of(0.8 * 12.0)
val CORAL_OUTTAKE_TRANSLATION: Translation2d =
getTranslation2d(Units.Meters.of(0.3))
val CORAL_OUTTAKE_HEIGHT: Distance = Units.Meter.of(0.4)
val CORAL_OUTTAKE_VELOCITY: LinearVelocity = Units.MetersPerSecond.of(3.0)
val CORAL_OUTTAKE_ANGLE: Angle = Units.Degrees.zero()
val ALGAE_OUTTAKE_HEIGHT: Distance = Units.Meter.of(0.4)
val ALGAE_OUTTAKE_VELOCITY: LinearVelocity = Units.MetersPerSecond.of(3.0)
val ALGAE_OUTTAKE_ANGLE: Angle = Units.Degrees.zero()
val INTAKE_WIDTH: Distance = Units.Meters.of(0.64)
val INTAKE_LENGTH_EXTENDED: Distance = Units.Meters.of(0.35)
val FAR_OUTTAKE_VOLTAGE: Voltage = Units.Volts.of(0.7 * 12.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

import edu.wpi.first.units.Units
import edu.wpi.first.units.measure.Voltage
import org.ironmaple.simulation.IntakeSimulation
import org.team9432.annotation.Logged

interface RollerIO {
val inputs: LoggedRollerInputs

fun setVoltage(voltage: Voltage) {}

fun getIntakeSimulation(): IntakeSimulation? = null

fun updateInputs() {}

@Logged
open class RollerInputs {

Check warning on line 18 in src/main/kotlin/frc/robot/subsystems/intake/roller/RollerIO.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Class "RollerInputs" is never used
var appliedVoltage: Voltage = Units.Volts.zero()
}
}
15 changes: 10 additions & 5 deletions src/main/kotlin/frc/robot/subsystems/intake/roller/RollerIOSim.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
IntakeSimulation.IntakeSide.FRONT,
1
)

override fun getIntakeSimulation(): IntakeSimulation? {

Check warning on line 28 in src/main/kotlin/frc/robot/subsystems/intake/roller/RollerIOSim.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Redundant nullable return type

'getIntakeSimulation' always returns non-null type
return intakeSimulation
}

private val motor =
TalonFXSim(
1,
Expand All @@ -46,18 +51,18 @@
driveSimulation
.driveTrainSimulatedChassisSpeedsFieldRelative,
driveSimulation.simulatedDriveTrainPose.rotation,
CORAL_OUTTAKE_HEIGHT,
CORAL_OUTTAKE_VELOCITY,
CORAL_OUTTAKE_ANGLE
ALGAE_OUTTAKE_HEIGHT,
ALGAE_OUTTAKE_VELOCITY,
ALGAE_OUTTAKE_ANGLE
)
)
}

override fun setVoltage(voltage: Voltage) {
motor.setControl(controlRequest.withOutput(voltage))
if (voltage != Units.Volts.zero()) {
if (voltage < Units.Volts.zero()) {
intakeSimulation.startIntake()
} else {
} else if (voltage > Units.Volts.zero()) {
intakeSimulation.stopIntake()
Comment on lines +63 to 66
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use triggers here, too.

visualizeOuttakeGamePieceIfNeeded()
}
Expand Down
Loading