To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.javaOpen lugnet.robotics.rcx.java in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / Java / 211
210  |  212
Subject: 
Re: Help with Clock
Newsgroups: 
lugnet.robotics.rcx.java
Date: 
Tue, 3 Sep 2002 14:43:42 GMT
Viewed: 
4324 times
  
"Roger Glassey" <glassey@ieor.berkeley.edu> writes:

In lugnet.robotics.rcx.java, Scott Makos writes:
I am using legjos and...

having problems understanding the clock/timers.

1.  Are their only one timer clock?

2.  How do you acess the timers clock?  What code would I use?



Scott
Here is a Stopwatch class that does the sort of thing that Jeurgen discussed
in his message.  You can instantiate as many stopwatches as you want to keep
track of the elapsed time between different events.

Interesting, I should browse through the classes every now and then ...

One thing to note is that josx.platform.rcx is not the right place
for it, as it is independent of the RCX platform (maybe josx.util ?).

import josx.platform.rcx.*;

/**
* Elapsed time watch (in milliseconds) <br>
* To use - construct a new instance.
*  @author Roger Glassey
*  version 2
*/
public class Stopwatch{
/**
records system clock time (in milliseconds) when reset() was executed
*/
private int t0 = 0;

/**
constructor: make a new stopwatch and reset it
*/
public Stopwatch() { reset();}
/**
Reset watch to zero
*/
public void reset(){
t0 = ((int)System.currentTimeMillis());
}
/**
Return elapsed time in milliseconds
*/
public int elapsed( ){
return ((int)System.currentTimeMillis()) -t0;
}

/**
This method returns after  delay   milliseconds
*/
public void wait(int delay) {
reset();
while (elapsed()<delay);

I think it would be better just to sleep here, as that leaves the
processor to work on other threads.  It should have about the same
precision of one time slice with the current scheduler (and with an
improved scheduler it might even be made more precise).

}
}

Another useful method would be to wait until a certain point in time
(i.e. like wait without the reset).


Jürgen

--
Jürgen Stuber <stuber@loria.fr>
http://www.loria.fr/~stuber/



Message has 1 Reply:
  Re: Help with Clock
 
What about turning the timer off that turns the RCX power off. What would be the class and method or is it a ROM routine. Thanks, Scott (22 years ago, 4-Sep-02, to lugnet.robotics.rcx.java)

Message is in Reply To:
  Re: Help with Clock
 
(...) Here is a Stopwatch class that does the sort of thing that Jeurgen discussed in his message. You can instantiate as many stopwatches as you want to keep track of the elapsed time between different events. import josx.platform.rcx.*; /** * (...) (22 years ago, 3-Sep-02, to lugnet.robotics.rcx.java)

6 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR