You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/130_ros_time.md
+40-11Lines changed: 40 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,16 @@ Slower than real time simulation is necessary for complicated systems where accu
39
39
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.
40
40
Additionally if the simulation is paused the system can also pause using the same mechanism.
41
41
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
+
42
52
### Challenges in using abstracted time
43
53
44
54
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
70
80
71
81
`SystemTime` will be directly tied to the system clock.
72
82
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
+
73
89
#### Steady Time
74
90
75
91
Example use cases for this include hardware drivers which are interacting with peripherals with hardware timeouts.
76
92
77
93
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.
78
94
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
85
96
86
97
#### Default Time Source
87
98
@@ -100,7 +111,7 @@ The developer has the opportunity to register callbacks with the handler to clea
100
111
101
112
The frequency of publishing the `/clock` as well as the granularity are not specified as they are application specific.
102
113
103
-
##### No Advanced Estimating Clock
114
+
##### No Advanced Estimating Clock By Default
104
115
105
116
There are more advanced techniques which could be included to attempt to estimate the propagation properties and extrapolate between time ticks.
106
117
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
115
126
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.
116
127
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.
117
128
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.
119
133
120
134
## Implementation
121
135
122
136
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`.
123
137
However, if a client library chooses to not use the shared implementation then it must implement the functionality itself.
124
138
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
+
125
144
### Public API
126
145
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.
129
149
The implementation will also provide a `Timer` object which will provide periodic callback functionality for all the abstractions.
130
150
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
+
131
159
### RCL implementation
132
160
133
161
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.
135
164
136
165
It will provide implementations parallel to the public datastructures and storage which the client library can depend upon and to which it can delegate.
137
166
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