Skip to content

Commit 7c91f94

Browse files
author
Minggang Wang
authored
Merge pull request #221 from minggangw/fix-issue-218
Do copy the property if it is an array
2 parents 2175273 + db5161e commit 7c91f94

File tree

3 files changed

+132
-2
lines changed

3 files changed

+132
-2
lines changed

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.0.2",
3+
"version": "0.0.3",
44
"description": "Generate JavaScript object from ROS IDL(.msg) files",
55
"authors": [
66
"Minggang Wang <[email protected]>",

rosidl_gen/templates/message.dot

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ class {{=objectWrapper}} {
194194
if (typeof other === 'object' && other._refObject) {
195195
this._refObject = new {{=refObjectType}}(other._refObject.toObject());
196196
{{~ it.spec.fields :field}}
197-
{{? field.type.isArray || !field.type.isPrimitiveType || (field.type.type === 'string' && it.spec.msgName !== 'String')}}
197+
{{? field.type.isArray}}
198+
this._wrapperFields.{{=field.name}} = {{=getWrapperNameByType(field.type)}}.createArray();
199+
this._wrapperFields.{{=field.name}}.copy(other._wrapperFields.{{=field.name}});
200+
{{?? !field.type.isPrimitiveType || (field.type.type === 'string' && it.spec.msgName !== 'String')}}
198201
this._wrapperFields.{{=field.name}} = new {{=getWrapperNameByType(field.type)}}(other._wrapperFields.{{=field.name}});
199202
{{?}}
200203
{{~}}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// Copyright (c) 2017 Intel Corporation. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const assert = require('assert');
18+
const rclnodejs = require('../index.js');
19+
20+
/* eslint-disable camelcase */
21+
describe('Rclnodejs non primitive message type testing', function() {
22+
this.timeout(60 * 1000);
23+
24+
before(function() {
25+
return rclnodejs.init();
26+
});
27+
28+
after(function() {
29+
rclnodejs.shutdown();
30+
});
31+
32+
it('geometry_msgs/msg/Point checking', function() {
33+
const Point = rclnodejs.require('geometry_msgs/msg/Point');
34+
35+
let point = new Point();
36+
point.x = 1.5;
37+
point.y = 2.75;
38+
point.z = -0.5;
39+
40+
let pointClone = new Point(point);
41+
assert.deepStrictEqual(1.5, pointClone.x);
42+
assert.deepStrictEqual(2.75, pointClone.y);
43+
assert.deepStrictEqual(-0.5, pointClone.z);
44+
});
45+
46+
it('sensor_msgs/msg/JointState checking', function() {
47+
const JointState = rclnodejs.require('sensor_msgs/msg/JointState');
48+
49+
let jointState = new JointState();
50+
jointState.header.stamp.sec = 11223;
51+
jointState.header.stamp.nanosec = 44556;
52+
jointState.header.frame_id = '1234567x';
53+
jointState.name = ['Willy', 'Tacky'];
54+
jointState.position = [1, 7, 3, 4, 2, 2, 8];
55+
jointState.velocity = [8, 9, 6, 4];
56+
jointState.effort = [1, 0, 2, 6, 7];
57+
58+
let jointStateClone = new JointState(jointState);
59+
assert.deepStrictEqual(11223, jointStateClone.header.stamp.sec);
60+
assert.deepStrictEqual(44556, jointStateClone.header.stamp.nanosec);
61+
assert.deepStrictEqual('1234567x', jointStateClone.header.frame_id);
62+
assert.deepStrictEqual(['Willy', 'Tacky'], jointStateClone.name);
63+
assert.deepStrictEqual(Float64Array.from([1, 7, 3, 4, 2, 2, 8]), jointStateClone.position);
64+
assert.deepStrictEqual(Float64Array.from([8, 9, 6, 4]), jointStateClone.velocity);
65+
assert.deepStrictEqual(Float64Array.from([1, 0, 2, 6, 7]), jointStateClone.effort);
66+
});
67+
68+
it('geometry_msgs/msg/Transform checking', function() {
69+
const Transform = rclnodejs.require('geometry_msgs/msg/Transform');
70+
71+
let transform = new Transform();
72+
transform.translation.x = 1.5;
73+
transform.translation.y = 2.75;
74+
transform.translation.z = 3.0;
75+
transform.rotation.x = 1.5;
76+
transform.rotation.y = 2.75;
77+
transform.rotation.z = 3.0;
78+
transform.rotation.w = 1.0;
79+
80+
let transformClone = new Transform(transform);
81+
assert.deepStrictEqual(1.5, transformClone.translation.x);
82+
assert.deepStrictEqual(2.75, transformClone.translation.y);
83+
assert.deepStrictEqual(3.0, transformClone.translation.z);
84+
assert.deepStrictEqual(1.5, transformClone.rotation.x);
85+
assert.deepStrictEqual(2.75, transformClone.rotation.y);
86+
assert.deepStrictEqual(3.0, transformClone.rotation.z);
87+
assert.deepStrictEqual(1.0, transformClone.rotation.w);
88+
});
89+
90+
it('std_msgs/msg/Float32MultiArray checking', function() {
91+
const Float32MultiArray = rclnodejs.require('std_msgs/msg/Float32MultiArray');
92+
const MultiArrayDimension = rclnodejs.require('std_msgs/msg/MultiArrayDimension');
93+
94+
let float32MultiArray = new Float32MultiArray();
95+
let heightDimension = new MultiArrayDimension();
96+
heightDimension.label = 'height';
97+
heightDimension.size = 480;
98+
heightDimension.stride = 921600;
99+
100+
let weightDimension = new MultiArrayDimension();
101+
weightDimension.label = 'weight';
102+
weightDimension.size = 640;
103+
weightDimension.stride = 1920;
104+
105+
let channelDimension = new MultiArrayDimension();
106+
channelDimension.label = 'channel';
107+
channelDimension.size = 3;
108+
channelDimension.stride = 8;
109+
110+
float32MultiArray.layout.dim.fill([heightDimension, weightDimension, channelDimension]);
111+
float32MultiArray.layout.data_offset = 1024;
112+
float32MultiArray.data = [1.0, 2.0, 3.0, 8.5, 6.75, 0.5, -0.25];
113+
114+
let float32MultiArrayClone = new Float32MultiArray(float32MultiArray);
115+
assert.deepStrictEqual('height', float32MultiArrayClone.layout.dim.data[0].label);
116+
assert.deepStrictEqual(480, float32MultiArrayClone.layout.dim.data[0].size);
117+
assert.deepStrictEqual(921600, float32MultiArrayClone.layout.dim.data[0].stride);
118+
assert.deepStrictEqual('weight', float32MultiArrayClone.layout.dim.data[1].label);
119+
assert.deepStrictEqual(640, float32MultiArrayClone.layout.dim.data[1].size);
120+
assert.deepStrictEqual(1920, float32MultiArrayClone.layout.dim.data[1].stride);
121+
assert.deepStrictEqual('channel', float32MultiArrayClone.layout.dim.data[2].label);
122+
assert.deepStrictEqual(3, float32MultiArrayClone.layout.dim.data[2].size);
123+
assert.deepStrictEqual(8, float32MultiArrayClone.layout.dim.data[2].stride);
124+
assert.deepStrictEqual(1024, float32MultiArrayClone.layout.data_offset);
125+
assert.deepStrictEqual(Float32Array.from([1.0, 2.0, 3.0, 8.5, 6.75, 0.5, -0.25]), float32MultiArrayClone.data);
126+
});
127+
});

0 commit comments

Comments
 (0)