so im working on making a swerve program for future projects but im having issues comenting the default command in my robot container for the joystick
public class RobotContainer {
private final SwerveSubsystem swerveSubsystem = new SwerveSubsystem();
private final XboxController DJ = new XboxController(OperatorConstants.controller1);
/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
swerveSubsystem.setDefaultCommand(new SwerveControllerCommand(
swerveSubsystem,
() → -DJ.getRawAxis(OperatorConstants.Left_Stick_Y),
() → DJ.getRawAxis(OperatorConstants.left_Stick_X),
() → DJ.getRawAxis(OperatorConstants.Right_Stick_X),
() → !DJ.getRawButton(OperatorConstants.AbuttonC1)));
// Configure the trigger bindings
configureBindings();
}
this is the text that is giving me a load of errors and i cant seem to make it right in any way if anyone could help it would be great.
Heres the github to the program so you guys can take a look :GitHub - Chozenm/FRC
Could you provide the actual error you’re getting? It’s not clear from your message. Is it a compiler error? red squiggles in vscode? something not working quite right at runtime?
Ah okay, so that first error is telling you exactly what the problem is. You’re trying to pass in a Subsystem and 4 DoubleSupplier objects to the constructor of SwerveControllerCommand, but such a constructor doesn’t exist. The available options can be found here: SwerveControllerCommand (WPILib API 2023.2.1-57-gb879a6f)
What were you working from that led to you using those parameters?
Looks like you are using the Example Swerve Controller Command project. You picked the way to follow a trajectory. Right above that is the way to follow a Joystick.
// Configure default commands
m_robotDrive.setDefaultCommand(
// The left stick controls translation of the robot.
// Turning is controlled by the X axis of the right stick.
new RunCommand(
() ->
m_robotDrive.drive(
m_driverController.getLeftY(),
m_driverController.getLeftX(),
m_driverController.getRightX(),
false),
m_robotDrive));
}
I was hopeful that between our two strong hints that OP would realize finding random code somewhere isn’t as good as using the official current release of examples. Likely the code used to work perfectly and maybe it was even last year’s example but is now too far out of context.
The current VSC available Java example SwerveControllerCommand should be all newcomers go-to project for command-based. SwerveBot is what my team used starting last year without command-based.
You may have figured out the issue from @Fletch1373 and @SLAB-Mr.Thomas great advice. Looking at your code on Github, are you trying to run the command named “Swerve” ?
I didnt know the existence of a swerve example for wpilib im using the 0 to autonomous swerve video as a base to my code i resolved the problem but im not sure if its right could you guys take a look?
As usual there are about a million different ways to accomplish the same thing.
Watch carefully the types of the lambdas and methods in use and what types are required.
For example, in the SwerveControllerCommand project I cited with using the m_robotDrive.drive method it is NOT returning a command but a command is required at that time because you are setting the default command. The RunCommand turns the drive into a command - a wrapper if you will.
The new Swerve(...) cited in post 12 @Kartikr27 is already a command and thus does not need to be wrapped in a command.
Either way works fine. You see both used a lot and need to be comfortable recognizing them.
The error does match your code in that you are trying to execute the method SwerveSubsystem in class Swerve. Certainly that’s not what you meant to try to do.
The 3rd image shows a method called SwerveJoystickCmd in an un-shown shown class. With a name including the phrase Cmd you might be trying to create a command yet the method does not return anything (void) and certainly not a Command.
If you are determined to try to salvage use of the SDS example from years ago, you’ll have to pay very close attention to the Java syntax and sort out what you are trying to do and how does the SDS code almost accomplish that. I have seen threads on CD suggesting no longer using the SDS code as out of date. I can’t judge that as my team used that code for only about 2 days when we first got our swerve modules and we moved quickly to the SwerveBot example in WPILib. Maybe others can lead you through that code.