I use the Command-Robot template, I program the P2 buttons using the subsystem and commands, however for the commands to be executed within the teleOp, I need to use the setDefaultCommand function in the subsystem, that’s where the problem comes from, this setDefaultCommand
it is conflicting with the auto commands, so the actions that I place within the pathPlanner are not executed because of this, and I found a solution using the JoystickButton
, but I didn’t find the complete solution, because I don’t know how to configure the commands using the JoystickButton to trigger such as leftTrigger and rightTrigger, I was able to easily use the bumpers and common buttons, but I don’t know how to use the triggers and I wanted to know if you could help me
private void configureBindings() {
new JoystickButton(controleXbox, Button.kA.value).onTrue(new InstantCommand(swerve::zeroGyro));
new JoystickButton(operatorControl, XboxController.Button.kA.value).onTrue(Commands.runOnce(() -> {
cSubsystem.coletar();
}, cSubsystem, lSubsystem)).onFalse(Commands.runOnce(() -> {
cSubsystem.stop();
}, cSubsystem));
}
I use Logitech controls, but I was unable to configure one using the correct library, so I chose to use XboxController, but if I want to use XboxController.Axis.rightTrigger.value, the trigger id does not work, what is the right trigger? on xboxController is another button on the logitech controller
We are using the CommandXboxController
class. We use this driver_joystick_.rightTrigger(0.5).whileTrue(~~~command~~~)
Also I would recommend using a StartEnd Command instead on a runOnce. This would allow you to not have to do an onFalse check.
This is how we do a similar process for turning on and off our pickups.
driver_joystick_.leftTrigger(0.5).whileTrue(Commands.startEnd(
() -> PickupSubsystem.setPickupMode(),
() -> PickupSubsystem.setIdleMode(),
PickupSubsystem));
driver_joystick_.leftTrigger(0.5).whileTrue
- checks for the trigger to be pulled more than 50%
() -> PickupSubsystem.getShooterInstance().setPickupMode(),
- starts the pickup rollers when the StartEnd command begins
() -> PickupSubsystem.getShooterInstance().setIdleMode(),
- stops the pickup rollers when the StartEnd command finishes.
What was the initial problem you were trying to solve that requires this solution? I am a little confused what problems you had with pathplanner
thank you, maybe now the trigger problem will be solved.
public RobotContainer() {
gSubsystem.setDefaultCommand(new GanchoCmd(gSubsystem, controleXbox));
lSubsystem.setDefaultCommand(new LancadorCmd(lSubsystem, operatorControl));
configureBindings();
}
The problem with pathPlanner that you didn’t understand is that this setDefaultCommand line defines a default command for when no button is being pressed, but from what I understand, as no button is being pressed in auto, it keeps executing this default command, which does not allows the commands defined in the pathPlanner to be executed during the route. For example, our launcher sue command is supposed to stay locked, but in auto I want it to turn on for a while, but it doesn’t perform the shoot function
I think the problem you are having is that the commands you are using within the autonomous paths to operate the shooter and so on do not have those subsystems as requirements. This means that the default command for that subsystem is not stopped while they are running.
For example in RobotContainer.java
:
NamedCommands.registerCommand("shootSpeaker",
new InstantCommand(lSubsystem::shootSpeakerAuto));
should probably read:
NamedCommands.registerCommand("shootSpeaker",
new InstantCommand(lSubsystem::shootSpeakerAuto, lSubsystem));
@crh_redbird1 covered this below, but I just wanted to add that a plain InstantCommand
is probably the wrong choice here. You can make it run for a specific length of time by adding withTimeout()
or you can use until()
to add your own test for completion. I see in the auto file that you have wait
between your shooter commands, but I don’t think that’s doing what you intend.
NamedCommands.registerCommand("shootSpeaker",
new InstantCommand(lSubsystem::shootSpeakerAuto, lSubsystem)
.withTimeout(1.0));
So you need some sort of way to turn off your default command when you are call your commands for auto. Commands can have requirements that only allow one command per subsystem to run. If you have your auto Commands require the Lancador subsystem it should stop the default command while it is called.
NamedCommands.registerCommand("shootSpeaker", new InstantCommand(lSubsystem::shootSpeakerAuto, lSubsystem));
However I think another issue is your motors will only stay active for one loop of the code because it will switch back to your default command after shootSpeakerAuto
is done because its not being scheduled more than once.
To fix this problem I would probably recommend not using a command file. They are helpful, but due to your implementation it is giving you more issues to solve.
I would define all of your controls like I suggested in my previous reply. I would setup each of your functions in configureBindings
in RobotContainer
.
So for example here is what one of your operator controls would look like
operatorControl.y().whileTrue(Commands.startEnd(
() -> {lancador.coletorLancador(); lancador.cuspir();},
() -> lancador.stopCondutor();
lSubsystem));
You should think of a command as an action of the robot. You tell the robot to shoot
when you push a button. shoot
is your command and it tells your robot specifically what to do like turn on motors or aim.
To add to what @bovlb said above. I agree this could be resolved by creating a command with a timeout which would allow you to keep your default command. This is FIRST’s documentation on command types and how they work. Commands — FIRST Robotics Competition documentation For your usage I would look at a Run
command with a .withTimeout
Thank you, I believe that the simplest way to execute this is actually using the way you mentioned above rather than creating a command with a timeout, but I will test both ways to see which will be the most practical, but thank you very much.
I tried to use this mode, but I can’t implement it in my code, I did it inside public void configureBindings(){}
, im using new JoystickButton
, do I use this or something else instead of JoystickButton?
You shouldn’t have to do that anymore. Here is an example of how you would write the code above in the new format.
operatorControl.a().onTrue(Commands.startEnd(
() -> cSubsystem.coletar(),
() -> cSubsystem.stop(),
}, cSubsystem));
Here is the documentation for the new class
I tested it the way you told me, but it still gives an error, maybe I’m putting it in the wrong place, but I’m not sure, I’m writing it outside the robotContainer constructor, but I still don’t understand how I can use this within my code, I did exactly how you passed me.
Im coding here
I think you need to change line 48.
public static final XboxController controleXbox = new XboxController(Controle.xboxControle);
to
public static final CommandXboxController controleXbox = new CommandXboxController (Controle.xboxControle);
remove CommandXboxController(
from line 86
and the )
after the ;
on line 89
i tried, but dont change anything, i change for CommandXboxController
bcs before is only Joystick
, but im using my second joystick, not this controller, for P2 i use the Joystick class
Ohh ok sorry I missed that. Go ahead and change it back to JoystickButton.
I would expect it to look like this then
new JoystickButton(operatorControl, XboxController.Button.kA.value).onTrue(Commands.startEnd(
() -> cSubsystem.coletar(),
() -> cSubsystem.stop(),
}, cSubsystem)));
It looks like you already have this for one button. I would just repeat it for all of the button you have defined in your GanchoCmd
file and LancadorCmd
file.
yeah, but i want do to this for trigger RightTrigger e LeftTrigger, because i don’t know how can i do this for trigger on Joystick class, the generic class for Joystick
This Class, im using the XboxController class for the JoystickButton, why I didn’t understand anything about the generic class, even though I researched
Are you using an xbox controller or a large flight joystick for the operator?
logitech joystick
This is not syntactically correct. Get rid of the curly brace and one of the closing parens right before the semicolon
So the triggers are actually an axis not a button. I think you will need to create a boolean supplier for checking when the trigger is pressed and then use a Trigger instead of a JoystickButton to link it to a command
So I would write a method in RobotContainer that reads the joystick and returns true if it’s above a certain value. Then you would do this
configureBindings(){
new Trigger(this::getOperatorRightTrigger).onTrue(Commands.startEnd(
() -> cSubsystem.coletar(),
() -> cSubsystem.stop(),
cSubsystem));
~~~ Add other bindings ~~~
}
private boolean getOperatorRightTrigger(){
if(operatorControl.getRawAxis(~~Axis Number~~) > ~~define deadzone~~){
return true;
}
return false;
}
I’m not sure what the format is for the values coming from the trigger. At one point I thought it might have been -1 for not pressed and 1 for fully pressed or maybe it swaps between left and right.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.