From 3d6a3c164a1536d433aabce0d0e988d5307bc2d3 Mon Sep 17 00:00:00 2001 From: Jan Paul Posma Date: Tue, 7 Jan 2020 18:33:09 -0800 Subject: [PATCH] Add cbor-raw compression (#351) Add cbor-raw compression and a `getTopicsAndRawTypes` service function. This is a companion PR to https://github.com/RobotWebTools/rosbridge_suite/pull/452. Please see that PR for more details and motivation. --- build/roslib.js | 50 +++++++++++++++++++++++++++---- build/roslib.min.js | 4 +-- src/core/Ros.js | 71 ++++++++++++++++++++++++++++++++++++++++++--- src/core/Topic.js | 5 ++-- 4 files changed, 116 insertions(+), 14 deletions(-) diff --git a/build/roslib.js b/build/roslib.js index b7ce072b0..9c1aa0f98 100644 --- a/build/roslib.js +++ b/build/roslib.js @@ -2425,6 +2425,7 @@ Ros.prototype.getActionServers = function(callback, failedCallback) { * * @param callback function with params: * * topics - Array of topic names + * * types - Array of message type names */ Ros.prototype.getTopics = function(callback, failedCallback) { var topicsClient = new Service({ @@ -2856,6 +2857,38 @@ Ros.prototype.decodeTypeDefs = function(defs) { return decodeTypeDefsRec(defs[0], defs); }; +/** + * Retrieves list of topics and their associated type definitions. + * + * @param callback function with params: + * * topics - Array of topic names + * * types - Array of message type names + * * typedefs_full_text - Array of full definitions of message types, similar to `gendeps --cat` + */ +Ros.prototype.getTopicsAndRawTypes = function(callback, failedCallback) { + var topicsAndRawTypesClient = new Service({ + ros : this, + name : '/rosapi/topics_and_raw_types', + serviceType : 'rosapi/TopicsAndRawTypes' + }); + + var request = new ServiceRequest(); + if (typeof failedCallback === 'function'){ + topicsAndRawTypesClient.callService(request, + function(result) { + callback(result); + }, + function(message){ + failedCallback(message); + } + ); + }else{ + topicsAndRawTypesClient.callService(request, function(result) { + callback(result); + }); + } +}; + module.exports = Ros; @@ -3166,7 +3199,7 @@ var Message = require('./Message'); * * ros - the ROSLIB.Ros connection handle * * name - the topic name, like /cmd_vel * * messageType - the message type, like 'std_msgs/String' - * * compression - the type of compression to use, like 'png' or 'cbor' + * * compression - the type of compression to use, like 'png', 'cbor', or 'cbor-raw' * * throttle_rate - the rate (in ms in between messages) at which to throttle the topics * * queue_size - the queue created at bridge side for re-publishing webtopics (defaults to 100) * * latch - latch the topic when publishing @@ -3188,7 +3221,8 @@ function Topic(options) { // Check for valid compression types if (this.compression && this.compression !== 'png' && - this.compression !== 'cbor' && this.compression !== 'none') { + this.compression !== 'cbor' && this.compression !== 'cbor-raw' && + this.compression !== 'none') { this.emit('warning', this.compression + ' compression is not supported. No compression will be used.'); this.compression = 'none'; @@ -3677,6 +3711,7 @@ var Goal = require('../actionlib/Goal'); var Service = require('../core/Service.js'); var ServiceRequest = require('../core/ServiceRequest.js'); +var Topic = require('../core/Topic.js'); var Transform = require('../math/Transform'); @@ -3721,7 +3756,8 @@ function TFClient(options) { this.republisherUpdateRequested = false; // Create an Action client - this.actionClient = this.ros.ActionClient({ + this.actionClient = new ActionClient({ + ros : options.ros, serverName : this.serverName, actionName : 'tf2_web_republisher/TFSubscriptionAction', omitStatus : true, @@ -3729,7 +3765,8 @@ function TFClient(options) { }); // Create a Service client - this.serviceClient = this.ros.Service({ + this.serviceClient = new Service({ + ros: options.ros, name: this.repubServiceName, serviceType: 'tf2_web_republisher/RepublishTFs' }); @@ -3815,7 +3852,8 @@ TFClient.prototype.processResponse = function(response) { this.currentTopic.unsubscribe(); } - this.currentTopic = this.ros.Topic({ + this.currentTopic = new Topic({ + ros: this.ros, name: response.topic_name, messageType: 'tf2_web_republisher/TFArray' }); @@ -3887,7 +3925,7 @@ TFClient.prototype.dispose = function() { module.exports = TFClient; -},{"../actionlib/ActionClient":8,"../actionlib/Goal":10,"../core/Service.js":16,"../core/ServiceRequest.js":17,"../math/Transform":24}],29:[function(require,module,exports){ +},{"../actionlib/ActionClient":8,"../actionlib/Goal":10,"../core/Service.js":16,"../core/ServiceRequest.js":17,"../core/Topic.js":20,"../math/Transform":24}],29:[function(require,module,exports){ var Ros = require('../core/Ros'); var mixin = require('../mixin'); diff --git a/build/roslib.min.js b/build/roslib.min.js index 96c6e2679..b51529ee7 100644 --- a/build/roslib.min.js +++ b/build/roslib.min.js @@ -1,2 +1,2 @@ -!function(){function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c||a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g>2,f=0;f>6),d.push(128|63&g)):g<55296?(d.push(224|g>>12),d.push(128|g>>6&63),d.push(128|63&g)):(g=(1023&g)<<10,g|=1023&a.charCodeAt(++b),g+=65536,d.push(240|g>>18),d.push(128|g>>12&63),d.push(128|g>>6&63),d.push(128|63&g))}return m(3,d.length),i(d);default:var j;if(Array.isArray(a))for(j=a.length,m(4,j),b=0;b>5!==a)throw"Invalid indefinite length element";return c}function s(a,b){for(var c=0;c>10),a.push(56320|1023&d))}}function t(){var a,e,f=l(),g=f>>5,m=31&f;if(7===g)switch(m){case 25:return i();case 26:return j();case 27:return k()}if(e=q(m),e<0&&(g<2||6=0;)o+=e,n.push(h(e));var u=new Uint8Array(o),v=0;for(a=0;a=0;)s(w,e);else s(w,e);return String.fromCharCode.apply(null,w);case 4:var x;if(e<0)for(x=[];!p();)x.push(t());else for(x=new Array(e),a=0;a0&&f._listeners.length>this._maxListeners&&(f._listeners.warned=!0,g.call(this,f._listeners.length,h))):f._listeners=b,!0;h=a.shift()}return!0}var k=Array.isArray?Array.isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)},l=10;h.EventEmitter2=h,h.prototype.delimiter=".",h.prototype.setMaxListeners=function(a){a!==d&&(this._maxListeners=a,this._conf||(this._conf={}),this._conf.maxListeners=a)},h.prototype.event="",h.prototype.once=function(a,b){return this._once(a,b,!1)},h.prototype.prependOnceListener=function(a,b){return this._once(a,b,!0)},h.prototype._once=function(a,b,c){return this._many(a,1,b,c),this},h.prototype.many=function(a,b,c){return this._many(a,b,c,!1)},h.prototype.prependMany=function(a,b,c){return this._many(a,b,c,!0)},h.prototype._many=function(a,b,c,d){function e(){return 0===--b&&f.off(a,e),c.apply(this,arguments)}var f=this;if("function"!=typeof c)throw new Error("many only accepts instances of Function");return e._origin=c,this._on(a,e,d),f},h.prototype.emit=function(){this._events||e.call(this);var a=arguments[0];if("newListener"===a&&!this.newListener&&!this._events.newListener)return!1;var b,c,d,f,g,h=arguments.length;if(this._all&&this._all.length){if(g=this._all.slice(),h>3)for(b=new Array(h),f=0;f3)for(b=new Array(h-1),f=1;f3)for(b=new Array(j),f=1;f3)for(b=new Array(j-1),f=1;f0&&this._events[a].length>this._maxListeners&&(this._events[a].warned=!0,g.call(this,this._events[a].length,a))):this._events[a]=b,this)},h.prototype.off=function(a,b){function c(a){if(a!==d){var b=Object.keys(a);for(var e in b){var f=b[e],g=a[f];g instanceof Function||"object"!=typeof g||null===g||(Object.keys(g).length>0&&c(a[f]),0===Object.keys(g).length&&delete a[f])}}}if("function"!=typeof b)throw new Error("removeListener only takes instances of Function");var e,f=[];if(this.wildcard){var g="string"==typeof a?a.split(this.delimiter):a.slice();f=i.call(this,null,g,this.listenerTree,0)}else{if(!this._events[a])return this;e=this._events[a],f.push({_listeners:e})}for(var h=0;h0){for(b=this._all,c=0,d=b.length;c1)for(var c=1;cb.secs)&&(a.secs0&&(this.parent=b[0].getAttribute("link"));var c=a.xml.getElementsByTagName("child");c.length>0&&(this.child=c[0].getAttribute("link"));var d=a.xml.getElementsByTagName("limit");d.length>0&&(this.minval=parseFloat(d[0].getAttribute("lower")),this.maxval=parseFloat(d[0].getAttribute("upper")));var h=a.xml.getElementsByTagName("origin");if(0===h.length)this.origin=new e;else{var i=h[0].getAttribute("xyz"),j=new f;i&&(i=i.split(" "),j=new f({x:parseFloat(i[0]),y:parseFloat(i[1]),z:parseFloat(i[2])}));var k=h[0].getAttribute("rpy"),l=new g;if(k){k=k.split(" ");var m=parseFloat(k[0]),n=parseFloat(k[1]),o=parseFloat(k[2]),p=m/2,q=n/2,r=o/2,s=Math.sin(p)*Math.cos(q)*Math.cos(r)-Math.cos(p)*Math.sin(q)*Math.sin(r),t=Math.cos(p)*Math.sin(q)*Math.cos(r)+Math.sin(p)*Math.cos(q)*Math.sin(r),u=Math.cos(p)*Math.cos(q)*Math.sin(r)-Math.sin(p)*Math.sin(q)*Math.cos(r),v=Math.cos(p)*Math.cos(q)*Math.cos(r)+Math.sin(p)*Math.sin(q)*Math.sin(r);l=new g({x:s,y:t,z:u,w:v}),l.normalize()}this.origin=new e({position:j,orientation:l})}}var e=a("../math/Pose"),f=a("../math/Vector3"),g=a("../math/Quaternion");b.exports=d},{"../math/Pose":22,"../math/Quaternion":23,"../math/Vector3":25}],34:[function(a,b,c){function d(a){this.name=a.xml.getAttribute("name"),this.visuals=[];for(var b=a.xml.getElementsByTagName("visual"),c=0;c0&&(this.textureFilename=b[0].getAttribute("filename"));var c=a.xml.getElementsByTagName("color");c.length>0&&(this.color=new e({xml:c[0]}))}var e=a("./UrdfColor");d.prototype.isLink=function(){return null===this.color&&null===this.textureFilename};var f=a("object-assign");d.prototype.assign=function(a){return f(this,a)},b.exports=d},{"./UrdfColor":31,"object-assign":3}],36:[function(a,b,c){function d(a){this.scale=null,this.type=f.URDF_MESH,this.filename=a.xml.getAttribute("filename");var b=a.xml.getAttribute("scale");if(b){var c=b.split(" ");this.scale=new e({x:parseFloat(c[0]),y:parseFloat(c[1]),z:parseFloat(c[2])})}}var e=a("../math/Vector3"),f=a("./UrdfTypes");b.exports=d},{"../math/Vector3":25,"./UrdfTypes":39}],37:[function(a,b,c){function d(a){a=a||{};var b=a.xml,c=a.string;if(this.materials={},this.links={},this.joints={},c){var d=new h;b=d.parseFromString(c,"text/xml")}var i=b.documentElement;this.name=i.getAttribute("name");for(var j=i.childNodes,k=0;k0){for(var A=z[0],B=null,C=0;C0&&(this.material=new j({xml:F[0]}))}var e=a("../math/Pose"),f=a("../math/Vector3"),g=a("../math/Quaternion"),h=a("./UrdfCylinder"),i=a("./UrdfBox"),j=a("./UrdfMaterial"),k=a("./UrdfMesh"),l=a("./UrdfSphere");b.exports=d},{"../math/Pose":22,"../math/Quaternion":23,"../math/Vector3":25,"./UrdfBox":30,"./UrdfCylinder":32,"./UrdfMaterial":35,"./UrdfMesh":36,"./UrdfSphere":38}],41:[function(a,b,c){b.exports=a("object-assign")({UrdfBox:a("./UrdfBox"),UrdfColor:a("./UrdfColor"),UrdfCylinder:a("./UrdfCylinder"),UrdfLink:a("./UrdfLink"),UrdfMaterial:a("./UrdfMaterial"),UrdfMesh:a("./UrdfMesh"),UrdfModel:a("./UrdfModel"),UrdfSphere:a("./UrdfSphere"),UrdfVisual:a("./UrdfVisual")},a("./UrdfTypes"))},{"./UrdfBox":30,"./UrdfColor":31,"./UrdfCylinder":32,"./UrdfLink":34,"./UrdfMaterial":35,"./UrdfMesh":36,"./UrdfModel":37,"./UrdfSphere":38,"./UrdfTypes":39,"./UrdfVisual":40,"object-assign":3}],42:[function(a,b,c){"use strict";function d(){j||(j=!0,console.warn("CBOR 64-bit integer array values may lose precision. No further warnings."))}function e(a){d();for(var b=a.byteLength,c=a.byteOffset,e=b/8,f=a.buffer.slice(c,c+b),g=new Uint32Array(f),h=new Array(e),j=0;j>2,f=0;f>6),d.push(128|63&g)):g<55296?(d.push(224|g>>12),d.push(128|g>>6&63),d.push(128|63&g)):(g=(1023&g)<<10,g|=1023&a.charCodeAt(++b),g+=65536,d.push(240|g>>18),d.push(128|g>>12&63),d.push(128|g>>6&63),d.push(128|63&g))}return m(3,d.length),i(d);default:var j;if(Array.isArray(a))for(j=a.length,m(4,j),b=0;b>5!==a)throw"Invalid indefinite length element";return c}function s(a,b){for(var c=0;c>10),a.push(56320|1023&d))}}function t(){var a,e,f=l(),g=f>>5,m=31&f;if(7===g)switch(m){case 25:return i();case 26:return j();case 27:return k()}if(e=q(m),e<0&&(g<2||6=0;)o+=e,n.push(h(e));var u=new Uint8Array(o),v=0;for(a=0;a=0;)s(w,e);else s(w,e);return String.fromCharCode.apply(null,w);case 4:var x;if(e<0)for(x=[];!p();)x.push(t());else for(x=new Array(e),a=0;a0&&f._listeners.length>this._maxListeners&&(f._listeners.warned=!0,g.call(this,f._listeners.length,h))):f._listeners=b,!0;h=a.shift()}return!0}var k=Array.isArray?Array.isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)},l=10;h.EventEmitter2=h,h.prototype.delimiter=".",h.prototype.setMaxListeners=function(a){a!==d&&(this._maxListeners=a,this._conf||(this._conf={}),this._conf.maxListeners=a)},h.prototype.event="",h.prototype.once=function(a,b){return this._once(a,b,!1)},h.prototype.prependOnceListener=function(a,b){return this._once(a,b,!0)},h.prototype._once=function(a,b,c){return this._many(a,1,b,c),this},h.prototype.many=function(a,b,c){return this._many(a,b,c,!1)},h.prototype.prependMany=function(a,b,c){return this._many(a,b,c,!0)},h.prototype._many=function(a,b,c,d){function e(){return 0===--b&&f.off(a,e),c.apply(this,arguments)}var f=this;if("function"!=typeof c)throw new Error("many only accepts instances of Function");return e._origin=c,this._on(a,e,d),f},h.prototype.emit=function(){this._events||e.call(this);var a=arguments[0];if("newListener"===a&&!this.newListener&&!this._events.newListener)return!1;var b,c,d,f,g,h=arguments.length;if(this._all&&this._all.length){if(g=this._all.slice(),h>3)for(b=new Array(h),f=0;f3)for(b=new Array(h-1),f=1;f3)for(b=new Array(j),f=1;f3)for(b=new Array(j-1),f=1;f0&&this._events[a].length>this._maxListeners&&(this._events[a].warned=!0,g.call(this,this._events[a].length,a))):this._events[a]=b,this)},h.prototype.off=function(a,b){function c(a){if(a!==d){var b=Object.keys(a);for(var e in b){var f=b[e],g=a[f];g instanceof Function||"object"!=typeof g||null===g||(Object.keys(g).length>0&&c(a[f]),0===Object.keys(g).length&&delete a[f])}}}if("function"!=typeof b)throw new Error("removeListener only takes instances of Function");var e,f=[];if(this.wildcard){var g="string"==typeof a?a.split(this.delimiter):a.slice();f=i.call(this,null,g,this.listenerTree,0)}else{if(!this._events[a])return this;e=this._events[a],f.push({_listeners:e})}for(var h=0;h0){for(b=this._all,c=0,d=b.length;c1)for(var c=1;cb.secs)&&(a.secs0&&(this.parent=b[0].getAttribute("link"));var c=a.xml.getElementsByTagName("child");c.length>0&&(this.child=c[0].getAttribute("link"));var d=a.xml.getElementsByTagName("limit");d.length>0&&(this.minval=parseFloat(d[0].getAttribute("lower")),this.maxval=parseFloat(d[0].getAttribute("upper")));var h=a.xml.getElementsByTagName("origin");if(0===h.length)this.origin=new e;else{var i=h[0].getAttribute("xyz"),j=new f;i&&(i=i.split(" "),j=new f({x:parseFloat(i[0]),y:parseFloat(i[1]),z:parseFloat(i[2])}));var k=h[0].getAttribute("rpy"),l=new g;if(k){k=k.split(" ");var m=parseFloat(k[0]),n=parseFloat(k[1]),o=parseFloat(k[2]),p=m/2,q=n/2,r=o/2,s=Math.sin(p)*Math.cos(q)*Math.cos(r)-Math.cos(p)*Math.sin(q)*Math.sin(r),t=Math.cos(p)*Math.sin(q)*Math.cos(r)+Math.sin(p)*Math.cos(q)*Math.sin(r),u=Math.cos(p)*Math.cos(q)*Math.sin(r)-Math.sin(p)*Math.sin(q)*Math.cos(r),v=Math.cos(p)*Math.cos(q)*Math.cos(r)+Math.sin(p)*Math.sin(q)*Math.sin(r);l=new g({x:s,y:t,z:u,w:v}),l.normalize()}this.origin=new e({position:j,orientation:l})}}var e=a("../math/Pose"),f=a("../math/Vector3"),g=a("../math/Quaternion");b.exports=d},{"../math/Pose":22,"../math/Quaternion":23,"../math/Vector3":25}],34:[function(a,b,c){function d(a){this.name=a.xml.getAttribute("name"),this.visuals=[];for(var b=a.xml.getElementsByTagName("visual"),c=0;c0&&(this.textureFilename=b[0].getAttribute("filename"));var c=a.xml.getElementsByTagName("color");c.length>0&&(this.color=new e({xml:c[0]}))}var e=a("./UrdfColor");d.prototype.isLink=function(){return null===this.color&&null===this.textureFilename};var f=a("object-assign");d.prototype.assign=function(a){return f(this,a)},b.exports=d},{"./UrdfColor":31,"object-assign":3}],36:[function(a,b,c){function d(a){this.scale=null,this.type=f.URDF_MESH,this.filename=a.xml.getAttribute("filename");var b=a.xml.getAttribute("scale");if(b){var c=b.split(" ");this.scale=new e({x:parseFloat(c[0]),y:parseFloat(c[1]),z:parseFloat(c[2])})}}var e=a("../math/Vector3"),f=a("./UrdfTypes");b.exports=d},{"../math/Vector3":25,"./UrdfTypes":39}],37:[function(a,b,c){function d(a){a=a||{};var b=a.xml,c=a.string;if(this.materials={},this.links={},this.joints={},c){var d=new h;b=d.parseFromString(c,"text/xml")}var i=b.documentElement;this.name=i.getAttribute("name");for(var j=i.childNodes,k=0;k0){for(var A=z[0],B=null,C=0;C0&&(this.material=new j({xml:F[0]}))}var e=a("../math/Pose"),f=a("../math/Vector3"),g=a("../math/Quaternion"),h=a("./UrdfCylinder"),i=a("./UrdfBox"),j=a("./UrdfMaterial"),k=a("./UrdfMesh"),l=a("./UrdfSphere");b.exports=d},{"../math/Pose":22,"../math/Quaternion":23,"../math/Vector3":25,"./UrdfBox":30,"./UrdfCylinder":32,"./UrdfMaterial":35,"./UrdfMesh":36,"./UrdfSphere":38}],41:[function(a,b,c){b.exports=a("object-assign")({UrdfBox:a("./UrdfBox"),UrdfColor:a("./UrdfColor"),UrdfCylinder:a("./UrdfCylinder"),UrdfLink:a("./UrdfLink"),UrdfMaterial:a("./UrdfMaterial"),UrdfMesh:a("./UrdfMesh"),UrdfModel:a("./UrdfModel"),UrdfSphere:a("./UrdfSphere"),UrdfVisual:a("./UrdfVisual")},a("./UrdfTypes"))},{"./UrdfBox":30,"./UrdfColor":31,"./UrdfCylinder":32,"./UrdfLink":34,"./UrdfMaterial":35,"./UrdfMesh":36,"./UrdfModel":37,"./UrdfSphere":38,"./UrdfTypes":39,"./UrdfVisual":40,"object-assign":3}],42:[function(a,b,c){"use strict";function d(){j||(j=!0,console.warn("CBOR 64-bit integer array values may lose precision. No further warnings."))}function e(a){d();for(var b=a.byteLength,c=a.byteOffset,e=b/8,f=a.buffer.slice(c,c+b),g=new Uint32Array(f),h=new Array(e),j=0;j