Go to Post Anything is capable of happening in FIRST. - Dorienne [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 11-12-2015, 14:47
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 255
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Command based code secan

This is my first year helping a team with some robot code. We are focusing on the command base robot model. We would like to do some acceleration control and other timed loops. I'm familiar with Vex and have done similar control using while loop and using a wait instruction at the end to use as the time calculation. With the FRC system do i or can i use a loop and wait code or use the FRC periodic cycle? I may not be using the right term to describe what I'm looking for but I hope you understand and can direct me.

Thanks
Reply With Quote
  #2   Spotlight this post!  
Unread 11-12-2015, 14:54
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,722
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 code secan

Quote:
Originally Posted by cpapplefamily View Post
This is my first year helping a team with some robot code. We are focusing on the command base robot model. We would like to do some acceleration control and other timed loops. I'm familiar with Vex and have done similar control using while loop and using a wait instruction at the end to use as the time calculation. With the FRC system do i or can i use a loop and wait code or use the FRC periodic cycle? I may not be using the right term to describe what I'm looking for but I hope you understand and can direct me.

Thanks
If you are using the command based structure then using long running loops and wait commands can be very detrimental. What you want to do is us the execute methods of your commands to the time. You can treat the execute method like it is the body of a loop.
Reply With Quote
  #3   Spotlight this post!  
Unread 11-12-2015, 15:31
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 255
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: Command based code secan

Quote:
Originally Posted by notmattlythgoe View Post
If you are using the command based structure then using long running loops and wait commands can be very detrimental. What you want to do is us the execute methods of your commands to the time. You can treat the execute method like it is the body of a loop.
I understand enough that long loops would be bad in this environment. Do I use waits and loops in the execute method? Then use the isFinished() command or a condition of the loop to end the code. What happens the loop was running still when the execute method is called again and again. Or do I record the time since last execute to calculate my time sensitive code? most of the documentation I read is is the execute and isFinished is called "ABOUT" 50 times / sec or every 20ms.

This is not what I'm aiming for but simply put every 1 sec i want to add 10 to double myCounter

Code:
double myCounter = 0;

while(true){

   myCounter = myCounter + 10;
   wait(1000); //Wait 1 sec

}
Reply With Quote
  #4   Spotlight this post!  
Unread 11-12-2015, 15:35
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,722
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 code secan

Quote:
Originally Posted by cpapplefamily View Post
I understand enough that long loops would be bad in this environment. Do I use waits and loops in the execute method? Then use the isFinished() command or a condition of the loop to end the code. What happens the loop was running still when the execute method is called again and again. Or do I record the time since last execute to calculate my time sensitive code? most of the documentation I read is is the execute and isFinished is called "ABOUT" 50 times / sec or every 20ms.

This is not what I'm aiming for but simply put every 1 sec i want to add 10 to double myCounter

Code:
double myCounter = 0;

while(true){

   myCounter = myCounter + 10;
   wait(1000); //Wait 1 sec

}
You would not want to put any loops or waits in the execute method and instead check the time there to see if you should add 10 to the counter.
Reply With Quote
  #5   Spotlight this post!  
Unread 11-12-2015, 15:37
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 255
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: Command based code secan

pseudo code

Code:
public class myCounterCommand extends CommandBase {

double myCounter;

   protected void initialize() {
      myCounter = 0;
   }
....
....
....

   protected void execute() {
      myCounter = myCounter + 10;
      
      wait(1000);
    }
or do I

Code:
...
...
   protected void execute() {
      while(true){
         myCounter = myCounter + 10;
      
         wait(1000);
      }
    }
here since the first called execute is not done will sequential calls be skipped?

here what happens the 49 times this execute is called when the wait is not done?


or do I

Code:
double lastScan,thisScan:
...
...
   protected void execute() {
     
      thisScan = *some clock value;

      if(thisScan < lastScan + 1000){

         myCounter = myCounter + 10;
         lastScan = thisScan;

      }

    }
Seems then we can only safely calculate with time values Greater than 20ms and could be of by +19ms

Last edited by cpapplefamily : 11-12-2015 at 15:47. Reason: added comments
Reply With Quote
  #6   Spotlight this post!  
Unread 11-12-2015, 15:42
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,722
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 code secan

Quote:
Originally Posted by cpapplefamily View Post
pseudo code

Code:
public class myCounterCommand extends CommandBase {

double myCounter;

   protected void initialize() {
      myCounter = 0;
   }
....
....
....

   protected void execute() {
      myCounter = myCounter + 10;
      
      wait(1000);
    }
or do I

Code:
...
...
   protected void execute() {
      while(true){
         myCounter = myCounter + 10;
      
         wait(1000);
      }
    }
here since the first called execute is not done will sequential calls be skipped?

here what happens the 49 times this execute is called when the wait is not done?
This will actually cause your entire robot to lock up for 1 second. A general rule of thumb when using the Command Based structure is to never use a wait().

Instead use a Date field to store the time and increment your count when the time has exceeded a second.
Reply With Quote
  #7   Spotlight this post!  
Unread 11-12-2015, 15:58
GeeTwo's Avatar
GeeTwo GeeTwo is online now
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,654
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Command based code secan

This one is closer:
Quote:
Originally Posted by cpapplefamily View Post

or do I

Code:
double lastScan,thisScan:
...
...
   protected void execute() {
     
      thisScan = *some clock value;

      if(thisScan < lastScan + 1000){

         myCounter = myCounter + 10;
         lastScan = thisScan;

      }

    }
Seems then we can only safely calculate with time values Greater than 20ms and could be of by +19ms
but the comparison in the if statement should be ">" or ">=", not "<".
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #8   Spotlight this post!  
Unread 12-12-2015, 01:04
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 255
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: Command based code secan

< -- > Yep was quick pseudo code. I didn't put to much though into it. Are there timing charts that show how the different methods in a command react?

So the same is true with wait() and a while(true) loop that may never end that other commands would never be scheduled or executed?
Reply With Quote
  #9   Spotlight this post!  
Unread 12-12-2015, 09:46
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,722
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 code secan

Quote:
Originally Posted by cpapplefamily View Post
< -- > Yep was quick pseudo code. I didn't put to much though into it. Are there timing charts that show how the different methods in a command react?

So the same is true with wait() and a while(true) loop that may never end that other commands would never be scheduled or executed?
That is correct. The Schedule that controls the commands in sequence not parallel. So if one command is stuck in the execute method then the other commands will never execute.
Reply With Quote
  #10   Spotlight this post!  
Unread 12-12-2015, 10:12
GeeTwo's Avatar
GeeTwo GeeTwo is online now
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,654
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Command based code secan

Quote:
Originally Posted by cpapplefamily View Post
< -- > Yep was quick pseudo code. I didn't put to much though into it. Are there timing charts that show how the different methods in a command react?

So the same is true with wait() and a while(true) loop that may never end that other commands would never be scheduled or executed?
I am not familiar with any timing charts.

On the second question, the execute() command will be called repeatedly, so you should structure it to do its work in less time (preferably much less time) than the call periodicity. In particular, you should avoid system calls with indeterminate duration, such as object instantiation, and other activities which may trigger garbage collection. IIRC, we usually turn GC off, because as long as the code doesn't constantly declare and release variables, you won't burn through the heap in three minutes. If you could burn through it that quickly, you would almost certainly see it during practice sessions which run many times as long.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #11   Spotlight this post!  
Unread 12-12-2015, 20:30
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 255
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: Command based code secan

All this input is great. When it comes right down to it, attempt to assure the methods completes before the next iteration of the command < 20ms. I maybe beating this to death but it must be predicable what would happen if the method was not complete on the next iteration like item 1 it initialize() was not complete would the execute() simply start in the first positive clock after it completed. Same with item 2 if the execute() was not complete would the isFinshed() still run and a new execute() start only after the previous finished on a positive clock cycle.

These timing charts are what I expect may happen. The last timing chart has not been discussed here but if the command is scheduled to run but has not finished. Would the end() method run and a new initialize() start?

In the PLC world I work with professionally if I have a periodic task that does not complete before the next period I get a minor error and that iteration is skipped nothing horrific happens only I loose a scan.
Attached Thumbnails
Click image for larger version

Name:	Command Period 2.JPG
Views:	17
Size:	113.3 KB
ID:	19549  
Reply With Quote
  #12   Spotlight this post!  
Unread 12-12-2015, 21:27
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,572
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: Command based code secan

Your picture for #1 is correct, for that command only. #2 is not correct, because isFinished will not run while execute is still running. In addition, it will also delay the execution of every other command. You could think of it as there only being a single clock, and any command method can stretch the clock.
Reply With Quote
  #13   Spotlight this post!  
Unread 13-12-2015, 23:58
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 255
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: Command based code secan

Quote:
Originally Posted by Joe Ross View Post
Your picture for #1 is correct, for that command only. #2 is not correct, because isFinished will not run while execute is still running. In addition, it will also delay the execution of every other command. You could think of it as there only being a single clock, and any command method can stretch the clock.
We are getting somewhere now. I shifted the isFinished() to after execute() completes and before the next iteration of execute(). Also attempted to depict the second command and how it would be effected by other commands methods taking longer than one period on the second part "Special Conditions". Take a look.
Attached Thumbnails
Click image for larger version

Name:	Command Period 3.JPG
Views:	10
Size:	176.5 KB
ID:	19552  
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 10:50.

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