Skip to content

Commit 4249771

Browse files
authored
Create robotics.js
1 parent c6e0176 commit 4249771

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

routes/robotics.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import express from 'express';
2+
import * as ROS from 'ros-nodejs';
3+
4+
const router = express.Router();
5+
const ros = new ROS.Node({
6+
url: 'ws://localhost:9090',
7+
topics: ['cmd_vel', 'odom'],
8+
});
9+
10+
router.post('/move-robot', (req, res) => {
11+
const { velocity } = req.body;
12+
const msg = new ROS.Message({
13+
linear: { x: velocity.x, y: velocity.y, z: velocity.z },
14+
angular: { x: velocity.rx, y: velocity.ry, z: velocity.rz },
15+
});
16+
ros.publish('cmd_vel', msg);
17+
res.json({ message: 'Robot moving' });
18+
});
19+
20+
router.get('/get-robot-odometry', (req, res) => {
21+
const odom = ros.subscribe('odom');
22+
res.json({ odom });
23+
});
24+
25+
export default router;

0 commit comments

Comments
 (0)