In our code, we are attempting to activate an autonomous action using timestamp. The action will be running during TeleOp. Timer.delay() doesn’t work in this situation, so how would you suggest programming an action (using states) after a certain amount of time in the timestamp has passed. The action is timing how long a motor should run for when dumping cargo if that helps any.
You don’t say whether you’re using just plain iterative programming using TimedRobot or using the command-based framework. With plain iterative programming, the typical way to do this is to create an instance of the Timer class that persists across calls to teleopPeriodic (e.g. as a class instance member). Call start() on it when you want the timer to start, then the get() function will return the elapsed time in seconds since start() was called. e.g. something like:
Timer myTimer = new Timer();
...
teleopPeriodic() {
if (joy1.getTrigger()) {
timer.start();
motor.set(1.0);
}
if (timer.get() > 1.0) {
motor.set(0.0);
timer.stop();
timer.reset();
}
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.