|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Hi everyone!
I have recently run into an interesting issue, it appears that the timer (edu.wpi.first.wpilibj.Timer) resets, when you .stop() and then .start(). Is there a different timer I should be using or a better way to implement the one I have? I am looking for it to resume exactly where it left off, closer to a pause/resume than a start/stop. Thanks for the help! |
|
#2
|
|||
|
|||
|
Re: Timer resets when resumed
I don't know if there is a pause sort of thing. You could try setting an integer equal to the value of the timer before you stop it, and setting the value of the timer equal to the variable after you restart it. Not sure if that would work, but it's a thought!
|
|
#3
|
|||
|
|||
|
Re: Timer resets when resumed
Thanks for the reply! I had previously considered this, however unless I'm mistaken, there also is no Set() method.
|
|
#4
|
|||
|
|||
|
Re: Timer resets when resumed
Quote:
Code:
85 public synchronized double get() {
86 if (m_running) {
87 return ((double) ((getMsClock() - m_startTime) + m_accumulatedTime)) / 1000.0;
88 } else {
89 return m_accumulatedTime;
90 }
91 }
107 public synchronized void start() {
108 m_startTime = getMsClock();
109 m_running = true;
110 }
118 public synchronized void stop() {
119 final double temp = get();
120 m_accumulatedTime = temp;
121 m_running = false;
122 }
|
|
#5
|
|||
|
|||
|
Re: Timer resets when resumed
Interesting! Must be an issue with how I use it...unfortunately I don't have the code in front of me right now, I'll post it later today. Thanks for the help!
|
|
#6
|
|||
|
|||
|
Re: Timer resets when resumed
Ok, after doing testing I have narrowed down the timer reset to the line
Code:
timer.start(); Code:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Custom;
import edu.wpi.first.wpilibj.Timer;
/**
*
* @author Robotics
*/
public class TimerTest {
Timer autoTimer;
public void robotInit(){
}
public void autonomousInit(){
autoTimer = new Timer();
autoTimer.start();
}
public void autonomousPeriodic() {
System.out.println("AutoTimer First: " + autoTimer.get());
Timer.delay(2);
System.out.println("AutoTimer Second: " + autoTimer.get()+"\n\n");
autoTimer.stop();
Timer.delay(2);
System.out.println("AutoTimer Third: " + autoTimer.get()+"\n\n");
Timer.delay(2);
autoTimer.start();
System.out.println("AutoTimer Fourth: " + autoTimer.get()+"\n\n");
}
public void teleopInit(){
}
public void teleopPeriodic() {
}
public void testInit(){
}
public void testPeriodic() {
}
public void disabledInit(){
}
}
I have actually solved my problem using an offshoot of what @legts suggested. Thanks for the help! |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|