-
Notifications
You must be signed in to change notification settings - Fork 1
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
Wojtaszek - Autonomous and other stuff #6
base: main
Are you sure you want to change the base?
Conversation
…utton is pressed on the XBox controller
… Arcade Left and right, and tank mode.
My First Pull Request
Adding PID logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic looks good! I would make some minor changes to enhance reusability, but functionally ok as-is.
At the least, add a comment for the "A" button and confirm you means to remove the field from the SmartDashboard.
shooter.setDefaultCommand( | ||
new ShooterCommand( | ||
shooter, | ||
() -> mainController.getLeftTriggerAxis(), | ||
() -> mainController.getRightTriggerAxis())); | ||
|
||
mainController.a().toggleOnTrue(new AutonomousDistance(drive)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add a comment saying that this binds the "A" button to execute the AutonomousDistance routine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated this to be part of the autonomous command logic.
* | ||
* @param drivetrain The drivetrain subsystem on which this command will run | ||
*/ | ||
public AutonomousDistance(DriveSubsystemXrp drivetrain) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change the "DriveSystemXrp" (the implementation) to "Drive" (the interface), so that this command could be re-used in any subsystem that implements the Drive interface. E.g. we could have the same command work on Romi, XRP, and even the actual comp bot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would reccomend I do this? I would have to add a function to the Drive interface for getting the left and right positions. In the current code I do this by accessing that data through the DriveSubsystemXRP through the drivedifferentialIOXrp/DriveDifferentialIo class/interface but that is really specific to robots with a left and right wheels. Adding that logic to the Drive interface would limit it and all derived implementations to 2wd bots.
import frc.robot.subsystems.drive.DriveSubsystemXrp; | ||
|
||
public class DriveDistance extends Command { | ||
private final DriveSubsystemXrp drive; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same: Change DriveSubsystemXrp --> Drive
speed = driveSpeed; | ||
drive = driveSubsystem; | ||
|
||
pidController = new PIDController(1.0, 0.0, 0.0); // Adjust PID constants as needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the command re-usable on any robot, the PID Controller should be passed into the command, the constant could be moved to Constants.java, the constants could be passed in, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
public void execute() { | ||
double leftDistance = leftWheelStartPosition - drive.getLeftPositionMeters(); | ||
double rightDistance = rightWheelStartPosition - drive.getRightPositionMeters(); | ||
System.out.println("Left: " + leftDistance + " Right: " + rightDistance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "production" code shouldn't print to the console. Try to add AdvantageKit logging for these values. See https://docs.advantagekit.org/data-flow/recording-outputs/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it but will use advantage kit in the future
public class DriveTime extends Command { | ||
private final double duration; | ||
private final double speed; | ||
private final DriveSubsystemXrp drive; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DriveSubsystemXrp --> Drive
// Create a DifferentialDriveKinematics object with the track width | ||
kinematics = new DifferentialDriveKinematics(DriveConstants.trackWidthMeters); | ||
|
||
addRequirements(drive); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you change DriveSubsystemXrp --> Drive, then this needs to be cast to a Subsystem: addRequirements((Subsystem) drive);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the DriveTime command work? I tried something similar using drive(1 m/s) + WaitCommand(5 sec) + drive(0 m/s), and the XRP only drove for a split second.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I plan on removing this. Right now I don't see a use for this class.
|
||
// START: Setup Odometry | ||
SmartDashboard.putData("Field", field); | ||
// END: Setup Odometry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to remove the "Field" from the smartdashboard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. I put it back.
I think that I have logic that should be in the subsystem in the command logic for the "DriveDistance". I will probably clean that up.