Go to Post please take the time to kick me in the butt. - Andy Baker [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-02-2012, 17:00
JakobLover JakobLover is offline
Registered User
FRC #3039
 
Join Date: Feb 2012
Location: Destrehan
Posts: 1
JakobLover is an unknown quantity at this point
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!
  #2   Spotlight this post!  
Unread 11-02-2012, 17:22
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,751
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
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
  #3   Spotlight this post!  
Unread 11-02-2012, 18:10
CRLS97 CRLS97 is offline
Registered User
FRC #0097
 
Join Date: Jan 2011
Location: Cambridge
Posts: 28
CRLS97 is an unknown quantity at this point
Re: Benefits of "Periodic Tasks VI"?

Quote:
Originally Posted by Greg McKaskle View Post
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.
In our teams code the bulk of our code is in Periodic Tasks.vi However in our Teleop.vi code I'm having the robot read a digital input and a global data so we have a couple different ways of controlling the robot. Could this be causing our -44601 error? I can actually notice a significant lag (like half a second) between a joystick movement and the robot movement and it's somewhat annoying while we're testing. I even tried having both periodic tasks and vision disabled and the error remained...
  #4   Spotlight this post!  
Unread 11-02-2012, 18:25
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,077
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Benefits of "Periodic Tasks VI"?

Quote:
Originally Posted by CRLS97 View Post
In our teams code the bulk of our code is in Periodic Tasks.vi However in our Teleop.vi code I'm having the robot read a digital input and a global data so we have a couple different ways of controlling the robot. Could this be causing our -44601 error? I can actually notice a significant lag (like half a second) between a joystick movement and the robot movement and it's somewhat annoying while we're testing. I even tried having both periodic tasks and vision disabled and the error remained...
I can't give an example in LabVIEW because I don't have it installed here, but here's a skeletal pseudo-C code:

Code:
while (1) {

if (!run_me) {sleep(20ms); continue;}

run_me= false;

doSomething;

sleep(250ms);

doSomethingElse;
}
The global boolean "run_me" tells the task to run once.

Notice the "sleep(20ms)" which prevents the task from chewing up an undue amount of CPU time.

  #5   Spotlight this post!  
Unread 11-02-2012, 18:41
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,521
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
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?
  #6   Spotlight this post!  
Unread 11-02-2012, 18:45
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,077
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Benefits of "Periodic Tasks VI"?

Quote:
Originally Posted by Tom Line View Post
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?
I'm not sure I follow you, Tom: more quickly and more precisely compared to what?

Quote:
Or are the motor set-speeds tied to the control station packets somehow?
TeleOp is not strictly speaking periodic; it's event-driven: It runs whenever data packets are sent, which occurs about every 20ms. You can then read that new data within TeleOp and act on it immediately within TeleOp, as long as you can do so well within 20ms. If your TeleOp code takes longer than 20ms to execute, you'll miss the next data packet.

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.


Last edited by Ether : 11-02-2012 at 18:49.
  #7   Spotlight this post!  
Unread 11-02-2012, 18:47
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,567
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Benefits of "Periodic Tasks VI"?

Quote:
Originally Posted by Tom Line View Post
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?
Jaguars are updated at 200hz, and Victors at 100hz, so yes you could update the motors much faster then telop (50hz). Whether that translates into better control depends on the mechanical time constant of the system.
  #8   Spotlight this post!  
Unread 11-02-2012, 22:03
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,751
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
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
  #9   Spotlight this post!  
Unread 11-02-2012, 23:32
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,521
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Re: Benefits of "Periodic Tasks VI"?

Quote:
Originally Posted by Joe Ross View Post
Jaguars are updated at 200hz, and Victors at 100hz, so yes you could update the motors much faster then telop (50hz). Whether that translates into better control depends on the mechanical time constant of the system.
Thanks Joe. I understand the concept of a mechanical time constant regarding motors and magnetic fields, but how would someone even begin to estimate such a thing for an FRC robot?

I think I'm going to go do some online reading as well.
  #10   Spotlight this post!  
Unread 12-02-2012, 16:50
CRLS97 CRLS97 is offline
Registered User
FRC #0097
 
Join Date: Jan 2011
Location: Cambridge
Posts: 28
CRLS97 is an unknown quantity at this point
Re: Benefits of "Periodic Tasks VI"?

Quote:
Originally Posted by Ether View Post
I can't give an example in LabVIEW because I don't have it installed here, but here's a skeletal pseudo-C code:

Code:
while (1) {

if (!run_me) {sleep(20ms); continue;}

run_me= false;

doSomething;

sleep(250ms);

doSomethingElse;
}
The global boolean "run_me" tells the task to run once.

Notice the "sleep(20ms)" which prevents the task from chewing up an undue amount of CPU time.

Ether, are you implying that if my global variable returns false, then it waits 20ms BEFORE doing whatever else is in that case statement? If so, wouldn't that cause the error since the Teleop code is taking >20ms to complete one cycle?
  #11   Spotlight this post!  
Unread 12-02-2012, 16:55
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,077
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Benefits of "Periodic Tasks VI"?

Quote:
Originally Posted by CRLS97 View Post
Ether, are you implying that if my global variable returns false, then it waits 20ms BEFORE doing whatever else is in that case statement?
No, it releases the processor for 20ms before looping back* to the top of the while loop and checking the "run_me" boolean again. There is no case statement in the pseudo-code I posted so I'm not sure what you were referring to.


Quote:
If so, wouldn't that cause the error since the Teleop code is taking >20ms to complete one cycle?
No. The while loop goes into the periodic tasks vi. The while loop runs in parallel with TeleOp.


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"

Last edited by Ether : 12-02-2012 at 17:03.
  #12   Spotlight this post!  
Unread 12-02-2012, 17:47
Chris_Elston's Avatar
Chris_Elston Chris_Elston is offline
Controls Engineer
AKA: chakorules
FRC #1501 (Team THRUST)
Team Role: Engineer
 
Join Date: Feb 2004
Rookie Year: 2001
Location: Huntington, Indiana
Posts: 747
Chris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond repute
Re: Benefits of "Periodic Tasks VI"?

Quote:
Originally Posted by Greg McKaskle View Post
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
Greg, so I don't wanna hi-jack but I sort of have the same question here because the period tasks are new in the 2012 framework compared to the 2011, 2010 and 2009 framework.

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
__________________
Team T.H.R.U.S.T. 1501
Download all of our past robot's source code here:Repository

Favorite CD quote:
"That can't be their 'bot. not nearly enough (if any) rivets to be a 1501 machine." ~RogerR: Team #1369
  #13   Spotlight this post!  
Unread 12-02-2012, 17:55
ratdude747's Avatar
ratdude747 ratdude747 is offline
Official Scorekeeper
AKA: Larry Bolan
no team
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Madison, IN
Posts: 1,064
ratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond repute
Re: Benefits of "Periodic Tasks VI"?

Quote:
Originally Posted by Chris_Elston View Post
Greg, so I don't wanna hi-jack but I sort of have the same question here because the period tasks are new in the 2012 framework compared to the 2011, 2010 and 2009 framework.

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

*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.
__________________
Dean's List Semi-finalist 2010
1747 Harrison Boiler Robotics 2008-2010, 2783 Engineers of Tomorrow 2011, Event Volunteer 2012-current

DISCLAIMER: Any opinions/comments posted are solely my personal opinion and does not reflect the views/opinions of FIRST, IndianaFIRST, or any other organization.
  #14   Spotlight this post!  
Unread 12-02-2012, 19:49
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,751
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
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
  #15   Spotlight this post!  
Unread 12-02-2012, 20:02
ratdude747's Avatar
ratdude747 ratdude747 is offline
Official Scorekeeper
AKA: Larry Bolan
no team
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Madison, IN
Posts: 1,064
ratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond repute
Re: Benefits of "Periodic Tasks VI"?

Quote:
Originally Posted by Greg McKaskle View Post
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
The Main reason I always used global variables was to keep teleop things in teleop. This does two things; it means that if you ever want to change that value during autonomous, it is an easy switch; it also means that if a random act of god caused a controller issue during autonomous, no problems would occur (like if a ball being tossed in the stands randomly bounced and hit a joystick).

Consider it a matter of programmer's preference... its how I learned to write code and it has always worked for me.
__________________
Dean's List Semi-finalist 2010
1747 Harrison Boiler Robotics 2008-2010, 2783 Engineers of Tomorrow 2011, Event Volunteer 2012-current

DISCLAIMER: Any opinions/comments posted are solely my personal opinion and does not reflect the views/opinions of FIRST, IndianaFIRST, or any other organization.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 00:51.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi