Constructor
class
new Node(nodeName, namespaceopt, contextopt, optionsopt)
Create a ROS2Node.
model using the ros2 client library (rcl) lifecyle api.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
nodeName |
string | The name used to register in ROS. | ||
namespace |
string |
<optional> |
'' | The namespace used in ROS. |
context |
Context |
<optional> |
Context.defaultContext() | The context to create the node in. |
options |
NodeOptions |
<optional> |
NodeOptions.defaultOptions | The options to configure the new node behavior. |
- Source:
Throws:
If the given context is not registered.
Type
Error
Members
member
context
Get the context in which this node was created.
- Source:
member
spinning
Determine if this node is spinning.
- Source:
Methods
function
_runWithMessageType(Type, callback) → {undefined}
Invokes the callback with a raw message of the given type. After the callback completes
the message will be destroyed.
Parameters:
| Name | Type | Description |
|---|---|---|
Type |
function | Message type to create. |
callback |
function | Callback to invoke. First parameter will be the raw message, and the second is a function to retrieve the deserialized message. |
- Source:
Returns:
Type
undefined
function
_setParametersAtomically(parameters, declareParameterMode) → {SetParameterResult}
Internal method for updating parameters atomically.
Prior to setting the parameters each SetParameterEventCallback registered
using setOnParameterEventCallback() is called in succession with the parameters
list. Any SetParameterEventCallback that retuns does not return a successful
result will cause the entire operation to terminate with no changes to the
parameters. When all SetParameterEventCallbacks return successful then the
list of parameters is updated.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
parameters |
Array.<Paramerter> | The parameters to update. | |
declareParameterMode |
boolean | false | When true parameters are being declared; otherwise they are being changed. |
- Source:
Returns:
- A single collective result.
Type
SetParameterResult
function
addOnSetParametersCallback(callback) → {undefined}
Add a callback to the front of the list of callbacks invoked for parameter declaration
and setting. No checks are made for duplicate callbacks.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
SetParametersCallback | The callback to add. |
- Source:
Returns:
Type
undefined
function
countPublishers(topic) → {number}
Return the number of publishers on a given topic.
Parameters:
| Name | Type | Description |
|---|---|---|
topic |
string | The name of the topic. |
- Source:
Returns:
- Number of publishers on the given topic.
Type
number
function
countSubscribers(topic) → {number}
Return the number of subscribers on a given topic.
Parameters:
| Name | Type | Description |
|---|---|---|
topic |
string | The name of the topic. |
- Source:
Returns:
- Number of subscribers on the given topic.
Type
number
function
createClient(typeClass, serviceName, options) → {Client}
Create a Client.
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
typeClass |
function | string | object | The ROS message class, OR a string representing the message class, e.g. 'std_msgs/msg/String', OR an object representing the message class, e.g. {package: 'std_msgs', type: 'msg', name: 'String'} | |||||||||
serviceName |
string | The service name to request. | |||||||||
options |
object | The options argument used to parameterize the client.
Properties
|
- Source:
Returns:
- An instance of Client.
Type
Client
function
createGuardCondition(callback) → {GuardCondition}
Create a guard condition.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | The callback to be called when the guard condition is triggered. |
- Source:
Returns:
- An instance of GuardCondition.
Type
GuardCondition
function
createPublisher(typeClass, topic, options) → {Publisher}
Create a Publisher.
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
typeClass |
function | string | object | The ROS message class, OR a string representing the message class, e.g. 'std_msgs/msg/String', OR an object representing the message class, e.g. {package: 'std_msgs', type: 'msg', name: 'String'} | |||||||||
topic |
string | The name of the topic. | |||||||||
options |
object | The options argument used to parameterize the publisher.
Properties
|
- Source:
Returns:
- An instance of Publisher.
Type
Publisher
function
(async) createRate(hz) → {Promise.<Rate>}
Create a Rate.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
hz |
number | 1 | The frequency of the rate timer; default is 1 hz. |
- Source:
Returns:
- Promise resolving to new instance of Rate.
Type
Promise.<Rate>
function
createService(typeClass, serviceName, options, callback) → {Service}
Create a Service.
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
typeClass |
function | string | object | The ROS message class, OR a string representing the message class, e.g. 'std_msgs/msg/String', OR an object representing the message class, e.g. {package: 'std_msgs', type: 'msg', name: 'String'} | |||||||||
serviceName |
string | The service name to offer. | |||||||||
options |
object | The options argument used to parameterize the service.
Properties
|
|||||||||
callback |
RequestCallback | The callback to be called when receiving request. |
- Source:
- See:
Returns:
- An instance of Service.
Type
Service
function
createSubscription(typeClass, topic, options, callback) → {Subscription}
Create a Subscription with optional content-filtering.
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
typeClass |
function | string | object | The ROS message class, OR a string representing the message class, e.g. 'std_msgs/msg/String', OR an object representing the message class, e.g. {package: 'std_msgs', type: 'msg', name: 'String'} | ||||||||||||||||||||||||||||||||
topic |
string | The name of the topic. | ||||||||||||||||||||||||||||||||
options |
object | The options argument used to parameterize the subscription.
Properties
|
||||||||||||||||||||||||||||||||
callback |
SubscriptionCallback | The callback to be call when receiving the topic subscribed. The topic will be an instance of null-terminated Buffer when options.isRaw is true. |
- Source:
- See:
Throws:
- May throw an RMW error if content-filter is malformed.
Type
ERROR
Returns:
- An instance of Subscription.
Type
Subscription
function
createTimer(period, callback, clockopt) → {Timer}
Create a Timer.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
period |
number | The number representing period in millisecond. | ||
callback |
function | The callback to be called when timeout. | ||
clock |
Clock |
<optional> |
null | The clock which the timer gets time from. |
- Source:
Returns:
- An instance of Timer.
Type
Timer
function
declareParameter(parameter, descriptoropt, ignoreOverideopt) → {Parameter}
Declare a parameter.
Internally, register a parameter and it's descriptor.
If a parameter-override exists, it's value will replace that of the parameter
unless ignoreOverride is true.
If the descriptor is undefined, then a ParameterDescriptor will be inferred
from the parameter's state.
If a parameter by the same name has already been declared then an Error is thrown.
A parameter must be undeclared before attempting to redeclare it.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
parameter |
Parameter | Parameter to declare. | ||
descriptor |
ParameterDescriptor |
<optional> |
Optional descriptor for parameter. | |
ignoreOveride |
boolean |
<optional> |
false | When true disregard any parameter-override that may be present. |
- Source:
Returns:
- The newly declared parameter.
Type
Parameter
function
declareParameters(parameters, descriptorsopt, ignoreOverrides) → {Array.<Parameter>}
Declare a list of parameters.
Internally register parameters with their corresponding descriptor one by one
in the order they are provided. This is an atomic operation. If an error
occurs the process halts and no further parameters are declared.
Parameters that have already been processed are undeclared.
While descriptors is an optional parameter, when provided there must be
a descriptor for each parameter; otherwise an Error is thrown.
If descriptors is not provided then a descriptor will be inferred
from each parameter's state.
When a parameter-override is available, the parameter's value
will be replaced with that of the parameter-override unless ignoreOverrides
is true.
If a parameter by the same name has already been declared then an Error is thrown.
A parameter must be undeclared before attempting to redeclare it.
Prior to declaring the parameters each SetParameterEventCallback registered
using setOnParameterEventCallback() is called in succession with the parameters
list. Any SetParameterEventCallback that retuns does not return a successful
result will cause the entire operation to terminate with no changes to the
parameters. When all SetParameterEventCallbacks return successful then the
list of parameters is updated.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
parameters |
Array.<Parameter> | The parameters to declare. | ||
descriptors |
Array.<ParameterDescriptor> |
<optional> |
Optional descriptors, a 1-1 correspondence with parameters. | |
ignoreOverrides |
boolean | false | When true, parameter-overrides are not considered, i.e.,ignored. |
- Source:
Returns:
- The declared parameters.
Type
Array.<Parameter>
function
destroy() → {undefined}
Destroy all resource allocated by this node, including
Timers/Publishers/Subscriptions
/Clients/Services
- Source:
Returns:
Type
undefined
function
destroyClient(client) → {undefined}
Destroy a Client.
Parameters:
| Name | Type | Description |
|---|---|---|
client |
Client | The Client to be destroyed. |
- Source:
Returns:
Type
undefined
function
destroyGuardCondition(guard) → {undefined}
Destroy a guard condition.
Parameters:
| Name | Type | Description |
|---|---|---|
guard |
GuardCondition | The guard condition to be destroyed. |
- Source:
Returns:
Type
undefined
function
destroyPublisher(publisher) → {undefined}
Destroy a Publisher.
Parameters:
| Name | Type | Description |
|---|---|---|
publisher |
Publisher | The Publisher to be destroyed. |
- Source:
Returns:
Type
undefined
function
destroyService(service) → {undefined}
Destroy a Service.
Parameters:
| Name | Type | Description |
|---|---|---|
service |
Service | The Service to be destroyed. |
- Source:
Returns:
Type
undefined
function
destroySubscription(subscription) → {undefined}
Destroy a Subscription.
Parameters:
| Name | Type | Description |
|---|---|---|
subscription |
Subscription | The Subscription to be destroyed. |
- Source:
Returns:
Type
undefined
function
destroyTimer(timer) → {undefined}
Destroy a Timer.
Parameters:
| Name | Type | Description |
|---|---|---|
timer |
Timer | The Timer to be destroyed. |
- Source:
Returns:
Type
undefined
function
getClock() → {Clock}
Get the clock used by the node.
- Source:
Returns:
- The nodes clock.
Type
Clock
function
getLogger() → {Logger}
Get the nodes logger.
- Source:
Returns:
- The logger for the node.
Type
Logger
function
getNodeNames() → {Array.<string>}
Get the list of nodes discovered by the provided node.
- Source:
Returns:
- An array of the names.
Type
Array.<string>
function
getNodeNamesAndNamespaces() → {Array.<{name: string, namespace: string}>}
Get the list of nodes and their namespaces discovered by the provided node.
- Source:
Returns:
An array of the names and namespaces.
Type
Array.<{name: string, namespace: string}>
function
getParameter(name) → {Parameter}
Get a declared parameter by name.
If unable to locate a declared parameter then a
parameter with type == PARAMETER_NOT_SET is returned.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The name of the parameter. |
- Source:
Returns:
- The parameter.
Type
Parameter
function
getParameterDescriptor(name) → {ParameterDescriptor}
Get a declared parameter descriptor by name.
If unable to locate a declared parameter descriptor then a
descriptor with type == PARAMETER_NOT_SET is returned.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The name of the parameter descriptor to find. |
- Source:
Returns:
- The parameter descriptor.
Type
ParameterDescriptor
function
getParameterDescriptors(namesopt) → {Array.<ParameterDescriptor>}
Find a list of declared ParameterDescriptors.
If no names are provided return all declared descriptors.
If unable to locate a declared descriptor then a
descriptor with type == PARAMETER_NOT_SET is returned in
it's place.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
names |
Array.<string> |
<optional> |
The names of the declared parameter descriptors to find or null indicating to return all declared descriptors. |
- Source:
Returns:
- The parameter descriptors.
Type
Array.<ParameterDescriptor>
function
getParameterNames() → {Array.<string>}
Get the names of all declared parameters.
- Source:
Returns:
- The declared parameter names or empty array if
no parameters have been declared.
Type
Array.<string>
function
getParameterOverrides() → {Array.<Parameter>}
Get the list of parameter-overrides found on the commandline and
in the NodeOptions.parameter_overrides property.
- Source:
Returns:
- An array of Parameters.
Type
Array.<Parameter>
function
getParameterTypes(namesopt) → {Uint8Array}
Get the types of given parameters.
Return the types of given parameters.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
names |
Array.<string> |
<optional> |
The names of the declared parameters. |
- Source:
Returns:
- The types.
Type
Uint8Array
function
getParameters(namesopt) → {Array.<Parameter>}
Get a list of parameters.
Find and return the declared parameters.
If no names are provided return all declared parameters.
If unable to locate a declared parameter then a
parameter with type == PARAMETER_NOT_SET is returned in
it's place.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
names |
Array.<string> |
<optional> |
The names of the declared parameters to find or null indicating to return all declared parameters. |
- Source:
Returns:
- The parameters.
Type
Array.<Parameter>
function
getPublisherNamesAndTypesByNode(nodeName, namespace, noDemangle) → {Array.<{name: string, types: Array.<string>}>}
Get the list of published topics discovered by the provided node for the remote node name.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
nodeName |
string | The name of the node. | |
namespace |
string | The name of the namespace. | |
noDemangle |
boolean | false | If true topic names and types returned will not be demangled, default: false. |
- Source:
Returns:
- An array of the names and types.
Type
Array.<{name: string, types: Array.<string>}>
function
getServiceNamesAndTypes() → {Array.<{name: string, types: Array.<string>}>}
Get the list of services discovered by the provided node.
- Source:
Returns:
- An array of the names and types.
Type
Array.<{name: string, types: Array.<string>}>
function
getServiceNamesAndTypesByNode(nodeName, namespace) → {Array.<{name: string, types: Array.<string>}>}
Get the list of service topics discovered by the provided node for the remote node name.
Parameters:
| Name | Type | Description |
|---|---|---|
nodeName |
string | The name of the node. |
namespace |
string | The name of the namespace. |
- Source:
Returns:
- An array of the names and types.
Type
Array.<{name: string, types: Array.<string>}>
function
getSubscriptionNamesAndTypesByNode(nodeName, namespace, noDemangle) → {Array.<{name: string, types: Array.<string>}>}
Get the list of published topics discovered by the provided node for the remote node name.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
nodeName |
string | The name of the node. | |
namespace |
string | The name of the namespace. | |
noDemangle |
boolean | false | If true topic names and types returned will not be demangled, default: false. |
- Source:
Returns:
- An array of the names and types.
Type
Array.<{name: string, types: Array.<string>}>
function
getTopicNamesAndTypes(noDemangle) → {Array.<{name: string, types: Array.<string>}>}
Get the list of topics discovered by the provided node.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
noDemangle |
boolean | false | If true topic names and types returned will not be demangled, default: false. |
- Source:
Returns:
- An array of the names and types.
Type
Array.<{name: string, types: Array.<string>}>
function
hasParameter(name) → {boolean}
Determine if a parameter has been declared.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | name of parameter |
- Source:
Returns:
- Return true if parameter is declared; false otherwise.
Type
boolean
function
hasParameterDescriptor(name) → {boolean}
Determine if a parameter descriptor exists.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The name of a descriptor to for. |
- Source:
Returns:
- True if a descriptor has been declared; otherwise false.
Type
boolean
function
name() → {string}
Get the name of the node.
- Source:
Returns:
Type
string
function
namespace() → {string}
Get the namespace of the node.
- Source:
Returns:
Type
string
function
now() → {Time}
Get the current time using the node's clock.
- Source:
Returns:
- The current time.
Type
Time
function
removeOnSetParametersCallback(callback) → {undefined}
Remove a callback from the list of SetParametersCallbacks.
If the callback is not found the process is a nop.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
SetParametersCallback | The callback to be removed |
- Source:
Returns:
Type
undefined
function
setParameter(parameter) → {rclnodejs.rcl_interfaces.msg.SetParameterResult}
Replace a declared parameter.
The parameter being replaced must be a declared parameter who's descriptor
is not readOnly; otherwise an Error is thrown.
Parameters:
| Name | Type | Description |
|---|---|---|
parameter |
Parameter | The new parameter. |
- Source:
Returns:
- The result of the operation.
Type
rclnodejs.rcl_interfaces.msg.SetParameterResult
function
setParameters(parameters) → {Array.<rclnodejs.rcl_interfaces.msg.SetParameterResult>}
Replace a list of declared parameters.
Declared parameters are replaced in the order they are provided and
a ParameterEvent is published for each individual parameter change.
Prior to setting the parameters each SetParameterEventCallback registered
using setOnParameterEventCallback() is called in succession with the parameters
list. Any SetParameterEventCallback that retuns does not return a successful
result will cause the entire operation to terminate with no changes to the
parameters. When all SetParameterEventCallbacks return successful then the
list of parameters is updated.
If an error occurs, the process is stopped and returned. Parameters
set before an error remain unchanged.
Parameters:
| Name | Type | Description |
|---|---|---|
parameters |
Array.<Parameter> | The parameters to set. |
- Source:
Returns:
- A list of SetParameterResult, one for each parameter that was set.
Type
Array.<rclnodejs.rcl_interfaces.msg.SetParameterResult>
function
setParametersAtomically(parameters) → {rclnodejs.rcl_interfaces.msg.SetParameterResult}
Repalce a list of declared parameters atomically.
Declared parameters are replaced in the order they are provided.
A single ParameterEvent is published collectively for all changed
parameters.
Prior to setting the parameters each SetParameterEventCallback registered
using setOnParameterEventCallback() is called in succession with the parameters
list. Any SetParameterEventCallback that retuns does not return a successful
result will cause the entire operation to terminate with no changes to the
parameters. When all SetParameterEventCallbacks return successful then the
list of parameters is updated.d
If an error occurs, the process stops immediately. All parameters updated to
the point of the error are reverted to their previous state.
Parameters:
| Name | Type | Description |
|---|---|---|
parameters |
Array.<Parameter> | The parameters to set. |
- Source:
Returns:
- describes the result of setting 1 or more parameters.
Type
rclnodejs.rcl_interfaces.msg.SetParameterResult
function
spin(node, timeoutopt) → {undefined}
Trigger the event loop to continuously check for and route.
incoming events.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
node |
Node | The node to be spun up. | ||
timeout |
number |
<optional> |
10 | Timeout to wait in milliseconds. Block forever if negative. Don't wait if 0. |
- Source:
Throws:
If the node is already spinning.
Type
Error
Returns:
Type
undefined
function
spinOnce(node, timeoutopt) → {undefined}
Spin the node and trigger the event loop to check for one incoming event. Thereafter the node
will not received additional events until running additional calls to spin() or spinOnce().
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
node |
Node | The node to be spun. | ||
timeout |
number |
<optional> |
10 | Timeout to wait in milliseconds. Block forever if negative. Don't wait if 0. |
- Source:
Throws:
If the node is already spinning.
Type
Error
Returns:
Type
undefined
function
startSpinning()
Use spin().
- Source:
function
stop() → {undefined}
Terminate spinning - no further events will be received.
- Source:
Returns:
Type
undefined
function
stopSpinning() → {undefined}
Terminate spinning - no further events will be received.
- Deprecated:
- since 0.18.0, Use stop().
- Source:
Returns:
Type
undefined
function
undeclareParameter(name) → {undefined}
Undeclare a parameter.
Readonly parameters can not be undeclared or updated.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | Name of parameter to undeclare. |
- Source:
Returns:
-
Type
undefined
function
(static) getDefaultOptions() → {Options}
Create an Options instance initialized with default values.
- Source:
Returns:
- The new initialized instance.
Type
Options
Example
{
enableTypedArray: true,
isRaw: false,
qos: QoS.profileDefault,
contentFilter: undefined,
}