@@ -53,6 +53,9 @@ import VueHotkey from "v-hotkey";
5353import Vue from ' vue'
5454import html2canvas from ' html2canvas' ;
5555import canvasToImage from ' canvas-to-image'
56+ import * as ROSLIB from ' roslib'
57+ import ros from ' ./ws-connection/ROS-connection.js'
58+ import properties_ph from " ./assets/json/properties_ph.json"
5659
5760
5861Vue .use (VueHotkey);
@@ -66,6 +69,7 @@ export default {
6669 error: ' ' ,
6770 online: [],
6871 textVariant: ' dark' ,
72+ peripherals: properties_ph,
6973 }
7074 },
7175 components: {
@@ -105,7 +109,102 @@ export default {
105109 // if (window.location.href.indexOf(item.toLowerCase()) === -1){
106110 // window.location = "http://" + item.toLowerCase() + ".local";
107111 // }
108- },
112+ },
113+ mergeDeep (target , source ) {
114+ for (const key in source) {
115+ if (source[key] instanceof Object && key in target) {
116+ // Recursively merge if both properties are objects
117+ target[key] = this .mergeDeep (target[key], source[key]);
118+ } else {
119+ // Otherwise, directly assign
120+ target[key] = source[key];
121+ }
122+ }
123+ return target;
124+ },
125+ getPeripherals (){
126+
127+ var listParametersService = new ROSLIB.Service ({
128+ ros : ros,
129+ name : ' /io/telemetrix/list_parameters' ,
130+ serviceType : ' rcl_interfaces/srv/ListParameters'
131+ });
132+
133+ var getParameterService = new ROSLIB.Service ({
134+ ros : ros,
135+ name : ' /io/telemetrix/get_parameters' ,
136+ serviceType : ' rcl_interfaces/srv/GetParameters'
137+ });
138+
139+ let _this = this ;
140+ let peripheral_list = Object .keys (this .peripherals );
141+ let hardware_list = peripheral_list .filter (item => ! item .includes (" motor" ));
142+ hardware_list .push (" motor" );
143+ hardware_list .push (" device" );
144+ let peripherals = {' sensors' : {}, ' actuators' : {}, ' devices' : {} };
145+ let params = {};
146+
147+ var request = {
148+ prefixes: hardware_list,
149+ depth: 0
150+ };
151+
152+ // Get all the parameters
153+ listParametersService .callService (request, function (result ) {
154+
155+ let param_names = result .result .names ;
156+ var req = {
157+ names: param_names
158+ };
159+
160+ // Get the values of all the parameters
161+ getParameterService .callService (req, function (res ){
162+
163+ let values = res .values ;
164+ for (let param_id in values){
165+
166+ let value = 0 ;
167+ if (values[param_id].type == 2 ){
168+ value = values[param_id].integer_value ;
169+ } else if (values[param_id].type == 3 ){
170+ value = values[param_id].double_value ;
171+ } else if (values[param_id].type == 4 ){
172+ value = values[param_id].string_value ;
173+ }
174+
175+ let item = param_names[param_id].split (" ." ).reduceRight ((acc , key ) => ({ [key]: acc }), value);
176+ params = _this .mergeDeep (params, item);
177+ }
178+
179+ // Fix motor issues (TODO: we need to redesign the motor setup
180+ let new_params = {}
181+ for (let type in params){
182+ if (type == " motor" ){
183+ for (let instance in params[type]){
184+ new_params[params[type][instance].type + " _motor" ] = new_params[params[type][instance].type + " _motor" ] || {};
185+ new_params[params[type][instance].type + " _motor" ][instance] = params[type][instance];
186+ }
187+ } else {
188+ new_params[type] = params[type];
189+ }
190+ }
191+ params = new_params;
192+
193+ // Save everything in sensors/actuators
194+ for (let type in params){
195+ console .log (type);
196+ if (type == " device" ){
197+ peripherals[' devices' ] = params[type];
198+ } else if (_this .peripherals [type].rel_path .split (" \\ " )[0 ] == " Sensors" ){
199+ peripherals[' sensors' ][type] = params[type];
200+ } else {
201+ peripherals[' actuators' ][type] = params[type];
202+ }
203+ }
204+ _this .$store .dispatch (' setPeripherals' , peripherals);
205+ });
206+ });
207+ },
109208 checkLogin () {
110209 this .submitted = true ;
111210 const { username , password } = this ;
@@ -129,11 +228,14 @@ export default {
129228 this .$store .dispatch (' setUser' , response .data )
130229 }
131230 })
132- }
231+ },
133232 },
134233 mounted () { // TODO: could this be beforeMount?
135234
136- axios .get (" /api/self" )
235+ console .log (" Retrieving ROS parameters" );
236+ this .getPeripherals ();
237+
238+ axios .get (" /api/self" )
137239 .then ((response ) => {
138240 this .$store .dispatch (' setUser' , response .data )
139241 })
0 commit comments