Go to Post Glue it, screw it, bolt it, rivet it, weld it. If the design is flawed it will fail. - Gdeaver [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 13-02-2014, 11:09
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: 336
fovea1959 will become famous soon enough
More resolution than 20ms

We need to watch a sensor, then cut a motor off 100ms later.

Right now we are watching the sensor, waiting for it to trip, set t0, and then watching the elapsed time (System.currentTimeMillis() - t0), and returning true from isFinished() when the elapsed time > 100ms (not doing this all at once, it happens over successive calls to isFinish(), as it should be). All as advertised, dead-simple, and worked the first time...

Doing this in isFinished() *is* introducing wobble in the 100ms: because we only get the CPU every 20ms, we could be as little as 0.00000001ms or much as 19.9999999999ms late in seeing the sensor go, and would could be as little as 0.00000001ms or as much as 19.9999999999ms late in seeing the time elapse. We can adjust for consistent delay, but the +/- 19.9999999999ms overall is something I'd like to tighten up.

I know the PID code starts it's own thread, so we can use that as a model if we want to have a separate (tighter) thread handle this.

Has anyone else done this simpler-than-PID case already? I'm willing to work from scratch using the PID code as a base, but am resistant to reinventing wheels...

Also, do we have access to any interrupt and timer capability on the FPGA from Java that would be helpful here?

Last edited by fovea1959 : 13-02-2014 at 11:28.
Reply With Quote
  #2   Spotlight this post!  
Unread 13-02-2014, 11:53
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 434
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: More resolution than 20ms

I created a class earlier in the season which would latch the output state of a solenoid for a specified duration.
After the duration has elapsed, the output is de-energized.

This implementation makes use of the TimerTask class.

It should be pretty easy to modify this class for your own use.

https://gist.github.com/jcorcoran/7b1ffd41391144ea8df1

I've tried to comment the code sufficiently, but if you have any questions feel free to contact me.
__________________
http://team2168.org
Reply With Quote
  #3   Spotlight this post!  
Unread 13-02-2014, 13:45
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: 336
fovea1959 will become famous soon enough
Re: More resolution than 20ms

awesome, simple, and easy to explain to students.

is multithreading in Java on the cRIO robust? Do the TimerTasks get scheduled in a timely manner?

Last edited by fovea1959 : 13-02-2014 at 13:50.
Reply With Quote
  #4   Spotlight this post!  
Unread 13-02-2014, 13:48
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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: More resolution than 20ms

Quote:
Originally Posted by fovea1959 View Post
is multithreading in Java on the cRIO robust?
I have a related question. Is multithreading in Java on the cRIO handled by the JVM, or does the JVM make calls to vxWorks to handle that?


Reply With Quote
  #5   Spotlight this post!  
Unread 13-02-2014, 17:00
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 434
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: More resolution than 20ms

Quote:
Originally Posted by fovea1959 View Post
is multithreading in Java on the cRIO robust? Do the TimerTasks get scheduled in a timely manner?
Yes. It works well enough that we haven't had to really dig into the implementation. We've used an implementation similar to what I linked above to create periodicly executing threads without any problems in the past.

We haven't tried to quanitfy their limitations.
__________________
http://team2168.org
Reply With Quote
  #6   Spotlight this post!  
Unread 14-02-2014, 11:14
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: 336
fovea1959 will become famous soon enough
Re: More resolution than 20ms

thanks. It ended up being a very simple solution, and quite responsive. Will play with how often to reschedule our TimerTask() and see what happens to CPU utilitization, but it shouldn't be major (look at switch, look at timer, look at state, poke motor controller, update dashboard)...
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 12:42.

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