|
|
|
| Our gears mesh perfectly! |
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Breaking loops when switching to tele-op?
Our drivers are worried about the robot getting stuck in a while loop during autonomous, rendering the robot completely unusable for the rest of the match.
Do loops automatically break when the robot is automatically switched to tele-op or is this a legitimate concern? Thanks! |
|
#2
|
||||
|
||||
|
Re: Breaking loops when switching to tele-op?
Quote:
|
|
#3
|
|||
|
|||
|
Re: Breaking loops when switching to tele-op?
You don't mention what language you are using. LabVIEW aborts the autonomous when the period ends. It will break out of loops.
I don't believe the other language frameworks do that. Greg McKaskle |
|
#4
|
||||
|
||||
|
Re: Breaking loops when switching to tele-op?
What you could do is look for the Tele start signal in your loop and if it sees it break.
|
|
#5
|
||||
|
||||
|
Re: Breaking loops when switching to tele-op?
Quote:
Code:
while(isOperatorControl() && isEnabled()) {
You can test out if your code breaks by using the "practice" mode in driver station. As a rule of thumb: while trues are a sin 'round these parts. |
|
#6
|
||||||
|
||||||
|
Re: Breaking loops when switching to tele-op?
Iterative robot does not break out of loops for you. Rather it moves the loop into the framework. If you have your own loop in iterative, you'll have the same problem as sample.
|
|
#7
|
||||
|
||||
|
Re: Breaking loops when switching to tele-op?
I'm going to assume you're using IterativeRobot, since SampleRobot (or implementations of RobotBase) should really only be used if you're 100% certain you know what you're doing.
You'll notice IterativeRobot has both Init and Periodic functions for Robot, Autonomous, Teleop, Test and Disabled (e.g. AutonomousPeriodic, TeleopPeriodic, RobotInit, etc). The Init functions are called when you enter that mode, and the Periodic functions are called on a regular basis. You can think of the Periodic functions as being inside of the loop, and the Init functions above the loop. The robot main loop follows a process to ensure you don't end up 'locking up' the program in the loop. It goes like this: Check state (from driverstation) -> If different from the last, call <state>Init -> Call <state>Periodic -> Repeat During each iteration, the state is checked, and the appropriate periodic function is called. Because of this, it's important not to lock up the Periodic functions (e.g. don't put in your own loops unless they have a set number of iterations, such as iterating over motors). "But how can I do motor.set(val); sleep(3); motor.set(0)?" This is fairly simple. Instead of putting a sleep in the periodic function, check if that time has elapsed. Something like this: Code:
void AutonomousInit() {
start_time = now();
}
void AutonomousPeriodic() {
if (now() - start_time < 3) {
motor.Set(val);
} else {
motor.Set(0);
}
}
|
|
#8
|
|||
|
|||
|
Re: Breaking loops when switching to tele-op?
Quote:
|
|
#9
|
||||
|
||||
|
Re: Breaking loops when switching to tele-op?
I know. I'm stating that the problem that any fear of a problem that SampleRobot presents with their while loops can be solved with IterativeRobot.
|
|
#10
|
|||
|
|||
|
Re: Breaking loops when switching to tele-op?
Just tested with practice mode (thanks for the idea). Can confirm that it gets stuck for the rest of teleop.
|
|
#11
|
||||
|
||||
|
Re: Breaking loops when switching to tele-op?
We use LabView. Last year we got stuck in a control loop for Autonomous during an entire match. The problem code was a while loop running in Timed Tasks that never completed its task. If the while loops are executing within the Autonomous VI you should be safe but beware of loops running in Timed Tasks because that VI is running in Teleop as well as Autonomous.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|