When using the command based framework, is it valid to schedule commands within robot.py in teleopPeriodic, instead of configuring buttons in robotcontainer.py?
Ex:
def teleopPeriodic(self) -> None:
if self.container.driverController.getAButton():
MyCommand(self.container.drive).schedule()
That looks like it would keep creating and scheduling new instances of MyCommand as long as the A button is held, so after holding A down for 1 second you’d have 50 copies of MyCommand running.
I think it needs to be more like this:
// Somewhere else like in some *init() code create
self.my_command = MyCommand(self.container.drive)
def teleopPeriodic(self) -> None:
if self.container.driverController.getAButton():
self.my_command.schedule()
It’s OK to keep calling schedule(). First time around it actually starts the command. If the command is already running, schedule() doesn’t do anything.
Edit: I suspect I didn’t read your question carefully enough, so you probably already knew that. FWIW, I’m not a commands-based expert, but it does seem to me that it’s an anti-pattern to even have a command robot with a teleopPeriodic that does anything other than running the scheduler.
You can, but to make it do anything useful you’d have to re-engineer the internals of the Trigger class (in particular, the edgefinding logic) and you’d miss out on all of the convenient features of the existing implementation. This seems like a poor use of resources.