rclnodejs 0.22.3 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,9 +38,9 @@ async function generateAll() {
38
38
  const generatedPath = path.join(__dirname, '../generated/');
39
39
  const pkgInfos = getPkgInfos(generatedPath);
40
40
 
41
- // write message.d.ts file
42
- const messagesFilePath = path.join(__dirname, '../types/interfaces.d.ts');
43
- const fd = fs.openSync(messagesFilePath, 'w');
41
+ // write interfaces.d.ts file
42
+ const interfacesFilePath = path.join(__dirname, '../types/interfaces.d.ts');
43
+ const fd = fs.openSync(interfacesFilePath, 'w');
44
44
  savePkgInfoAsTSD(pkgInfos, fd);
45
45
  await wait(500); // hack to avoid random segfault
46
46
  fs.closeSync(fd);
@@ -235,7 +235,9 @@ function saveMsgAsTSD(rosMsgInterface, fd) {
235
235
  fd,
236
236
  ` export interface ${rosMsgInterface.type().interfaceName} {\n`
237
237
  );
238
- const useSamePkg = isInternalActionMsgInterface(rosMsgInterface);
238
+ const useSamePkg =
239
+ isInternalActionMsgInterface(rosMsgInterface) ||
240
+ isInternalServiceEventMsgInterface(rosMsgInterface);
239
241
  saveMsgFieldsAsTSD(rosMsgInterface, fd, 8, ';', '', useSamePkg);
240
242
  fs.writeSync(fd, ' }\n');
241
243
  }
@@ -270,7 +272,6 @@ function saveMsgFieldsAsTSD(
270
272
  useSamePackageSubFolder && field.type.pkgName === type.pkgName
271
273
  ? type.subFolder
272
274
  : 'msg';
273
-
274
275
  let fieldType = fieldType2JSName(field, subFolder);
275
276
  let tp = field.type.isPrimitiveType ? '' : typePrefix;
276
277
  if (typePrefix === 'rclnodejs.') {
@@ -346,13 +347,6 @@ function isMsgInterface(rosInterface) {
346
347
  return rosInterface.hasOwnProperty('ROSMessageDef');
347
348
  }
348
349
 
349
- function isServiceMsgInterface(rosMsgInterface) {
350
- if (!isMsgInterface(rosMsgInterface)) return false;
351
-
352
- let name = rosMsgInterface.type().interfaceName;
353
- return name.endsWith('_Request') || name.endsWith('_Response');
354
- }
355
-
356
350
  function isInternalActionMsgInterface(rosMsgInterface) {
357
351
  let name = rosMsgInterface.type().interfaceName;
358
352
  return (
@@ -364,6 +358,15 @@ function isInternalActionMsgInterface(rosMsgInterface) {
364
358
  );
365
359
  }
366
360
 
361
+ function isInternalServiceEventMsgInterface(rosMsgInterface) {
362
+ let name = rosMsgInterface.type().interfaceName;
363
+ let subFolder = rosMsgInterface.type().subFolder;
364
+ return (
365
+ (subFolder == 'srv' || subFolder == 'action')
366
+ && name.endsWith('_Event')
367
+ );
368
+ }
369
+
367
370
  function isSrvInterface(rosInterface) {
368
371
  return (
369
372
  rosInterface.hasOwnProperty('Request') &&
@@ -1,4 +1,4 @@
1
- # rclnodejs [![Build Status](https://travis-ci.org/RobotWebTools/rclnodejs.svg?branch=develop)](https://travis-ci.org/RobotWebTools/rclnodejs)
1
+ # rclnodejs ![GitHub Workflow Status](https://github.com/RobotWebTools/rclnodejs/actions/workflows/linux-build-and-test.yml/badge.svg?branch=iron-irwini)
2
2
 
3
3
  `rclnodejs` is a Node.js client for the Robot Operating System (ROS 2). It provides a simple and easy JavaScript API for ROS 2 programming. TypeScript declarations are included to support use of rclnodejs in TypeScript projects.
4
4
 
@@ -18,7 +18,7 @@ rclnodejs.init().then(() => {
18
18
 
19
19
  **Node.js**
20
20
 
21
- - [Node.js](https://nodejs.org/en/) version between 10.23 - 17.x.
21
+ - [Node.js](https://nodejs.org/en/) version >= 16.13.0.
22
22
 
23
23
  **ROS 2 SDK**
24
24
 
@@ -43,14 +43,13 @@ npm i rclnodejs@x.y.z
43
43
 
44
44
  #### RCLNODEJS - ROS 2 Version Compatibility
45
45
 
46
- | RCLNODEJS Version | Compatible ROS 2 Release |
47
- | :-------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
48
- | [0.21.4 (current)](https://www.npmjs.com/package/rclnodejs/v/0.21.4) ([API](http://robotwebtools.org/rclnodejs/docs/0.21.3/index.html)) | [Humble Hawksbill](https://github.com/ros2/ros2/releases/tag/release-humble-20220523)<br>[Galactic Geochelone](https://github.com/ros2/ros2/releases/tag/release-galactic-20210716)<br>[Foxy Fitzroy](https://github.com/ros2/ros2/releases/tag/release-foxy-20201211)<br>[Eloquent Elusor](https://github.com/ros2/ros2/releases/tag/release-eloquent-20200124) |
49
- | [0.10.3](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.3) | [Dashing Diademata - Patch 4](https://github.com/ros2/ros2/releases/tag/release-dashing-20191018) |
46
+ | RCLNODEJS Version | Compatible ROS 2 LTS |
47
+ | :------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------: |
48
+ | latest version (currently [v0.22.3](https://github.com/RobotWebTools/rclnodejs/tree/0.22.3)) | [Humble](https://github.com/RobotWebTools/rclnodejs/tree/humble-hawksbill)<br>[Iron](https://github.com/RobotWebTools/rclnodejs/tree/iron-irwini) |
50
49
 
51
50
  ## Documentation
52
51
 
53
- API [documentation](http://robotwebtools.org/rclnodejs/docs/index.html) is available online.
52
+ API [documentation](https://robotwebtools.github.io/rclnodejs/docs/index.html) is available online.
54
53
 
55
54
  ## JavaScript Examples
56
55
 
@@ -36,6 +36,10 @@
36
36
  #include <rosidl_generator_c/string_functions.h>
37
37
  #endif
38
38
 
39
+ #if ROS_VERSION > 2205
40
+ #include <rcl/service_introspection.h>
41
+ #endif
42
+
39
43
  #include <iostream>
40
44
  #include <memory>
41
45
  #include <string>
@@ -1120,6 +1124,68 @@ NAN_METHOD(SendResponse) {
1120
1124
  RCL_RET_OK, rcl_get_error_string().str);
1121
1125
  }
1122
1126
 
1127
+ #if ROS_VERSION > 2205 // 2205 == Humble
1128
+ NAN_METHOD(ConfigureServiceIntrospection) {
1129
+ v8::Local<v8::Context> currentContent = Nan::GetCurrentContext();
1130
+
1131
+ RclHandle* node_handle = RclHandle::Unwrap<RclHandle>(
1132
+ Nan::To<v8::Object>(info[1]).ToLocalChecked());
1133
+ rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
1134
+
1135
+ rcl_clock_t* clock = reinterpret_cast<rcl_clock_t*>(
1136
+ RclHandle::Unwrap<RclHandle>(
1137
+ Nan::To<v8::Object>(info[2]).ToLocalChecked())
1138
+ ->ptr());
1139
+
1140
+ std::string interface_name(
1141
+ *Nan::Utf8String(info[3]->ToString(currentContent).ToLocalChecked()));
1142
+ std::string package_name(
1143
+ *Nan::Utf8String(info[4]->ToString(currentContent).ToLocalChecked()));
1144
+ const rosidl_service_type_support_t* ts =
1145
+ GetServiceTypeSupport(package_name, interface_name);
1146
+
1147
+ if (ts) {
1148
+ rcl_publisher_options_t publisher_ops = rcl_publisher_get_default_options();
1149
+ auto qos_profile = GetQoSProfile(info[5]);
1150
+ if (qos_profile) {
1151
+ publisher_ops.qos = *qos_profile;
1152
+ }
1153
+
1154
+ rcl_service_introspection_state_t state =
1155
+ static_cast<rcl_service_introspection_state_t>(
1156
+ Nan::To<uint32_t>(info[6]).ToChecked());
1157
+
1158
+ bool configureForService = Nan::To<bool>(info[7]).FromJust();
1159
+
1160
+ if (configureForService) {
1161
+ RclHandle* service_handle = RclHandle::Unwrap<RclHandle>(
1162
+ Nan::To<v8::Object>(info[0]).ToLocalChecked());
1163
+ rcl_service_t* service =
1164
+ reinterpret_cast<rcl_service_t*>(service_handle->ptr());
1165
+
1166
+ THROW_ERROR_IF_NOT_EQUAL(
1167
+ rcl_service_configure_service_introspection(service, node, clock, ts,
1168
+ publisher_ops, state),
1169
+ RCL_RET_OK, rcl_get_error_string().str);
1170
+
1171
+ } else {
1172
+ RclHandle* client_handle = RclHandle::Unwrap<RclHandle>(
1173
+ Nan::To<v8::Object>(info[0]).ToLocalChecked());
1174
+ rcl_client_t* client =
1175
+ reinterpret_cast<rcl_client_t*>(client_handle->ptr());
1176
+
1177
+ THROW_ERROR_IF_NOT_EQUAL(
1178
+ rcl_client_configure_service_introspection(client, node, clock, ts,
1179
+ publisher_ops, state),
1180
+ RCL_RET_OK, rcl_get_error_string().str);
1181
+ }
1182
+
1183
+ } else {
1184
+ Nan::ThrowError(GetErrorMessageAndClear().c_str());
1185
+ }
1186
+ }
1187
+ #endif
1188
+
1123
1189
  NAN_METHOD(ValidateFullTopicName) {
1124
1190
  v8::Local<v8::Context> currentContent = Nan::GetCurrentContext();
1125
1191
  int validation_result;
@@ -2011,6 +2077,11 @@ std::vector<BindingMethod> binding_methods = {
2011
2077
  {"serviceServerIsAvailable", ServiceServerIsAvailable},
2012
2078
  {"publishRawMessage", PublishRawMessage},
2013
2079
  {"rclTakeRaw", RclTakeRaw},
2014
- {"", nullptr}};
2080
+ {"", nullptr}
2081
+ #if ROS_VERSION > 2205 // 2205 == Humble
2082
+ ,
2083
+ {"configureServiceIntrospection", ConfigureServiceIntrospection}
2084
+ #endif
2085
+ };
2015
2086
 
2016
2087
  } // namespace rclnodejs
package/types/base.d.ts CHANGED
@@ -21,6 +21,7 @@
21
21
  /// <reference path="qos.d.ts" />
22
22
  /// <reference path="rate.d.ts" />
23
23
  /// <reference path="service.d.ts" />
24
+ /// <reference path="service_introspection.d.ts" />
24
25
  /// <reference path="subscription.d.ts" />
25
26
  /// <reference path="time_source.d.ts" />
26
27
  /// <reference path="time.d.ts" />
package/types/client.d.ts CHANGED
@@ -40,6 +40,18 @@ declare module 'rclnodejs' {
40
40
  * Name of the service to which requests are made.
41
41
  */
42
42
  readonly serviceName: string;
43
+
44
+ /**
45
+ * Configure introspection.
46
+ * @param clock - Clock to use for service event timestamps
47
+ * @param QoSProfile - QOS profile for the service event publisher
48
+ * @param introspectionState - The state to set introspection to
49
+ */
50
+ configureIntrospection(
51
+ clock: Clock,
52
+ serviceEventPubQOS: QoS,
53
+ introspectionState: ServiceIntrospectionStates
54
+ ): void;
43
55
  }
44
56
 
45
57
  namespace Client {