I don’t know how I can make a timed autonomous command for new 2020 command based framework. Since the new command doesn’t provided “Timed Command” class.
I tired using the java thread method as you can see but when I pressed the button to trigger the command the robot quite.
Never use Thread.sleep. It will delay the comms you need to make the code run.
You have at least two options:
Add a timeout variable that you increment every tick
Or
Try the new .withTimeout(). Not experienced with that so can’t help.
I have tired withTimeout() before but it didn’t workout well for me. It made robot quite every time a command is called. I notice it’s a part of ParallelRaceGroup.
NT: server: client CONNECTED: 10.65.93.172 port 54681
Unhandled exception: edu.wpi.first.hal.util.UncleanStatusException: Code: -1029. HAL: Resource already allocated
Error at frc.robot.subsystems.DriveTrain.<init>(DriveTrain.java:25): Unhandled exception: edu.wpi.first.hal.util.UncleanStatusException: Code: -1029. HAL: Resource already allocated
at edu.wpi.first.hal.PWMJNI.initializePWMPort(Native Method)
at edu.wpi.first.wpilibj.PWM.<init>(PWM.java:62)
at edu.wpi.first.wpilibj.PWMSpeedController.<init>(PWMSpeedController.java:25)
at edu.wpi.first.wpilibj.Spark.<init>(Spark.java:52)
at frc.robot.subsystems.DriveTrain.<init>(DriveTrain.java:25)
at frc.robot.commands.DriveStraightAuto.<init>(DriveStraightAuto.java:26)
at frc.robot.RobotContainer.<init>(RobotContainer.java:43)
at frc.robot.Robot.robotInit(Robot.java:40)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:64)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:276)
at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:348)
at frc.robot.Main.main(Main.java:27)
Robots should not quit, but yours did!
Warning at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:291): Robots should not quit, but yours did!
The startCompetition() method (or methods called by it) should have handled the exception above.
Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:293): The startCompetition() method (or methods called by it) should have handled the exception above.
pure virtual method called
terminate called without an active exception
What @Amicus1 said. The error you’re getting is Resource already allocated and it’s not related to using .withTimeout().
Because you’re instantiating the drivetrain multiple times, you’re instantiating hardware multiple times, which is not possible.
Is this what you mean or one without it so I have to define the drivetrain in the command.
public DriveStraightAuto(DriveTrain drive) {
// Add your commands in the super() call, e.g.
// super(new FooCommand(), new BarCommand());
super(new TankdriveControl(drive, .5, .5).withTimeout(3));
}
Unhandled exception: java.lang.NullPointerException
Error at java.base/java.util.Objects.requireNonNull(Unknown Source): Unhandled exception: java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Unknown Source)
at java.base/java.util.ImmutableCollections$Set12.<init>(Unknown Source)
at java.base/java.util.Set.of(Unknown Source)
at edu.wpi.first.wpilibj2.command.CommandBase.addRequirements(CommandBase.java:36)
at frc.robot.commands.TankdriveControl.<init>(TankdriveControl.java:26)
at frc.robot.commands.DriveStraightAuto.<init>(DriveStraightAuto.java:26)
at frc.robot.RobotContainer.<init>(RobotContainer.java:43)
at frc.robot.Robot.robotInit(Robot.java:40)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:64)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:276)
at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:348)
at frc.robot.Main.main(Main.java:27)
Robots should not quit, but yours did!
Warning at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:291): Robots should not quit, but yours did!
The startCompetition() method (or methods called by it) should have handled the exception above.
Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:293): The startCompetition() method (or methods called by it) should have handled the exception above.
NT: server: client CONNECTED: 10.65.93.11 port 44984
Ithout even seeing your code I can tell you the drivetrain object you passed in was null.
This happens in line 23 of TankDriveControl when you set the passed in parameter d to the null drive instead of the other way around. Simple error, just swap the two.
My problem has been resolved thanks to all of you who helped me out.
So the initial problem I had was that I couldn’t come up with a way to set the timeout for command for this year due to changes of command based framework. After I got help from wonderful people I was able to fix this problem. So there is help from wpilib API for timeout it’s called .withTimeout(sec). It work just like timeout from old command framework but with this you have to initialize this within your autonomous command so like super(new TankdriveControl(drive, .6, .7).withTimeout(3));. Just make sure you’re not passing in new object inside the same command (this is one of the problem I was having), constructor would be helpful in that scenario.