Go to Post Honestly, I can't understand why anyone wouldn't want to be a mentor. The fools don't know what they are missing. - Steven Smith [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 Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 10-01-2011, 17:36
danielcezar danielcezar is offline
Registered User
AKA: Daniel Cezar
FRC #1382 (Etep Team)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Brazil
Posts: 8
danielcezar is an unknown quantity at this point
How do I use interrupt in Java?

I've been spent i lot of time trying to figure out how to use interrupt in java for FRC, but i didnt find anywhere on the web.

I need to use a interrupt with encoder and another one by time, each 25ms, a interruption be called.

thanks
Reply With Quote
  #2   Spotlight this post!  
Unread 11-01-2011, 02:19
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: How do I use interrupt in Java?

Quote:
Originally Posted by danielcezar View Post
I've been spent i lot of time trying to figure out how to use interrupt in java for FRC, but i didnt find anywhere on the web.

I need to use a interrupt with encoder and another one by time, each 25ms, a interruption be called.

thanks
If you look that the DigitalInput class in WPILibJ, you will notice that it inherits the InterruptableSensorBase methods. You can use that to interrupt on inputs hooked to an encoder.

The real question is why you think you need interrupts at all. The Encoder class in WPILibJ accesses hardware quadrature decoders in the FPGA that remove the need for interrupts or timers. If you are using simple encoders, then you can use the Counter class in WPILibJ. Both of these classes will keep track of how far the encoder has gone and will tell you how fast it's moving.

-Joe
Reply With Quote
  #3   Spotlight this post!  
Unread 11-01-2011, 06:12
danielcezar danielcezar is offline
Registered User
AKA: Daniel Cezar
FRC #1382 (Etep Team)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Brazil
Posts: 8
danielcezar is an unknown quantity at this point
Re: How do I use interrupt in Java?

And what about a Timer interrupt?
Reply With Quote
  #4   Spotlight this post!  
Unread 11-01-2011, 08:54
derekwhite's Avatar
derekwhite derekwhite is offline
Java Virtual Machine Hacker
no team (FIRST@Oracle)
Team Role: Programmer
 
Join Date: May 2009
Rookie Year: 2009
Location: Burlington, MA
Posts: 127
derekwhite is on a distinguished road
Re: How do I use interrupt in Java?

In Java the simplest thing to do is create a high priority thread that runs in a loop calling sleep (or WPILibj's Timer.delay) for 25 ms.

You can also use the java.util.Timer class for more complex activities. scheduleAtFixedRate() may be something to look at.
Reply With Quote
  #5   Spotlight this post!  
Unread 12-01-2011, 18:15
danielcezar danielcezar is offline
Registered User
AKA: Daniel Cezar
FRC #1382 (Etep Team)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Brazil
Posts: 8
danielcezar is an unknown quantity at this point
Re: How do I use interrupt in Java?

The only problem is that when i call sleep, the software stops at all, so i cant move the robot while this.

Should i call inside the thread or not?
Reply With Quote
  #6   Spotlight this post!  
Unread 12-01-2011, 18:37
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: How do I use interrupt in Java?

Quote:
Originally Posted by danielcezar View Post
The only problem is that when i call sleep, the software stops at all, so i cant move the robot while this.

Should i call inside the thread or not?
You should call it in a separate thread if it blocks the execution of code you don't want blocked.

Perhaps you should take a step back and explain what it is that you are trying to accomplish instead of asking how to implement the solution that you've come up with. Chances are there is a better way to accomplish it.

-Joe
Reply With Quote
  #7   Spotlight this post!  
Unread 12-01-2011, 18:47
danielcezar danielcezar is offline
Registered User
AKA: Daniel Cezar
FRC #1382 (Etep Team)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Brazil
Posts: 8
danielcezar is an unknown quantity at this point
Re: How do I use interrupt in Java?

I'm trying to call a interrupt each 25ms, because i want to write my own PID control, and with this interrupt i'm acumulate the error to calc the integral.

someone here said me to use a thread, and i did it, a diferent class with with the thread, overwriting the run method. But when i try to call .sleep to wait each 25ms, it stops the intire robot.
Reply With Quote
  #8   Spotlight this post!  
Unread 12-01-2011, 19:01
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: How do I use interrupt in Java?

Quote:
Originally Posted by danielcezar View Post
I'm trying to call a interrupt each 25ms, because i want to write my own PID control, and with this interrupt i'm acumulate the error to calc the integral.
Have you tried the built-in PID classes?

Quote:
Originally Posted by danielcezar View Post
someone here said me to use a thread, and i did it, a diferent class with with the thread, overwriting the run method. But when i try to call .sleep to wait each 25ms, it stops the intire robot.
I think we would need to see the code you use to start the thread to know if you are actually running in a separate thread. Also, if you are calling out into C land, you will block the whole Java VM until you return (unless you are using the "BlockingFunction" class).
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:46.

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