Hello everyone, We are a team that is switching from Labview which we knew well to Java to be able to run Swerve drive. So we were able to copy and get enough code to get the robot to run and we can even get our bot to back up in auton. We are hoping someone can help us get our launcher system to fire before be back up. We used timed robot when we set up the bot but realize now we should have done command but it too late to rewrite. So to sum up does anyone have a base code “outline” to run launcher then back up. Thanks for any help. We are very new to Java.
Do you have a link to your team’s repository?
We started with code from the REV starter bot. here is the link GitHub - joecoleman/Starter-bot-team-5547-2024
Thank you for taking a look
Going off of the rev starter code, you can create a sequential command to run a basic auto. Sequential command groups run commands in order. I used the command line being called for the right bumper to run the shooter and gave it a timeout of 1 second. You can use the same logic for intake and arm positions.
It might be good to look into command based coding so you don’t have to use timers (and other benefits), but this should work for what you want to do. Let me know if there are any issues with the code.
public Command getAutonomousCommand() {
return new SequentialCommandGroup(
new RunCommand(() -> m_launcher.runLauncher(m_launcher)).withTimeout(1), // Runs the shooter for one second
swerveControllerCommand.andThen(() -> m_robotDrive.drive(0, 0, 0, false, false)) // Drives back using the Swerve Controller Command
}
Yeah we are going to explore command based in the future. Rev helped get us going we are reverse engineering everything from there. 0 to autonomous videos have been great help too. I am not a coder and we don’t have coding classes I do know LabVIEW but trying to get where we can collaborate more so the Java switch it is.
Do we need to add in anything anywhere else? and do we need integers in the robot drive, 0,0,0?
Also i guess we would need to make the launcher spin up first then the intake feed the launcher, then move back.
I forgot to close the sequential command group.
public Command getAutonomousCommand() {
return new SequentialCommandGroup(
new RunCommand(() -> m_launcher.runLauncher(m_launcher)).withTimeout(1), // Runs the shooter for one second
swerveControllerCommand.andThen(() -> m_robotDrive.drive(0, 0, 0, false, false)) // Drives back using the Swerve Controller Command
);
}
Let me know if that fixes it.
I copied and pasted it and it got worse. 3 errors.
What did your autonomous command look like before? Were you using swerveControllerCommand?
The same code came with a trajectory to follow we are looking to add the launcher/intake to that if possible.
Do you have a screenshot of your previous auto code?
public Command getAutonomousCommand() {
// Create config for trajectory
TrajectoryConfig config =
new TrajectoryConfig(
AutoConstants.kMaxSpeedMetersPerSecond,
AutoConstants.kMaxAccelerationMetersPerSecondSquared)
// Add kinematics to ensure max speed is actually obeyed
.setKinematics(DriveConstants.kDriveKinematics);
// An example trajectory to follow. All units in meters.
Trajectory exampleTrajectory =
TrajectoryGenerator.generateTrajectory(
// Start at the origin facing the +X direction
new Pose2d(0, 0, new Rotation2d(0)),
// Pass through these two interior waypoints, making an 's' curve path
List.of(new Translation2d(1, 1), new Translation2d(2, -1)),
// End 3 meters straight ahead of where we started, facing forward
new Pose2d(3, 0, new Rotation2d(0)),
config);
var thetaController =
new ProfiledPIDController(
AutoConstants.kPThetaController, 0, 0, AutoConstants.kThetaControllerConstraints);
thetaController.enableContinuousInput(-Math.PI, Math.PI);
SwerveControllerCommand swerveControllerCommand =
new SwerveControllerCommand(
exampleTrajectory,
m_robotDrive::getPose, // Functional interface to feed supplier
DriveConstants.kDriveKinematics,
// Position controllers
new PIDController(AutoConstants.kPXController, 0, 0),
new PIDController(AutoConstants.kPYController, 0, 0),
thetaController,
m_robotDrive::setModuleStates,
m_robotDrive);
// Reset odometry to the starting pose of the trajectory.
m_robotDrive.resetOdometry(exampleTrajectory.getInitialPose());
// Run path following command, then stop at the end.
return swerveControllerCommand.andThen(() -> m_robotDrive.drive(0, 0, 0, false, false));
}
I combined the sequential command group with your other auto command. The thetacontroller and trajectory need to be included to properly build the swerveControllerCommand.
public Command getAutonomousCommand() {
// Create config for trajectory
TrajectoryConfig config =
new TrajectoryConfig(
AutoConstants.kMaxSpeedMetersPerSecond,
AutoConstants.kMaxAccelerationMetersPerSecondSquared)
// Add kinematics to ensure max speed is actually obeyed
.setKinematics(DriveConstants.kDriveKinematics);
// An example trajectory to follow. All units in meters.
Trajectory exampleTrajectory =
TrajectoryGenerator.generateTrajectory(
// Start at the origin facing the +X direction
new Pose2d(0, 0, new Rotation2d(0)),
// Pass through these two interior waypoints, making an 's' curve path
List.of(new Translation2d(1, 1), new Translation2d(2, -1)),
// End 3 meters straight ahead of where we started, facing forward
new Pose2d(3, 0, new Rotation2d(0)),
config);
var thetaController =
new ProfiledPIDController(
AutoConstants.kPThetaController, 0, 0, AutoConstants.kThetaControllerConstraints);
thetaController.enableContinuousInput(-Math.PI, Math.PI);
SwerveControllerCommand swerveControllerCommand =
new SwerveControllerCommand(
exampleTrajectory,
m_robotDrive::getPose, // Functional interface to feed supplier
DriveConstants.kDriveKinematics,
// Position controllers
new PIDController(AutoConstants.kPXController, 0, 0),
new PIDController(AutoConstants.kPYController, 0, 0),
thetaController,
m_robotDrive::setModuleStates,
m_robotDrive);
// Reset odometry to the starting pose of the trajectory.
m_robotDrive.resetOdometry(exampleTrajectory.getInitialPose());
// Run path following command, then stop at the end.
return new SequentialCommandGroup(
new RunCommand(() -> m_launcher.runLauncher(m_launcher)).withTimeout(1), // Runs the shooter for one second
swerveControllerCommand.andThen(() -> m_robotDrive.drive(0, 0, 0, false, false)) // Drives back using the Swerve Controller Command
);
}
We put that in but the build fails. Do to format violations it says. Thoughts? maybe a different approach
Not sure what to do next. The first example is a general implementation of how you add another command to your swerve driving auto. Hard to know exactly what to change with your code. If you have any general or conceptual questions, I can answer those.
I appreciate so much you trying. Its difficult to be so close. Thanks again. You are awesome.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.