Skip to content

Commit

Permalink
Merge pull request #2 from StuyPulse/JanTenth
Browse files Browse the repository at this point in the history
Jan tenth
  • Loading branch information
Keobkeig committed Jan 12, 2024
2 parents bae79e9 + 63f08ce commit fdae878
Show file tree
Hide file tree
Showing 18 changed files with 515 additions and 62 deletions.
1 change: 1 addition & 0 deletions networktables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
92 changes: 92 additions & 0 deletions simgui-ds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"keyboardJoysticks": [
{
"axisConfig": [
{
"decKey": 65,
"incKey": 68
},
{
"decKey": 87,
"incKey": 83
},
{
"decKey": 69,
"decayRate": 0.0,
"incKey": 82,
"keyRate": 0.009999999776482582
}
],
"axisCount": 3,
"buttonCount": 4,
"buttonKeys": [
90,
88,
67,
86
],
"povConfig": [
{
"key0": 328,
"key135": 323,
"key180": 322,
"key225": 321,
"key270": 324,
"key315": 327,
"key45": 329,
"key90": 326
}
],
"povCount": 1
},
{
"axisConfig": [
{
"decKey": 74,
"incKey": 76
},
{
"decKey": 73,
"incKey": 75
}
],
"axisCount": 2,
"buttonCount": 4,
"buttonKeys": [
77,
44,
46,
47
],
"povCount": 0
},
{
"axisConfig": [
{
"decKey": 263,
"incKey": 262
},
{
"decKey": 265,
"incKey": 264
}
],
"axisCount": 2,
"buttonCount": 6,
"buttonKeys": [
260,
268,
266,
261,
269,
267
],
"povCount": 0
},
{
"axisCount": 0,
"buttonCount": 0,
"povCount": 0
}
]
}
39 changes: 39 additions & 0 deletions simgui.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"NTProvider": {
"types": {
"/FMSInfo": "FMSInfo",
"/SmartDashboard/Autonomous": "String Chooser",
"/SmartDashboard/Field": "Field2d",
"/SmartDashboard/Odometry/Field": "Field2d",
"/SmartDashboard/Sim Field": "Field2d"
},
"windows": {
"/SmartDashboard/Autonomous": {
"window": {
"visible": true
}
},
"/SmartDashboard/Sim Field": {
"window": {
"visible": true
}
}
}
},
"NetworkTables": {
"transitory": {
"SmartDashboard": {
"Sim Field": {
"open": true
},
"SimDrivetrain": {
"open": true
},
"open": true
}
}
},
"NetworkTables Info": {
"visible": true
}
}
25 changes: 16 additions & 9 deletions src/main/java/com/stuypulse/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
package com.stuypulse.robot;

