RobotWebTools / rclnodejs

Node.js version of ROS 2.0 client
https://docs.ros.org/en/humble/Concepts/Basic/About-Client-Libraries.html?highlight=rclnodejs#community-maintained
Apache License 2.0
325 stars 71 forks source link

Types for creating an Action Client not Updating with Sources Action Message Types #688

Closed caelinsutch closed 4 years ago

caelinsutch commented 4 years ago

Problem example:

// Variable actionType has to be a certain string value. Types don't update when sourcing additional packages
const newActionClient = new ActionClient(node, actionType as ActionTypeClassName, actionName);

newActionClient.sendGoal(data).then(v => {
  log.debug('Action Complete!');
})
mattrichard commented 4 years ago

Right now the message types are only generated during postinstall or at runtime when calling init(). I can see how this would be a problem with TypeScript since you need to be able to compile everything before init() can be run again. We'll either need to make the action types more flexible or find better ways to update the generated message typings when additional packages are sourced.

For now, you can workaround this issue by manually regenerating the message typings using the following command. This should at least unblock you until there's a proper solution.

node node_modules/rclnodejs/scripts/generate_messages.js
minggangw commented 4 years ago

We once planed to implement that the message generator could generate the JS messages from IDL dynamically if the required message cannot be found, but can be found through PATH (the new package will be added after you source the xxx_install.sh).

Unfortunately, you have to manually delete the generated\ folder in order to trigger to generate the messages completely again, or workaround as @mattrichard said. Thanks!

caelinsutch commented 4 years ago

For now, you can workaround this issue by manually regenerating the message typings using the following command. This should at least unblock you until there's a proper solution.

I got this error:

Start JavaScript message generation...
Caught error: TypeError: Cannot read property 'fields' of undefined
caelinsutch commented 4 years ago

Update - Even after deleting generated and even the entire folder and reinstalling, I'm still not getting all my packages sourced. For example, when calling a the service /save_maps from Slamtoolbox, I'm getting the error The message required does not exist: slam_toolbox, srv, SaveMap. In the same terminal window, I can run that service from the command line.

This is from the CLI:


➜ ros2 service type /save_map 
slam_toolbox/srv/SaveMap
wayneparrott commented 4 years ago

I'm able to isolate the problem to the slam_toolbox does not follow the ROS naming convention for placing services interfaces (idl) in a folder named srv. Instead slam_toolbox services idl lives in a folder named srvs here.

I'll submit a PR that is a bit more robust handling of such situations.

A short term workaround is to manually change 1 line of code in node_modules/rclnodejs/rclgen_tsd/index.js line as shown below. 2020-08-02_22-16-33