Skip to content
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

replacement basic auto #54

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

public class Constants {

public static final double autoDriveTime = 5;

public final class ArmConstants {

public static final int wristMotorID = 19; //19?
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc.robot.commands.auto.Auto;

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

private final Timer m_timer = new Timer();

private RobotContainer m_robotContainer;

private final Timer loopTimer = new Timer();
Expand Down Expand Up @@ -53,9 +52,7 @@ public void robotInit() {
/** This function is run once each time the robot enters autonomous mode. */
@Override
public void autonomousInit() {
m_timer.reset();
m_timer.start();

m_robotContainer.getAutonomous().schedule();

}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.commands.ArmMove;
import frc.robot.commands.DriveWithJoysticks;
import frc.robot.commands.auto.Auto;
import frc.robot.subsystems.ArmSubsystem;
import frc.robot.subsystems.ArmSubsystem.Mode;
import frc.robot.subsystems.drive.DriveSubsystem;
Expand Down Expand Up @@ -44,6 +46,7 @@ public RobotContainer() {
));
configureButtonBindings();

SmartDashboard.putNumber("Auto Drive Time", 5);
}

private void configureButtonBindings() {
Expand All @@ -64,5 +67,9 @@ private void configureButtonBindings() {

}

public Command getAutonomous() {
return new Auto(arm, drive, Constants.autoDriveTime);
}


}
23 changes: 14 additions & 9 deletions src/main/java/frc/robot/commands/auto/Auto.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package frc.robot.commands.auto;

import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandBase;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.ParallelRaceGroup;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import edu.wpi.first.wpilibj2.command.WaitCommand;
import frc.robot.commands.ArmMove;
Expand All @@ -17,17 +20,19 @@ public class Auto extends SequentialCommandGroup {


public Auto(ArmSubsystem arm, DriveSubsystem drive, double driveTime) {
addRequirements(arm);
addRequirements(drive);

addCommands(
new InstantCommand(() -> arm.setMode(Mode.SHOOT_HIGH)),
new WaitCommand(1),
new InstantCommand(() -> arm.setMode(Mode.IDLE)),
new ParallelRaceGroup(
new ArmMove(arm, Mode.SHOOT_HIGH).raceWith(new WaitCommand(1.0)),
new ParallelRaceGroup (
Copy link
Member

Choose a reason for hiding this comment

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

Is ParallelRaceGroup correct here? Will ArmMove complete and end the race?

Copy link
Member

Choose a reason for hiding this comment

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

ArmMove never is finished, so it shouldn't win the race against the wait

new ArmMove(arm, Mode.INTAKE),
new RunCommand(() -> drive.setGoalChassisSpeeds(new ChassisSpeeds(0.5, 0, 0))),
new WaitCommand(driveTime)
)
);

),
new InstantCommand(() -> SmartDashboard.putBoolean("drive finished", true)),
new InstantCommand(() -> drive.setGoalChassisSpeeds(new ChassisSpeeds(0, 0, 0))),
new ArmMove(arm, Mode.STOW)
);
}


}