![]() |
Benefits of "Periodic Tasks VI"?
What are the benefits of running while loops and all in the Periodic Tasks VI rather than Teleop? Does it help the code run faster? Do you run things in Periodic Tasks just like you would in Teleop? Any kind of summary to the pros, cons, and operation of Periodic Tasks would be very much appreciated!
|
Re: Benefits of "Periodic Tasks VI"?
TeleOp is called every 20ms in response to a message from the DS. Your code will not process messages from the driver station and field management system until the code returns. So, if you want to start a motor, wait while it cranks for 250ms, and then release a solenoid, that means it will stall out the normal execution of the code that allows the driver to control the robot. It will execute with the last motor command, and then if the watchdog or safety mechanisms are enabled, the motor will probably shut down because your code is not sending updates.
By comparison, Periodic tasks run in parallel. The loops initially share data with TeleOp via globals, but are not otherwise intertwined. The do not hold up teleop, and they do not wait for a message to arrive. They are a great place to have code that waits for sensors or timers and triggers because of a driver action or environmental action. Does that help? Greg McKaskle |
Re: Benefits of "Periodic Tasks VI"?
Quote:
|
Re: Benefits of "Periodic Tasks VI"?
Quote:
Code:
while (1) {Notice the "sleep(20ms)" which prevents the task from chewing up an undue amount of CPU time. |
Re: Benefits of "Periodic Tasks VI"?
So, if we were to put a motor set-speed in periodic tasks, we could update the motor speed far more quickly and control that motor more precisely, correct?
Or are the motor set-speeds tied to the control station packets somehow? |
Re: Benefits of "Periodic Tasks VI"?
Quote:
Quote:
Reading joystick values in a 10ms periodic task doesn't get new joystick data any faster. Reading sensors on your robot faster than 20ms gets new sensor data that can be used to alter motor commands if you think you need to do that. |
Re: Benefits of "Periodic Tasks VI"?
Quote:
|
Re: Benefits of "Periodic Tasks VI"?
When a robot has lag, the first thing I'd check is errors being displayed in the Diagnostics tab. The errors indicate and issue, and catching the unhanded errors is quite expensive and adds the lag.
Once the errors are clean, I'd check on the CPU usage in the Charts tab of the DS. Greg McKaskle |
Re: Benefits of "Periodic Tasks VI"?
Quote:
I think I'm going to go do some online reading as well. |
Re: Benefits of "Periodic Tasks VI"?
Quote:
|
Re: Benefits of "Periodic Tasks VI"?
Quote:
Quote:
Read the posts linked below. Seriously, read and study them. You will be glad you did: http://www.chiefdelphi.com/forums/sh...96&postcount=3 http://www.chiefdelphi.com/forums/sh...21&postcount=6 http://www.chiefdelphi.com/forums/sh...43&postcount=4 * the "continue" statement in C means "go back to the top of the loop" |
Re: Benefits of "Periodic Tasks VI"?
Quote:
If there is a button on a joystick that is pressed to turn on a motor setting, you're saying it's best to place this in periodic tasks? Rather than place the motor set output in telop? Should we only put robot drive code or joystick to robot drive in teleop and let's say all other components in period tasks? thanks. Chris |
Re: Benefits of "Periodic Tasks VI"?
Quote:
*I have not actually seen the 2012 framework and I am going off of my programming work in 2011* What I would do is put the motor setting in periodic and the control for it in teleop. you connect the two with a global variable. (teleop writes to it, periodic reads it) Likewise, you write to the global variable in autonomous as well. Hope that helps. |
Re: Benefits of "Periodic Tasks VI"?
I'm pretty sure the Periodic tasks have been there since the beginning. The Vision task is basically the same thing, but specialized to be throttled by camera images showing up.
Joystick values show up when new control packets arrive. So the teleop is designed to be a great place to catch the latest joystick "events" and respond to them with the least latency. For some operations, where the joystick is the most important trigger and the response is quick, teleop is a great place to put the code. If the code is also triggered by time, takes more than 20ms to complete the operation, or includes sensor measurement to complete a control loop, Periodic may be a better place. As ratdude said, using teleop joystick data to update set points and time to run the control algorithm is a pretty common situation. That naturally minimizes the latency of both inputs. Note that it is pretty easy to read the joystick wherever you like, so this can often simplify some of the communication between Periodic and teleop and not require using a global just to hold the joystick state. Greg McKaskle |
Re: Benefits of "Periodic Tasks VI"?
Quote:
Consider it a matter of programmer's preference... its how I learned to write code and it has always worked for me. |
Re: Benefits of "Periodic Tasks VI"?
Ok, this brings up another question I've been thinking about.
Greg, if a speed has not changed from the last loop, is there any reason to call the set speed command? Will not calling it result in a watchdog? |
Re: Benefits of "Periodic Tasks VI"?
Quote:
(safety measure to prevent runaway robots) |
Re: Benefits of "Periodic Tasks VI"?
Quote:
|
Re: Benefits of "Periodic Tasks VI"?
Quote:
|
Re: Benefits of "Periodic Tasks VI"?
Quote:
|
Re: Benefits of "Periodic Tasks VI"?
Thanks Joe. So - if you've disabled the motor safeties, what happens if set speed is not called for say, 2 or 3 seconds. Does the motor stay at the last set point?
I ask because some of the Beta teams saw a noticeable improvement in CPU usage by putting a simple if/then around their set speed and only calling it on a change. |
Re: Benefits of "Periodic Tasks VI"?
Quote:
If a motor's safety feature is not enabled, it will keep its last commanded output value indefinitely. That includes switching from autonomous to teleoperated mode (or vice versa, which can happen during testing), so you should make sure your motors are initialized to something reasonable when such things happen. |
Re: Benefits of "Periodic Tasks VI"?
There are several watchdog and safety mechanisms in effect.
The system watchdog will shutdown the robot outputs when the DS communications is interrupted or an estop takes place. The 100ms timeout is controlled by the Robot Safety mechanism and it automatically zeroes configured robotDrive motors after 100ms. Not setting RobotDrive every 20ms will lower CPU usage, but I'm curious as to how much. Greg McKaskle |
Re: Benefits of "Periodic Tasks VI"?
Quote:
our team is using UDP to transmit between the Dashboard and the cRIO, which appears to be delaying the watchdog being fed, and interrupting robot communications. the port we're using for the socket isn't being used anywhere else in the code, from what we can see, so what could it be? |
Re: Benefits of "Periodic Tasks VI"?
Quote:
|
Re: Benefits of "Periodic Tasks VI"?
Can you describe more? Perhaps post some code?
Greg Mckaskle |
| All times are GMT -5. The time now is 20:18. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi