Skip to content

Commit 5f8b099

Browse files
authored
Merge pull request #144 from ros2/update_time
Update the Time article
2 parents 5e64254 + 6b19b3c commit 5f8b099

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

articles/130_ros_time.md

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ Slower than real time simulation is necessary for complicated systems where accu
3939
Often the simulation is the limiting factor for the system and as such the simulator can be a time source for faster or slower playback.
4040
Additionally if the simulation is paused the system can also pause using the same mechanism.
4141

42+
## Approach
43+
44+
To provide a simplified time interface we will provide a ROS time and duration datatype.
45+
To query for the latest time a ROS Clock interface will be provided.
46+
A TimeSource can manage one or more Clock instances.
47+
48+
49+
## Clock
50+
51+
4252
### Challenges in using abstracted time
4353

4454
There are many algorithms for synchronization and they can typically achieve accuracies which are better than the latency of the network communications between devices on the network.
@@ -70,18 +80,19 @@ For convenience in these cases we will also provide the same API as above, but u
7080

7181
`SystemTime` will be directly tied to the system clock.
7282

83+
#### ROS Time
84+
85+
The `ROSTime` will report the same as `SystemTime` when an ROS Time Source is not active.
86+
When the ROS time source is active `ROSTime` will return the latest value reported by the Time Source.
87+
`ROSTime` is considered active when the parameter `using_sim_time` is set on the node.
88+
7389
#### Steady Time
7490

7591
Example use cases for this include hardware drivers which are interacting with peripherals with hardware timeouts.
7692

7793
In nodes which require the use of `SteadyTime` or `SystemTime` for interacting with hardware or other peripherals it is expected that they do a best effort to isolate any `SystemTime` or `SteadyTime` information inside their implementation and translate external interfaces to use the ROS time abstraction when communicating over the ROS network.
7894

79-
#### ROS Time
80-
81-
The `ROSTime` will report the same as `SystemTime` when an ROS Time Source is not active.
82-
When the ROS time source is active `ROSTime` will return the latest value reported by the Time Source.
83-
84-
### ROS Time Sources
95+
### ROS Time Source
8596

8697
#### Default Time Source
8798

@@ -100,7 +111,7 @@ The developer has the opportunity to register callbacks with the handler to clea
100111

101112
The frequency of publishing the `/clock` as well as the granularity are not specified as they are application specific.
102113

103-
##### No Advanced Estimating Clock
114+
##### No Advanced Estimating Clock By Default
104115

105116
There are more advanced techniques which could be included to attempt to estimate the propagation properties and extrapolate between time ticks.
106117
However all of these techniques will require making assumptions about the future behavior of the time abstraction.
@@ -115,23 +126,41 @@ It is possible that the user may have access to an out of band time source which
115126
It might be possible that for their use case a more advanced algorithm would be needed to propagate the simulated time with adequate precision or latency with restricted bandwidth or connectivity.
116127
The user will be able to switch out the time source for either each instance of their Time object as well as have the ability to override the default for the process.
117128

118-
It is possible to use an external time source such as GPS in as a ROSTime source, but it is recommended to integrate a time source like that using standard ntp integrations with the system clock since that is already an established mechanism and will not need to deal with more complicated changes such as time jumps.
129+
It is possible to use an external time source such as GPS in as a ROSTime source, but it is recommended to integrate a time source like that using standard NTP integrations with the system clock since that is already an established mechanism and will not need to deal with more complicated changes such as time jumps.
130+
131+
For the current implementation a `TimeSource` API will be defined such that it can be overridden in code.
132+
If in the future a common implementation is found that would be generally useful it could be extended to optionally dynamically select the alternative TimeSource via a parameter similar to enabling the simulated time.
119133

120134
## Implementation
121135

122136
The `SystemTime`, `SteadyTime`, and `ROSTime` API's will be provided by each client library in an idiomatic way, but they may share a common implementation, e.g. provided by `rcl`.
123137
However, if a client library chooses to not use the shared implementation then it must implement the functionality itself.
124138

139+
`SteadyTime` will be typed differently than the interchangable `SystemTime` and `ROSTime`.
140+
This is because SystemTime and ROSTime have a common base class with runtime checks that they are valid to compare against each other.
141+
However SteadyTime is never comparable to SystemTime or SteadyTime so it would actually have a separate implementation of the same API.
142+
Thus you could get protection from misusing them at compile time (in compiled languages) instead of only catching it at runtime.
143+
125144
### Public API
126145

127-
In each implementation will provide `Time`, `Duration`, and `Rate` datatypes, for all three time source abstraction..
128-
The `Duration` will support a `sleep_for` function as well as a `sleep_until` method.
146+
In each implementation will provide `Time`, `Duration`, and `Rate` datatypes, for all three time source abstractions.
147+
148+
The `Clock` will support a `sleep_for` function as well as a `sleep_until` method using a `Duration` or `Time` argument respectively.
129149
The implementation will also provide a `Timer` object which will provide periodic callback functionality for all the abstractions.
130150

151+
It will also support registering callback before and after a time jump.
152+
The first callback will be to allow proper preparations for a time jump.
153+
The latter will allow code to respond to the change in time and include the new time specifically as well as a quantification of the jump.
154+
155+
Any API which is blocking will allow a set of flags to indicate the appropriate behavior in case of time jump.
156+
This will allow the user to choose to error immediately on a time jump or choose to ignore.
157+
When registering a callback for jumps a filter for the minimum backwards or forwards distance will be possible and well as whether a clock change is to be included.
158+
131159
### RCL implementation
132160

133161
In `rcl` there will be datatypes and methods to implement each of the three time abstractions for each of the core datatypes.
134-
However at the `rcl` level the implementation will be incomplete as it will not have a threading model and will rely on the higher level implementation to provide any threading functionality such as is required by sleep methods.
162+
However at the `rcl` level the implementation will be incomplete as it will not have a threading model and will rely on the higher level implementation to provide any threading functionality which is required by sleep methods.
163+
It also will require appropriate threading to support the reception of `TimeSource` data.
135164

136165
It will provide implementations parallel to the public datastructures and storage which the client library can depend upon and to which it can delegate.
137166
The underlying datatypes will also provide ways to register notifications, however it is the responsibility of the client library implementation to collect and dispatch user callbacks.

0 commit comments

Comments
 (0)