Im having some issues setting the default comannd for my subsystem in my robot container

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(
() → -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


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

thank you for the attention.

First off, thank you for linking to your code!

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?

sorry for taking long

1 Like

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
        // The left stick controls translation of the robot.
        // Turning is controlled by the X axis of the right stick.
        new RunCommand(
            () ->

Good call. Yeah, there’s definitely a line missing from OP’s code (likely the one in your snippet).

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?

yes sir

Personally, I do not use

 new RunCommand

I would just do

swerveSubsystem.setDefaultCommand( new Swerve(...))

is there any particular reason that i should try putting that? because i tried and it gave me several errors looks like RunCommand is the way to go

That is what works for me. What errors are you getting?

not several errors my bad.

You may be passing in the wrong parameters. Can you send your code currently please?

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 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 run command dosent seem to work it says that the method is undefined

and here is the Swerve command

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.

so should i start to make my code based on the swerve example from the WPILIB?

and there are 3 different swerve examples witch one is the best to learn from?