githubEdit

TimerEx

package com.skeletonarmy.marrow

Overview

TimerEx is an extended timer utility built on top of ElapsedTime. It provides convenient methods for tracking elapsed time, remaining time, and includes extra features such as pause/resume support.

TimerEx can be used as:

  • A simple stopwatch (no duration provided).

  • A countdown timer for match time.

Check out the "Time Awareness" page to learn how to use TimerEx for autonomous behaviors.


Usage

Setup

To use TimerEx, simply instantiate it with your desired settings (default unit is seconds):

TimerEx stopwatch = new TimerEx();
TimerEx stopwatch = new TimerEx(TimeUnit unit);

TimerEx timer = new TimerEx(double duration);
TimerEx timer = new TimerEx(double duration, TimeUnit unit);

To start the timer, call start():

Methods

The TimerEx class provides the following methods:

Method
Description

start()

Starts the timer (safe to call multiple times, only runs once).

restart()

Resets the timer.

pause()

Pauses the timer.

resume()

Resumes the timer.

getElapsed()

Returns the time passed since the timer was started.

getRemaining()

Returns the remaining time for the duration.

isLessThan(double timeLeft)

Returns true if remaining time is less than timeLeft.

isMoreThan(double timeLeft)

Returns true if remaining time is greater than timeLeft.

isDone()

Returns true if the timer reached 0.

isOn()

Returns true if the timer is currently running.


Example Usage

Here’s an example autonomous that uses TimerEx together with SolversLib’s command system:

circle-info

This is by no means a functional autonomous program.

Last updated