Go to Post Driving and using the cell phone and taking a picture with it. Where is your Safety Captain? - GaryVoshol [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-10-2014, 04:58
GuyM142's Avatar
GuyM142 GuyM142 is offline
Registered User
AKA: Guy
FRC #3339 (BumbleBee)
Team Role: Mentor
 
Join Date: Jul 2013
Rookie Year: 2012
Location: Israel
Posts: 156
GuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really nice
Parallel loops vs. One loop?

Hey guys,
We have several loops in our robot code (in periodic tasks vi) each controls a different sub system and all of them have a 20ms delay in them.
I was wondering if this is the right way to do it.
Will it make the code (Especially teleop.vi) run faster if I will merge all of the loops into one main loop with a 20ms delay?
__________________
2016-2017 - Programming Mentor
Curie Sub-Division Champions with 694, 379 & 1511
2015 - Team Captain & Head of Programming Crew
Carson Sub-Division Champions with 1325, 20 & 1711
First ever Israeli team on Einstein
2014 - Team Captain & Head of Programming Crew
2013 - Head of Programming Crew
2012 - Member of Programming Crew
Reply With Quote
  #2   Spotlight this post!  
Unread 09-10-2014, 09:36
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,713
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Parallel loops vs. One loop?

It is more efficient to combine them into one loop, but not significantly. If they are affecting Teleop at all then you need to rethink your code design.

Before doing anything I'd suggest measuring the rates of all your loops to see how they are affecting overall timing.
One or more of your loops may not be running as fast as 20ms and that would impact Teleop worst of all.

Look under Support Code" in your project and you will see Elapsed Times.vi
Drop a copy of this vi into each of your loops, and into teleop, and give them unique names so they can be told apart.
Open the front panel of Elapsed Times and run your code in debug from Robot Main. Elapsed Times will tell you how long each loop is actually taking.
Each of your loops should be taking just a few ms longer than 20ms. If you see any that are taking significantly longer than that, then you will need to slow down the loop to a more reasonable time or you will need to streamline your code more.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
Reply With Quote
  #3   Spotlight this post!  
Unread 09-10-2014, 11:13
Greg McKaskle Greg McKaskle is online now
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,748
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: Parallel loops vs. One loop?

Are you asking because you have CPU issues? LabVIEW is quite efficient at doing parallel loops, so ideally you make the decision based on what makes sense.

Let's compare having one 20ms loop where we place all subsystems that run at that rate into the single loop, to having multiple loops all running at 20ms. The biggest difference is that the parallel loops are not synchronized. You don't know which starts first, which finishes first, etc. Additionally, if something happens in one loop that would delay it, it will not have much impact on the other loops.

If the code is in one loop, the data connections can directly synchronize things. You may need this, you may not. Additionally, if one operation starts to take longer, it directly affects all things in that loop.

If you have CPU issues or want to gain understanding of how often a loop is running, please follow what is in Mike's post. If you have other questions, please post them in more detail, perhaps even including your code.

Greg McKaskle
Reply With Quote
  #4   Spotlight this post!  
Unread 10-10-2014, 16:06
GuyM142's Avatar
GuyM142 GuyM142 is offline
Registered User
AKA: Guy
FRC #3339 (BumbleBee)
Team Role: Mentor
 
Join Date: Jul 2013
Rookie Year: 2012
Location: Israel
Posts: 156
GuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really nice
Re: Parallel loops vs. One loop?

Quote:
Originally Posted by Mark McLeod View Post
It is more efficient to combine them into one loop, but not significantly. If they are affecting Teleop at all then you need to rethink your code design.

Before doing anything I'd suggest measuring the rates of all your loops to see how they are affecting overall timing.
One or more of your loops may not be running as fast as 20ms and that would impact Teleop worst of all.

Look under Support Code" in your project and you will see Elapsed Times.vi
Drop a copy of this vi into each of your loops, and into teleop, and give them unique names so they can be told apart.
Open the front panel of Elapsed Times and run your code in debug from Robot Main. Elapsed Times will tell you how long each loop is actually taking.
Each of your loops should be taking just a few ms longer than 20ms. If you see any that are taking significantly longer than that, then you will need to slow down the loop to a more reasonable time or you will need to streamline your code more.
Thanks, I'll check that.

And about the code design, our code design is based on state machines where every sub system has a different state machine in periodic tasks (a loop) which get commands from other vi's about state changes (or it changes states by itself, depends on the sub system)

for example,
we have the state machine for out hammer sub system (which kicks the ball)
the states it has:
1. Hammer Ready
2. Shooting
3. Hammer Down
4. Reloading

the loop runs in the periodic waiting for a command from any other vi (in the form of a global variable).
the teleop contains all the operating code and sends the commands according to the driver's actions.
so pressing on a certaing button will send a "Kick" command and the Hammer state machine will move to shooting state, in the shooting state we have all the code that control the hammer and actually make it kick and when it finishes kicking it automatically moves to 'Hammer Down' state.

What do you think about our code design?
we found it very easy to program and debug using this method.
Reply With Quote
  #5   Spotlight this post!  
Unread 10-10-2014, 16:35
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,713
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Parallel loops vs. One loop?

Your code design sounds fine.
That's how we also implement most complex robot functions.

With that style you can save some processing overhead by reducing how fast you check the global variable. For instance, a human button press can be checked more slowly, such as every 100ms, and the human probably won't notice any lag.

But measure how long everything is taking first. You may find a coding error elsewhere.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 10-10-2014 at 21:46.
Reply With Quote
  #6   Spotlight this post!  
Unread 10-10-2014, 21:44
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,557
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: Parallel loops vs. One loop?

I'm curious whether there's any noticeable difference on the roboRIO with dual cores, or whether there are enough other processes running that it doesn't matter.
Reply With Quote
  #7   Spotlight this post!  
Unread 12-10-2014, 00:55
tcjinaz tcjinaz is offline
Tim
FRC #3853
Team Role: Mentor
 
Join Date: May 2011
Rookie Year: 2011
Location: Arizona
Posts: 206
tcjinaz has a spectacular aura abouttcjinaz has a spectacular aura about
Re: Parallel loops vs. One loop?

Quote:
Originally Posted by Joe Ross View Post
I'm curious whether there's any noticeable difference on the roboRIO with dual cores, or whether there are enough other processes running that it doesn't matter.
Isn't the cRio a dual core PowerPC, ~400mHz?
Given that, it's not the number of cores that will matter, the roboRio will provide more MIPS just on clock speed (yeah, I know, how deep are the pipelines), plus some architectural enhancements. I kinda suspect the RTOS switch may be a wash, but I have not dug deep enough to comment. Just on OS bigotry I like the switch to Linux.
__________________
Software Mentor
3853 Pridetronics[

Reply With Quote
  #8   Spotlight this post!  
Unread 13-10-2014, 07:52
Greg McKaskle Greg McKaskle is online now
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,748
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: Parallel loops vs. One loop?

The cRIO is single core.

Greg McKaskle
Reply With Quote
Reply


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 08:01.

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