-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
constants support in messages #550
Comments
Thanks for your question, I checked the usage of const variable defined in const ImageMarker = rclnodejs.require('visualization_msgs/msg/ImageMarker');
const LINE_LIST = ImageMarker.LINE_LIST; // you get 2 here. Not sure it's what you want or you could suggest a better usage, thanks! |
Maybe I should introduce a little bit of the message objects used in
const node = rclnodejs.createNode('publisher_message_example_node');
const publisher = node.createPublisher('sensor_msgs/msg/JointState', 'JointState');
publisher.publish({
header: {
stamp: {
sec: 123456,
nanosec: 789,
},
frame_id: 'main frame',
},
name: ['Tom', 'Jerry'],
position: [1, 2],
velocity: [2, 3],
effort: [4, 5, 6],
}); see https://github.com/RobotWebTools/rclnodejs/blob/develop/example/publisher-message-example.js
let JointState = rclnodejs.require('sensor_msgs/msg/JointState'); // rclnodejs.require('sensor_msgs').msg.JointState;
let state = new JointState();
state.position = [1, 2];
state.velocity = [2, 3];
state.effort = [4, 5, 6]; Currently, most the usage is shown by the first way, because it's easier and more obvious and you can use |
Thanks! I wasn't aware of the |
@wayneparrott added the TS support recently, I know he is busy implementing another important feature of rclnodejs, so Wayne would you please have a look if you have time? or @koonpeng you could help to submit a PR based on your requirement, thanks a lot! |
I have been using a tool I made to generate typescript interfaces, now that rclnodejs has support for typescript, it would be better to use the native support. I will try to see if I can make a PR for this, thanks! |
@koonpeng thanks for identifying my goof up on the type-alias msg constants. Definitely not what I envisioned. After reviewing, I'm not sure what I was thinking at the time I impl'ed this. I was experimented with a couple of approaches. Please share suggestions/PR for improvement. In the meantime I plan to carve out some time to look into resolving this asap as well. |
A quick thought is to represent the IDL constants for a type_class/msg in interfaces.d.ts as an object literal similar to the snippet below. In this case a dev would need to know that in addition to importing ImageMarker he would also need to import ImageMarkerConstants.
Thoughts? |
normally this wouldnt work because |
#551 This PR improve typing information and generate constants as |
is there a way to reference the constant value like in rclpy? Something like
I can see that constants are generated in the js messages like so
But it needs to be imported like so
which doesn't seem like the intended usage.
Also, the typescript interfaces are generated like this
The constants have to be defined in objects that implements the type.
Is there an easier way to reference the constants in rclnodejs?
The text was updated successfully, but these errors were encountered: