UNPKG

robotics-dev

Version:

Robotics.dev P2P SDK client for robot control

65 lines (52 loc) 1.84 kB
# ROBOTICS.DEV App Builder Run ROS2 AI P2P robotics apps anywhere! This Robotics.dev NodeJS SDK automatically connects to Robotics.dev and uses peer-to-peer data channels to send and receive ROS2 messages between robots and cloud, edge, and developer machines as well as send twist movement commands and text to speak on the robot. ```` npm install robotics-dev ```` Here's an example of basic robotics.dev P2P app using this SDK. ```` //import robotics from 'robotics-dev'; const robotics = require('robotics-dev'); // Define movement commands const moveForward = { linear: {x: 0.2, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0} }; const turnLeft = { linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.2} }; const turnRight = { linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: -0.2} }; const stop = { linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0} }; var robotId = 'eeeaa722-...-9a53-c945a5822b60'; // Connect to robotics.dev robotics.connect({ server: 'ws://192.168.0.47:3001', robot: robotId, token: '5a66b323-...-9169-77a95014f339' }, (rosMessage) => { // rosMessage is already parsed by the SDK if (rosMessage.topic === '/camera2d') { console.log("Base64 image: ", rosMessage.data.data); } if(oneTime){ oneTime = false; robotics.speak('eeeaa722-b7b0-4799-9a53-c945a5822b60', 'this is a test') console.log('Moving robot forward at 20% speed...'); robotics.twist('eeeaa722-b7b0-4799-9a53-c945a5822b60', forwardTwist); // Stop after 5 seconds setTimeout(() => { console.log('Stopping robot...'); robotics.twist('eeeaa722-b7b0-4799-9a53-c945a5822b60', stopTwist); }, 5000); } }); ```` See examples directory for demos.