Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Switch to Spark Max + Encoders + Built in PID for auto #2

Merged
merged 31 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
70510b5
switch to spark max and switch encoders
jack60612 Jan 12, 2024
73b468e
Fully Finish Autonomous Code + Migrate PID
jack60612 Jan 12, 2024
5f3bbcd
cleanup drive code
jack60612 Jan 13, 2024
457a312
add encoder conversion factors for shooter and arm
jack60612 Jan 13, 2024
bc8811a
do last shooter initial changes
jack60612 Jan 13, 2024
07cbc5a
fix oversights, including radians not position
jack60612 Jan 13, 2024
a0b1bb8
Update PathplannerLib.json
jack60612 Jan 16, 2024
f997b02
fix their problem
jack60612 Jan 16, 2024
f6fe001
fix stuff
jack60612 Jan 19, 2024
bef2da4
sys id bs
jack60612 Jan 19, 2024
5b5562e
Update RobotContainer.java
jack60612 Jan 19, 2024
a2c0291
more profiling
jack60612 Jan 19, 2024
f5980ec
update constants
jack60612 Jan 19, 2024
b30af46
add sysid support to arm & shooter + feedforward
jack60612 Jan 19, 2024
f09f47d
add more deadzones
jack60612 Jan 19, 2024
ce62952
fix bad feedfoward implementation & add feedforward to shooter
jack60612 Jan 19, 2024
180e491
turn arm into stateful + add motion profile
jack60612 Jan 19, 2024
97cff90
remove 2nd arm motor
jack60612 Jan 19, 2024
f49d16e
Update build.gradle
jack60612 Jan 22, 2024
ded16d7
update
jack60612 Jan 22, 2024
ec2e80a
driveforward
jack60612 Jan 22, 2024
1681969
Update DriveSubsystem.java
jack60612 Jan 23, 2024
a8ee0cd
working auto
jack60612 Jan 23, 2024
02c41a7
spotless ....
jack60612 Jan 23, 2024
40aa157
Add controller deadzones to constants
jack60612 Jan 24, 2024
1f79f54
final
jack60612 Jan 24, 2024
51ba75e
add helperfunctions to utils folder
jack60612 Jan 24, 2024
1d3c77d
spotlessapply
jack60612 Jan 24, 2024
a6d634c
add LifterSubsystem
jack60612 Feb 4, 2024
24bf893
update vendor deps
jack60612 Feb 4, 2024
5a6ac87
added toggle bake mode
jack60612 Feb 5, 2024
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
6 changes: 6 additions & 0 deletions .DataLogTool/datalogtool.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"download": {
"localDir": "C:\\Users\\BeachBots\\Downloads",

Choose a reason for hiding this comment

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

What is this for? Can we avoid hard paths?

Copy link
Author

Choose a reason for hiding this comment

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

this i can just git ignore, it was autogenerated.

Copy link
Author

Choose a reason for hiding this comment

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

but its good to keap because team id so i think we could remove if needed

"serverTeam": "10.76.52.2"
}
}
1 change: 1 addition & 0 deletions .SysId/sysid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Binary file added FRC_20240119_152551-exported.wpilog
Binary file not shown.
Binary file added FRC_20240119_152551.wpilog
Binary file not shown.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2024.1.1"
id "edu.wpi.first.GradleRIO" version "2024.2.1"
id 'com.diffplug.spotless' version '6.20.0'
id "com.peterabeles.gversion" version "1.10"
}
Expand Down
31 changes: 31 additions & 0 deletions src/main/deploy/pathplanner/autos/DriveForward.auto
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"version": 1.0,
"startingPose": {
"position": {
"x": 2,
"y": 7.0
},
"rotation": 0
},
"command": {
"type": "sequential",
"data": {
"commands": [
{
"type": "path",
"data": {
"pathName": "DriveForward"
}
},
{
"type": "named",
"data": {
"name": "BrakeCommand"
}
}
]
}
},
"folder": null,
"choreoAuto": false
}
49 changes: 49 additions & 0 deletions src/main/deploy/pathplanner/paths/DriveForward.path
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"version": 1.0,
"waypoints": [
{
"anchor": {
"x": 2.0,
"y": 7.0
},
"prevControl": null,
"nextControl": {
"x": 3.0,
"y": 7.0
},
"isLocked": false,
"linkedName": null
},
{
"anchor": {
"x": 3.25,
"y": 7.0
},
"prevControl": {
"x": 2.25,
"y": 7.0
},
"nextControl": null,
"isLocked": false,
"linkedName": null
}
],
"rotationTargets": [],
"constraintZones": [],
"eventMarkers": [],
"globalConstraints": {
"maxVelocity": 1.0,
"maxAcceleration": 0.5,
"maxAngularVelocity": 540.0,
"maxAngularAcceleration": 720.0
},
"goalEndState": {
"velocity": 0.0,
"rotation": 0,
"rotateFast": false
},
"reversed": false,
"folder": null,
"previewStartingState": null,
"useDefaultConstraints": false
}
2 changes: 1 addition & 1 deletion src/main/deploy/pathplanner/paths/Example Path.path
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"maxAngularAcceleration": 720.0
},
"goalEndState": {
"velocity": 0,
"velocity": 0.0,
"rotation": 0,
"rotateFast": false
},
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@ public final class Constants {
public static final class CANConstants {
// CAN Bus Devices
/// Drive Train Motors
public static final int MOTORFRONTRIGHTID = 11;
public static final int MOTORBACKRIGHTID = 12;
public static final int MOTORFRONTLEFTID = 13;
public static final int MOTORBACKLEFTID = 14;
public static final int MOTORFRONTRIGHTID = 14;
public static final int MOTORBACKRIGHTID = 13;
public static final int MOTORFRONTLEFTID = 12;
public static final int MOTORBACKLEFTID = 11;
/// Arm Motors
public static final int MOTORARMMAINID = 21;
public static final int MOTORARMSECONDARYID = 22;
/// Shooter Motors
public static final int MOTORSHOOTERID = 31;
/// Lifter Motors
public static final int MOTORLIFTERLEFTID = 41;
public static final int MOTORLIFTERRIGHTID = 42;
}

public static final double MAX_SPEED = 0.8;
public static final double LIFTERSPEED = 0.5;

// USB Devices
public static final int CONTROLLERUSBINDEX = 0;
public static final int FLIGHTSTICKUSBINDEX = 1;
// On-Controller joystick deadzone
public static final double CONTROLLERDEADZONE = 0.1;

// Game Controller Buttons
// Now In RobotContainer as Native Triggers.
Expand All @@ -44,9 +49,4 @@ public static final class CANConstants {
public static final int ULTRASONICSHOOTERPORT = 0;

// Digital Ports
/// Encoder Ports
public static final int DRIVEENCODERLEFTA = 0;
public static final int DRIVEENCODERLEFTB = 1;
public static final int DRIVEENCODERRIGHTA = 2;
public static final int DRIVEENCODERRIGHTB = 3;
}
39 changes: 29 additions & 10 deletions src/main/java/frc/robot/DriveConstants.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package frc.robot;

import com.pathplanner.lib.util.ReplanningConfig;
import edu.wpi.first.math.controller.SimpleMotorFeedforward;
import edu.wpi.first.math.kinematics.DifferentialDriveKinematics;
import edu.wpi.first.math.util.Units;

Expand All @@ -13,29 +12,49 @@
*/
public final class DriveConstants {
// general drive constants
// https://www.chiefdelphi.com/t/encoders-velocity-to-m-s/390332/2
// https://sciencing.com/convert-rpm-linear-speed-8232280.html
public static final double WHEEL_DIAMETER = Units.inchesToMeters(6); // meters
public static final double PULSES_PER_REV = 2048; // resolution of encoder
public static final double GEAR_RATIO = 1;
public static final double DISTANCE_PER_PULSE =
public static final double kTrackwidthMeters = 0.60048;
// this is not used and is handled by the rev encoder.
public static final double PULSES_PER_REV = 1;
public static final double GEAR_RATIO = 8.46; // 8.46:1
// basically converted from rotations to to radians to then meters using the wheel diameter.
// the diameter is already *2 so we don't need to multiply by 2 again.
public static final double POSITION_CONVERSION_RATIO =
(Math.PI * WHEEL_DIAMETER) / PULSES_PER_REV / GEAR_RATIO;
public static final double VELOCITY_CONVERSION_RATIO = POSITION_CONVERSION_RATIO / 60;
// Kinematic constants

// These characterization values MUST be determined either experimentally or theoretically
// for *your* robot's drive.
// The Robot Characterization Toolsuite provides a convenient tool for obtaining these
// values for your robot.
// Feed Forward Constants
public static final double Ks = 0.76856; // volts
public static final double Kv = 2.4467; // VoltSecondsPerMeter
public static final double Ka = 0.58646; // VoltSecondsSquaredPerMeter
public static final SimpleMotorFeedforward FeedForward = new SimpleMotorFeedforward(Ks, Kv, Ka);
public static final double ksDriveVolts = 0.16213;
TimeToDie2 marked this conversation as resolved.
Show resolved Hide resolved
public static final double kvDriveVoltSecondsPerMeter = 2.2194;
public static final double kaDriveVoltSecondsSquaredPerMeter = 0.33599;
// Max speed Constants
public static final double kMaxOutputDrive = 1.0;
public static final double kMinOutputDrive = -1.0;
// Feed Back / PID Constants
public static final double kPDriveVel = 3.6293;
public static final double kPDriveVel = 0.00034388;
public static final double kIDriveVel = 0.0;
public static final double kDDriveVel = 0.0;
public static final double kIzDriveVel = 0.0; // error before integral takes effect

public static final double kPDrivePos = 5.7745;
public static final double kIDrivePos = 0.0;
public static final double kDDrivePos = 0.55289;
public static final double kIzDrivePos = 0.0; // error before integral takes effect
// Helper class that converts a chassis velocity (dx and dtheta components) to left and right
// wheel velocities for a differential drive.
public static final double kTrackwidthMeters = 0.60048;
public static final DifferentialDriveKinematics kDriveKinematics =
new DifferentialDriveKinematics(kTrackwidthMeters);
// Default path replanning config. See the API for the options
public static final ReplanningConfig autoReplanningConfig = new ReplanningConfig();

// Motor Controller PID Slots
public static final int kDrivetrainVelocityPIDSlot = 0;
public static final int kDrivetrainPositionPIDSlot = 1;
}
51 changes: 9 additions & 42 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

package frc.robot;

import edu.wpi.first.cameraserver.CameraServer;
import edu.wpi.first.cscore.UsbCamera;
import edu.wpi.first.cscore.VideoSink;
import edu.wpi.first.wpilibj.DataLogManager;
// import edu.wpi.first.cscore.VideoSource.ConnectionStrategy;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import org.littletonrobotics.urcl.URCL;

/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
Expand All @@ -25,11 +22,6 @@ public class Robot extends TimedRobot {

private RobotContainer m_robotContainer;

private UsbCamera camera1;
private UsbCamera camera2;
private VideoSink mainCameraServer;
private int cameraCounter = 2;

/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
Expand All @@ -40,28 +32,14 @@ public void robotInit() {
// autonomous chooser on the dashboard.
m_robotContainer = new RobotContainer();

camera1 = CameraServer.startAutomaticCapture(0);
camera2 = CameraServer.startAutomaticCapture(1);
mainCameraServer = CameraServer.getServer();
// Tell both cameras to always stream.
// camera1.setConnectionStrategy(ConnectionStrategy.kKeepOpen);
// camera2.setConnectionStrategy(ConnectionStrategy.kKeepOpen);

// this is to put git info in the dashboard & Logs, uses new 2024 BuildConstants.java
String branchName = BuildConstants.GIT_BRANCH;
String commitHash = BuildConstants.GIT_SHA;
String commitTime = BuildConstants.GIT_DATE;
String buildTime = BuildConstants.BUILD_DATE;

System.out.println("Branch: " + branchName);
System.out.println("Commit: " + commitHash);
System.out.println("Commit Time: " + commitTime);
System.out.println("Build Time: " + buildTime);

SmartDashboard.putString("Branch", branchName);
SmartDashboard.putString("Commit", commitHash);
SmartDashboard.putString("CommitTime", commitTime);
SmartDashboard.putString("BuildTime", buildTime);
if (m_robotContainer.enableAutoProfiling) {
DataLogManager.start();
URCL.start();
}
}

/**
Expand All @@ -78,6 +56,9 @@ public void robotPeriodic() {
// and running subsystem periodic() methods. This must be called from the robot's periodic
// block in order for anything in the Command-based framework to work.
CommandScheduler.getInstance().run();
if (m_robotContainer.enableAutoProfiling) {
System.out.println("WARNING, AUTO PROFILE IS ENABLED!");
}
}

/** This function is called once each time the robot enters Disabled mode. */
Expand Down Expand Up @@ -111,20 +92,6 @@ public void teleopInit() {
if (m_autonomousCommand != null) {
m_autonomousCommand.cancel();
}
m_robotContainer
.getCameraButton()
.onTrue(
new InstantCommand(
() -> {
cameraCounter++;
if (cameraCounter % 2 == 0) {
System.out.println("Setting Camera 2");
mainCameraServer.setSource(camera2);
} else {
System.out.println("Setting Camera 1");
mainCameraServer.setSource(camera1);
}
}));
}

/** This function is called periodically during operator control. */
Expand Down
Loading
Loading