12-26-2022 restore Return-to-Top function. Header-only link is no longer recognized, now requires full URL.
@ -17,7 +17,7 @@ But what if other activities need to happen while that motor runs? In Autonomou
|
|||||||
|
|
||||||
Timers provide a more flexible solution.
|
Timers provide a more flexible solution.
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
## Timer Menu
|
## Timer Menu
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ In FTC Blocks, timer commands are found in the menu at the left side, under Util
|
|||||||
|
|
||||||
In general you will create your own timer, then use pre-made commands or <u>methods</u> to access the contents of that timer. This is not as simple as 'look at the clock' in real life. There are more steps, based on the structure and protections of Object-Oriented Programming (OOP). Java is an OOP language, and Blocks is based on Java.
|
In general you will create your own timer, then use pre-made commands or <u>methods</u> to access the contents of that timer. This is not as simple as 'look at the clock' in real life. There are more steps, based on the structure and protections of Object-Oriented Programming (OOP). Java is an OOP language, and Blocks is based on Java.
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
## Create a Timer
|
## Create a Timer
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ The default unit of reporting time is Seconds, for a timer created with the simp
|
|||||||
|
|
||||||
A new timer begins running as soon as it's created, even in the Initialize section, starting with the current time on the **system clock**. However you will probably **not** rely on that starting time value, because you will use the timer later in your OpMode when the system time has changed. Pressing the DS phone's Start button at the beginning of Autonomous or TeleOp does <u>not</u> restart your timer.
|
A new timer begins running as soon as it's created, even in the Initialize section, starting with the current time on the **system clock**. However you will probably **not** rely on that starting time value, because you will use the timer later in your OpMode when the system time has changed. Pressing the DS phone's Start button at the beginning of Autonomous or TeleOp does <u>not</u> restart your timer.
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
## Initialize a Timer
|
## Initialize a Timer
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ This Block uses a method called **"reset"**, from the class called ElapsedTime.
|
|||||||
|
|
||||||
Note: this tutorial will reserve the term <i>clock</i> to mean only the high-level system clock that runs on the RC phone or Control Hub, independent of the FTC apps and OpMode. It cannot be reset by the OpMode.
|
Note: this tutorial will reserve the term <i>clock</i> to mean only the high-level system clock that runs on the RC phone or Control Hub, independent of the FTC apps and OpMode. It cannot be reset by the OpMode.
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
## What Time is It?
|
## What Time is It?
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ The units will be Seconds or Milliseconds, based on how the timer was created.
|
|||||||
|
|
||||||
Here the variable "currentTime" receives and holds the number of seconds (or milliseconds) that myTimer has been running, effectively starting from zero as noted above. Finally you have the number you want, but remember that this number is **fixed**, not changing. It was the time value at the exact moment you checked myTimer.
|
Here the variable "currentTime" receives and holds the number of seconds (or milliseconds) that myTimer has been running, effectively starting from zero as noted above. Finally you have the number you want, but remember that this number is **fixed**, not changing. It was the time value at the exact moment you checked myTimer.
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
## Telemetry
|
## Telemetry
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ You may find that a constantly changing time value causes programming or calcula
|
|||||||
|
|
||||||
Here the Telemetry Block builds a message showing the variable currentTime, containing a value retrieved from your timer. Although its value may be updating constantly in a Repeat loop, currentTime is not actually the running stopwatch. Again, keep in mind that the variable holds a **fixed, saved value**.
|
Here the Telemetry Block builds a message showing the variable currentTime, containing a value retrieved from your timer. Although its value may be updating constantly in a Repeat loop, currentTime is not actually the running stopwatch. Again, keep in mind that the variable holds a **fixed, saved value**.
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
Telemetry can give a **final time report** from variables that recorded the duration of actions or time between actions. When developing new Autonomous OpModes, this tool can help you optimize performance and identify wasted time.
|
Telemetry can give a **final time report** from variables that recorded the duration of actions or time between actions. When developing new Autonomous OpModes, this tool can help you optimize performance and identify wasted time.
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ When testing your OpMode, make sure the final Telemetry message **stays on the s
|
|||||||
> The 'round' Block from the Math menu is a suitable alternate for Milliseconds.
|
> The 'round' Block from the Math menu is a suitable alternate for Milliseconds.
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
## Timer Examples
|
## Timer Examples
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ Here are five common uses of timers in FTC:
|
|||||||
|
|
||||||
More advanced applications are mentioned at the end of this tutorial.
|
More advanced applications are mentioned at the end of this tutorial.
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
## 1. Loop for Time
|
## 1. Loop for Time
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ In the more formal recommended version, create the timer in the Initialize secti
|
|||||||
|
|
||||||
<p align="center">[[/images/Timers-in-FTC-Blocks/0230-Example-1-loop-Telemetry.png|]]<p>
|
<p align="center">[[/images/Timers-in-FTC-Blocks/0230-Example-1-loop-Telemetry.png|]]<p>
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
## 2. Measure Duration of Action
|
## 2. Measure Duration of Action
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ Create the 'stopwatch' timer in the Initialize section, then **reset** that time
|
|||||||
|
|
||||||
Again, **timers don't stop**; all you can do is read the time value at one moment. Here the stored post-action timer value is displayed immediately as Telemetry. For testing only, a long Sleep command can keep your Telemetry on the DS screen, before the OpMode ends.
|
Again, **timers don't stop**; all you can do is read the time value at one moment. Here the stored post-action timer value is displayed immediately as Telemetry. For testing only, a long Sleep command can keep your Telemetry on the DS screen, before the OpMode ends.
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
## 3. Safety Timeout
|
## 3. Safety Timeout
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ As noted by the blue comments, inside the loop you could set a variable indicati
|
|||||||
|
|
||||||
Test to make sure the safety time limit is **not shorter** than the intended action, under various conditions.
|
Test to make sure the safety time limit is **not shorter** than the intended action, under various conditions.
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
## 4. Match Timer
|
## 4. Match Timer
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ You might prefer to instantiate a timer only where needed. It makes sense in th
|
|||||||
> <p align="center">[[/images/Timers-in-FTC-Blocks/0480-Example-4-tip-assign.png|]]<p>
|
> <p align="center">[[/images/Timers-in-FTC-Blocks/0480-Example-4-tip-assign.png|]]<p>
|
||||||
> Caution: this replacement is not exactly the same. It can also assign False, where the original IF-DO did not handle the False scenario. Programmers must consider these differences.
|
> Caution: this replacement is not exactly the same. It can also assign False, where the original IF-DO did not handle the False scenario. Programmers must consider these differences.
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
## 5. Device Timer in TeleOp
|
## 5. Device Timer in TeleOp
|
||||||
|
|
||||||
@ -213,7 +213,7 @@ This example also shows how to capture only the first moment of the button being
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
## Other Timer Blocks
|
## Other Timer Blocks
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ This Block does allow plugging in a different starting time as a raw number in N
|
|||||||
|
|
||||||
The above Block also creates a <u>new</u> timer, allowing you to specify Seconds or Milliseconds as the unit provided by the new timer. Most of the examples above use the basic version with a default resolution of Seconds. Again, this choice affects only programming and display; the actual underlying timer accuracy is in Nanoseconds. This command starts the timer at the current system time.
|
The above Block also creates a <u>new</u> timer, allowing you to specify Seconds or Milliseconds as the unit provided by the new timer. Most of the examples above use the basic version with a default resolution of Seconds. Again, this choice affects only programming and display; the actual underlying timer accuracy is in Nanoseconds. This command starts the timer at the current system time.
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
<p align="center">[[/images/Timers-in-FTC-Blocks/0630-Elapsed-StartTime.png|]]<p>
|
<p align="center">[[/images/Timers-in-FTC-Blocks/0630-Elapsed-StartTime.png|]]<p>
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ The above Block returns the current elapsed time in Seconds, even if the timer n
|
|||||||
|
|
||||||
The above Block returns the current elapsed time in Milliseconds, even if the timer normally provides Seconds.
|
The above Block returns the current elapsed time in Milliseconds, even if the timer normally provides Seconds.
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
<p align="center">[[/images/Timers-in-FTC-Blocks/0660-Elapsed-resolution.png|]]<p>
|
<p align="center">[[/images/Timers-in-FTC-Blocks/0660-Elapsed-resolution.png|]]<p>
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ The above Block returns a <u>text</u> field indicating whether the timer was cre
|
|||||||
|
|
||||||
The above Block writes a message to the system log file, for later analysis. The message shows the timer's current elapsed time in its specified units, preceded by "TIMER:" and a custom **text label** for identification in the (very detailed) log file. Logging can be a useful substitute for Telemetry, when studying a sequence of very close events, disconnected events, or rare events. Elsewhere this FTC wiki describes downloading system logs for [Robot Controller (RC) phones](Managing-a-Smartphone-Robot-Controller#Downloading-the-Log-File) and for [REV Control Hubs](Managing-a-Control-Hub#Downloading-the-Log-File).
|
The above Block writes a message to the system log file, for later analysis. The message shows the timer's current elapsed time in its specified units, preceded by "TIMER:" and a custom **text label** for identification in the (very detailed) log file. Logging can be a useful substitute for Telemetry, when studying a sequence of very close events, disconnected events, or rare events. Elsewhere this FTC wiki describes downloading system logs for [Robot Controller (RC) phones](Managing-a-Smartphone-Robot-Controller#Downloading-the-Log-File) and for [REV Control Hubs](Managing-a-Control-Hub#Downloading-the-Log-File).
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
<p align="center">[[/images/Timers-in-FTC-Blocks/0680-Elapsed-to-text.png|]]<p>
|
<p align="center">[[/images/Timers-in-FTC-Blocks/0680-Elapsed-to-text.png|]]<p>
|
||||||
|
|
||||||
@ -276,7 +276,7 @@ Think of Runtime as a special timer instantiated as the first action in the init
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
## Multiple Timers and Potential Uses
|
## Multiple Timers and Potential Uses
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ This tutorial described basic use of Timers in Blocks programming. Timers also
|
|||||||
* complex task automation in Auto and TeleOp
|
* complex task automation in Auto and TeleOp
|
||||||
* custom PI and PID control algorithms
|
* custom PI and PID control algorithms
|
||||||
|
|
||||||
[<p align="right"><i>Return to Top</i>](#introduction)<p>
|
<p align="right"><i>[[Return to Top|https://github.com/FIRST-Tech-Challenge/FtcRobotController/wiki/Timers in FTC Blocks]]</i><p>
|
||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user