Skip to content

Commit

Permalink
10 update yagsl (#11)
Browse files Browse the repository at this point in the history
* Updated Configs

* Updated Configs

* Changed PID and max speed

* Changed PID and max speed

* updated conversion factor

* Update yagsl.json

* Changed PID

* Fixed Swerve

* Added Corner Rotation Support

---------

Co-authored-by: Micah Rao <[email protected]>
  • Loading branch information
falOn-Dev and Micah Rao authored Dec 25, 2023
1 parent 2ac80d2 commit 6575420
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 146 deletions.
18 changes: 9 additions & 9 deletions src/main/deploy/swerve/modules/backleft.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"location": {
"front": -10.3,
"left": 10.3
},
"absoluteEncoderOffset": 38.388,
"drive": {
"type": "sparkmax",
"id": 7,
Expand All @@ -9,18 +14,13 @@
"id": 10,
"canbus": null
},
"inverted": {
"angle": true,
"drive": false
},
"encoder": {
"type": "cancoder",
"id": 3,
"canbus": null
},
"inverted": {
"drive": false,
"angle": true
},
"absoluteEncoderOffset": 38.388,
"location": {
"front": -10.3,
"left": 10.3
}
}
18 changes: 9 additions & 9 deletions src/main/deploy/swerve/modules/backright.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
{
"location": {
"front": -10.3,
"left": -10.3
},
"absoluteEncoderOffset": 188.503,
"drive": {
"type": "sparkmax",
"id": 11,
"canbus": null
},
"inverted": {
"drive": true,
"angle": true
},
"angle": {
"type": "sparkmax",
"id": 13,
Expand All @@ -13,14 +22,5 @@
"type": "cancoder",
"id": 2,
"canbus": null
},
"inverted": {
"drive": true,
"angle": true
},
"absoluteEncoderOffset": 188.503,
"location": {
"front": -10.3,
"left": -10.3
}
}
18 changes: 9 additions & 9 deletions src/main/deploy/swerve/modules/frontleft.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"location": {
"front": 10.3,
"left": 10.3
},
"absoluteEncoderOffset": 111.955,
"drive": {
"type": "sparkmax",
"id": 8,
Expand All @@ -9,18 +14,13 @@
"id": 14,
"canbus": null
},
"inverted": {
"angle": true,
"drive": false
},
"encoder": {
"type": "cancoder",
"id": 5,
"canbus": null
},
"inverted": {
"drive": false,
"angle": true
},
"absoluteEncoderOffset": 111.955,
"location": {
"front": 10.3,
"left": 10.3
}
}
18 changes: 9 additions & 9 deletions src/main/deploy/swerve/modules/frontright.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
{
"location": {
"front": 10.3,
"left": -10.3
},
"absoluteEncoderOffset": 22.345,
"drive": {
"type": "sparkmax",
"id": 6,
"canbus": null
},
"inverted": {
"drive": true,
"angle": true
},
"angle": {
"type": "sparkmax",
"id": 1,
Expand All @@ -13,14 +22,5 @@
"type": "cancoder",
"id": 4,
"canbus": null
},
"inverted": {
"drive": true,
"angle": true
},
"absoluteEncoderOffset": 22.345,
"location": {
"front": 10.3,
"left": -10.3
}
}
18 changes: 7 additions & 11 deletions src/main/deploy/swerve/modules/physicalproperties.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
{
"wheelDiameter": 4,
"gearRatio": {
"drive": 8.14,
"angle": 21.42
},
"optimalVoltage": 12,
"wheelGripCoefficientOfFriction": 1.19,
"currentLimit": {
"drive": 40,
"angle": 20
},
"conversionFactor": {
"angle": 16.806722689075627,
"drive": 0.03921201641335663
},
"rampRate": {
"drive": 0.5,
"angle": 0.25
},
"encoderPulsePerRotation": {
"drive": 1,
"angle": 1
},
"wheelGripCoefficientOfFriction": 1.19
}
}
2 changes: 0 additions & 2 deletions src/main/deploy/swerve/swervedrive.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"maxSpeed": 12,
"optimalVoltage": 12,
"imu": {
"type": "pigeon2",
"id": 15,
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/frc/robot/RobotContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import edu.wpi.first.wpilibj2.command.button.Trigger
import frc.robot.Constants.OperatorConstants
import frc.robot.commands.Autos
import frc.robot.commands.ExampleCommand
import frc.robot.commands.swerve.TeleopDrive
import frc.robot.commands.swerve.CornerSpinCommand
import frc.robot.commands.swervedrive.drivebase.TeleopDrive
import frc.robot.commands.vision.TrackTargetCommand
import frc.robot.subsystems.ExampleSubsystem
import frc.robot.subsystems.LimelightSubsystem
Expand Down Expand Up @@ -40,7 +41,12 @@ object RobotContainer {
{ -controller.leftX },
{ -controller.rightX },
{ controller.hid.leftBumper },
false,
{ controller.hid.rightBumper }
)

val cornerSpin: CornerSpinCommand = CornerSpinCommand(
{ -controller.rightX },
{ controller.hid.leftBumper },
{ controller.hid.rightBumper }
)

Expand All @@ -64,5 +70,7 @@ object RobotContainer {
controller.b().onTrue(drivebase.runOnce { drivebase.zeroGyro() })

controller.a().toggleOnTrue(trackTarget)

controller.x().toggleOnTrue(cornerSpin)
}
}
56 changes: 56 additions & 0 deletions src/main/java/frc/robot/commands/swerve/CornerSpinCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package frc.robot.commands.swerve

