Go to Post FIRST is an addiction but at least it is one of the healthiest addictions you can have (if you wear your safety goggles!). - Pavan Dave [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 26-01-2015, 21:11
nathanzentner08 nathanzentner08 is offline
Registered User
FRC #2073
 
Join Date: Jan 2015
Location: Sacramento
Posts: 6
nathanzentner08 is an unknown quantity at this point
Command Based Programming (Threads?)

I was under the assumption that when you used the a Command Group and added parallel that it would handle them as separate threads. I was testing this out with my group and when I put a Timer.delay in the execute method of one command, it held up all execution. Is this multi-threaded based? Are there other ways to run things within threads within the WPILibJ?
Reply With Quote
  #2   Spotlight this post!  
Unread 26-01-2015, 22:18
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Command Based Programming (Threads?)

If you're using Timer.delay than you're fundamentally missing the purpose of the command based structure... essentially you should be split into three different parts (the code before the wait, the wait itself, and the code after the wait) and they should all be non-interruptive commands.
Reply With Quote
  #3   Spotlight this post!  
Unread 26-01-2015, 22:25
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: Command Based Programming (Threads?)

Command-based programming is just an extension of iterative that makes it easier to schedule and trigger actions. It gives you most of the benefits of multithreading without the added complexity of worrying about deadlocks and race conditions.

All commands run in the same thread, so they can't ever block. When commands are run, they are added to a queue which the scheduler executes iteratively.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #4   Spotlight this post!  
Unread 26-01-2015, 22:25
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
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: Command Based Programming (Threads?)

Quote:
Originally Posted by Arhowk View Post
they should all be non-interruptive commands.
What does "non-interruptive" mean?

Reply With Quote
  #5   Spotlight this post!  
Unread 26-01-2015, 22:29
TFleig78's Avatar
TFleig78 TFleig78 is offline
Registered User
AKA: Tyler
FRC #0078 (Air Strike)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Rhode Island
Posts: 58
TFleig78 will become famous soon enoughTFleig78 will become famous soon enough
Re: Command Based Programming (Threads?)

Quote:
Originally Posted by Ether View Post
What does "non-interruptive" mean?

He probably meant interruptible.
From the wpilib website:

When a command is scheduled, the Scheduler checks to make sure that no other commands are using the same subsystems that the new command requires. If one or more of the subsystems is currently in use, and the current command is interruptible, it will be interrupted and the new command will be scheduled. If the current command is not interruptible, the new command will fail to be scheduled.
Reply With Quote
  #6   Spotlight this post!  
Unread 26-01-2015, 22:43
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
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: Command Based Programming (Threads?)

Quote:
Originally Posted by Ether View Post
What does "non-interruptive" mean?
Quote:
Originally Posted by TFleig78 View Post
He probably meant interruptible.
You probably meant non-interruptible?

Quote:
Originally Posted by TFleig78 View Post
If the current command is not interruptible, the new command will fail to be scheduled.
So if all the commands should be "non-interruptive", and non-interruptive means non-interruptible, then all new commands will fail to be scheduled if any command is presently running?


Reply With Quote
  #7   Spotlight this post!  
Unread 26-01-2015, 22:59
TFleig78's Avatar
TFleig78 TFleig78 is offline
Registered User
AKA: Tyler
FRC #0078 (Air Strike)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Rhode Island
Posts: 58
TFleig78 will become famous soon enoughTFleig78 will become famous soon enough
Re: Command Based Programming (Threads?)

Quote:
Originally Posted by Ether View Post
You probably meant non-interruptible?



So if all the commands should be "non-interruptive", and non-interruptive means non-interruptible, then all new commands will fail to be scheduled if any command is presently running?


Yes, I meant non-interruptible.

And yes, the currently running command would have to end before any other command that requires the same subsystem could be scheduled. This is only true if you set the command's interruptible property to false.
Reply With Quote
  #8   Spotlight this post!  
Unread 26-01-2015, 23:03
gixxy's Avatar
gixxy gixxy is offline
Programming and Arduino Mentor
AKA: Gustave Michel III
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Ruston, LA
Posts: 207
gixxy is on a distinguished road
Re: Command Based Programming (Threads?)

The way commands are run in the Command Based Structure are via a queue. The execute method of each scheduled command is executed in sequence (I assume in the order added to the queue). This means that each command's execute method shouldn't contain anything that will sleep the thread (delays) or otherwise tie the thread up for long periods of time (intensive camera calculations). Such actions will lead to decreased robot responsiveness.

There are many other ways to implement non-blocking timers, if you describe what it is you mean I can help point you in the right direction.

I believe by "non-interruptive" Arhowk meant non-blocking. As far as interrupts on a command, they are only used when a new command is added to the queue that uses the SAME subsystem as another queued command. So, if the first is not interruptible, the second command will not run, if it is, the first command will be interrupted and the second will take over. Command Interrupts do not refer to commands using different subsystems in any way.
__________________
Programmer - A creature known for converting Caffeine into Code.
Studying Computer Science @ Louisiana Tech University
Associate Consultant @ Fenway Group

2012-13: 3946 - Head of Programming, Electrical and Web
2014 - 3468 - Programming Mentor
2015 - Present - Lurker
Reply With Quote
  #9   Spotlight this post!  
Unread 26-01-2015, 23:20
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
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: Command Based Programming (Threads?)

Quote:
Originally Posted by gixxy View Post
I believe by "non-interruptive" Arhowk meant non-blocking.
@Arhowk: is that what you meant?


Reply With Quote
  #10   Spotlight this post!  
Unread 27-01-2015, 06:44
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Command Based Programming (Threads?)

Quote:
Originally Posted by Ether View Post
@Arhowk: is that what you meant?


yes... by non-interruptive, I meant code that does not engage the use of the java stall commands (Timer.delay, Object.wait, Thread.sleep)
Reply With Quote
  #11   Spotlight this post!  
Unread 27-01-2015, 08:43
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Command Based Programming (Threads?)

The way the Command Based Structure is designed is to keep a list of all currently running commands. Every ~20ms each of these commands will be executed one at a time. Each of the commands should be designed to execute very quickly so it does not delay the execution of the other commands that are being executed. This means, if you delay the execution by some means this will cause the other commands after it in the list to wait on the delayed command.
Reply With Quote
  #12   Spotlight this post!  
Unread 27-01-2015, 09:18
nathanzentner08 nathanzentner08 is offline
Registered User
FRC #2073
 
Join Date: Jan 2015
Location: Sacramento
Posts: 6
nathanzentner08 is an unknown quantity at this point
Re: Command Based Programming (Threads?)

Our thought was to have an image processing Command, that would have taken a bit more time and processing power, that ran in a parallel Command Group, but since it isn't really parallel, then the main thread would be stuck in the Image Processing command until it returned.

This non-threaded functionality could affect our driving (Essentially Everything) because if the thread is working on image processing then it is not available to change speed on our motors. (This is just a simple example.)

Im coaching the team and talking about parallel processing and trying to show an example based on the API that is given. The more I work with it, the more I find it isn't really there.

It's alright that it is not in there, but the documentation says:

"... instead of waiting for the child to finish, a CommandGroup will have it run at the same time as the subsequent Commands. ..."
Reply With Quote
  #13   Spotlight this post!  
Unread 27-01-2015, 09:25
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Command Based Programming (Threads?)

Quote:
Originally Posted by nathanzentner08 View Post
Our thought was to have an image processing Command, that would have taken a bit more time and processing power, that ran in a parallel Command Group, but since it isn't really parallel, then the main thread would be stuck in the Image Processing command until it returned.

This non-threaded functionality could affect our driving (Essentially Everything) because if the thread is working on image processing then it is not available to change speed on our motors. (This is just a simple example.)

Im coaching the team and talking about parallel processing and trying to show an example based on the API that is given. The more I work with it, the more I find it isn't really there.

It's alright that it is not in there, but the documentation says:

"... instead of waiting for the child to finish, a CommandGroup will have it run at the same time as the subsequent Commands. ..."
It will run it similar to how commands for different subsystems would run at the "same time". If you execute method takes a long time to execute it will slow everything else down.

Last night we created a separate thread that will run our vision processing so it doesn't slow down the processing of commands. I can assist you with this if you'd like.
Reply With Quote
  #14   Spotlight this post!  
Unread 27-01-2015, 09:50
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
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: Command Based Programming (Threads?)

Quote:
Originally Posted by notmattlythgoe View Post
If you execute method takes a long time to execute it will slow everything else down.
Within the command-based architecture, what is the recommended way to implement a delay (for example, in a firing sequence).


Reply With Quote
  #15   Spotlight this post!  
Unread 27-01-2015, 09:58
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Command Based Programming (Threads?)

Quote:
Originally Posted by Ether View Post
Within the command-based architecture, what is the recommended way to implement a delay (for example, in a firing sequence).


I would suggest using a WaitCommand in a CommandGroup. Below is an example that will fire, then wait 1 second before firing again and then finishing the CommandGroup.

Code:
public FiringCommandGroup extends CommandGroup {

     public FiringCommandGroup() {
          addSequential(new FireCommand());
          addSeqiential(new waitCommand(1));
          addSequential(new FireCommand());
     }
}
Another way to do it would be to check the time passed in the execute method of a command to see if the period of time you want to wait has passed.

Commands also have a timeSinceInitialixed() method that will return the time in seconds since the command was initialized(aka started). This could be used to check to see if a command has been running for a certain period of time.
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 11:19.

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