This is a minimal example of nodeJS that uses rclnodejs to create a publisher to publish messages to turtlesim.
-
If you have problem installing rclnodejs, make sure that your entire path does not have whitespace in between. For example, your folder name should be "MyProjects" instead of "My Projects".
-
If you have error saying "Error: could not find the
cargo
executable.", you need to:- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- REFERENCE: https://www.rust-lang.org/tools/install
- npm install
npm start
-
You can refer to node_modules/rclnodejs/types/interfaces.d.ts and see what are the available messages. For example, you can look for "namespace geometry_msgs"->"namespace msg"->"export interface Twist" and see the interface of geometry_msgs/msg/Twist.
-
You can then use "rclnodejs.createMessageObject('geometry_msgs/msg/Twist');" to create a message object, and then use that to edit the twistMsg.linear and twistMsg.angular
-
You may also refer to the official examples of rclnodejs.