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

Commit

Permalink
the vision doesnt work
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGamer1002 committed Apr 25, 2023
1 parent 676d24f commit 8ce49b1
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 1,128 deletions.
484 changes: 0 additions & 484 deletions final-final-final.json

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/main/java/frc/robot/Interfaces/CANSparkMax.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ public void initSendable(SendableBuilder builder) {
builder.addDoubleProperty("Encoder Position", this::getAbsoluteEncoderPosition, null);
builder.addDoubleProperty("Encoder Velocity", this::getAbsoluteEncoderVelocity, null);

builder.addDoubleProperty("Conversion Factor", this::getPositionConversionFactor, this::setPositionConversionFactor);


}

/**
Expand Down Expand Up @@ -470,5 +473,16 @@ public double getAbsoluteEncoderVelocity() {
}


public double getPositionConversionFactor() {
throwIfClosed();
return getAbsoluteEncoder(Type.kDutyCycle).getPositionConversionFactor();
}

public void setPositionConversionFactor(double a) {
throwIfClosed();
getAbsoluteEncoder(Type.kDutyCycle).setPositionConversionFactor(a);
}



}
11 changes: 7 additions & 4 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import frc.robot.commands.*;
import frc.robot.subsystems.*;
import frc.robot.subsystems.Tracking.Target;
import io.github.oblarg.oblog.Logger;

/**
Expand Down Expand Up @@ -45,7 +44,7 @@ public class RobotContainer {
private final Tank m_Tank = new Tank();
private final PID m_PID = new PID();
private final PDP m_PDP = new PDP();
private final Target m_Target = new Target();
private final Vision m_Vision = new Vision(m_Tank);



Expand All @@ -63,6 +62,7 @@ public class RobotContainer {
private final FineDriveCommand m_FineDriveCommand = new FineDriveCommand(m_Tank);
private final PlaceCubeSecondLevelCommand m_PlaceCubeSecondLevelCommand = new PlaceCubeSecondLevelCommand(m_Tank,
m_Arm, m_Claw);
private final TrackPiece m_TrackPiece = new TrackPiece(m_Vision, m_Tank);

// private final XTracking m_XTracking = new XTracking(m_Tank, null, m_Target);
// private final YTracking m_YTracking = new YTr
Expand All @@ -89,6 +89,7 @@ public RobotContainer() {
tab.add(m_MoveArmYCommand);
tab.add(m_PDP);
tab.add(m_PlaceCubeSecondLevelCommand);
tab.add(m_Vision);

tab.add(m_PID);
tab.add(m_PlaceConeSecondLevelCommand);
Expand Down Expand Up @@ -121,8 +122,10 @@ private void configureButtonBindings() {
.whileTrue(m_FineDriveCommand);
new JoystickButton(m_armController2, XboxController.Button.kY.value).whileTrue(m_PlaceConeSecondLevelCommand);

new JoystickButton(m_armController2, XboxController.Button.kStart.value)
.onTrue(m_AutoCommand)

new JoystickButton(m_armController2, XboxController.Button.kX.value).whileTrue(m_TrackPiece);



// new JoystickButton(m_armController2, XboxController.Button.kB.value)
// .whileTrue(m_PlaceConeSecondLevelCommand);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/commands/DriveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void initialize() {
public void execute() {
// double check getMaxSpeed(), might be wrong

Tank.arcadeDrive(
m_drivebase.arcadeDrive(
/* rotation */RobotContainer.getAdjustedTurningStickInput() * Constants.CanConstants.maxSpeed,
/* speed */RobotContainer.getAdjustedForwardStickInput() * 0.7);

Expand All @@ -42,7 +42,7 @@ public void execute() {

@Override
public void end(boolean interrupted) {
Tank.arcadeDrive(0, 0);
m_drivebase.arcadeDrive(0, 0);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/commands/FineDriveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public void initialize() {
@Override
public void execute() {
// double check getMaxSpeed(), might be wrong
Tank.arcadeDrive(
m_drivebase.arcadeDrive(
RebindHat.ControllerToYAxis() * 0.43, RebindHat.ControllerToXAxis() * 0.43);
}

@Override
public void end(boolean interrupted) {
Tank.arcadeDrive(0, 0);
m_drivebase.arcadeDrive(0, 0);
}

@Override
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/frc/robot/commands/PickUpPiece.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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;

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

// NOTE: Consider using this command inline, rather than writing a subclass. For more
// information, see:
// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html
public class PickUpPiece extends SequentialCommandGroup {
/** Creates a new PickUpPiece. */
public PickUpPiece() {
// Add your commands in the addCommands() call, e.g.
// addCommands(new FooCommand(), new BarCommand());
addCommands();
}
}
43 changes: 0 additions & 43 deletions src/main/java/frc/robot/commands/PickUpPieceCommand.java

This file was deleted.

68 changes: 0 additions & 68 deletions src/main/java/frc/robot/commands/PieceTracking.java

This file was deleted.

47 changes: 47 additions & 0 deletions src/main/java/frc/robot/commands/TrackPiece.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.Tank;
import frc.robot.subsystems.Vision;

public class TrackPiece extends CommandBase {
/** Creates a new TrackPiece. */
private Vision m_Vision;
private Tank m_Tank;
public TrackPiece(Vision vision, Tank tank) {
// Use addRequirements() here to declare subsystem dependencies.
m_Vision = vision;
m_Tank = tank;
addRequirements(m_Vision, m_Tank);
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
m_Tank.arcadeDrive(0.05, m_Vision.getController().calculate(m_Vision.getMeasurement(), m_Vision.getSetpoint()));
SmartDashboard.putString("a", "pid on");
}

@Override
public void execute() {
SmartDashboard.putNumber(getName(), m_Vision.getController().calculate(m_Vision.getMeasurement(), m_Vision.getSetpoint()));
}
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
m_Vision.disable();
m_Tank.arcadeDrive(0,0);
SmartDashboard.putString("a", "pid off");
}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return m_Vision.atSetpoint();
}
}
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/subsystems/Tank.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public double getMaxSpeed() {
* @param speed The forward/backward speed.
* @param rotation The rotation speed.
*/
public static void arcadeDrive(double speed, double rotation) {
public void arcadeDrive(double speed, double rotation) {

drive.arcadeDrive(
-speed * Math.pow(Math.abs(speed), 0.5), rotation * Math.pow(Math.abs(rotation), 0.5));
Expand Down
Loading

0 comments on commit 8ce49b1

Please sign in to comment.