How do I update an autonomous program live

I am working with the autonomous program below, and the centralX value is updated by my Robot.Java program through teleopPeriodic(), which is running every few miliseconds or so. However, in the constructor of this class, it can’t get the live value because of the addSequential() setup (I’m pretty sure that’s why). Is there another way to set up an autonomous command like this that would allow the live, updated centralX to be reflected within the actual list of commands, so the if statement changes live as well?

That version of the command-based framework is deprecated (it’ll be removed completely next year). You might find it easier to do this in the new framework, which uses functional interfaces to make it easier to send things other than static values to commands.

1 Like

First thing the way the command framework works the if condition will be evaluated once when the command object is constructed. Either driving left of right will be added to the sequence according to the centralX value at that time and your TestAuto command will always drive in the same direction. I assume this is not what you want, but I don’t have the full picture.

My suggestion would be two fold:

  1. Move your if condition inside the DriveTimed command (or a new one, such as SteerTimed). That way in that command you can check centralX and drive either left or right accordingly.
  2. Store your centralX value the same way you store your subsystem in your robot class. That way you can access it from inside your command the same way you access your subsystems and update the value from the robot periodic method.

Finally as @Oblarg mentioned this command framework is deprecated, so you should eventually look at the new command framework. Personally I would do that in the off season though.

Thanks!

1 Like

ConditionalCommand is designed to choose between two commands at the time that initialize is run.

https://first.wpi.edu/wpilib/allwpilib/docs/release/java/edu/wpi/first/wpilibj/command/ConditionalCommand.html

That will make things much easier, appreciate it.

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