0.1.8 • Published 4 years ago
@wayneparrott/rclnodejs-types v0.1.8
TypeScript declarations for rclnodejs
This project provides type declaration files (*.d.ts) for use when coding your ROS2 rclnodejs nodes, interfaces, publishers, subscribers and clients using TypeScript.
Installation
npm install @wayneparrott/rclnodejs-types --save-dev
Configuration
In your project tsconfig.json file, update the "typeRoots" property to include @wayneparrott/rclnodejs-types as shown below:
"typeRoots": [
"node_modules/@wayneparrott/rclnodejs-types",
"node_modules/@types"
]
You will also need to install the rclnodejs package separately from this project as well as the ROS2 environment:
npm i rclnodejs
See ROS2 for installation options.
Example
import * as rclnodejs from 'rclnodejs';
const node: rclnodejs.Node;
const publisher: rclnodejs.Publisher;
const logger: rclnodejs.Logger;
async function init() {
await rclnodejs.init();
node = rclnodejs.createNode('ExampleNode');
logger = rclnodejs.Logging.getLogger('exampleLogger')
logger.info('node created');
publisher = node.createPublisher('std_msgs/msg/String', 'topic');
node.spin();
}
init();
publisher.publish('hello world');
logger.info('published msg');
node.destroy();
rclnodejs.shutdown();