Java code errors help

New to Command-based programming. Followed some tutorials, looked at example code and learned the basics, but having some issues. Every time I move the joystick to control the drivetrain, I get these errors and it only moves in short intervals. When I move the joystick to full power, the robot moves a tiny bit, then stops, and keeps repeating that loop. My guess is that it is restarting MecanumDrive_Command every instance of TeleopPeriodic, but I’m not sure how to fix that.

Errors I’m getting:

Link to code

Note: I commented out certain methods (ie: end(), disabledPeriodic(), and interrupted()). When I didn’t have them commented out, the robot would just start stuttering.

Any help is greatly appreciated!

Just a quick look at your code, it seems like in your code

DriveTrain_Subsystem->TeleopDrive()

you are creating a mecanumDrive object every time.

robotDrive = new MecanumDrive(leftFront, leftRear, rightFront, rightRear);

you might want to move that line of code into it’s own method, e.g. InitRobot(), in that same file, DriveTrain_Subsystem.

Then in your MecanumDrive_Command->initialize(), call that InitRobot() method you’d just made.

Thanks! I’ll try that. Quick question about the scheduler. Does Scheduler.getInstance().run() run every command that exists in the project, or just those that have a button called to it in the OI?

Not sure if I’m answering your question correctly (and someone more knowledgeable could answer this), but I think the Scheduler will reference any subsystem(s) you had created and run any command you’d set to in the initDefaultCommand() method

so in your case, only the MecanumDrive_Command

Oh ok, that makes sense. Thank you!

Actually, this site have good information For the 2020 season software documentation has been moved to https://docs.wpilib.org. Documentation for KOP items can still be found here. | FRC KOP Documentation

In short, three ways commands are called but I think your question is answered by 2 and 3.

  1. Manually, by calling the start() method on the command (used for autonomous)
  2. Automatically by the scheduler based on button/trigger actions specified in the code (typically defined in the OI class but checked by the Scheduler).
  3. Automatically when a previous command completes (default commands and command groups).

and here’s the diagram: