Skip to content

Commit 69b08d1

Browse files
author
Minggang Wang
committed
Align with ROS 2 Dashing
We have the latest stable ROS 2 - Dashing released recently. To make our Node.js client workable on it, this PR makes a series of changes to achieve this goal, please see below: - Support wstring (https://design.ros2.org/articles/idl_interface_definition.html) - Support default value - API updates for rmw preallocation work - Update the test case, as some message has been removed or changed Fix #493
1 parent 5eb82ee commit 69b08d1

File tree

9 files changed

+167
-155
lines changed

9 files changed

+167
-155
lines changed

appveyor.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ before_build:
2525
- appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2018-06-12-1/eigen.3.3.4.nupkg
2626
- appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2017-04-04-1/tinyxml-usestl.2.6.2.nupkg
2727
- appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2018-06-12-1/tinyxml2.6.0.0.nupkg
28-
- choco install -y -s c:\download\ asio eigen tinyxml-usestl tinyxml2
28+
- appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2019-02-15-1/log4cxx.0.10.0.nupkg
29+
- choco install -y -s c:\download\ asio eigen tinyxml-usestl tinyxml2 log4cxx
2930
- appveyor DownloadFile http://ci.ros2.org/view/packaging/job/packaging_windows/lastSuccessfulBuild/artifact/ws/ros2-package-windows-AMD64.zip
3031
- 7z x -y "c:\download\ros2-package-windows-AMD64.zip" -o"c:\" > nul
3132
- setx -m OPENSSL_CONF C:\OpenSSL-Win64\bin\openssl.cfg
3233
- set PATH=C:\OpenSSL-Win64\bin;%PATH%
3334
- setx AMENT_PYTHON_EXECUTABLE "c:\Python37"
3435
- refreshenv
3536
- "SET PATH=%PYTHON3%;%PYTHON3%\\bin;%PYTHON3%\\Scripts;%PATH%"
36-
- python -m pip install -U catkin_pkg empy git+https://github.com/lark-parser/[email protected] pyparsing pyyaml setuptools colcon-common-extensions numpy
37+
- python -m pip install -U catkin_pkg empy lark-parser lxml numpy opencv-python pyparsing pyyaml setuptools colcon-common-extensions numpy
3738

3839
build_script:
3940
- cd c:\proj\rclnodejs

rosidl_gen/generator.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rosidl-generator",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"description": "Generate JavaScript object from ROS IDL(.msg) files",
55
"main": "index.js",
66
"authors": [

rosidl_gen/primitive_types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module.exports = {
5858
char: ref.types.char,
5959
byte: ref.types.byte,
6060
string: StringRefStruct,
61+
wstring: StringRefStruct,
6162
initString: initString
6263
};
6364

rosidl_gen/templates/message.dot

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function getPrimitiveNameByType(type) {
6060
return 'Char';
6161
} else if (type.type === 'byte') {
6262
return 'Byte';
63-
} else if (type.type === 'string') {
63+
} else if (type.type === 'string' || type.type === 'wstring') {
6464
return 'String';
6565
} else {
6666
return '';
@@ -279,11 +279,25 @@ class {{=objectWrapper}} {
279279
this._{{=field.name}}Intialized = true;
280280
{{??}}
281281
{{? field.type.isPrimitiveType && !field.type.isArray}}
282+
{{? field.default_value === null}}
282283
this._{{=field.name}}Intialized = false;
284+
{{?? field.type.type === 'string'}}
285+
this._refObject.{{=field.name}} = "{{=field.default_value.replace(/"/g, '\\"')}}";
286+
this._{{=field.name}}Intialized = true;
287+
{{??}}
288+
this._refObject.{{=field.name}} = {{=field.default_value}};
289+
this._{{=field.name}}Intialized = true;
290+
{{?}}
283291
{{?}}
284292

285293
{{? field.type.isArray}}
286294
this._wrapperFields.{{=field.name}} = {{=getWrapperNameByType(field.type)}}.createArray();
295+
{{? field.default_value !== null && field.type.isPrimitiveType && !isTypedArrayType(field.type)}}
296+
this._{{=field.name}}Array = {{=JSON.stringify(field.default_value)}};
297+
{{?}}
298+
{{? field.default_value !== null && field.type.isPrimitiveType && isTypedArrayType(field.type)}}
299+
this._wrapperFields.{{=field.name}}.fill({{=getTypedArrayName(field.type)}}.from({{=JSON.stringify(field.default_value)}}));
300+
{{?}}
287301
{{?? !field.type.isPrimitiveType || (field.type.type === 'string' && it.spec.msgName !== 'String')}}
288302
this._wrapperFields.{{=field.name}} = new {{=getWrapperNameByType(field.type)}}();
289303
{{?? it.spec.msgName === 'String'}}
@@ -337,9 +351,15 @@ class {{=objectWrapper}} {
337351
this._refObject.{{=field.name}}[i] = this._wrapperFields.{{=field.name}}.data[i];
338352
}
339353
{{?? field.type.isArray && field.type.isPrimitiveType && !isTypedArrayType(field.type)}}
340-
this._wrapperFields.{{=field.name}}.fill(this._{{=field.name}}Array);
341-
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);
342-
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
354+
if (!own) {
355+
this._wrapperFields.{{=field.name}}.fill(this._{{=field.name}}Array);
356+
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);
357+
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
358+
} else {
359+
this._wrapperFields.{{=field.name}}.fill([]);
360+
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);
361+
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
362+
}
343363
{{?? field.type.isArray && !field.type.isPrimitiveType && field.type.isFixedSizeArray}}
344364
for (let i = 0; i < this._wrapperFields.{{=field.name}}.data.length; i++) {
345365
this._refObject.{{=field.name}}[i] = this._wrapperFields.{{=field.name}}.data[i].freeze(own, checkConsistency);
@@ -348,6 +368,13 @@ class {{=objectWrapper}} {
348368
{{?? !field.type.isPrimitiveType || field.type.isArray}}
349369
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);
350370
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
371+
{{? field.type.isArray && field.type.isPrimitiveType }}
372+
if (own) {
373+
this._wrapperFields.{{=field.name}}.fill({{=getTypedArrayName(field.type)}}.from([]));
374+
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);
375+
this._refObject.{{=field.name}} = this._wrapperFields.{{=field.name}}.refObject;
376+
}
377+
{{?}}
351378
{{?? field.type.type === 'string' && it.spec.msgName !== 'String'}}
352379
if (own) {
353380
this._wrapperFields.{{=field.name}}.freeze(own, checkConsistency);

rosidl_parser/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def get_json_object_from_msg_spec_object(msg_spec_object):
3434
for field in msg_spec_object.fields:
3535
dict_field = {'name': field.name}
3636
dict_field['type'] = get_json_object_from_type_object(field.type)
37+
dict_field['default_value'] = field.default_value
3738
fields.append(dict_field)
3839

3940
constants = []

src/executor.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void Executor::Run(void* arg) {
9696

9797
try {
9898
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
99-
rcl_ret_t ret = rcl_wait_set_init(&wait_set, 0, 2, 0, 0, 0,
99+
rcl_ret_t ret = rcl_wait_set_init(&wait_set, 0, 2, 0, 0, 0, 0,
100100
executor->context_, rcl_get_default_allocator());
101101
if (ret != RCL_RET_OK) {
102102
throw std::runtime_error(std::string("Init waitset failed: ") +
@@ -119,7 +119,9 @@ void Executor::Run(void* arg) {
119119
0u,
120120
handle_manager->timer_count(),
121121
handle_manager->client_count(),
122-
handle_manager->service_count()) != RCL_RET_OK) {
122+
handle_manager->service_count(),
123+
// TODO(minggang): support events.
124+
0u) != RCL_RET_OK) {
123125
std::string error_message = std::string("Failed to resize: ")
124126
+ std::string(rcl_get_error_string().str);
125127
throw std::runtime_error(error_message);

src/rcl_bindings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ NAN_METHOD(RclTake) {
390390
rcl_subscription_t* subscription =
391391
reinterpret_cast<rcl_subscription_t*>(subscription_handle->ptr());
392392
void* msg_taken = node::Buffer::Data(info[1]->ToObject());
393-
rcl_ret_t ret = rcl_take(subscription, msg_taken, nullptr);
393+
rcl_ret_t ret = rcl_take(subscription, msg_taken, nullptr, nullptr);
394394

395395
if (ret != RCL_RET_OK && ret != RCL_RET_SUBSCRIPTION_TAKE_FAILED) {
396396
Nan::ThrowError(rcl_get_error_string().str);
@@ -495,7 +495,7 @@ NAN_METHOD(Publish) {
495495
RclHandle::Unwrap<RclHandle>(info[0]->ToObject())->ptr());
496496

497497
void* buffer = node::Buffer::Data(info[1]->ToObject());
498-
THROW_ERROR_IF_NOT_EQUAL(rcl_publish(publisher, buffer), RCL_RET_OK,
498+
THROW_ERROR_IF_NOT_EQUAL(rcl_publish(publisher, buffer, nullptr), RCL_RET_OK,
499499
rcl_get_error_string().str);
500500

501501
info.GetReturnValue().Set(Nan::Undefined());

test/test-bounded-array.js

Lines changed: 0 additions & 144 deletions
This file was deleted.

0 commit comments

Comments
 (0)