Instantiate ROSLIB
Hi,
I am using roslibjs in Vuejs. I have been declaring an instance of ROSLIB.Ros in every .vue pages that needs subscribing to topics (eg. dashboard.vue, maintenance.vue etc)
import ROSLIB from "roslib" const ros = new ROSLIB.Ros({ url: 'ws://localhost:9090' });
Connection is successful and I can read every topic that I am subscribed to. My question is, is there a way to create the above instance only once in let's say main.js instead of creating the instance in every .vue page?. I tried creating a global variable in main.js and tried passing it to a .vue page but I somehow could not assign the global variable to the ros parameter. This was what I tried.
In main.js
const urltemp = 'ws://' + process.env.VUEAPPDEVICEIP + ':' + process.env.VUEAPPDEVICE_PORT
const ros = new ROSLIB.Ros({ url: url_temp }); app.config.globalProperties.rosGlobal = ros;
In dashboard.vue
data: function() { return { rosLocal: this.rosGlobal, } },
//topic subscriber var subworkitem_status = new ROSLIB.Topic({ ros: this.rosLocal,
name: '/topicName', messageType: '/msgType' });
Somehow it seems the variable rosLocal cannot be accessed in the script tag. But I can access the variable in template using {{rosLocal}}
Any help is much appreciated.
Thanks
Asked by stanshi on 2022-12-07 01:47:12 UTC
Comments