Skip to content

Commit accf186

Browse files
committed
Extract the Time section to its own page
This is about to get a bit more complicated so it seems likely it will benefit from being on its own page.
1 parent b4063cb commit accf186

File tree

4 files changed

+62
-44
lines changed

4 files changed

+62
-44
lines changed

_data/sidebar_tree.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ tree:
88
tree:
99
- url: /competition-simulator/programming
1010
title: Programming
11+
tree:
12+
- url: /competition-simulator/programming/time
13+
title: Time
1114
- url: /IDE/
1215
title: IDE
1316
tree:

competition-simulator/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,4 @@ speeds (▶▶ and ▶▶▶).
112112

113113
These differences mean that your code will need to use a different mechanism to
114114
find the current time or to sleep within the simulation. Find out more by
115-
heading over to the [programming docs on time](./programming#time).
115+
heading over to the [programming docs on time](./programming/time).

competition-simulator/programming.md renamed to competition-simulator/programming/index.md

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -108,46 +108,6 @@ In the simulated environment, time advances only at the pace that the simulator
108108
is run. As a result, using `time.time` to know how long your robot has been
109109
running for or `time.sleep` to wait for some duration will be unreliable.
110110

111-
Instead the simulated `Robot` API provides some alternatives which you are
112-
encouraged to use instead.
113-
114-
#### Sleeping
115-
116-
If you want to wait for something to happen within the simulation, and you can
117-
be reasonably confident that it will take a given amount of time, you can use
118-
`Robot.sleep` method to pause your code for a given duration.
119-
120-
Internally this uses the simulation's own clock and so is suitable for use in
121-
place of `time.sleep`. Note that, just as with `time.sleep`, while your code is
122-
sleeping your robot will continue any actions it was doing.
123-
124-
``` python
125-
R = Robot()
126-
127-
# Blink the output
128-
R.ruggeduinos[0].digital_write(A_PIN, 1)
129-
R.sleep(1.5) # Sleep for a second and a half of simulation time
130-
R.ruggeduinos[0].digital_write(A_PIN, 0)
131-
```
132-
133-
#### Getting the current time
134-
135-
If you need to measure the time since some previous moment within the simulator,
136-
`Robot.time` can be used in place of `time.time` to get a number (in seconds)
137-
which increases in line with simulation time.
138-
139-
Time zero as returned by this method is the point at which the simulation began,
140-
however you should not rely on that being a useful reference point as it may not
141-
be the moment at which the _match_ began.
142-
143-
``` python
144-
R = Robot()
145-
146-
then = R.time()
147-
148-
# .. do some other things ..
149-
150-
now = R.time()
151-
152-
duration = now - then
153-
```
111+
As a result the API present in the simulator supports a slightly different
112+
approach to handling time. See the documentation about [simulated time](./time)
113+
for more details.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
layout: page
3+
title: Simulated Time
4+
---
5+
6+
# Simulated Time
7+
8+
In the simulated environment, time advances only at the pace that the simulator
9+
is run and in cooperation with the controller code (such as the code controlling
10+
your robot). As a result, using `time.time` to know how long your robot has been
11+
running for or `time.sleep` to wait for some duration may be unreliable.
12+
13+
Instead the simulated `Robot` API provides some alternatives which you are
14+
encouraged to use instead.
15+
16+
## Sleeping
17+
18+
If you want to wait for something to happen within the simulation, and you can
19+
be reasonably confident that it will take a given amount of time, you can use
20+
`Robot.sleep` method to pause your code for a given duration.
21+
22+
Internally this uses the simulation's own clock and so is suitable for use in
23+
place of `time.sleep`. Note that, just as with `time.sleep`, while your code is
24+
sleeping your robot will continue any actions it was doing.
25+
26+
``` python
27+
R = Robot()
28+
29+
# Blink the output
30+
R.ruggeduinos[0].digital_write(A_PIN, 1)
31+
R.sleep(1.5) # Sleep for a second and a half of simulation time
32+
R.ruggeduinos[0].digital_write(A_PIN, 0)
33+
```
34+
35+
## Getting the current time
36+
37+
If you need to measure the time since some previous moment within the simulator,
38+
`Robot.time` can be used in place of `time.time` to get a number (in seconds)
39+
which increases in line with simulation time.
40+
41+
Time zero as returned by this method is the point at which the simulation began,
42+
however you should not rely on that being a useful reference point as it may not
43+
be the moment at which the _match_ began.
44+
45+
``` python
46+
R = Robot()
47+
48+
then = R.time()
49+
50+
# .. do some other things ..
51+
52+
now = R.time()
53+
54+
duration = now - then
55+
```

0 commit comments

Comments
 (0)