import edu.wpi.first.wpilibj2.command.CommandBase
import SwerveSubsystem
import edu.wpi.first.math.geometry.Translation2d
import edu.wpi.first.math.util.Units
import frc.robot.util.SingletonXboxController
import swervelib.SwerveController
import java.util.function.BooleanSupplier
import java.util.function.DoubleSupplier

class CornerSpinCommand(rotation: DoubleSupplier, driveMode: BooleanSupplier,
slowMode: BooleanSupplier) : CommandBase() {
private val swerveSubsystem = SwerveSubsystem

private val rotation: DoubleSupplier

private val driveMode: BooleanSupplier
private val slowMode: BooleanSupplier

private val controller: SwerveController



init {
// each subsystem used by the command must be passed into the addRequirements() method
addRequirements(swerveSubsystem)
this.rotation = rotation
this.driveMode = driveMode
this.slowMode = slowMode

controller = swerveSubsystem.getSwerveController()
}

override fun initialize() {}

override fun execute() {
var rot = rotation.asDouble
val driveMode = driveMode.asBoolean

val center: Translation2d = SingletonXboxController.getPOVasCorner()

if(slowMode.asBoolean){
rot *= 0.6
}

swerveSubsystem.drive(Translation2d(0.0, 0.0), rot * controller.config.maxAngularVelocity, false, center)
}

override fun isFinished(): Boolean {
// TODO: Make this return true when this Command no longer needs to run execute()
return false
}

override fun end(interrupted: Boolean) {}
}
93 changes: 54 additions & 39 deletions src/main/java/frc/robot/commands/swerve/TeleopDrive.kt
Original file line number Diff line number Diff line change
@@ -1,67 +1,82 @@
package frc.robot.commands.swerve
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc.robot.commands.swervedrive.drivebase

import edu.wpi.first.wpilibj2.command.CommandBase
import SwerveSubsystem
import SwerveSubsystem.drive
import SwerveSubsystem.getSwerveController
import edu.wpi.first.math.geometry.Translation2d
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard
import edu.wpi.first.wpilibj2.command.CommandBase
import swervelib.SwerveController
import java.util.function.BooleanSupplier
import java.util.function.DoubleSupplier
import kotlin.contracts.contract

class TeleopDrive(vForward: DoubleSupplier, vSide: DoubleSupplier, omega: DoubleSupplier,
driveMode: BooleanSupplier, isOpenLoop: Boolean, slowMode: BooleanSupplier) : CommandBase() {
private val swerveSubsystem = SwerveSubsystem

private val vForward: DoubleSupplier
private val vSide: DoubleSupplier
/**
* An example command that uses an example subsystem.
*/
class TeleopDrive(
vX: DoubleSupplier, vY: DoubleSupplier, omega: DoubleSupplier,
driveMode: BooleanSupplier, slowMode: BooleanSupplier
) : CommandBase() {
private val vX: DoubleSupplier
private val vY: DoubleSupplier
private val omega: DoubleSupplier
private val driveMode: BooleanSupplier
private val isOpenLoop: Boolean
private val slowMode: BooleanSupplier

private val swerveController: SwerveController


private val controller: SwerveController
private val swerve: SwerveSubsystem

/**
* Creates a new ExampleCommand.
*
* @param swerve The subsystem used by this command.
*/
init {
// each subsystem used by the command must be passed into the addRequirements() method
addRequirements(swerveSubsystem)

this.vForward = vForward
this.vSide = vSide
this.swerve = SwerveSubsystem
this.vX = vX
this.vY = vY
this.omega = omega
this.driveMode = driveMode
this.isOpenLoop = isOpenLoop
this.slowMode = slowMode
this.swerveController = swerveSubsystem.getSwerveController()



controller = swerve.getSwerveController()
// Use addRequirements() here to declare subsystem dependencies.
addRequirements(swerve)
}

// Called when the command is initially scheduled.
override fun initialize() {}

// Called every time the scheduler runs while the command is scheduled.
override fun execute() {
var xVelocity = vForward.getAsDouble()
var yVelocity = vSide.getAsDouble()
var angleVelocity = omega.getAsDouble()

if(slowMode.asBoolean){
var xVelocity = vX.asDouble
var yVelocity = vY.asDouble
var angVelocity = omega.asDouble
val slowMode = slowMode.asBoolean
SmartDashboard.putNumber("vX", xVelocity)
SmartDashboard.putNumber("vY", yVelocity)
SmartDashboard.putNumber("omega", angVelocity)

if(slowMode){
xVelocity *= 0.6
yVelocity *= 0.6
angleVelocity *= 0.6
angVelocity *= 0.6
}

var speed: Translation2d = Translation2d(xVelocity * swerveController.config.maxSpeed , yVelocity * swerveController.config.maxSpeed)

swerveSubsystem.drive(speed, angleVelocity * swerveController.config.maxAngularVelocity, driveMode.asBoolean)


// Drive using raw values.
swerve.drive(
Translation2d(xVelocity * swerve.maximumSpeed, yVelocity * swerve.maximumSpeed),
angVelocity * controller.config.maxAngularVelocity,
driveMode.asBoolean
)
}

// Called once the command ends or is interrupted.
override fun end(interrupted: Boolean) {}

// Returns true when the command should end.
override fun isFinished(): Boolean {
// TODO: Make this return true when this Command no longer needs to run execute()
return false
}

override fun end(interrupted: Boolean) {}
}
}
Loading

0 comments on commit 6575420

Please sign in to comment.