tachybridge-roslib-compat
v0.1.3
Published
roslib-style compatibility adapter powered by tachybridge-wasm
Readme
tachybridge-roslib-compat
tachybridge-roslib-compat provides a roslib-style API on top of tachybridge-wasm.
Purpose
- Reduce migration cost from existing roslib-style code
- Use
tachybridge-wasminternally fortopic,service, and native action flows
Install
npm install tachybridge-roslib-compatExample
import { Ros, Topic, Service, Action, Cli } from "tachybridge-roslib-compat";
const ros = new Ros({ url: "ws://127.0.0.1:9090" });
const topic = new Topic({ ros, name: "/demo/out", messageType: "std_msgs/String" });
topic.subscribe((msg) => console.log(msg));
topic.publish({ text: "hello" });
const service = new Service({ ros, name: "/demo/sum", serviceType: "example/AddTwoInts" });
service.callService({ a: 1, b: 2 }, (res) => console.log(res));
const action = new Action({ ros, name: "/arm/move", actionType: "demo/MoveArm" });
const id = action.sendGoal({ x: 1 }, (result) => console.log(result));
action.cancelGoal(id);
const cli = new Cli({ ros, command: "ros2 node list" });
cli.run((res) => console.log(res.output));
const cliRes = await cli.execute("ros2 node list");
console.log(cliRes.output);For CBOR binary frames:
const ros = new Ros({ url: "ws://127.0.0.1:9090", codec: "cbor" });Limits
- Not a full 1:1 implementation of all roslib APIs
ActionClient/Goalobject model is not includedtopic.compressionis forwarded to subscribe op (none/png/cbor/cbor-raw)
CLI Wrapping
Use Cli for roslib-style callback usage:
const cli = new Cli({ ros, command: "ros2 node list" });
cli.run(
(response) => console.log(response.output),
(error) => console.error(error)
);Or use promise style:
const response = await cli.execute("ros2 node list");
console.log(response.success, response.return_code, response.output);Test
npm run test -w tachybridge-roslib-compat