Constructor
new Clock(clockTypeopt)
Create a Clock.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
clockType |
ClockType |
<optional> |
Clock.ClockType.SYSTEM_TIME | The type of the clock to be created. |
- Source:
Members
clockType
Get ClockType of this Clock object.
- Source:
Methods
addClockCallback(callbackObject, onClockChange, minForward, minBackward)
Add a clock callback.
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callbackObject |
object | The object containing callback methods.
Properties
|
||||||||||||
onClockChange |
boolean | Whether to call the callback on clock change. | ||||||||||||
minForward |
bigint | Minimum forward jump in nanoseconds to trigger the callback. | ||||||||||||
minBackward |
bigint | Minimum backward jump in nanoseconds to trigger the callback. |
- Source:
now() → {Time}
Return the current time.
- Source:
Returns:
Return the current time.
- Type
- Time
removeClockCallback(callbackObject)
Remove a clock callback.
Parameters:
| Name | Type | Description |
|---|---|---|
callbackObject |
object | The callback object that was previously registered with addClockCallback(). |
- Source:
(async) sleepFor(duration, contextopt) → {Promise.<boolean>}
Sleep for a specified duration.
Equivalent to: clock.sleepUntil(clock.now() + duration, context)
When using a ROSClock, this may sleep forever if the TimeSource is misconfigured
and the context is never shut down. ROS time being activated or deactivated causes
this function to cease sleeping and return false.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
duration |
Duration | Duration of time to sleep for. | ||
context |
Context |
<optional> |
null | Context which when shut down will cause this sleep to wake early. If context is null, then the default context is used. |
- Source:
Throws:
-
if context has not been initialized or is shutdown.
- Type
- Error
Returns:
Promise that resolves to true if the full duration was slept,
or false if it woke for another reason.
- Type
- Promise.<boolean>
(async) sleepUntil(until, contextopt) → {Promise.<boolean>}
Sleep until a specific time is reached on this Clock.
When using a ROSClock, this may sleep forever if the TimeSource is misconfigured
and the context is never shut down. ROS time being activated or deactivated causes
this function to cease sleeping and return false.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
until |
Time | Time at which this function should stop sleeping. | ||
context |
Context |
<optional> |
null | Context whose validity will be checked while sleeping. If context is null, then the default context is used. If the context is found to be shut down before or by the time the wait completes, the returned promise resolves to false. |
- Source:
Throws:
-
-
if until is specified for a different type of clock than this one.
- Type
- TypeError
-
-
-
if context has not been initialized or is shutdown.
- Type
- Error
-
Returns:
Promise that resolves to true if 'until' was reached without
detecting a time jump or a shut down context, or false otherwise (for example, if a time
jump occurred or the context is no longer valid when the wait completes).
- Type
- Promise.<boolean>