You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to use the function Ros.prototype.decodeTypeDefs in my project to decode the results I got from the functions Ros.prototype.getMessageDetails and Ros.prototype.getServiceRequestDetails, but it only worked for simple message/request types.
Therefore I adjusted the existing function, so that it would also work for complex types, for example 'geometry_msgs/twist'.
I thought I'd post my solution here, if anyone has the same problem:
decodeTypeDefs(defs) {
var that = this;
// calls itself recursively to resolve type definition using hints.
var decodeTypeDefsRec = function (theType, hints) {
var typeDefDict = {};
for (var i = 0; i < theType.fieldnames.length; i++) {
var arrayLen = theType.fieldarraylen[i];
var fieldName = theType.fieldnames[i];
var fieldType = theType.fieldtypes[i];
// check if fieldType can be found in fieldnames
var complexFieldType = (defs.findIndex(def => def.type === fieldType) !== -1) ? true : false;
//if fieldType complex --> then change fieldarraylen to 0
arrayLen = complexFieldType ? 0 : arrayLen;
if (!complexFieldType) { // check if fieldType is complex
if (arrayLen === -1) {
typeDefDict[fieldName] = fieldType;
} else {
typeDefDict[fieldName] = [fieldType];
}
} else {
// lookup the name
var sub = false;
for (var j = 0; j < hints.length; j++) {
if (hints[j].type.toString() === fieldType.toString()) {
sub = hints[j];
break;
}
}
if (sub) {
console.log(true);
var subResult = decodeTypeDefsRec(sub, hints);
if (arrayLen === -1) {
} else {
typeDefDict[fieldName] = [subResult];
}
} else {
that.emit('error', 'Cannot find ' + fieldType + ' in decodeTypeDefs');
}
}
}
return typeDefDict;
};
return decodeTypeDefsRec(defs[0], defs);
}
The text was updated successfully, but these errors were encountered:
k-aguete
pushed a commit
to k-aguete/roslibjs
that referenced
this issue
Oct 21, 2022
I wanted to use the function Ros.prototype.decodeTypeDefs in my project to decode the results I got from the functions Ros.prototype.getMessageDetails and Ros.prototype.getServiceRequestDetails, but it only worked for simple message/request types.
Therefore I adjusted the existing function, so that it would also work for complex types, for example 'geometry_msgs/twist'.
I thought I'd post my solution here, if anyone has the same problem:
The text was updated successfully, but these errors were encountered: