Java command group running periodically

were trying to run a command group which involves zeroing our encoders then driving off those zeroed values, however, it seems like the command group is periodically and the encoders are constantly zeroing. Does anyone know how to solve this problem?

Here is the code we’re using to call the command group. (This is ran in robot periodic)

if (_joy.getRawButton(1)) {
  LowHatch.start();
  robot.cancel();
}
else {
  robot.start()
}

Do you do Command-based programming?

IterativeRobot?

TimedRobot?

You’ll need to put your code on github or somewhere where we can see the full view of it.

You’re starting the command anew in each loop iteration, about 50 times per second. In your OI file, why not bind the LowHatch command to run while button 1 is pressed?

http://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/wpilibj/command/CommandGroup.html
https://wpilib.screenstepslive.com/s/currentCS/m/java/l/599738-creating-groups-of-commands
Here is the WPI CommandGroup class and a WPI tutorial

If you are using command-based programming, I would use .whenPressed(CommandGroup) to initiate the commands.

If you run start() on a command that is already running, nothing should change. This is basically what the whileHeld() does as well.

If you could post the entirety of your code, preferably on Github, it would make our troubleshooting far easier. Thanks.

Here is the code sorry I couldn’t get in on GitHub
robot.zip (25.8 KB)

Here is the reference to “whenPressed” in OI.java: https://wpilib.screenstepslive.com/s/currentCS/m/java/l/599739-running-commands-on-joystick-input

So basically a combination of “whenPressed”, and command groups might get you where you are looking to go with the code.

Is there any particular reason you are using OI as if it were RobotMap, and then doing all your button handling manually instead of using Button objects in the OI to trigger Commands?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.