Can anyone tell me how to program a motor to a button in Java VScode?
Are you using the Command-based framework?
yes
The new or old one?
We’re using VSCode 2020, so I assume new.
Have you read the documentation?
If you did, where got you confused?
I did look over the documentation and was able to write a working drive train. I assume programming a motor to a button would be similar to programming motors to joysticks?
shooterSubsystem.setDefaultCommand(new RunCommand(
() -> shooterSubsystem.shooterSpeed(driverController.getRawAxis(XboxConstants.LEFT_TRIGGER_AXIS)),
shooterSubsystem));
^ For a trigger on the main controller
new JoystickButton(auxDriverController, Button.kB.value).whenPressed(() -> intakeSubsystem.intakeSpeed(1.0))
.whenReleased(() -> intakeSubsystem.intakeSpeed(0.0));
^ for a button, you can also use the .whileHeld(IntakeCommand) to run whatever the command is continuously.
Thanks I was wondering how to have the motor on only when the button is pressed.
Sorry for the bad formatting but I think you know what should be in the back ticks lol.
Yes thank you
The way my team does it is we have a method in the subsystems that sets it to a value. And the execute method of it’s command sets it to a constant speed. In the constructor of configurebuttonbindings do this…
(ButtonObj).whileHeld(new command(subsystem);
whileHeld can be replaced with any other method depending on the properties.
Why do you create a new command there?
in robotContainer we have an instance of each subsystem and we use a new instance of the command and pass in its parameter that way, not sure if theres any difference to if we do it this way instead of creating a command object but it might have to do with the initialize and isfinished methods.
EDIT: also im just not very comfortable with lambdas as you seem to be doing.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.