let ROSLIB = require('roslib');
import intl from 'react-intl-universal';
import { isLegal } from './message.type'
import { LocalStorage } from './localStorage'
import { notification } from 'antd';
let instance = null;
let reconnect = false;
/**
* 与 ROS 进行 pub/sub 通讯工具
* 单例模式
*
* 任意位置 用法:
* import { Networking } from './network'
* let network = new Networking();
* //发布消息
* network.publish(……);
*
* 订阅消息
* let sub = network.listen('/add_two_ints','rospy_tutorials/AddTwoInts',(name,data)=>{
* console.log(name,data)
* sub.unsubscribe();
* })
*
*
*/
export class Networking {
constructor() {
if (!instance) {
let t = this;
let localStorage = new LocalStorage();
let ip = localStorage.getItem("ip");
instance = new ROSLIB.Ros({
url: 'ws://' + ip + ':9090'
});
instance.on('connection', function () {
console.log('Connected to websocket server.');
instance.isConnect = true;
notification.close('closeMsg1');
notification.close('closeMsg2');
reconnect = false;
notification['success']({
message: intl.get('
通过rosbridge和roslibjs与 gauss 机械臂通信
最新推荐文章于 2024-08-10 07:25:10 发布