Go to Post Welcome to FIRST! You will soon figure out that there is no "exit strategy" from this program. - David Brinza [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 28-02-2014, 22:49
cgmv123's Avatar
cgmv123 cgmv123 is offline
FRC RI/FLL Field Manager
AKA: Max Vrany
FRC #1306 (BadgerBOTS)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Madison, WI
Posts: 2,073
cgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond repute
Re: Java wait Function

Timer.delay() is supposed to leave outputs set where they are as well, but I've had more success using Timer.getFPGATimestamp() in conjunction with a loop.
__________________
BadgerBOTS Robotics|@team1306|Facebook: BadgerBOTS
2016 FIRST Championship Tesla Division | 2016 Wisconsin Regional Engineering Inspiration Award

2015 FIRST Championship Carson Division | 2015 Wisconsin Regional Chairman's Award

2013 FIRST Championship Curie Division | 2013 Wisconsin Regional Chairman's Award

2012 FIRST Championship Archimedes Division | 2012 Wisconsin Regional Engineering Inspiration Award, Woodie Flowers Finalist Award (Lead Mentor Ben Senson)

Reply With Quote
  #2   Spotlight this post!  
Unread 01-03-2014, 09:10
Bryan Herbst's Avatar
Bryan Herbst Bryan Herbst is offline
Registered User
AKA: Bryan
FRC #2052 (KnightKrawler)
Team Role: Mentor
 
Join Date: Sep 2007
Rookie Year: 2007
Location: Minneapolis, Minnesota
Posts: 544
Bryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond repute
Re: Java wait Function

Quote:
Originally Posted by cgmv123 View Post
Timer.delay() is supposed to leave outputs set where they are as well, but I've had more success using Timer.getFPGATimestamp() in conjunction with a loop.
This is critical to understand.

Our team had similar requirements surrounding our catapult (do X, wait half a second, then do Y). Originally the programmers implemented this using Timer.delay().

The result was that when the drivers tried to perform the action while moving, but then stopped moving or changed directions during the action, the robot would keep moving.

Though .5 seconds doesn't sound like much, it is plenty of time for your robot to go just a little too far and injure someone, break something, or get you a penalty for going too far outside the arena.

Use Timer.delay() with caution.
__________________
Team 2052- Knightkrawler
Mentor and volunteer
Reply With Quote
  #3   Spotlight this post!  
Unread 01-03-2014, 09:42
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: Java wait Function

Quote:
Originally Posted by Tanis View Post
This is critical to understand.
^This.

Year in and year out I see programmers bumping up against this concept.

I think it's probably fair to say that some (many?) of them receive advice on how to fix the problem, but never really understand why there was a problem and why the fix fixed it.

Does anyone have a link to a clear, simple, well-written tutorial on concurrent processing for FRC that covers threads, state machines, and interrupts?



Last edited by Ether : 01-03-2014 at 13:18.
Reply With Quote
  #4   Spotlight this post!  
Unread 02-03-2014, 20:13
ProgrammerMatt ProgrammerMatt is offline
Programmer-Electrical-Mechanical
FRC #0228 (Gus)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Southington
Posts: 138
ProgrammerMatt is just really niceProgrammerMatt is just really niceProgrammerMatt is just really niceProgrammerMatt is just really nice
Re: Java wait Function

This is what I have done.

Inside op control:
Code:
if(INSERT SOMETHING HERE) {

new Thread() {
     public void run() {
          //Code to run here:
          Thread.sleep(time in ms);
          //More code
          }.start()
     }
}
What this does is every time the if statement becomes true it creates a thread and runs the code in run() {} then kills the thread. you can use Thread.sleep(); inside this and it will NOT affect your main code only whats in that thread.

This has worked well for me.

Hope this helps!

Matt
__________________
2015-2016 CSA
Software Engineering Student @ Johnson & Wales University
Team 228, Gus Robotics Inc.
Facebook
FLL Mentor for 1107, Edison Eagles!
2015- CT State Champions
2012- WPI Finalist(Thanks 1884 and 549), Spirt, Best Website
2011- WPI Chairman's award winners!
2010- WPI Champions! (thanks 230 & 20), WPI Engineering Inspiration, CT Best Website, CT VEX Champions (VRC228, VRC228b) (21-1-0)
2009- QCC VEX Champions (VRC228) (11-0-0), Innovate Award (VRC228)
Reply With Quote
  #5   Spotlight this post!  
Unread 02-03-2014, 21:19
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 330
fovea1959 will become famous soon enough
Re: Java wait Function

how does the thread get killed?
Reply With Quote
  #6   Spotlight this post!  
Unread 02-03-2014, 21:27
AlexBrinister AlexBrinister is offline
Registered User
AKA: Alex Brinister
FRC #1768 (RoboChiefs)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Bolton, MA
Posts: 93
AlexBrinister will become famous soon enough
Re: Java wait Function

My understanding is that the JVM handles it. From here, it seems like letting the JVM handle could introduce race conditions if you access the same data from multiple threads like that...

Alex Brinister
Reply With Quote
  #7   Spotlight this post!  
Unread 02-03-2014, 22:50
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 330
fovea1959 will become famous soon enough
Re: Java wait Function

ah. looked at it too fast. The thread completes normally when run() returns.
Reply With Quote
  #8   Spotlight this post!  
Unread 03-03-2014, 07:50
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,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: Java wait Function

Is safety configured for the drive base? I'd hope that the Java implementation would halt the drive motors when wait() or breakpoints delay for more than 100ms.

Greg McKaskle
Reply With Quote
  #9   Spotlight this post!  
Unread 03-03-2014, 08:47
AlexBrinister AlexBrinister is offline
Registered User
AKA: Alex Brinister
FRC #1768 (RoboChiefs)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Bolton, MA
Posts: 93
AlexBrinister will become famous soon enough
Re: Java wait Function

I think this is only enforced if you have the Motor Safety Helper enabled. This feature is optional in both the C++ and Java libraries and can be disabled by the programmer. It is generally better to keep it enabled but to extend the timeout period using the SetTimeout() function in whatever motor controller class you choose to use (Talon, Victor, CANJaguar, Jaguar, etc).

Alex Brinister
Reply With Quote
  #10   Spotlight this post!  
Unread 03-03-2014, 21: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,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: Java wait Function

What I intended to ask was whether the Motor Safety Helper was enabled when the robot motors ran for several seconds during the sleep() call.

Greg McKaskle
Reply With Quote
  #11   Spotlight this post!  
Unread 03-03-2014, 22:51
ProgrammerMatt ProgrammerMatt is offline
Programmer-Electrical-Mechanical
FRC #0228 (Gus)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Southington
Posts: 138
ProgrammerMatt is just really niceProgrammerMatt is just really niceProgrammerMatt is just really niceProgrammerMatt is just really nice
Re: Java wait Function

I have not turned motor safety helper on or off. So what ever it defaults to is what it is set to and it still works for me.
__________________
2015-2016 CSA
Software Engineering Student @ Johnson & Wales University
Team 228, Gus Robotics Inc.
Facebook
FLL Mentor for 1107, Edison Eagles!
2015- CT State Champions
2012- WPI Finalist(Thanks 1884 and 549), Spirt, Best Website
2011- WPI Chairman's award winners!
2010- WPI Champions! (thanks 230 & 20), WPI Engineering Inspiration, CT Best Website, CT VEX Champions (VRC228, VRC228b) (21-1-0)
2009- QCC VEX Champions (VRC228) (11-0-0), Innovate Award (VRC228)
Reply With Quote
  #12   Spotlight this post!  
Unread 04-03-2014, 06:46
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,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: Java wait Function

Does the default result in zombie robots? I'd hope not. It should take effort to produce a zombie robot.

Also, if you are turning off the safety config, please ensure that everyone running the robot knows how to disable or estop the robot. Personally, I'd only turn it off when the robot is on blocks and I want the motors to keep running while I'm at a breakpoint.

Greg McKaskle
Reply With Quote
  #13   Spotlight this post!  
Unread 14-03-2014, 15:45
NotInControl NotInControl is offline
Controls Engineer
AKA: Kevin
FRC #2168 (Aluminum Falcons)
Team Role: Engineer
 
Join Date: Oct 2011
Rookie Year: 2004
Location: Groton, CT
Posts: 261
NotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond repute
Re: Java wait Function

Quote:
Originally Posted by cgmv123 View Post
Timer.delay() is supposed to leave outputs set where they are as well, but I've had more success using Timer.getFPGATimestamp() in conjunction with a loop.
If I remember correctly, Timer.delay() is a wrapper and simply calls Thread.sleep().

This causes the calling thread to sleep, and thus will cause your robot to hang unless called from a separate thread.

Use time stamps as mentioned.

System.getCurrentTimeMillis, or the FPGA timer, or anything else in a loop,

or spawn a separate thread and call thread.sleep() in the new thread.

But do not call Thread.sleep or Timer.Delay in the same thread as your TeleOp/Auto periodic functions.

Hope this helps,
Kevin
__________________
Controls Engineer, Team 2168 - The Aluminum Falcons
[2016 Season] - World Championship Controls Award, District Controls Award, 3rd BlueBanner
-World Championship- #45 seed in Quals, World Championship Innovation in Controls Award - Curie
-NE Championship- #26 seed in Quals, winner(195,125,2168)
[2015 Season] - NE Championship Controls Award, 2nd Blue Banner
-NE Championship- #26 seed in Quals, NE Championship Innovation in Controls Award
-MA District Event- #17 seed in Quals, Winner(2168,3718,3146)
[2014 Season] - NE Championship Controls Award & Semi-finalists, District Controls Award, Creativity Award, & Finalists
-NE Championship- #36 seed in Quals, SemiFinalist(228,2168,3525), NE Championship Innovation in Controls Award
-RI District Event- #7 seed in Quals, Finalist(1519,2168,5163), Innovation in Controls Award
-Groton District Event- #9 seed in Quals, QuarterFinalist(2168, 125, 5112), Creativity Award
[2013 Season] - WPI Regional Winner - 1st Blue Banner
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:38.

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