Go to Post Andy Baker is so awsome, that his presence alone at the competition caused the scoring system to crash....multiple times...at all 8 regionals. - Andy Grady [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 15-02-2015, 22:01
importsjc importsjc is offline
Registered User
FRC #1405
 
Join Date: Jan 2015
Location: Rochester
Posts: 5
importsjc is an unknown quantity at this point
Question Timer resets when resumed

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   Spotlight this post!  
Unread 15-02-2015, 22:20
legts legts is offline
Autonomous Queen
FRC #2399 (The Fighting Unicorns)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2012
Location: Ohio
Posts: 78
legts is an unknown quantity at this point
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   Spotlight this post!  
Unread 16-02-2015, 07:49
importsjc importsjc is offline
Registered User
FRC #1405
 
Join Date: Jan 2015
Location: Rochester
Posts: 5
importsjc is an unknown quantity at this point
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   Spotlight this post!  
Unread 16-02-2015, 08:02
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 990
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: Timer resets when resumed

Quote:
Originally Posted by importsjc View Post
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().
Looking at the source for the Timer class, it definitely should continue increasing if you stop() then start() again.

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             }
Can you post your code showing your usage so we can see if anything jumps out as to why you're seeing it reset?
  #5   Spotlight this post!  
Unread 16-02-2015, 08:07
importsjc importsjc is offline
Registered User
FRC #1405
 
Join Date: Jan 2015
Location: Rochester
Posts: 5
importsjc is an unknown quantity at this point
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   Spotlight this post!  
Unread 16-02-2015, 21:21
importsjc importsjc is offline
Registered User
FRC #1405
 
Join Date: Jan 2015
Location: Rochester
Posts: 5
importsjc is an unknown quantity at this point
Re: Timer resets when resumed

Ok, after doing testing I have narrowed down the timer reset to the line
Code:
timer.start();
here is some test code that is resetting when you start and then stop.

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(){
    }
    
}
you should notice that after the timer is re-started the autoTimer.get(); printout becomes 0.

I have actually solved my problem using an offshoot of what @legts suggested.

Thanks for the help!
Closed Thread


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 21:03.

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