import com.stuypulse.robot.commands.auton.DoNothingAuton;
import com.stuypulse.robot.commands.drivetrain.DriveDrive;
import com.stuypulse.robot.commands.drivetrain.DrivetrainDrive;
import com.stuypulse.robot.commands.drivetrain.DrivetrainDriveForever;
import com.stuypulse.robot.commands.launcher.LaunchPrepare;
import com.stuypulse.robot.commands.launcher.LauncherIntakeNote;
import com.stuypulse.robot.commands.launcher.LauncherStop;
import com.stuypulse.robot.commands.odometry.OdometryRealign;
import com.stuypulse.robot.constants.Ports;
import com.stuypulse.robot.subsystems.drivetrain.Drivetrain;
import com.stuypulse.robot.subsystems.drivetrain.AbstractDrivetrain;
import com.stuypulse.robot.subsystems.launcher.Launcher;
import com.stuypulse.robot.subsystems.odometry.AbstractOdometry;
import com.stuypulse.robot.subsystems.vision.AbstractVision;
import com.stuypulse.stuylib.input.Gamepad;
import com.stuypulse.stuylib.input.gamepads.AutoGamepad;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
Expand All @@ -29,8 +32,10 @@ public class RobotContainer {
public final Gamepad operator = new AutoGamepad(Ports.Gamepad.OPERATOR);

// Subsystem
public final Drivetrain drivetrain = Drivetrain.getInstance();
public final Launcher launcher = Launcher.getInstance();
public final AbstractDrivetrain drivetrain = AbstractDrivetrain.getInstance();
// public final Launcher launcher = Launcher.getInstance();
//public final AbstractOdometry odometry = AbstractOdometry.getInstance();
//public final AbstractVision vision = AbstractVision.getInstance();

// Autons
private static SendableChooser<Command> autonChooser = new SendableChooser<>();
Expand All @@ -48,7 +53,7 @@ public RobotContainer() {
/****************/

private void configureDefaultCommands() {
drivetrain.setDefaultCommand(new DrivetrainDrive(drivetrain, driver));
drivetrain.setDefaultCommand(new DrivetrainDrive(driver));
}

/***************/
Expand All @@ -73,10 +78,12 @@ private void configureDriverBindings() {

private void configureOperatorBindings() {
// odometry
driver.getDPadUp().onTrue(new OdometryRealign(Rotation2d.fromDegrees(180)));
driver.getDPadLeft().onTrue(new OdometryRealign(Rotation2d.fromDegrees(-90)));
driver.getDPadDown().onTrue(new OdometryRealign(Rotation2d.fromDegrees(0)));
driver.getDPadRight().onTrue(new OdometryRealign(Rotation2d.fromDegrees(90)));
//driver.getDPadUp().onTrue(new OdometryRealign(Rotation2d.fromDegrees(180)));
//driver.getDPadLeft().onTrue(new OdometryRealign(Rotation2d.fromDegrees(-90)));
//driver.getDPadDown().onTrue(new OdometryRealign(Rotation2d.fromDegrees(0)));
//driver.getDPadRight().onTrue(new OdometryRealign(Rotation2d.fromDegrees(90)));

driver.getLeftButton().onTrue(new DrivetrainDriveForever(2));
}

/**************/
Expand Down
87 changes: 87 additions & 0 deletions src/main/java/com/stuypulse/robot/commands/AngleAlign.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.stuypulse.robot.commands;

import com.stuypulse.robot.constants.Settings.Alignment;
import com.stuypulse.robot.subsystems.drivetrain.AbstractDrivetrain;
import com.stuypulse.robot.subsystems.odometry.AbstractOdometry;
import com.stuypulse.robot.subsystems.odometry.Odometry;
import com.stuypulse.robot.subsystems.vision.AbstractVision;
import com.stuypulse.stuylib.control.angle.feedback.AnglePIDController;
import com.stuypulse.stuylib.math.Angle;
import com.stuypulse.stuylib.streams.angles.AFuser;
import com.stuypulse.stuylib.streams.booleans.BStream;
import com.stuypulse.stuylib.streams.booleans.filters.BDebounceRC;
import com.stuypulse.stuylib.streams.numbers.filters.IFilter;
import com.stuypulse.stuylib.streams.numbers.filters.LowPassFilter;

import edu.wpi.first.wpilibj2.command.Command;

public class AngleAlign extends Command {
private final AbstractDrivetrain drivetrain;
private final AbstractOdometry odometry;
private final AbstractVision vision;

private final AFuser angleError;
private IFilter speedAdjFilter;

protected final AnglePIDController angleController;

private final BStream finished;

public AngleAlign() {
this.drivetrain = AbstractDrivetrain.getInstance();
this.odometry = Odometry.getInstance();
this.vision = AbstractVision.getInstance();

this.angleError = new AFuser(Alignment.FUSION_FILTER.get(),
() -> Angle.fromRotation2d(vision.getOutput().get(0).getPrimaryTag().getPose().toPose2d().getRotation()),
() -> Angle.fromRotation2d(odometry.getPose().getRotation())
);

this.speedAdjFilter = new LowPassFilter(Alignment.SPEED_ADJ_FILTER.get());

this.angleController = new AnglePIDController(Alignment.Rotation.P, Alignment.Rotation.I, Alignment.Rotation.D);

this.finished = BStream.create(this::isAligned)
//TODO: check to see if it is degrees or radians
.and(() -> angleController.isDoneDegrees(Alignment.ALIGNED_THRESHOLD_ANGLE.get()))
.filtered(new BDebounceRC.Rising(Alignment.DEBOUNCE_TIME));

addRequirements(drivetrain, odometry, vision);
}

public boolean isAligned() {
// check to see if the robot is within a threshold of the april tag target
return Math.abs(angleError.get().toDegrees()) < Alignment.ALIGNED_THRESHOLD_ANGLE.get();
}

private double getTurn() {
// //calcs with the setpoint angle of line between tag and robot to the current angle of the robot
// return angleController.update(
// /* angle of line between tag and robot*/
// angleController.getSetpoint()
// ,
// odometry.getRotation());
return 0;
}

@Override
public void initialize() {
odometry.resetOdometery(odometry.getPose());
angleController.reset();
angleError.reset();
}

@Override
public void execute() {
}

@Override
public boolean isFinished() {
return finished.get();
}

@Override
public void end(boolean interrupted) {
drivetrain.stop();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.stuypulse.robot.commands.drivetrain;

import com.stuypulse.robot.subsystems.drivetrain.AbstractDrivetrain;
import com.stuypulse.stuylib.input.Gamepad;

import edu.wpi.first.wpilibj2.command.Command;

// DriveCommand.java
public class DriveDrive extends Command {

private AbstractDrivetrain drivetrain;
private Gamepad gamepad;

public DriveDrive(AbstractDrivetrain drivetrain, Gamepad gamepad) {
this.drivetrain = drivetrain;
this.gamepad = gamepad;

addRequirements(drivetrain);
}

public void execute() {
drivetrain.tankDriveVolts(gamepad.getLeftTrigger(), gamepad.getRightTrigger());
}

}
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package com.stuypulse.robot.commands.drivetrain;

import com.stuypulse.robot.subsystems.drivetrain.Drivetrain;
import com.stuypulse.robot.subsystems.drivetrain.AbstractDrivetrain;
import com.stuypulse.stuylib.input.Gamepad;
import com.stuypulse.stuylib.math.SLMath;
import com.stuypulse.stuylib.streams.numbers.IStream;

import edu.wpi.first.wpilibj2.command.Command;

public class DrivetrainDrive extends Command {
public final Drivetrain drivetrain;
private final Gamepad driver;
public final AbstractDrivetrain drivetrain;

double rightSpeed;
double leftSpeed;

private final IStream speed;
private final IStream angle;

public DrivetrainDrive(Drivetrain drivetrain, Gamepad driver) {
this.drivetrain = drivetrain;
this.driver = driver;
public DrivetrainDrive(Gamepad driver) {
this.drivetrain = AbstractDrivetrain.getInstance();

this.speed = IStream.create(
() -> driver.getRightY() - driver.getLeftY())
Expand All @@ -41,9 +39,6 @@ public DrivetrainDrive(Drivetrain drivetrain, Gamepad driver) {

@Override
public void execute() {
if (driver.getRawLeftButton() || driver.getRawRightButton()) {
drivetrain.curvatureDrive(speed.get(), angle.get(), true);
}
else drivetrain.stop();
drivetrain.arcadeDrive(speed.get(), angle.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@

package com.stuypulse.robot.commands.drivetrain;

import com.stuypulse.robot.subsystems.drivetrain.Drivetrain;
import com.stuypulse.robot.subsystems.drivetrain.AbstractDrivetrain;

import edu.wpi.first.wpilibj2.command.Command;

public class DrivetrainDriveForever extends Command {
private final Drivetrain drivetrain;
private final AbstractDrivetrain drivetrain;
private final double speed;

public DrivetrainDriveForever(Drivetrain drivetrain, double speed) {
this.drivetrain = drivetrain;
public DrivetrainDriveForever(double speed) {
this.drivetrain = AbstractDrivetrain.getInstance();
this.speed = speed;

addRequirements(drivetrain);
}

@Override
public void initialize() {
drivetrain.tankDriveVolts(speed, speed);
}

@Override
public void execute() {
drivetrain.curvatureDrive(speed, 0, false);
drivetrain.tankDriveVolts(speed, speed);
}
}
Loading

0 comments on commit fdae878

Please sign in to comment.