File tree Expand file tree Collapse file tree 4 files changed +28
-8
lines changed
wpilibj/src/main/java/edu/wpi/first/wpilibj Expand file tree Collapse file tree 4 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ void TimedRobot::StartCompetition() {
46
46
if (currentTime.count () == 0 || status != 0 ) {
47
47
break ;
48
48
}
49
- Timer::s_loopTimestamp = currentTime;
49
+ Timer::SetLoopTimestamp ( currentTime) ;
50
50
51
51
callback.func ();
52
52
Original file line number Diff line number Diff line change @@ -34,8 +34,6 @@ units::second_t GetTime();
34
34
* the timer so Get() won't return a negative duration.
35
35
*/
36
36
class Timer {
37
- friend class TimedRobot ;
38
-
39
37
public:
40
38
/* *
41
39
* Create a new timer object.
@@ -132,16 +130,27 @@ class Timer {
132
130
133
131
/* *
134
132
* Return the system clock time in seconds for the start of the current
135
- * periodic loop. This is in the same time base as getFPGATimestamp (), but is
133
+ * periodic loop. This is in the same time base as GetFPGATimestamp (), but is
136
134
* stable through a loop. This value is only valid for robot programs that use
137
135
* TimedRobot. It is updated at the beginning of every periodic callback
138
- * (including the normal periodic loop).
136
+ * (including the normal periodic loop). Calling this from threads other than
137
+ * than the main periodic loop has undefined behavior.
139
138
*
140
139
* @return Robot running time in seconds, as of the start of the current
141
140
* periodic function.
142
141
*/
143
142
static units::second_t GetLoopTimestamp () { return s_loopTimestamp; }
144
143
144
+ /* *
145
+ * Sets the timestamp returned by GetLoopTimestamp(). Intended for library
146
+ * use; calling this from team code may result in unexpected behavior.
147
+ *
148
+ * @param timestamp timestamp in seconds
149
+ */
150
+ static void SetLoopTimestamp (units::second_t timestamp) {
151
+ s_loopTimestamp = timestamp;
152
+ }
153
+
145
154
/* *
146
155
* Return the approximate match time.
147
156
*
Original file line number Diff line number Diff line change @@ -127,7 +127,7 @@ public void startCompetition() {
127
127
if (currentTime == 0 ) {
128
128
break ;
129
129
}
130
- Timer .s_loopTimestamp = currentTime / 1000000.0 ;
130
+ Timer .setLoopTimestamp ( currentTime / 1000000.0 ) ;
131
131
132
132
callback .func .run ();
133
133
Original file line number Diff line number Diff line change 11
11
* get() won't return a negative duration.
12
12
*/
13
13
public class Timer {
14
- static double s_loopTimestamp ;
14
+ private static double s_loopTimestamp ;
15
15
16
16
/**
17
17
* Return the system clock time in seconds. Return the time from the FPGA hardware clock in
@@ -27,14 +27,25 @@ public static double getFPGATimestamp() {
27
27
* Return the system clock time in seconds for the start of the current periodic loop. This is
28
28
* in the same time base as getFPGATimestamp(), but is stable through a loop. This value is only
29
29
* valid for robot programs that use TimedRobot. It is updated at the beginning of every periodic
30
- * callback (including the normal periodic loop).
30
+ * callback (including the normal periodic loop). Calling this from threads other than than the
31
+ * main periodic loop has undefined behavior.
31
32
*
32
33
* @return Robot running time in seconds, as of the start of the current periodic function.
33
34
*/
34
35
public static double getLoopTimestamp () {
35
36
return s_loopTimestamp ;
36
37
}
37
38
39
+ /**
40
+ * Sets the timestamp returned by getLoopTimestamp(). Intended for library use; calling this from
41
+ * team code may result in unexpected behavior.
42
+ *
43
+ * @param timestamp timestamp in seconds
44
+ */
45
+ public static void setLoopTimestamp (double timestamp ) {
46
+ s_loopTimestamp = timestamp ;
47
+ }
48
+
38
49
/**
39
50
* Return the approximate match time. The FMS does not send an official match time to the robots,
40
51
* but does send an approximate match time. The value will count down the time remaining in the
You can’t perform that action at this time.
0 commit comments