From f5141a68e55292b241580583d4043df7d2323a6a Mon Sep 17 00:00:00 2001 From: Graeme Yeates Date: Fri, 12 Sep 2014 10:17:46 -0400 Subject: [PATCH 1/7] Make source files UMD compliant --- include/EventEmitter2/LICENSE | 9 - include/EventEmitter2/eventemitter2.js | 573 ------------------------- package.json | 54 +++ src/RosLib.js | 43 +- src/RosLibBrowser.js | 1 + src/actionlib/ActionClient.js | 26 +- src/actionlib/Goal.js | 20 +- src/actionlib/SimpleActionServer.js | 36 +- src/core/Message.js | 6 +- src/core/Param.js | 27 +- src/core/Ros.js | 67 +-- src/core/Service.js | 12 +- src/core/ServiceRequest.js | 6 +- src/core/ServiceResponse.js | 6 +- src/core/Topic.js | 24 +- src/math/Pose.js | 19 +- src/math/Quaternion.js | 18 +- src/math/Transform.js | 17 +- src/math/Vector3.js | 16 +- src/tf/TFClient.js | 23 +- src/urdf/UrdfBox.js | 13 +- src/urdf/UrdfColor.js | 6 +- src/urdf/UrdfCylinder.js | 9 +- src/urdf/UrdfLink.js | 9 +- src/urdf/UrdfMaterial.js | 10 +- src/urdf/UrdfMesh.js | 12 +- src/urdf/UrdfModel.js | 19 +- src/urdf/UrdfSphere.js | 9 +- src/urdf/UrdfTypes.js | 6 + src/urdf/UrdfVisual.js | 37 +- src/util/DOMParser.js | 1 + src/util/WebSocket.js | 53 +++ src/util/shim/DOMParser.js | 1 + src/util/shim/EventEmitter2.js | 3 + src/util/shim/WebSocket.js | 1 + src/util/shim/canvas.js | 4 + utils/package.json | 16 - 37 files changed, 442 insertions(+), 770 deletions(-) delete mode 100644 include/EventEmitter2/LICENSE delete mode 100644 include/EventEmitter2/eventemitter2.js create mode 100644 package.json create mode 100644 src/RosLibBrowser.js create mode 100644 src/urdf/UrdfTypes.js create mode 100644 src/util/DOMParser.js create mode 100644 src/util/WebSocket.js create mode 100644 src/util/shim/DOMParser.js create mode 100644 src/util/shim/EventEmitter2.js create mode 100644 src/util/shim/WebSocket.js create mode 100644 src/util/shim/canvas.js delete mode 100644 utils/package.json diff --git a/include/EventEmitter2/LICENSE b/include/EventEmitter2/LICENSE deleted file mode 100644 index 7830fb9a9..000000000 --- a/include/EventEmitter2/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -(The MIT License) - -Copyright (c) 2011 hij1nx http://www.twitter.com/hij1nx - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/include/EventEmitter2/eventemitter2.js b/include/EventEmitter2/eventemitter2.js deleted file mode 100644 index bde69e853..000000000 --- a/include/EventEmitter2/eventemitter2.js +++ /dev/null @@ -1,573 +0,0 @@ -/*! - * EventEmitter2 - * https://github.com/hij1nx/EventEmitter2 - * - * Copyright (c) 2013 hij1nx - * Licensed under the MIT license. - */ -;!function(undefined) { - - var isArray = Array.isArray ? Array.isArray : function _isArray(obj) { - return Object.prototype.toString.call(obj) === "[object Array]"; - }; - var defaultMaxListeners = 10; - - function init() { - this._events = {}; - if (this._conf) { - configure.call(this, this._conf); - } - } - - function configure(conf) { - if (conf) { - - this._conf = conf; - - conf.delimiter && (this.delimiter = conf.delimiter); - conf.maxListeners && (this._events.maxListeners = conf.maxListeners); - conf.wildcard && (this.wildcard = conf.wildcard); - conf.newListener && (this.newListener = conf.newListener); - - if (this.wildcard) { - this.listenerTree = {}; - } - } - } - - function EventEmitter(conf) { - this._events = {}; - this.newListener = false; - configure.call(this, conf); - } - - // - // Attention, function return type now is array, always ! - // It has zero elements if no any matches found and one or more - // elements (leafs) if there are matches - // - function searchListenerTree(handlers, type, tree, i) { - if (!tree) { - return []; - } - var listeners=[], leaf, len, branch, xTree, xxTree, isolatedBranch, endReached, - typeLength = type.length, currentType = type[i], nextType = type[i+1]; - if (i === typeLength && tree._listeners) { - // - // If at the end of the event(s) list and the tree has listeners - // invoke those listeners. - // - if (typeof tree._listeners === 'function') { - handlers && handlers.push(tree._listeners); - return [tree]; - } else { - for (leaf = 0, len = tree._listeners.length; leaf < len; leaf++) { - handlers && handlers.push(tree._listeners[leaf]); - } - return [tree]; - } - } - - if ((currentType === '*' || currentType === '**') || tree[currentType]) { - // - // If the event emitted is '*' at this part - // or there is a concrete match at this patch - // - if (currentType === '*') { - for (branch in tree) { - if (branch !== '_listeners' && tree.hasOwnProperty(branch)) { - listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], i+1)); - } - } - return listeners; - } else if(currentType === '**') { - endReached = (i+1 === typeLength || (i+2 === typeLength && nextType === '*')); - if(endReached && tree._listeners) { - // The next element has a _listeners, add it to the handlers. - listeners = listeners.concat(searchListenerTree(handlers, type, tree, typeLength)); - } - - for (branch in tree) { - if (branch !== '_listeners' && tree.hasOwnProperty(branch)) { - if(branch === '*' || branch === '**') { - if(tree[branch]._listeners && !endReached) { - listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], typeLength)); - } - listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], i)); - } else if(branch === nextType) { - listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], i+2)); - } else { - // No match on this one, shift into the tree but not in the type array. - listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], i)); - } - } - } - return listeners; - } - - listeners = listeners.concat(searchListenerTree(handlers, type, tree[currentType], i+1)); - } - - xTree = tree['*']; - if (xTree) { - // - // If the listener tree will allow any match for this part, - // then recursively explore all branches of the tree - // - searchListenerTree(handlers, type, xTree, i+1); - } - - xxTree = tree['**']; - if(xxTree) { - if(i < typeLength) { - if(xxTree._listeners) { - // If we have a listener on a '**', it will catch all, so add its handler. - searchListenerTree(handlers, type, xxTree, typeLength); - } - - // Build arrays of matching next branches and others. - for(branch in xxTree) { - if(branch !== '_listeners' && xxTree.hasOwnProperty(branch)) { - if(branch === nextType) { - // We know the next element will match, so jump twice. - searchListenerTree(handlers, type, xxTree[branch], i+2); - } else if(branch === currentType) { - // Current node matches, move into the tree. - searchListenerTree(handlers, type, xxTree[branch], i+1); - } else { - isolatedBranch = {}; - isolatedBranch[branch] = xxTree[branch]; - searchListenerTree(handlers, type, { '**': isolatedBranch }, i+1); - } - } - } - } else if(xxTree._listeners) { - // We have reached the end and still on a '**' - searchListenerTree(handlers, type, xxTree, typeLength); - } else if(xxTree['*'] && xxTree['*']._listeners) { - searchListenerTree(handlers, type, xxTree['*'], typeLength); - } - } - - return listeners; - } - - function growListenerTree(type, listener) { - - type = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); - - // - // Looks for two consecutive '**', if so, don't add the event at all. - // - for(var i = 0, len = type.length; i+1 < len; i++) { - if(type[i] === '**' && type[i+1] === '**') { - return; - } - } - - var tree = this.listenerTree; - var name = type.shift(); - - while (name) { - - if (!tree[name]) { - tree[name] = {}; - } - - tree = tree[name]; - - if (type.length === 0) { - - if (!tree._listeners) { - tree._listeners = listener; - } - else if(typeof tree._listeners === 'function') { - tree._listeners = [tree._listeners, listener]; - } - else if (isArray(tree._listeners)) { - - tree._listeners.push(listener); - - if (!tree._listeners.warned) { - - var m = defaultMaxListeners; - - if (typeof this._events.maxListeners !== 'undefined') { - m = this._events.maxListeners; - } - - if (m > 0 && tree._listeners.length > m) { - - tree._listeners.warned = true; - console.error('(node) warning: possible EventEmitter memory ' + - 'leak detected. %d listeners added. ' + - 'Use emitter.setMaxListeners() to increase limit.', - tree._listeners.length); - console.trace(); - } - } - } - return true; - } - name = type.shift(); - } - return true; - } - - // By default EventEmitters will print a warning if more than - // 10 listeners are added to it. This is a useful default which - // helps finding memory leaks. - // - // Obviously not all Emitters should be limited to 10. This function allows - // that to be increased. Set to zero for unlimited. - - EventEmitter.prototype.delimiter = '.'; - - EventEmitter.prototype.setMaxListeners = function(n) { - this._events || init.call(this); - this._events.maxListeners = n; - if (!this._conf) this._conf = {}; - this._conf.maxListeners = n; - }; - - EventEmitter.prototype.event = ''; - - EventEmitter.prototype.once = function(event, fn) { - this.many(event, 1, fn); - return this; - }; - - EventEmitter.prototype.many = function(event, ttl, fn) { - var self = this; - - if (typeof fn !== 'function') { - throw new Error('many only accepts instances of Function'); - } - - function listener() { - if (--ttl === 0) { - self.off(event, listener); - } - fn.apply(this, arguments); - } - - listener._origin = fn; - - this.on(event, listener); - - return self; - }; - - EventEmitter.prototype.emit = function() { - - this._events || init.call(this); - - var type = arguments[0]; - - if (type === 'newListener' && !this.newListener) { - if (!this._events.newListener) { return false; } - } - - // Loop through the *_all* functions and invoke them. - if (this._all) { - var l = arguments.length; - var args = new Array(l - 1); - for (var i = 1; i < l; i++) args[i - 1] = arguments[i]; - for (i = 0, l = this._all.length; i < l; i++) { - this.event = type; - this._all[i].apply(this, args); - } - } - - // If there is no 'error' event listener then throw. - if (type === 'error') { - - if (!this._all && - !this._events.error && - !(this.wildcard && this.listenerTree.error)) { - - if (arguments[1] instanceof Error) { - throw arguments[1]; // Unhandled 'error' event - } else { - throw new Error("Uncaught, unspecified 'error' event."); - } - return false; - } - } - - var handler; - - if(this.wildcard) { - handler = []; - var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); - searchListenerTree.call(this, handler, ns, this.listenerTree, 0); - } - else { - handler = this._events[type]; - } - - if (typeof handler === 'function') { - this.event = type; - if (arguments.length === 1) { - handler.call(this); - } - else if (arguments.length > 1) - switch (arguments.length) { - case 2: - handler.call(this, arguments[1]); - break; - case 3: - handler.call(this, arguments[1], arguments[2]); - break; - // slower - default: - var l = arguments.length; - var args = new Array(l - 1); - for (var i = 1; i < l; i++) args[i - 1] = arguments[i]; - handler.apply(this, args); - } - return true; - } - else if (handler) { - var l = arguments.length; - var args = new Array(l - 1); - for (var i = 1; i < l; i++) args[i - 1] = arguments[i]; - - var listeners = handler.slice(); - for (var i = 0, l = listeners.length; i < l; i++) { - this.event = type; - listeners[i].apply(this, args); - } - return (listeners.length > 0) || !!this._all; - } - else { - return !!this._all; - } - - }; - - EventEmitter.prototype.on = function(type, listener) { - - if (typeof type === 'function') { - this.onAny(type); - return this; - } - - if (typeof listener !== 'function') { - throw new Error('on only accepts instances of Function'); - } - this._events || init.call(this); - - // To avoid recursion in the case that type == "newListeners"! Before - // adding it to the listeners, first emit "newListeners". - this.emit('newListener', type, listener); - - if(this.wildcard) { - growListenerTree.call(this, type, listener); - return this; - } - - if (!this._events[type]) { - // Optimize the case of one listener. Don't need the extra array object. - this._events[type] = listener; - } - else if(typeof this._events[type] === 'function') { - // Adding the second element, need to change to array. - this._events[type] = [this._events[type], listener]; - } - else if (isArray(this._events[type])) { - // If we've already got an array, just append. - this._events[type].push(listener); - - // Check for listener leak - if (!this._events[type].warned) { - - var m = defaultMaxListeners; - - if (typeof this._events.maxListeners !== 'undefined') { - m = this._events.maxListeners; - } - - if (m > 0 && this._events[type].length > m) { - - this._events[type].warned = true; - console.error('(node) warning: possible EventEmitter memory ' + - 'leak detected. %d listeners added. ' + - 'Use emitter.setMaxListeners() to increase limit.', - this._events[type].length); - console.trace(); - } - } - } - return this; - }; - - EventEmitter.prototype.onAny = function(fn) { - - if (typeof fn !== 'function') { - throw new Error('onAny only accepts instances of Function'); - } - - if(!this._all) { - this._all = []; - } - - // Add the function to the event listener collection. - this._all.push(fn); - return this; - }; - - EventEmitter.prototype.addListener = EventEmitter.prototype.on; - - EventEmitter.prototype.off = function(type, listener) { - if (typeof listener !== 'function') { - throw new Error('removeListener only takes instances of Function'); - } - - var handlers,leafs=[]; - - if(this.wildcard) { - var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); - leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0); - } - else { - // does not use listeners(), so no side effect of creating _events[type] - if (!this._events[type]) return this; - handlers = this._events[type]; - leafs.push({_listeners:handlers}); - } - - for (var iLeaf=0; iLeaf 0) { - fns = this._all; - for(i = 0, l = fns.length; i < l; i++) { - if(fn === fns[i]) { - fns.splice(i, 1); - return this; - } - } - } else { - this._all = []; - } - return this; - }; - - EventEmitter.prototype.removeListener = EventEmitter.prototype.off; - - EventEmitter.prototype.removeAllListeners = function(type) { - if (arguments.length === 0) { - !this._events || init.call(this); - return this; - } - - if(this.wildcard) { - var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); - var leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0); - - for (var iLeaf=0; iLeaf 0) { - that.visual = new ROSLIB.UrdfVisual({ + that.visual = new UrdfVisual({ xml : visuals[0] }); } @@ -34,5 +36,6 @@ ROSLIB.UrdfLink = function(options) { // Pass it to the XML parser initXml(xml); -}; +} +module.exports = UrdfLink; \ No newline at end of file diff --git a/src/urdf/UrdfMaterial.js b/src/urdf/UrdfMaterial.js index 456eacce1..918ffcf96 100644 --- a/src/urdf/UrdfMaterial.js +++ b/src/urdf/UrdfMaterial.js @@ -3,6 +3,8 @@ * @author Russell Toris - rctoris@wpi.edu */ +var UrdfColor = require('./UrdfColor'); + /** * A Material element in a URDF. * @@ -10,7 +12,7 @@ * @param options - object with following keys: * * xml - the XML element to parse */ -ROSLIB.UrdfMaterial = function(options) { +function UrdfMaterial(options) { options = options || {}; var that = this; var xml = options.xml; @@ -36,7 +38,7 @@ ROSLIB.UrdfMaterial = function(options) { var colors = xml.getElementsByTagName('color'); if (colors.length > 0) { // Parse the RBGA string - that.color = new ROSLIB.UrdfColor({ + that.color = new UrdfColor({ xml : colors[0] }); } @@ -44,4 +46,6 @@ ROSLIB.UrdfMaterial = function(options) { // Pass it to the XML parser initXml(xml); -}; +} + +module.exports = UrdfMaterial; \ No newline at end of file diff --git a/src/urdf/UrdfMesh.js b/src/urdf/UrdfMesh.js index cc51b61f4..234d6d981 100644 --- a/src/urdf/UrdfMesh.js +++ b/src/urdf/UrdfMesh.js @@ -3,6 +3,9 @@ * @author Russell Toris - rctoris@wpi.edu */ +var Vector3 = require('../math/Vector3'); +var UrdfTypes = require('./UrdfTypes'); + /** * A Mesh element in a URDF. * @@ -10,7 +13,7 @@ * @param options - object with following keys: * * xml - the XML element to parse */ -ROSLIB.UrdfMesh = function(options) { +function UrdfMesh(options) { options = options || {}; var that = this; var xml = options.xml; @@ -24,7 +27,7 @@ ROSLIB.UrdfMesh = function(options) { * @param xml - the XML element to parse */ var initXml = function(xml) { - that.type = ROSLIB.URDF_MESH; + that.type = UrdfTypes.URDF_MESH; that.filename = xml.getAttribute('filename'); // Check for a scale @@ -32,7 +35,7 @@ ROSLIB.UrdfMesh = function(options) { if (scale) { // Get the XYZ var xyz = scale.split(' '); - that.scale = new ROSLIB.Vector3({ + that.scale = new Vector3({ x : parseFloat(xyz[0]), y : parseFloat(xyz[1]), z : parseFloat(xyz[2]) @@ -42,5 +45,6 @@ ROSLIB.UrdfMesh = function(options) { // Pass it to the XML parser initXml(xml); -}; +} +module.exports = UrdfMesh; \ No newline at end of file diff --git a/src/urdf/UrdfModel.js b/src/urdf/UrdfModel.js index 798c45907..772eb7deb 100644 --- a/src/urdf/UrdfModel.js +++ b/src/urdf/UrdfModel.js @@ -3,6 +3,13 @@ * @author Russell Toris - rctoris@wpi.edu */ +var UrdfMaterial = require('./UrdfMaterial'); +var UrdfLink = require('./UrdfLink'); +var DOMParser = require('../util/DOMParser'); + +// See https://developer.mozilla.org/docs/XPathResult#Constants +var XPATH_FIRST_ORDERED_NODE_TYPE = 9; + /** * A URDF Model can be used to parse a given URDF into the appropriate elements. * @@ -11,7 +18,7 @@ * * xml - the XML element to parse * * string - the XML element to parse as a string */ -ROSLIB.UrdfModel = function(options) { +function UrdfModel(options) { options = options || {}; var that = this; var xml = options.xml; @@ -26,7 +33,7 @@ ROSLIB.UrdfModel = function(options) { */ var initXml = function(xmlDoc) { // Get the robot tag - var robotXml = xmlDoc.evaluate('//robot', xmlDoc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; + var robotXml = xmlDoc.evaluate('//robot', xmlDoc, null, XPATH_FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; // Get the robot name that.name = robotXml.getAttribute('name'); @@ -35,7 +42,7 @@ ROSLIB.UrdfModel = function(options) { for (var n in robotXml.childNodes) { var node = robotXml.childNodes[n]; if (node.tagName === 'material') { - var material = new ROSLIB.UrdfMaterial({ + var material = new UrdfMaterial({ xml : node }); // Make sure this is unique @@ -45,7 +52,7 @@ ROSLIB.UrdfModel = function(options) { that.materials[material.name] = material; } } else if (node.tagName === 'link') { - var link = new ROSLIB.UrdfLink({ + var link = new UrdfLink({ xml : node }); // Make sure this is unique @@ -76,4 +83,6 @@ ROSLIB.UrdfModel = function(options) { } // Pass it to the XML parser initXml(xml); -}; +} + +module.exports = UrdfModel; \ No newline at end of file diff --git a/src/urdf/UrdfSphere.js b/src/urdf/UrdfSphere.js index 4f170cba7..777af8b05 100644 --- a/src/urdf/UrdfSphere.js +++ b/src/urdf/UrdfSphere.js @@ -3,6 +3,8 @@ * @author Russell Toris - rctoris@wpi.edu */ +var UrdfTypes = require('./UrdfTypes'); + /** * A Sphere element in a URDF. * @@ -10,7 +12,7 @@ * @param options - object with following keys: * * xml - the XML element to parse */ -ROSLIB.UrdfSphere = function(options) { +function UrdfSphere(options) { options = options || {}; var that = this; var xml = options.xml; @@ -23,11 +25,12 @@ ROSLIB.UrdfSphere = function(options) { * @param xml - the XML element to parse */ var initXml = function(xml) { - that.type = ROSLIB.URDF_SPHERE; + that.type = UrdfTypes.URDF_SPHERE; that.radius = parseFloat(xml.getAttribute('radius')); }; // pass it to the XML parser initXml(xml); -}; +} +module.exports = UrdfSphere; \ No newline at end of file diff --git a/src/urdf/UrdfTypes.js b/src/urdf/UrdfTypes.js new file mode 100644 index 000000000..99572cc7c --- /dev/null +++ b/src/urdf/UrdfTypes.js @@ -0,0 +1,6 @@ +module.exports = { + URDF_SPHERE : 0, + URDF_BOX : 1, + URDF_CYLINDER : 2, + URDF_MESH : 3 +}; diff --git a/src/urdf/UrdfVisual.js b/src/urdf/UrdfVisual.js index 6a75f73f5..9b24153d4 100644 --- a/src/urdf/UrdfVisual.js +++ b/src/urdf/UrdfVisual.js @@ -3,6 +3,16 @@ * @author Russell Toris - rctoris@wpi.edu */ +var Pose = require('../math/Pose'); +var Vector3 = require('../math/Vector3'); +var Quaternion = require('../math/Quaternion'); + +var UrdfCylinder = require('./UrdfCylinder'); +var UrdfBox = require('./UrdfBox'); +var UrdfMaterial = require('./UrdfMaterial'); +var UrdfMesh = require('./UrdfMesh'); +var UrdfSphere = require('./UrdfSphere'); + /** * A Visual element in a URDF. * @@ -10,7 +20,7 @@ * @param options - object with following keys: * * xml - the XML element to parse */ -ROSLIB.UrdfVisual = function(options) { +function UrdfVisual(options) { options = options || {}; var that = this; var xml = options.xml; @@ -28,14 +38,14 @@ ROSLIB.UrdfVisual = function(options) { var origins = xml.getElementsByTagName('origin'); if (origins.length === 0) { // use the identity as the default - that.origin = new ROSLIB.Pose(); + that.origin = new Pose(); } else { // Check the XYZ var xyz = origins[0].getAttribute('xyz'); - var position = new ROSLIB.Vector3(); + var position = new Vector3(); if (xyz) { xyz = xyz.split(' '); - position = new ROSLIB.Vector3({ + position = new Vector3({ x : parseFloat(xyz[0]), y : parseFloat(xyz[1]), z : parseFloat(xyz[2]) @@ -44,7 +54,7 @@ ROSLIB.UrdfVisual = function(options) { // Check the RPY var rpy = origins[0].getAttribute('rpy'); - var orientation = new ROSLIB.Quaternion(); + var orientation = new Quaternion(); if (rpy) { rpy = rpy.split(' '); // Convert from RPY @@ -63,7 +73,7 @@ ROSLIB.UrdfVisual = function(options) { var w = Math.cos(phi) * Math.cos(the) * Math.cos(psi) + Math.sin(phi) * Math.sin(the) * Math.sin(psi); - orientation = new ROSLIB.Quaternion({ + orientation = new Quaternion({ x : x, y : y, z : z, @@ -71,7 +81,7 @@ ROSLIB.UrdfVisual = function(options) { }); orientation.normalize(); } - that.origin = new ROSLIB.Pose({ + that.origin = new Pose({ position : position, orientation : orientation }); @@ -92,19 +102,19 @@ ROSLIB.UrdfVisual = function(options) { // Check the type var type = shape.nodeName; if (type === 'sphere') { - that.geometry = new ROSLIB.UrdfSphere({ + that.geometry = new UrdfSphere({ xml : shape }); } else if (type === 'box') { - that.geometry = new ROSLIB.UrdfBox({ + that.geometry = new UrdfBox({ xml : shape }); } else if (type === 'cylinder') { - that.geometry = new ROSLIB.UrdfCylinder({ + that.geometry = new UrdfCylinder({ xml : shape }); } else if (type === 'mesh') { - that.geometry = new ROSLIB.UrdfMesh({ + that.geometry = new UrdfMesh({ xml : shape }); } else { @@ -115,7 +125,7 @@ ROSLIB.UrdfVisual = function(options) { // Material var materials = xml.getElementsByTagName('material'); if (materials.length > 0) { - that.material = new ROSLIB.UrdfMaterial({ + that.material = new UrdfMaterial({ xml : materials[0] }); } @@ -123,5 +133,6 @@ ROSLIB.UrdfVisual = function(options) { // Pass it to the XML parser initXml(xml); -}; +} +module.exports = UrdfVisual; \ No newline at end of file diff --git a/src/util/DOMParser.js b/src/util/DOMParser.js new file mode 100644 index 000000000..71c7d3bd2 --- /dev/null +++ b/src/util/DOMParser.js @@ -0,0 +1 @@ +module.exports = require('xmlshim').DOMParser; \ No newline at end of file diff --git a/src/util/WebSocket.js b/src/util/WebSocket.js new file mode 100644 index 000000000..ec06fb05b --- /dev/null +++ b/src/util/WebSocket.js @@ -0,0 +1,53 @@ +var ws = require('nodejs-websocket'); + +/** + * Provides a WebSocket browser compatible interface to the nodejs-websocket client library. This is used by ROSLIB.Ros directly. + * + * @constructor + */ +var WebSocket = function(url) { + this.url = url; + this.onopen = function() {}; // placeholder function + this.onclose = function() {}; // placeholder function + this.onerror = function() {}; // placeholder function + this.onmessage = function() {}; // placeholder function + var that = this; + this.wsconn = ws.connect(url, null, function(evt) { + that.readyState = that.wsconn.readyState; + // call onopen + that.onopen(evt); // TODO check compatible + }); + this.wsconn.on('close', function(evt) { + that.readyState = that.wsconn.readyState; + that.onclose(evt); + }); + this.wsconn.on('error', function(evt) { + that.readyState = that.wsconn.readyState; + that.onerror(evt); + }); + this.wsconn.on('text', function(fb) { + that.readyState = that.wsconn.readyState; + // do something with framebuffer + that.onmessage({ + data: fb + }); + }); + this.wsconn.on('binary', function(fb) { + that.readyState = that.wsconn.readyState; + // do something with framebuffer - rosbridge wraps binary in the JSON under the data property + // Thus this function should not be needed - we can safely ignore binary messages + }); +}; +WebSocket.prototype.close = function() { + this.wsconn.close(); +}; +WebSocket.prototype.send = function(messageJson) { + this.wsconn.sendText(messageJson); +}; +// Copied from https://github.com/sitegui/nodejs-websocket/blob/master/Connection.js#L75-L78 +WebSocket.CONNECTING = 0; +WebSocket.OPEN = 1; +WebSocket.CLOSING = 2; +WebSocket.CLOSED = 3; + +module.exports = WebSocket; \ No newline at end of file diff --git a/src/util/shim/DOMParser.js b/src/util/shim/DOMParser.js new file mode 100644 index 000000000..e2b55b6a8 --- /dev/null +++ b/src/util/shim/DOMParser.js @@ -0,0 +1 @@ +module.exports = global.DOMParser; \ No newline at end of file diff --git a/src/util/shim/EventEmitter2.js b/src/util/shim/EventEmitter2.js new file mode 100644 index 000000000..32084596b --- /dev/null +++ b/src/util/shim/EventEmitter2.js @@ -0,0 +1,3 @@ +module.exports = { + EventEmitter2: global.EventEmitter2 +}; \ No newline at end of file diff --git a/src/util/shim/WebSocket.js b/src/util/shim/WebSocket.js new file mode 100644 index 000000000..51289a11e --- /dev/null +++ b/src/util/shim/WebSocket.js @@ -0,0 +1 @@ +module.exports = global.WebSocket; \ No newline at end of file diff --git a/src/util/shim/canvas.js b/src/util/shim/canvas.js new file mode 100644 index 000000000..15845d668 --- /dev/null +++ b/src/util/shim/canvas.js @@ -0,0 +1,4 @@ +/* global document */ +module.exports = function Canvas() { + return document.createElement('canvas'); +}; \ No newline at end of file diff --git a/utils/package.json b/utils/package.json deleted file mode 100644 index f57251205..000000000 --- a/utils/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "roslibjs", - "devDependencies": { - "grunt": "~0.4.1", - "grunt-contrib-clean": "~0.4.0", - "grunt-contrib-concat": "~0.1.3", - "grunt-contrib-jshint": "~0.1.1", - "grunt-contrib-uglify": "~0.2.0", - "grunt-contrib-watch": "~0.3.1", - "grunt-jsdoc": "~0.3.0", - "grunt-karma": "^0.9.0", - "karma-chai": "^0.1.0", - "karma-mocha": "^0.1.9", - "karma-phantomjs-launcher": "^0.1.4" - } -} From d876ae062b74664c42a7d9b6497b72f30ce6fda2 Mon Sep 17 00:00:00 2001 From: Graeme Yeates Date: Fri, 12 Sep 2014 10:24:58 -0400 Subject: [PATCH 2/7] Refactor tests to support node --- utils/.jshintrc => .jshintrc | 6 ++-- utils/Gruntfile.js => Gruntfile.js | 45 +++++++++++++++++++----------- test/karma.conf.js | 4 +-- test/quaternion.test.js | 4 ++- test/require-shim.js | 10 +++++++ test/ros.test.js | 4 ++- test/transform.test.js | 3 +- test/urdf.test.js | 9 ++++-- 8 files changed, 57 insertions(+), 28 deletions(-) rename utils/.jshintrc => .jshintrc (79%) rename utils/Gruntfile.js => Gruntfile.js (62%) create mode 100644 test/require-shim.js diff --git a/utils/.jshintrc b/.jshintrc similarity index 79% rename from utils/.jshintrc rename to .jshintrc index d28b5b997..29d2df756 100644 --- a/utils/.jshintrc +++ b/.jshintrc @@ -1,7 +1,6 @@ { "globals": { - "module": true, - "EventEmitter2" : true + "global": true }, "curly": true, "eqeqeq": true, @@ -13,9 +12,8 @@ "undef": true, "boss": false, "eqnull": false, - "browser": true, + "node": true, "devel": true, - "es5": true, "strict": false, "trailing": true, "quotmark": "single", diff --git a/utils/Gruntfile.js b/Gruntfile.js similarity index 62% rename from utils/Gruntfile.js rename to Gruntfile.js index edfa74493..6bb733f19 100644 --- a/utils/Gruntfile.js +++ b/Gruntfile.js @@ -2,10 +2,10 @@ module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), - concat: { - build: { - src : ['../src/*.js', '../src/**/*.js'], - dest : '../build/roslib.js' + browserify: { + dist: { + src: ['./src/RosLibBrowser.js'], + dest: './build/roslib.js' } }, jshint: { @@ -14,23 +14,31 @@ module.exports = function(grunt) { }, files: [ 'Gruntfile.js', - '../build/roslib.js' + './src/**/*.js' ] }, karma: { build: { - configFile: '../test/karma.conf.js', + configFile: './test/karma.conf.js', singleRun: true, browsers: ['PhantomJS'] } }, + mochaTest: { + test: { + options: { + reporter: 'spec' + }, + src: ['test/**/*.test.js'] + } + }, uglify: { options: { report: 'min' }, build: { - src: '../build/roslib.js', - dest: '../build/roslib.min.js' + src: './build/roslib.js', + dest: './build/roslib.min.js' } }, watch: { @@ -42,7 +50,7 @@ module.exports = function(grunt) { '../src/*.js', '../src/**/*.js' ], - tasks: ['concat'] + tasks: ['browserify'] }, build_and_watch: { options: { @@ -51,8 +59,8 @@ module.exports = function(grunt) { files: [ 'Gruntfile.js', '.jshintrc', - '../src/*.js', - '../src/**/*.js' + './src/*.js', + './src/**/*.js' ], tasks: ['build'] } @@ -66,26 +74,29 @@ module.exports = function(grunt) { jsdoc: { doc: { src: [ - '../src/*.js', - '../src/**/*.js' + './src/*.js', + './src/**/*.js' ], options: { - destination: '../doc' + destination: './doc' } } } }); - grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.loadNpmTasks('grunt-browserify'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-jsdoc'); grunt.loadNpmTasks('grunt-karma'); + grunt.loadNpmTasks('grunt-mocha-test'); + - grunt.registerTask('dev', ['concat', 'watch']); - grunt.registerTask('build', ['concat', 'jshint', 'karma', 'uglify']); + grunt.registerTask('dev', ['browserify', 'watch']); + grunt.registerTask('test', ['jshint', 'mochaTest', 'browserify', 'karma']); + grunt.registerTask('build', ['test', 'uglify']); grunt.registerTask('build_and_watch', ['watch']); grunt.registerTask('doc', ['clean', 'jsdoc']); }; diff --git a/test/karma.conf.js b/test/karma.conf.js index bdc6d011a..808a8cfd5 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -9,11 +9,11 @@ module.exports = function(config) { // Testing frameworks frameworks: ['mocha', 'chai'], - // List of files / patterns to load in the browser files: [ - "../include/EventEmitter2/eventemitter2.js", + "../node_modules/eventemitter2/lib/eventemitter2.js", "../build/roslib.js", + "./require-shim.js", "*.test.js" ], diff --git a/test/quaternion.test.js b/test/quaternion.test.js index b62b3a994..425a6fb99 100644 --- a/test/quaternion.test.js +++ b/test/quaternion.test.js @@ -1,4 +1,6 @@ -var expect = chai.expect; +var expect = require('chai').expect; +var ROSLIB = require('..'); + describe('Quaternion', function() { diff --git a/test/require-shim.js b/test/require-shim.js new file mode 100644 index 000000000..cd9de5bcc --- /dev/null +++ b/test/require-shim.js @@ -0,0 +1,10 @@ +window.require = function require(path) { + switch (path) { + case 'eventemitter2': return {EventEmitter2: EventEmitter2}; + } + var lastIdx = path.lastIndexOf('/'), + path = lastIdx >= 0 ? path.slice(lastIdx + 1) : path; + + return typeof ROSLIB[path] != 'undefined' ? ROSLIB[path] : + typeof window[path] != 'undefined' ? window[path] : ROSLIB; +} \ No newline at end of file diff --git a/test/ros.test.js b/test/ros.test.js index 0a11d60d3..a4a7bf29a 100644 --- a/test/ros.test.js +++ b/test/ros.test.js @@ -1,4 +1,6 @@ -var expect = chai.expect; +var expect = require('chai').expect; +var EventEmitter2 = require('eventemitter2').EventEmitter2; +var ROSLIB = require('..'); describe('ROS', function() { diff --git a/test/transform.test.js b/test/transform.test.js index b1344d98b..25af82456 100644 --- a/test/transform.test.js +++ b/test/transform.test.js @@ -1,4 +1,5 @@ -var expect = chai.expect; +var expect = require('chai').expect; +var ROSLIB = require('..'); describe('Transform', function() { diff --git a/test/urdf.test.js b/test/urdf.test.js index 610ccc4d8..ec989f4f3 100644 --- a/test/urdf.test.js +++ b/test/urdf.test.js @@ -1,4 +1,9 @@ -var expect = chai.expect; +var expect = require('chai').expect; +var ROSLIB = require('..'); + +var DOMParser = typeof DOMParser == 'function' ? DOMParser : require('../src/util/DOMParser'); +// See https://developer.mozilla.org/docs/XPathResult#Constants +var XPATH_FIRST_ORDERED_NODE_TYPE = 9; var sample_urdf = function (){ return '' + @@ -36,7 +41,7 @@ describe('URDF', function() { it('is ignorant to the xml node', function(){ var parser = new DOMParser(); var xml = parser.parseFromString(sample_urdf(), 'text/xml'); - var robotXml = xml.evaluate('//robot', xml, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; + var robotXml = xml.evaluate('//robot', xml, null, XPATH_FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; expect(robotXml.getAttribute('name')).to.equal('test_robot'); }); }); From 5177d12955d421e6ca8cffd0278a9bc347992f3d Mon Sep 17 00:00:00 2001 From: Graeme Yeates Date: Fri, 12 Sep 2014 10:40:44 -0400 Subject: [PATCH 3/7] Rewrite install and build steps. Configure travis --- .travis.yml | 18 ++++---------- CONTRIBUTING.md | 34 ++++++++++++++++++++++++++ utils/README.md | 63 ------------------------------------------------- 3 files changed, 39 insertions(+), 76 deletions(-) create mode 100644 CONTRIBUTING.md delete mode 100644 utils/README.md diff --git a/.travis.yml b/.travis.yml index e74cf63c9..6d02b7d79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,9 @@ language: node_js - node_js: - "0.10" - -branches: - only: - - master - - develop - + - "0.11" +before_install: + # node-canvas dependency + - sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++ before_script: - - npm install -g karma grunt-cli - - cd utils - - npm install . - -script: - - grunt build + - npm install -g grunt-cli diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..96a0cc8d8 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,34 @@ +roslibjs Build Setup +==================== + +[Grunt](http://gruntjs.com/) is used for building, including concatenating, minimizing, documenting, linting, and testing. + +### Install Grunt and its Dependencies + + 1. Install [Node.js](http://nodejs.org/) for your environment + 2. Install the build task runner, [Grunt](http://gruntjs.com/) + ```sh + $ [sudo] npm install -g grunt + ``` + 3. Install the [Cario](http://cairographics.org/) graphics library + - [System specific instaructions](https://github.com/Automattic/node-canvas/wiki/_pages) + 4. Install the dependencies and build dependencies + ```sh + $ cd /path/to/roslibjs/ + $ [sudo] npm install + ``` + +### Build with Grunt + +Before proceeding, please confirm you have installed the dependencies above. + +To run the build tasks: + + 1. `cd /path/to/roslibjs/` + 2. `grunt build` + +`grunt build` will concatenate and minimize the files under src and replace roslib.js and roslib.min.js in the build directory. It will also run the linter and test cases. This is what [Travis CI](https://travis-ci.org/RobotWebTools/roslibjs) runs when a Pull Request is submitted. + +`grunt dev` will watch for any changes to any of the src/ files and automatically concatenate and minimize the files. This is ideal for those developing as you should only have to run `grunt dev` once. + +`grunt doc` will rebuild all JSDoc for the project. diff --git a/utils/README.md b/utils/README.md deleted file mode 100644 index a5baf769f..000000000 --- a/utils/README.md +++ /dev/null @@ -1,63 +0,0 @@ -roslibjs Build Setup -==================== - -[Grunt](http://gruntjs.com/) is used for building, including concatenating, minimizing, documenting, linting, and testing. - -### Install Grunt and its Dependencies - -#### Ubuntu 14.04 - - 1. Install Node.js and its package manager, NPM - * `sudo apt-get install nodejs npm` - * `sudo ln -s /usr/bin/nodejs /usr/bin/node` - 2. Install Grunt and the test runner [Karma](http://karma-runner.github.io/) - * `sudo npm install -g grunt-cli karma-cli` - * `sudo rm -rf ~/.npm ~/tmp` - 3. Install the Grunt tasks specific to this project - * `cd /path/to/roslibjs/utils/` - * `npm install .` - 4. (Optional) To generate the documentation, you'll need to setup Java. Documentation generation is not required for patches. - * `echo "export JAVA_HOME=/usr/lib/jvm/default-java/jre" >> ~/.bashrc` - * `source ~/.bashrc` - -#### Ubuntu 12.04 - - 1. Install Node.js and its package manager, NPM - * `sudo apt-get install python-software-properties` - * `sudo add-apt-repository ppa:chris-lea/node.js` - * `sudo apt-get update && sudo apt-get install nodejs` - 2. Install Grunt and the test runner [Karma](http://karma-runner.github.io/) - * `sudo npm install -g grunt-cli karma-cli` - * `sudo rm -rf ~/.npm ~/tmp` - 3. Install the Grunt tasks specific to this project - * `cd /path/to/roslibjs/utils/` - * `npm install .` - 4. (Optional) To generate the documentation, you'll need to setup Java. Documentation generation is not required for patches. - * `echo "export JAVA_HOME=/usr/lib/jvm/default-java/jre" >> ~/.bashrc` - * `source ~/.bashrc` - -#### OS X - - 1. Install Node.js and its package manager, NPM - * Go to [Node.js Downloads](http://nodejs.org/download/) - * Download and install the Universal pkg file. - 2. Install Grunt and the test runner [Karma](http://karma-runner.github.io/) - * `sudo npm install -g grunt-cli karma-cli` - 3. Install the Grunt tasks specific to this project - * `cd /path/to/roslibjs/utils/` - * `npm install .` - -### Build with Grunt - -Before proceeding, please confirm you have installed the dependencies above. - -To run the build tasks: - - 1. `cd /path/to/roslibjs/utils/` - 2. `grunt build` - -`grunt build` will concatenate and minimize the files under src and replace roslib.js and roslib.min.js in the build directory. It will also run the linter and test cases. This is what [Travis CI](https://travis-ci.org/RobotWebTools/roslibjs) runs when a Pull Request is submitted. - -`grunt dev` will watch for any changes to any of the src/ files and automatically concatenate and minimize the files. This is ideal for those developing as you should only have to run `grunt dev` once. - -`grunt doc` will rebuild all JSDoc for the project. From 4941cfb2843780a1bd434a53984aaa4fa2f60a78 Mon Sep 17 00:00:00 2001 From: Graeme Yeates Date: Fri, 12 Sep 2014 10:41:37 -0400 Subject: [PATCH 4/7] Example advantage: Use an Object.assign shim --- package.json | 1 + src/RosLib.js | 9 +++------ src/core/Message.js | 9 +++------ src/core/ServiceRequest.js | 9 +++------ src/core/ServiceResponse.js | 9 +++------ 5 files changed, 13 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 2a67b2b11..79f25acf1 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "canvas": "1.1.3", "eventemitter2": "~0.4.13", "nodejs-websocket": "~0.1.4", + "object-assign": "^1.0.0", "xmlshim": "~0.0.9" }, "browser": { diff --git a/src/RosLib.js b/src/RosLib.js index 822852bdf..be094be86 100644 --- a/src/RosLib.js +++ b/src/RosLib.js @@ -3,7 +3,7 @@ */ var ROSLIB = this.ROSLIB || { - REVISION : '0.10.0-SNAPSHOT', + REVISION : '0.10.0-SNAPSHOT' }; ROSLIB.Ros = require('./core/Ros'); @@ -35,10 +35,7 @@ ROSLIB.UrdfModel = require('./urdf/UrdfModel'); ROSLIB.UrdfSphere = require('./urdf/UrdfSphere'); ROSLIB.UrdfVisual = require('./urdf/UrdfVisual'); -//URDF types -var UrdfTypes = require('./urdf/UrdfTypes'); -Object.keys(UrdfTypes).forEach(function(type) { - ROSLIB[type] = UrdfTypes[type]; -}); +// Add URDF types +require('object-assign')(ROSLIB, require('./urdf/UrdfTypes')); module.exports = ROSLIB; \ No newline at end of file diff --git a/src/core/Message.js b/src/core/Message.js index 48c2ea282..c235c4ec6 100644 --- a/src/core/Message.js +++ b/src/core/Message.js @@ -2,6 +2,8 @@ * @author Brandon Alexander - baalexander@gmail.com */ +var assign = require('object-assign'); + /** * Message objects are used for publishing and subscribing to and from topics. * @@ -9,12 +11,7 @@ * @param values - object matching the fields defined in the .msg definition file */ function Message(values) { - var that = this; - values = values || {}; - - Object.keys(values).forEach(function(name) { - that[name] = values[name]; - }); + assign(this, values); } module.exports = Message; \ No newline at end of file diff --git a/src/core/ServiceRequest.js b/src/core/ServiceRequest.js index ddb5cbb20..6b77889a1 100644 --- a/src/core/ServiceRequest.js +++ b/src/core/ServiceRequest.js @@ -2,6 +2,8 @@ * @author Brandon Alexander - balexander@willowgarage.com */ +var assign = require('object-assign'); + /** * A ServiceRequest is passed into the service call. * @@ -9,12 +11,7 @@ * @param values - object matching the fields defined in the .srv definition file */ function ServiceRequest(values) { - var that = this; - values = values || {}; - - Object.keys(values).forEach(function(name) { - that[name] = values[name]; - }); + assign(this, values); } module.exports = ServiceRequest; \ No newline at end of file diff --git a/src/core/ServiceResponse.js b/src/core/ServiceResponse.js index 74d57d04d..444c11998 100644 --- a/src/core/ServiceResponse.js +++ b/src/core/ServiceResponse.js @@ -2,6 +2,8 @@ * @author Brandon Alexander - balexander@willowgarage.com */ +var assign = require('object-assign'); + /** * A ServiceResponse is returned from the service call. * @@ -9,12 +11,7 @@ * @param values - object matching the fields defined in the .srv definition file */ function ServiceResponse(values) { - var that = this; - values = values || {}; - - Object.keys(values).forEach(function(name) { - that[name] = values[name]; - }); + assign(this, values); } module.exports = ServiceResponse; \ No newline at end of file From 25fe287cf80c600d85c68022cf448be8e9177056 Mon Sep 17 00:00:00 2001 From: Graeme Yeates Date: Fri, 12 Sep 2014 10:42:09 -0400 Subject: [PATCH 5/7] Rebuild dist files --- build/roslib.js | 602 +++++++++++++++++++++++++++++--------------- build/roslib.min.js | 2 +- 2 files changed, 406 insertions(+), 198 deletions(-) diff --git a/build/roslib.js b/build/roslib.js index f0f9e768e..5d7ec4905 100644 --- a/build/roslib.js +++ b/build/roslib.js @@ -1,21 +1,97 @@ +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { - that.visual = new ROSLIB.UrdfVisual({ + that.visual = new UrdfVisual({ xml : visuals[0] }); } @@ -1642,14 +1790,17 @@ ROSLIB.UrdfLink = function(options) { // Pass it to the XML parser initXml(xml); -}; - +} +module.exports = UrdfLink; +},{"./UrdfVisual":28}],23:[function(require,module,exports){ /** * @author Benjamin Pitzer - ben.pitzer@gmail.com * @author Russell Toris - rctoris@wpi.edu */ +var UrdfColor = require('./UrdfColor'); + /** * A Material element in a URDF. * @@ -1657,7 +1808,7 @@ ROSLIB.UrdfLink = function(options) { * @param options - object with following keys: * * xml - the XML element to parse */ -ROSLIB.UrdfMaterial = function(options) { +function UrdfMaterial(options) { options = options || {}; var that = this; var xml = options.xml; @@ -1683,7 +1834,7 @@ ROSLIB.UrdfMaterial = function(options) { var colors = xml.getElementsByTagName('color'); if (colors.length > 0) { // Parse the RBGA string - that.color = new ROSLIB.UrdfColor({ + that.color = new UrdfColor({ xml : colors[0] }); } @@ -1691,13 +1842,18 @@ ROSLIB.UrdfMaterial = function(options) { // Pass it to the XML parser initXml(xml); -}; +} +module.exports = UrdfMaterial; +},{"./UrdfColor":20}],24:[function(require,module,exports){ /** * @author Benjamin Pitzer - ben.pitzer@gmail.com * @author Russell Toris - rctoris@wpi.edu */ +var Vector3 = require('../math/Vector3'); +var UrdfTypes = require('./UrdfTypes'); + /** * A Mesh element in a URDF. * @@ -1705,7 +1861,7 @@ ROSLIB.UrdfMaterial = function(options) { * @param options - object with following keys: * * xml - the XML element to parse */ -ROSLIB.UrdfMesh = function(options) { +function UrdfMesh(options) { options = options || {}; var that = this; var xml = options.xml; @@ -1719,7 +1875,7 @@ ROSLIB.UrdfMesh = function(options) { * @param xml - the XML element to parse */ var initXml = function(xml) { - that.type = ROSLIB.URDF_MESH; + that.type = UrdfTypes.URDF_MESH; that.filename = xml.getAttribute('filename'); // Check for a scale @@ -1727,7 +1883,7 @@ ROSLIB.UrdfMesh = function(options) { if (scale) { // Get the XYZ var xyz = scale.split(' '); - that.scale = new ROSLIB.Vector3({ + that.scale = new Vector3({ x : parseFloat(xyz[0]), y : parseFloat(xyz[1]), z : parseFloat(xyz[2]) @@ -1737,14 +1893,22 @@ ROSLIB.UrdfMesh = function(options) { // Pass it to the XML parser initXml(xml); -}; - +} +module.exports = UrdfMesh; +},{"../math/Vector3":17,"./UrdfTypes":27}],25:[function(require,module,exports){ /** * @author Benjamin Pitzer - ben.pitzer@gmail.com * @author Russell Toris - rctoris@wpi.edu */ +var UrdfMaterial = require('./UrdfMaterial'); +var UrdfLink = require('./UrdfLink'); +var DOMParser = require('../util/DOMParser'); + +// See https://developer.mozilla.org/docs/XPathResult#Constants +var XPATH_FIRST_ORDERED_NODE_TYPE = 9; + /** * A URDF Model can be used to parse a given URDF into the appropriate elements. * @@ -1753,7 +1917,7 @@ ROSLIB.UrdfMesh = function(options) { * * xml - the XML element to parse * * string - the XML element to parse as a string */ -ROSLIB.UrdfModel = function(options) { +function UrdfModel(options) { options = options || {}; var that = this; var xml = options.xml; @@ -1768,7 +1932,7 @@ ROSLIB.UrdfModel = function(options) { */ var initXml = function(xmlDoc) { // Get the robot tag - var robotXml = xmlDoc.evaluate('//robot', xmlDoc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; + var robotXml = xmlDoc.evaluate('//robot', xmlDoc, null, XPATH_FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; // Get the robot name that.name = robotXml.getAttribute('name'); @@ -1777,7 +1941,7 @@ ROSLIB.UrdfModel = function(options) { for (var n in robotXml.childNodes) { var node = robotXml.childNodes[n]; if (node.tagName === 'material') { - var material = new ROSLIB.UrdfMaterial({ + var material = new UrdfMaterial({ xml : node }); // Make sure this is unique @@ -1787,7 +1951,7 @@ ROSLIB.UrdfModel = function(options) { that.materials[material.name] = material; } } else if (node.tagName === 'link') { - var link = new ROSLIB.UrdfLink({ + var link = new UrdfLink({ xml : node }); // Make sure this is unique @@ -1818,13 +1982,17 @@ ROSLIB.UrdfModel = function(options) { } // Pass it to the XML parser initXml(xml); -}; +} +module.exports = UrdfModel; +},{"../util/DOMParser":29,"./UrdfLink":22,"./UrdfMaterial":23}],26:[function(require,module,exports){ /** * @author Benjamin Pitzer - ben.pitzer@gmail.com * @author Russell Toris - rctoris@wpi.edu */ +var UrdfTypes = require('./UrdfTypes'); + /** * A Sphere element in a URDF. * @@ -1832,7 +2000,7 @@ ROSLIB.UrdfModel = function(options) { * @param options - object with following keys: * * xml - the XML element to parse */ -ROSLIB.UrdfSphere = function(options) { +function UrdfSphere(options) { options = options || {}; var that = this; var xml = options.xml; @@ -1845,20 +2013,39 @@ ROSLIB.UrdfSphere = function(options) { * @param xml - the XML element to parse */ var initXml = function(xml) { - that.type = ROSLIB.URDF_SPHERE; + that.type = UrdfTypes.URDF_SPHERE; that.radius = parseFloat(xml.getAttribute('radius')); }; // pass it to the XML parser initXml(xml); -}; +} +module.exports = UrdfSphere; +},{"./UrdfTypes":27}],27:[function(require,module,exports){ +module.exports = { + URDF_SPHERE : 0, + URDF_BOX : 1, + URDF_CYLINDER : 2, + URDF_MESH : 3 +}; +},{}],28:[function(require,module,exports){ /** * @author Benjamin Pitzer - ben.pitzer@gmail.com * @author Russell Toris - rctoris@wpi.edu */ +var Pose = require('../math/Pose'); +var Vector3 = require('../math/Vector3'); +var Quaternion = require('../math/Quaternion'); + +var UrdfCylinder = require('./UrdfCylinder'); +var UrdfBox = require('./UrdfBox'); +var UrdfMaterial = require('./UrdfMaterial'); +var UrdfMesh = require('./UrdfMesh'); +var UrdfSphere = require('./UrdfSphere'); + /** * A Visual element in a URDF. * @@ -1866,7 +2053,7 @@ ROSLIB.UrdfSphere = function(options) { * @param options - object with following keys: * * xml - the XML element to parse */ -ROSLIB.UrdfVisual = function(options) { +function UrdfVisual(options) { options = options || {}; var that = this; var xml = options.xml; @@ -1884,14 +2071,14 @@ ROSLIB.UrdfVisual = function(options) { var origins = xml.getElementsByTagName('origin'); if (origins.length === 0) { // use the identity as the default - that.origin = new ROSLIB.Pose(); + that.origin = new Pose(); } else { // Check the XYZ var xyz = origins[0].getAttribute('xyz'); - var position = new ROSLIB.Vector3(); + var position = new Vector3(); if (xyz) { xyz = xyz.split(' '); - position = new ROSLIB.Vector3({ + position = new Vector3({ x : parseFloat(xyz[0]), y : parseFloat(xyz[1]), z : parseFloat(xyz[2]) @@ -1900,7 +2087,7 @@ ROSLIB.UrdfVisual = function(options) { // Check the RPY var rpy = origins[0].getAttribute('rpy'); - var orientation = new ROSLIB.Quaternion(); + var orientation = new Quaternion(); if (rpy) { rpy = rpy.split(' '); // Convert from RPY @@ -1919,7 +2106,7 @@ ROSLIB.UrdfVisual = function(options) { var w = Math.cos(phi) * Math.cos(the) * Math.cos(psi) + Math.sin(phi) * Math.sin(the) * Math.sin(psi); - orientation = new ROSLIB.Quaternion({ + orientation = new Quaternion({ x : x, y : y, z : z, @@ -1927,7 +2114,7 @@ ROSLIB.UrdfVisual = function(options) { }); orientation.normalize(); } - that.origin = new ROSLIB.Pose({ + that.origin = new Pose({ position : position, orientation : orientation }); @@ -1948,19 +2135,19 @@ ROSLIB.UrdfVisual = function(options) { // Check the type var type = shape.nodeName; if (type === 'sphere') { - that.geometry = new ROSLIB.UrdfSphere({ + that.geometry = new UrdfSphere({ xml : shape }); } else if (type === 'box') { - that.geometry = new ROSLIB.UrdfBox({ + that.geometry = new UrdfBox({ xml : shape }); } else if (type === 'cylinder') { - that.geometry = new ROSLIB.UrdfCylinder({ + that.geometry = new UrdfCylinder({ xml : shape }); } else if (type === 'mesh') { - that.geometry = new ROSLIB.UrdfMesh({ + that.geometry = new UrdfMesh({ xml : shape }); } else { @@ -1971,7 +2158,7 @@ ROSLIB.UrdfVisual = function(options) { // Material var materials = xml.getElementsByTagName('material'); if (materials.length > 0) { - that.material = new ROSLIB.UrdfMaterial({ + that.material = new UrdfMaterial({ xml : materials[0] }); } @@ -1979,5 +2166,26 @@ ROSLIB.UrdfVisual = function(options) { // Pass it to the XML parser initXml(xml); -}; - +} + +module.exports = UrdfVisual; +},{"../math/Pose":14,"../math/Quaternion":15,"../math/Vector3":17,"./UrdfBox":19,"./UrdfCylinder":21,"./UrdfMaterial":23,"./UrdfMesh":24,"./UrdfSphere":26}],29:[function(require,module,exports){ +(function (global){ +module.exports = global.DOMParser; +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],30:[function(require,module,exports){ +(function (global){ +module.exports = { + EventEmitter2: global.EventEmitter2 +}; +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],31:[function(require,module,exports){ +(function (global){ +module.exports = global.WebSocket; +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],32:[function(require,module,exports){ +/* global document */ +module.exports = function Canvas() { + return document.createElement('canvas'); +}; +},{}]},{},[3]); diff --git a/build/roslib.min.js b/build/roslib.min.js index 1eb3da1e6..e26bbbacb 100644 --- a/build/roslib.min.js +++ b/build/roslib.min.js @@ -1 +1 @@ -var ROSLIB=ROSLIB||{REVISION:"0.10.0-SNAPSHOT"};ROSLIB.URDF_SPHERE=0,ROSLIB.URDF_BOX=1,ROSLIB.URDF_CYLINDER=2,ROSLIB.URDF_MESH=3,ROSLIB.ActionClient=function(a){var b=this;a=a||{},this.ros=a.ros,this.serverName=a.serverName,this.actionName=a.actionName,this.timeout=a.timeout,this.goals={};var c=!1,d=new ROSLIB.Topic({ros:this.ros,name:this.serverName+"/feedback",messageType:this.actionName+"Feedback"}),e=new ROSLIB.Topic({ros:this.ros,name:this.serverName+"/status",messageType:"actionlib_msgs/GoalStatusArray"}),f=new ROSLIB.Topic({ros:this.ros,name:this.serverName+"/result",messageType:this.actionName+"Result"});this.goalTopic=new ROSLIB.Topic({ros:this.ros,name:this.serverName+"/goal",messageType:this.actionName+"Goal"}),this.cancelTopic=new ROSLIB.Topic({ros:this.ros,name:this.serverName+"/cancel",messageType:"actionlib_msgs/GoalID"}),this.goalTopic.advertise(),this.cancelTopic.advertise(),e.subscribe(function(a){c=!0,a.status_list.forEach(function(a){var c=b.goals[a.goal_id.id];c&&c.emit("status",a)})}),d.subscribe(function(a){var c=b.goals[a.status.goal_id.id];c&&(c.emit("status",a.status),c.emit("feedback",a.feedback))}),f.subscribe(function(a){var c=b.goals[a.status.goal_id.id];c&&(c.emit("status",a.status),c.emit("result",a.result))}),this.timeout&&setTimeout(function(){c||b.emit("timeout")},this.timeout)},ROSLIB.ActionClient.prototype.__proto__=EventEmitter2.prototype,ROSLIB.ActionClient.prototype.cancel=function(){var a=new ROSLIB.Message;this.cancelTopic.publish(a)},ROSLIB.Goal=function(a){var b=this;this.actionClient=a.actionClient,this.goalMessage=a.goalMessage,this.isFinished=!1;var c=new Date;this.goalID="goal_"+Math.random()+"_"+c.getTime(),this.goalMessage=new ROSLIB.Message({goal_id:{stamp:{secs:0,nsecs:0},id:this.goalID},goal:this.goalMessage}),this.on("status",function(a){b.status=a}),this.on("result",function(a){b.isFinished=!0,b.result=a}),this.on("feedback",function(a){b.feedback=a}),this.actionClient.goals[this.goalID]=this},ROSLIB.Goal.prototype.__proto__=EventEmitter2.prototype,ROSLIB.Goal.prototype.send=function(a){var b=this;b.actionClient.goalTopic.publish(b.goalMessage),a&&setTimeout(function(){b.isFinished||b.emit("timeout")},a)},ROSLIB.Goal.prototype.cancel=function(){var a=new ROSLIB.Message({id:this.goalID});this.actionClient.cancelTopic.publish(a)},ROSLIB.SimpleActionServer=function(a){var b=this;a=a||{},this.ros=a.ros,this.serverName=a.serverName,this.actionName=a.actionName,this.feedbackPublisher=new ROSLIB.Topic({ros:this.ros,name:this.serverName+"/feedback",messageType:this.actionName+"Feedback"}),this.feedbackPublisher.advertise();var c=new ROSLIB.Topic({ros:this.ros,name:this.serverName+"/status",messageType:"actionlib_msgs/GoalStatusArray"});c.advertise(),this.resultPublisher=new ROSLIB.Topic({ros:this.ros,name:this.serverName+"/result",messageType:this.actionName+"Result"}),this.resultPublisher.advertise();var d=new ROSLIB.Topic({ros:this.ros,name:this.serverName+"/goal",messageType:this.actionName+"Goal"}),e=new ROSLIB.Topic({ros:this.ros,name:this.serverName+"/cancel",messageType:"actionlib_msgs/GoalID"});this.statusMessage=new ROSLIB.Message({header:{stamp:{secs:0,nsecs:100},frame_id:""},status_list:[]}),this.currentGoal=null,this.nextGoal=null,d.subscribe(function(a){b.currentGoal?(b.nextGoal=a,b.emit("cancel")):(b.statusMessage.status_list=[{goal_id:a.goal_id,status:1}],b.currentGoal=a,b.emit("goal",a.goal))});var f=function(a,b){return a.secs>b.secs?!1:a.secs=0&&(c.cbs.splice(d,1),0===c.cbs.length&&delete this.frameInfos[a],this.needUpdate=!0)}},ROSLIB.UrdfBox=function(a){a=a||{};var b=this,c=a.xml;this.dimension=null,this.type=null;var d=function(a){b.type=ROSLIB.URDF_BOX;var c=a.getAttribute("size").split(" ");b.dimension=new ROSLIB.Vector3({x:parseFloat(c[0]),y:parseFloat(c[1]),z:parseFloat(c[2])})};d(c)},ROSLIB.UrdfColor=function(a){a=a||{};var b=this,c=a.xml;this.r=null,this.g=null,this.b=null,this.a=null;var d=function(a){var c=a.getAttribute("rgba").split(" ");return b.r=parseFloat(c[0]),b.g=parseFloat(c[1]),b.b=parseFloat(c[2]),b.a=parseFloat(c[3]),!0};d(c)},ROSLIB.UrdfCylinder=function(a){a=a||{};var b=this,c=a.xml;this.type=null,this.length=null,this.radius=null;var d=function(a){b.type=ROSLIB.URDF_CYLINDER,b.length=parseFloat(a.getAttribute("length")),b.radius=parseFloat(a.getAttribute("radius"))};d(c)},ROSLIB.UrdfLink=function(a){a=a||{};var b=this,c=a.xml;this.name=null,this.visual=null;var d=function(a){b.name=a.getAttribute("name");var c=a.getElementsByTagName("visual");c.length>0&&(b.visual=new ROSLIB.UrdfVisual({xml:c[0]}))};d(c)},ROSLIB.UrdfMaterial=function(a){a=a||{};var b=this,c=a.xml;this.name=null,this.textureFilename=null,this.color=null;var d=function(a){b.name=a.getAttribute("name");var c=a.getElementsByTagName("texture");c.length>0&&(b.textureFilename=c[0].getAttribute("filename"));var d=a.getElementsByTagName("color");d.length>0&&(b.color=new ROSLIB.UrdfColor({xml:d[0]}))};d(c)},ROSLIB.UrdfMesh=function(a){a=a||{};var b=this,c=a.xml;this.filename=null,this.scale=null,this.type=null;var d=function(a){b.type=ROSLIB.URDF_MESH,b.filename=a.getAttribute("filename");var c=a.getAttribute("scale");if(c){var d=c.split(" ");b.scale=new ROSLIB.Vector3({x:parseFloat(d[0]),y:parseFloat(d[1]),z:parseFloat(d[2])})}};d(c)},ROSLIB.UrdfModel=function(a){a=a||{};var b=this,c=a.xml,d=a.string;this.materials=[],this.links=[];var e=function(a){var c=a.evaluate("//robot",a,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;b.name=c.getAttribute("name");for(var d in c.childNodes){var e=c.childNodes[d];if("material"===e.tagName){var f=new ROSLIB.UrdfMaterial({xml:e});b.materials[f.name]?console.warn("Material "+f.name+"is not unique."):b.materials[f.name]=f}else if("link"===e.tagName){var g=new ROSLIB.UrdfLink({xml:e});b.links[g.name]?console.warn("Link "+g.name+" is not unique."):(g.visual&&g.visual.material&&(b.materials[g.visual.material.name]?g.visual.material=b.materials[g.visual.material.name]:g.visual.material&&(b.materials[g.visual.material.name]=g.visual.material)),b.links[g.name]=g)}}};if(d){var f=new DOMParser;c=f.parseFromString(d,"text/xml")}e(c)},ROSLIB.UrdfSphere=function(a){a=a||{};var b=this,c=a.xml;this.radius=null,this.type=null;var d=function(a){b.type=ROSLIB.URDF_SPHERE,b.radius=parseFloat(a.getAttribute("radius"))};d(c)},ROSLIB.UrdfVisual=function(a){a=a||{};var b=this,c=a.xml;this.origin=null,this.geometry=null,this.material=null;var d=function(a){var c=a.getElementsByTagName("origin");if(0===c.length)b.origin=new ROSLIB.Pose;else{var d=c[0].getAttribute("xyz"),e=new ROSLIB.Vector3;d&&(d=d.split(" "),e=new ROSLIB.Vector3({x:parseFloat(d[0]),y:parseFloat(d[1]),z:parseFloat(d[2])}));var f=c[0].getAttribute("rpy"),g=new ROSLIB.Quaternion;if(f){f=f.split(" ");var h=parseFloat(f[0]),i=parseFloat(f[1]),j=parseFloat(f[2]),k=h/2,l=i/2,m=j/2,n=Math.sin(k)*Math.cos(l)*Math.cos(m)-Math.cos(k)*Math.sin(l)*Math.sin(m),o=Math.cos(k)*Math.sin(l)*Math.cos(m)+Math.sin(k)*Math.cos(l)*Math.sin(m),p=Math.cos(k)*Math.cos(l)*Math.sin(m)-Math.sin(k)*Math.sin(l)*Math.cos(m),q=Math.cos(k)*Math.cos(l)*Math.cos(m)+Math.sin(k)*Math.sin(l)*Math.sin(m);g=new ROSLIB.Quaternion({x:n,y:o,z:p,w:q}),g.normalize()}b.origin=new ROSLIB.Pose({position:e,orientation:g})}var r=a.getElementsByTagName("geometry");if(r.length>0){var s=null;for(var t in r[0].childNodes){var u=r[0].childNodes[t];if(1===u.nodeType){s=u;break}}var v=s.nodeName;"sphere"===v?b.geometry=new ROSLIB.UrdfSphere({xml:s}):"box"===v?b.geometry=new ROSLIB.UrdfBox({xml:s}):"cylinder"===v?b.geometry=new ROSLIB.UrdfCylinder({xml:s}):"mesh"===v?b.geometry=new ROSLIB.UrdfMesh({xml:s}):console.warn("Unknown geometry type "+v)}var w=a.getElementsByTagName("material");w.length>0&&(b.material=new ROSLIB.UrdfMaterial({xml:w[0]}))};d(c)}; \ No newline at end of file +!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?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;gb.secs?!1:a.secs=0&&(c.cbs.splice(d,1),0===c.cbs.length&&delete this.frameInfos[a],this.needUpdate=!0)}},b.exports=c},{"../actionlib/ActionClient":4,"../actionlib/Goal":5,"../math/Transform":16}],19:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.dimension=null,this.type=null;var f=function(a){b.type=e.URDF_BOX;var c=a.getAttribute("size").split(" ");b.dimension=new d({x:parseFloat(c[0]),y:parseFloat(c[1]),z:parseFloat(c[2])})};f(c)}var d=a("../math/Vector3"),e=a("./UrdfTypes");b.exports=c},{"../math/Vector3":17,"./UrdfTypes":27}],20:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.r=null,this.g=null,this.b=null,this.a=null;var d=function(a){var c=a.getAttribute("rgba").split(" ");return b.r=parseFloat(c[0]),b.g=parseFloat(c[1]),b.b=parseFloat(c[2]),b.a=parseFloat(c[3]),!0};d(c)}b.exports=c},{}],21:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.type=null,this.length=null,this.radius=null;var e=function(a){b.type=d.URDF_CYLINDER,b.length=parseFloat(a.getAttribute("length")),b.radius=parseFloat(a.getAttribute("radius"))};e(c)}var d=a("./UrdfTypes");b.exports=c},{"./UrdfTypes":27}],22:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.name=null,this.visual=null;var e=function(a){b.name=a.getAttribute("name");var c=a.getElementsByTagName("visual");c.length>0&&(b.visual=new d({xml:c[0]}))};e(c)}var d=a("./UrdfVisual");b.exports=c},{"./UrdfVisual":28}],23:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.name=null,this.textureFilename=null,this.color=null;var e=function(a){b.name=a.getAttribute("name");var c=a.getElementsByTagName("texture");c.length>0&&(b.textureFilename=c[0].getAttribute("filename"));var e=a.getElementsByTagName("color");e.length>0&&(b.color=new d({xml:e[0]}))};e(c)}var d=a("./UrdfColor");b.exports=c},{"./UrdfColor":20}],24:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.filename=null,this.scale=null,this.type=null;var f=function(a){b.type=e.URDF_MESH,b.filename=a.getAttribute("filename");var c=a.getAttribute("scale");if(c){var f=c.split(" ");b.scale=new d({x:parseFloat(f[0]),y:parseFloat(f[1]),z:parseFloat(f[2])})}};f(c)}var d=a("../math/Vector3"),e=a("./UrdfTypes");b.exports=c},{"../math/Vector3":17,"./UrdfTypes":27}],25:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml,h=a.string;this.materials=[],this.links=[];var i=function(a){var c=a.evaluate("//robot",a,null,g,null).singleNodeValue;b.name=c.getAttribute("name");for(var f in c.childNodes){var h=c.childNodes[f];if("material"===h.tagName){var i=new d({xml:h});b.materials[i.name]?console.warn("Material "+i.name+"is not unique."):b.materials[i.name]=i}else if("link"===h.tagName){var j=new e({xml:h});b.links[j.name]?console.warn("Link "+j.name+" is not unique."):(j.visual&&j.visual.material&&(b.materials[j.visual.material.name]?j.visual.material=b.materials[j.visual.material.name]:j.visual.material&&(b.materials[j.visual.material.name]=j.visual.material)),b.links[j.name]=j)}}};if(h){var j=new f;c=j.parseFromString(h,"text/xml")}i(c)}var d=a("./UrdfMaterial"),e=a("./UrdfLink"),f=a("../util/DOMParser"),g=9;b.exports=c},{"../util/DOMParser":29,"./UrdfLink":22,"./UrdfMaterial":23}],26:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.radius=null,this.type=null;var e=function(a){b.type=d.URDF_SPHERE,b.radius=parseFloat(a.getAttribute("radius"))};e(c)}var d=a("./UrdfTypes");b.exports=c},{"./UrdfTypes":27}],27:[function(a,b){b.exports={URDF_SPHERE:0,URDF_BOX:1,URDF_CYLINDER:2,URDF_MESH:3}},{}],28:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.origin=null,this.geometry=null,this.material=null;var l=function(a){var c=a.getElementsByTagName("origin");if(0===c.length)b.origin=new d;else{var l=c[0].getAttribute("xyz"),m=new e;l&&(l=l.split(" "),m=new e({x:parseFloat(l[0]),y:parseFloat(l[1]),z:parseFloat(l[2])}));var n=c[0].getAttribute("rpy"),o=new f;if(n){n=n.split(" ");var p=parseFloat(n[0]),q=parseFloat(n[1]),r=parseFloat(n[2]),s=p/2,t=q/2,u=r/2,v=Math.sin(s)*Math.cos(t)*Math.cos(u)-Math.cos(s)*Math.sin(t)*Math.sin(u),w=Math.cos(s)*Math.sin(t)*Math.cos(u)+Math.sin(s)*Math.cos(t)*Math.sin(u),x=Math.cos(s)*Math.cos(t)*Math.sin(u)-Math.sin(s)*Math.sin(t)*Math.cos(u),y=Math.cos(s)*Math.cos(t)*Math.cos(u)+Math.sin(s)*Math.sin(t)*Math.sin(u);o=new f({x:v,y:w,z:x,w:y}),o.normalize()}b.origin=new d({position:m,orientation:o})}var z=a.getElementsByTagName("geometry");if(z.length>0){var A=null;for(var B in z[0].childNodes){var C=z[0].childNodes[B];if(1===C.nodeType){A=C;break}}var D=A.nodeName;"sphere"===D?b.geometry=new k({xml:A}):"box"===D?b.geometry=new h({xml:A}):"cylinder"===D?b.geometry=new g({xml:A}):"mesh"===D?b.geometry=new j({xml:A}):console.warn("Unknown geometry type "+D)}var E=a.getElementsByTagName("material");E.length>0&&(b.material=new i({xml:E[0]}))};l(c)}var d=a("../math/Pose"),e=a("../math/Vector3"),f=a("../math/Quaternion"),g=a("./UrdfCylinder"),h=a("./UrdfBox"),i=a("./UrdfMaterial"),j=a("./UrdfMesh"),k=a("./UrdfSphere");b.exports=c},{"../math/Pose":14,"../math/Quaternion":15,"../math/Vector3":17,"./UrdfBox":19,"./UrdfCylinder":21,"./UrdfMaterial":23,"./UrdfMesh":24,"./UrdfSphere":26}],29:[function(a,b){(function(a){b.exports=a.DOMParser}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],30:[function(a,b){(function(a){b.exports={EventEmitter2:a.EventEmitter2}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],31:[function(a,b){(function(a){b.exports=a.WebSocket}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],32:[function(a,b){b.exports=function(){return document.createElement("canvas")}},{}]},{},[3]); \ No newline at end of file From 2b3adc91c6b6924eac59a2bacfc2990cab1a88c8 Mon Sep 17 00:00:00 2001 From: Graeme Yeates Date: Sat, 13 Sep 2014 22:47:55 -0400 Subject: [PATCH 6/7] Simplify setup in readme; change websocket dep --- .travis.yml | 1 - CONTRIBUTING.md | 18 +++++++++++++++ build/roslib.js | 4 ++-- build/roslib.min.js | 2 +- package.json | 4 ++-- src/core/Ros.js | 2 +- src/util/WebSocket.js | 53 ------------------------------------------- 7 files changed, 24 insertions(+), 60 deletions(-) delete mode 100644 src/util/WebSocket.js diff --git a/.travis.yml b/.travis.yml index 6d02b7d79..eb4450521 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: node_js node_js: - "0.10" - - "0.11" before_install: # node-canvas dependency - sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 96a0cc8d8..867ee1f43 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,16 +7,34 @@ roslibjs Build Setup 1. Install [Node.js](http://nodejs.org/) for your environment 2. Install the build task runner, [Grunt](http://gruntjs.com/) + ```sh $ [sudo] npm install -g grunt ``` + 3. Install the [Cario](http://cairographics.org/) graphics library - [System specific instaructions](https://github.com/Automattic/node-canvas/wiki/_pages) 4. Install the dependencies and build dependencies + ```sh $ cd /path/to/roslibjs/ $ [sudo] npm install ``` + + +Easy installation for Ubuntu. `cd` to your local copy of this project. + +```sh +# Install Node.js and NPM +curl -sL https://deb.nodesource.com/setup | sudo bash - +sudo apt-get install nodejs + +# Install Cario +sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++ + +# Install this projects Deps +sudo npm install +``` ### Build with Grunt diff --git a/build/roslib.js b/build/roslib.js index 5d7ec4905..17aaa2b61 100644 --- a/build/roslib.js +++ b/build/roslib.js @@ -615,7 +615,7 @@ module.exports = Param; var Canvas = require('canvas'); var Image = Canvas.Image || global.Image; var EventEmitter2 = require('eventemitter2').EventEmitter2; -var WebSocket = require('../util/WebSocket'); +var WebSocket = require('ws'); var Service = require('./Service'); var ServiceRequest = require('./ServiceRequest'); @@ -987,7 +987,7 @@ Ros.prototype.decodeTypeDefs = function(defs) { module.exports = Ros; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../util/WebSocket":31,"./Service":10,"./ServiceRequest":11,"canvas":32,"eventemitter2":30}],10:[function(require,module,exports){ +},{"./Service":10,"./ServiceRequest":11,"canvas":32,"eventemitter2":30,"ws":31}],10:[function(require,module,exports){ /** * @author Brandon Alexander - baalexander@gmail.com */ diff --git a/build/roslib.min.js b/build/roslib.min.js index e26bbbacb..560a7c8ca 100644 --- a/build/roslib.min.js +++ b/build/roslib.min.js @@ -1 +1 @@ -!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?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;gb.secs?!1:a.secs=0&&(c.cbs.splice(d,1),0===c.cbs.length&&delete this.frameInfos[a],this.needUpdate=!0)}},b.exports=c},{"../actionlib/ActionClient":4,"../actionlib/Goal":5,"../math/Transform":16}],19:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.dimension=null,this.type=null;var f=function(a){b.type=e.URDF_BOX;var c=a.getAttribute("size").split(" ");b.dimension=new d({x:parseFloat(c[0]),y:parseFloat(c[1]),z:parseFloat(c[2])})};f(c)}var d=a("../math/Vector3"),e=a("./UrdfTypes");b.exports=c},{"../math/Vector3":17,"./UrdfTypes":27}],20:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.r=null,this.g=null,this.b=null,this.a=null;var d=function(a){var c=a.getAttribute("rgba").split(" ");return b.r=parseFloat(c[0]),b.g=parseFloat(c[1]),b.b=parseFloat(c[2]),b.a=parseFloat(c[3]),!0};d(c)}b.exports=c},{}],21:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.type=null,this.length=null,this.radius=null;var e=function(a){b.type=d.URDF_CYLINDER,b.length=parseFloat(a.getAttribute("length")),b.radius=parseFloat(a.getAttribute("radius"))};e(c)}var d=a("./UrdfTypes");b.exports=c},{"./UrdfTypes":27}],22:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.name=null,this.visual=null;var e=function(a){b.name=a.getAttribute("name");var c=a.getElementsByTagName("visual");c.length>0&&(b.visual=new d({xml:c[0]}))};e(c)}var d=a("./UrdfVisual");b.exports=c},{"./UrdfVisual":28}],23:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.name=null,this.textureFilename=null,this.color=null;var e=function(a){b.name=a.getAttribute("name");var c=a.getElementsByTagName("texture");c.length>0&&(b.textureFilename=c[0].getAttribute("filename"));var e=a.getElementsByTagName("color");e.length>0&&(b.color=new d({xml:e[0]}))};e(c)}var d=a("./UrdfColor");b.exports=c},{"./UrdfColor":20}],24:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.filename=null,this.scale=null,this.type=null;var f=function(a){b.type=e.URDF_MESH,b.filename=a.getAttribute("filename");var c=a.getAttribute("scale");if(c){var f=c.split(" ");b.scale=new d({x:parseFloat(f[0]),y:parseFloat(f[1]),z:parseFloat(f[2])})}};f(c)}var d=a("../math/Vector3"),e=a("./UrdfTypes");b.exports=c},{"../math/Vector3":17,"./UrdfTypes":27}],25:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml,h=a.string;this.materials=[],this.links=[];var i=function(a){var c=a.evaluate("//robot",a,null,g,null).singleNodeValue;b.name=c.getAttribute("name");for(var f in c.childNodes){var h=c.childNodes[f];if("material"===h.tagName){var i=new d({xml:h});b.materials[i.name]?console.warn("Material "+i.name+"is not unique."):b.materials[i.name]=i}else if("link"===h.tagName){var j=new e({xml:h});b.links[j.name]?console.warn("Link "+j.name+" is not unique."):(j.visual&&j.visual.material&&(b.materials[j.visual.material.name]?j.visual.material=b.materials[j.visual.material.name]:j.visual.material&&(b.materials[j.visual.material.name]=j.visual.material)),b.links[j.name]=j)}}};if(h){var j=new f;c=j.parseFromString(h,"text/xml")}i(c)}var d=a("./UrdfMaterial"),e=a("./UrdfLink"),f=a("../util/DOMParser"),g=9;b.exports=c},{"../util/DOMParser":29,"./UrdfLink":22,"./UrdfMaterial":23}],26:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.radius=null,this.type=null;var e=function(a){b.type=d.URDF_SPHERE,b.radius=parseFloat(a.getAttribute("radius"))};e(c)}var d=a("./UrdfTypes");b.exports=c},{"./UrdfTypes":27}],27:[function(a,b){b.exports={URDF_SPHERE:0,URDF_BOX:1,URDF_CYLINDER:2,URDF_MESH:3}},{}],28:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.origin=null,this.geometry=null,this.material=null;var l=function(a){var c=a.getElementsByTagName("origin");if(0===c.length)b.origin=new d;else{var l=c[0].getAttribute("xyz"),m=new e;l&&(l=l.split(" "),m=new e({x:parseFloat(l[0]),y:parseFloat(l[1]),z:parseFloat(l[2])}));var n=c[0].getAttribute("rpy"),o=new f;if(n){n=n.split(" ");var p=parseFloat(n[0]),q=parseFloat(n[1]),r=parseFloat(n[2]),s=p/2,t=q/2,u=r/2,v=Math.sin(s)*Math.cos(t)*Math.cos(u)-Math.cos(s)*Math.sin(t)*Math.sin(u),w=Math.cos(s)*Math.sin(t)*Math.cos(u)+Math.sin(s)*Math.cos(t)*Math.sin(u),x=Math.cos(s)*Math.cos(t)*Math.sin(u)-Math.sin(s)*Math.sin(t)*Math.cos(u),y=Math.cos(s)*Math.cos(t)*Math.cos(u)+Math.sin(s)*Math.sin(t)*Math.sin(u);o=new f({x:v,y:w,z:x,w:y}),o.normalize()}b.origin=new d({position:m,orientation:o})}var z=a.getElementsByTagName("geometry");if(z.length>0){var A=null;for(var B in z[0].childNodes){var C=z[0].childNodes[B];if(1===C.nodeType){A=C;break}}var D=A.nodeName;"sphere"===D?b.geometry=new k({xml:A}):"box"===D?b.geometry=new h({xml:A}):"cylinder"===D?b.geometry=new g({xml:A}):"mesh"===D?b.geometry=new j({xml:A}):console.warn("Unknown geometry type "+D)}var E=a.getElementsByTagName("material");E.length>0&&(b.material=new i({xml:E[0]}))};l(c)}var d=a("../math/Pose"),e=a("../math/Vector3"),f=a("../math/Quaternion"),g=a("./UrdfCylinder"),h=a("./UrdfBox"),i=a("./UrdfMaterial"),j=a("./UrdfMesh"),k=a("./UrdfSphere");b.exports=c},{"../math/Pose":14,"../math/Quaternion":15,"../math/Vector3":17,"./UrdfBox":19,"./UrdfCylinder":21,"./UrdfMaterial":23,"./UrdfMesh":24,"./UrdfSphere":26}],29:[function(a,b){(function(a){b.exports=a.DOMParser}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],30:[function(a,b){(function(a){b.exports={EventEmitter2:a.EventEmitter2}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],31:[function(a,b){(function(a){b.exports=a.WebSocket}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],32:[function(a,b){b.exports=function(){return document.createElement("canvas")}},{}]},{},[3]); \ No newline at end of file +!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?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;gb.secs?!1:a.secs=0&&(c.cbs.splice(d,1),0===c.cbs.length&&delete this.frameInfos[a],this.needUpdate=!0)}},b.exports=c},{"../actionlib/ActionClient":4,"../actionlib/Goal":5,"../math/Transform":16}],19:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.dimension=null,this.type=null;var f=function(a){b.type=e.URDF_BOX;var c=a.getAttribute("size").split(" ");b.dimension=new d({x:parseFloat(c[0]),y:parseFloat(c[1]),z:parseFloat(c[2])})};f(c)}var d=a("../math/Vector3"),e=a("./UrdfTypes");b.exports=c},{"../math/Vector3":17,"./UrdfTypes":27}],20:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.r=null,this.g=null,this.b=null,this.a=null;var d=function(a){var c=a.getAttribute("rgba").split(" ");return b.r=parseFloat(c[0]),b.g=parseFloat(c[1]),b.b=parseFloat(c[2]),b.a=parseFloat(c[3]),!0};d(c)}b.exports=c},{}],21:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.type=null,this.length=null,this.radius=null;var e=function(a){b.type=d.URDF_CYLINDER,b.length=parseFloat(a.getAttribute("length")),b.radius=parseFloat(a.getAttribute("radius"))};e(c)}var d=a("./UrdfTypes");b.exports=c},{"./UrdfTypes":27}],22:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.name=null,this.visual=null;var e=function(a){b.name=a.getAttribute("name");var c=a.getElementsByTagName("visual");c.length>0&&(b.visual=new d({xml:c[0]}))};e(c)}var d=a("./UrdfVisual");b.exports=c},{"./UrdfVisual":28}],23:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.name=null,this.textureFilename=null,this.color=null;var e=function(a){b.name=a.getAttribute("name");var c=a.getElementsByTagName("texture");c.length>0&&(b.textureFilename=c[0].getAttribute("filename"));var e=a.getElementsByTagName("color");e.length>0&&(b.color=new d({xml:e[0]}))};e(c)}var d=a("./UrdfColor");b.exports=c},{"./UrdfColor":20}],24:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.filename=null,this.scale=null,this.type=null;var f=function(a){b.type=e.URDF_MESH,b.filename=a.getAttribute("filename");var c=a.getAttribute("scale");if(c){var f=c.split(" ");b.scale=new d({x:parseFloat(f[0]),y:parseFloat(f[1]),z:parseFloat(f[2])})}};f(c)}var d=a("../math/Vector3"),e=a("./UrdfTypes");b.exports=c},{"../math/Vector3":17,"./UrdfTypes":27}],25:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml,h=a.string;this.materials=[],this.links=[];var i=function(a){var c=a.evaluate("//robot",a,null,g,null).singleNodeValue;b.name=c.getAttribute("name");for(var f in c.childNodes){var h=c.childNodes[f];if("material"===h.tagName){var i=new d({xml:h});b.materials[i.name]?console.warn("Material "+i.name+"is not unique."):b.materials[i.name]=i}else if("link"===h.tagName){var j=new e({xml:h});b.links[j.name]?console.warn("Link "+j.name+" is not unique."):(j.visual&&j.visual.material&&(b.materials[j.visual.material.name]?j.visual.material=b.materials[j.visual.material.name]:j.visual.material&&(b.materials[j.visual.material.name]=j.visual.material)),b.links[j.name]=j)}}};if(h){var j=new f;c=j.parseFromString(h,"text/xml")}i(c)}var d=a("./UrdfMaterial"),e=a("./UrdfLink"),f=a("../util/DOMParser"),g=9;b.exports=c},{"../util/DOMParser":29,"./UrdfLink":22,"./UrdfMaterial":23}],26:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.radius=null,this.type=null;var e=function(a){b.type=d.URDF_SPHERE,b.radius=parseFloat(a.getAttribute("radius"))};e(c)}var d=a("./UrdfTypes");b.exports=c},{"./UrdfTypes":27}],27:[function(a,b){b.exports={URDF_SPHERE:0,URDF_BOX:1,URDF_CYLINDER:2,URDF_MESH:3}},{}],28:[function(a,b){function c(a){a=a||{};var b=this,c=a.xml;this.origin=null,this.geometry=null,this.material=null;var l=function(a){var c=a.getElementsByTagName("origin");if(0===c.length)b.origin=new d;else{var l=c[0].getAttribute("xyz"),m=new e;l&&(l=l.split(" "),m=new e({x:parseFloat(l[0]),y:parseFloat(l[1]),z:parseFloat(l[2])}));var n=c[0].getAttribute("rpy"),o=new f;if(n){n=n.split(" ");var p=parseFloat(n[0]),q=parseFloat(n[1]),r=parseFloat(n[2]),s=p/2,t=q/2,u=r/2,v=Math.sin(s)*Math.cos(t)*Math.cos(u)-Math.cos(s)*Math.sin(t)*Math.sin(u),w=Math.cos(s)*Math.sin(t)*Math.cos(u)+Math.sin(s)*Math.cos(t)*Math.sin(u),x=Math.cos(s)*Math.cos(t)*Math.sin(u)-Math.sin(s)*Math.sin(t)*Math.cos(u),y=Math.cos(s)*Math.cos(t)*Math.cos(u)+Math.sin(s)*Math.sin(t)*Math.sin(u);o=new f({x:v,y:w,z:x,w:y}),o.normalize()}b.origin=new d({position:m,orientation:o})}var z=a.getElementsByTagName("geometry");if(z.length>0){var A=null;for(var B in z[0].childNodes){var C=z[0].childNodes[B];if(1===C.nodeType){A=C;break}}var D=A.nodeName;"sphere"===D?b.geometry=new k({xml:A}):"box"===D?b.geometry=new h({xml:A}):"cylinder"===D?b.geometry=new g({xml:A}):"mesh"===D?b.geometry=new j({xml:A}):console.warn("Unknown geometry type "+D)}var E=a.getElementsByTagName("material");E.length>0&&(b.material=new i({xml:E[0]}))};l(c)}var d=a("../math/Pose"),e=a("../math/Vector3"),f=a("../math/Quaternion"),g=a("./UrdfCylinder"),h=a("./UrdfBox"),i=a("./UrdfMaterial"),j=a("./UrdfMesh"),k=a("./UrdfSphere");b.exports=c},{"../math/Pose":14,"../math/Quaternion":15,"../math/Vector3":17,"./UrdfBox":19,"./UrdfCylinder":21,"./UrdfMaterial":23,"./UrdfMesh":24,"./UrdfSphere":26}],29:[function(a,b){(function(a){b.exports=a.DOMParser}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],30:[function(a,b){(function(a){b.exports={EventEmitter2:a.EventEmitter2}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],31:[function(a,b){(function(a){b.exports=a.WebSocket}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],32:[function(a,b){b.exports=function(){return document.createElement("canvas")}},{}]},{},[3]); \ No newline at end of file diff --git a/package.json b/package.json index 79f25acf1..790816451 100644 --- a/package.json +++ b/package.json @@ -18,14 +18,14 @@ "dependencies": { "canvas": "1.1.3", "eventemitter2": "~0.4.13", - "nodejs-websocket": "~0.1.4", "object-assign": "^1.0.0", + "ws": "^0.4.32", "xmlshim": "~0.0.9" }, "browser": { "canvas": "./src/util/shim/canvas.js", "eventemitter2": "./src/util/shim/EventEmitter2.js", - "./src/util/WebSocket.js": "./src/util/shim/WebSocket.js", + "ws": "./src/util/shim/WebSocket.js", "./src/util/DOMParser.js": "./src/util/shim/DOMParser.js" }, "description": "roslibjs", diff --git a/src/core/Ros.js b/src/core/Ros.js index 200aaa0fc..898abe951 100644 --- a/src/core/Ros.js +++ b/src/core/Ros.js @@ -5,7 +5,7 @@ var Canvas = require('canvas'); var Image = Canvas.Image || global.Image; var EventEmitter2 = require('eventemitter2').EventEmitter2; -var WebSocket = require('../util/WebSocket'); +var WebSocket = require('ws'); var Service = require('./Service'); var ServiceRequest = require('./ServiceRequest'); diff --git a/src/util/WebSocket.js b/src/util/WebSocket.js deleted file mode 100644 index ec06fb05b..000000000 --- a/src/util/WebSocket.js +++ /dev/null @@ -1,53 +0,0 @@ -var ws = require('nodejs-websocket'); - -/** - * Provides a WebSocket browser compatible interface to the nodejs-websocket client library. This is used by ROSLIB.Ros directly. - * - * @constructor - */ -var WebSocket = function(url) { - this.url = url; - this.onopen = function() {}; // placeholder function - this.onclose = function() {}; // placeholder function - this.onerror = function() {}; // placeholder function - this.onmessage = function() {}; // placeholder function - var that = this; - this.wsconn = ws.connect(url, null, function(evt) { - that.readyState = that.wsconn.readyState; - // call onopen - that.onopen(evt); // TODO check compatible - }); - this.wsconn.on('close', function(evt) { - that.readyState = that.wsconn.readyState; - that.onclose(evt); - }); - this.wsconn.on('error', function(evt) { - that.readyState = that.wsconn.readyState; - that.onerror(evt); - }); - this.wsconn.on('text', function(fb) { - that.readyState = that.wsconn.readyState; - // do something with framebuffer - that.onmessage({ - data: fb - }); - }); - this.wsconn.on('binary', function(fb) { - that.readyState = that.wsconn.readyState; - // do something with framebuffer - rosbridge wraps binary in the JSON under the data property - // Thus this function should not be needed - we can safely ignore binary messages - }); -}; -WebSocket.prototype.close = function() { - this.wsconn.close(); -}; -WebSocket.prototype.send = function(messageJson) { - this.wsconn.sendText(messageJson); -}; -// Copied from https://github.com/sitegui/nodejs-websocket/blob/master/Connection.js#L75-L78 -WebSocket.CONNECTING = 0; -WebSocket.OPEN = 1; -WebSocket.CLOSING = 2; -WebSocket.CLOSED = 3; - -module.exports = WebSocket; \ No newline at end of file From 3b27edfee9376b38c8f17e2aa24cf151ad6d791d Mon Sep 17 00:00:00 2001 From: Graeme Yeates Date: Mon, 29 Sep 2014 13:49:17 -0400 Subject: [PATCH 7/7] Run examples in Travis --- .gitignore | 2 + .travis.yml | 22 ++++++- Gruntfile.js | 17 +++-- build/roslib.js | 91 +++++++++++--------------- examples/fibonacci.html | 4 +- examples/fibonacci_server.html | 6 +- examples/math.html | 2 +- examples/simple.html | 8 +-- examples/tf.html | 2 +- examples/urdf.html | 12 ++-- package.json | 3 +- test/examples/check-topics.examples.js | 24 +++++++ test/examples/fibonacci.example.js | 51 +++++++++++++++ test/examples/karma.conf.js | 63 ++++++++++++++++++ test/examples/setup_examples.sh | 23 +++++++ test/examples/tf.example.js | 23 +++++++ test/karma.conf.js | 19 ++++-- test/math-examples.test.js | 81 +++++++++++++++++++++++ 18 files changed, 368 insertions(+), 85 deletions(-) create mode 100644 test/examples/check-topics.examples.js create mode 100644 test/examples/fibonacci.example.js create mode 100644 test/examples/karma.conf.js create mode 100644 test/examples/setup_examples.sh create mode 100644 test/examples/tf.example.js create mode 100644 test/math-examples.test.js diff --git a/.gitignore b/.gitignore index 39a72c4e4..34f59397d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .vagrant doc node_modules +*.out +*.log \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index eb4450521..9af2efaca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,28 @@ language: node_js node_js: - "0.10" +addons: + firefox: "31.0" # 3.4->31.0 +os: + - linux before_install: # node-canvas dependency - sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++ + # ROS deps for examples + - sudo sh -c 'echo "deb http://packages.ros.org/ros-shadow-fixed/ubuntu precise main" > /etc/apt/sources.list.d/ros-latest.list' + - wget http://packages.ros.org/ros.key -O - | sudo apt-key add - + - sudo apt-get update -qq + - sudo apt-get install ros-hydro-ros-base + - sudo apt-get install ros-hydro-rosbridge-server ros-hydro-tf2-web-republisher ros-hydro-common-tutorials ros-hydro-rospy-tutorials ros-hydro-actionlib-tutorials + - npm install -g grunt-cli karma-cli + + # Set up Xfvb for Firefox headless testing + - "export DISPLAY=:99.0" + - "sh -e /etc/init.d/xvfb start" before_script: - - npm install -g grunt-cli + - source /opt/ros/hydro/setup.bash + - sh test/examples/setup_examples.sh +script: + - rostopic list + - npm test + - npm run test-examples diff --git a/Gruntfile.js b/Gruntfile.js index 6bb733f19..a6390c07b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -21,15 +21,19 @@ module.exports = function(grunt) { build: { configFile: './test/karma.conf.js', singleRun: true, - browsers: ['PhantomJS'] + browsers: ['Firefox'] } }, mochaTest: { + options: { + reporter: 'spec', + timeout: 5000 + }, test: { - options: { - reporter: 'spec' - }, - src: ['test/**/*.test.js'] + src: ['test/*.test.js'] + }, + examples: { + src: ['test/examples/*.js'] } }, uglify: { @@ -95,9 +99,8 @@ module.exports = function(grunt) { grunt.registerTask('dev', ['browserify', 'watch']); - grunt.registerTask('test', ['jshint', 'mochaTest', 'browserify', 'karma']); + grunt.registerTask('test', ['jshint', 'mochaTest:test', 'browserify', 'karma']); grunt.registerTask('build', ['test', 'uglify']); grunt.registerTask('build_and_watch', ['watch']); grunt.registerTask('doc', ['clean', 'jsdoc']); }; - diff --git a/build/roslib.js b/build/roslib.js index 17aaa2b61..6a5601847 100644 --- a/build/roslib.js +++ b/build/roslib.js @@ -1115,7 +1115,8 @@ function Topic(options) { this.queue_size = options.queue_size || 100; // Check for valid compression types - if (this.compression && this.compression !== 'png' && this.compression !== 'none') { + if (this.compression && this.compression !== 'png' && + this.compression !== 'none') { this.emit('warning', this.compression + ' compression is not supported. No compression will be used.'); } @@ -1138,28 +1139,21 @@ Topic.prototype.__proto__ = EventEmitter2.prototype; */ Topic.prototype.subscribe = function(callback) { var that = this; - - this.on('message', function(message) { - callback(message); - }); - + this.on('message', callback); this.ros.on(this.name, function(data) { var message = new Message(data); that.emit('message', message); }); - this.ros.idCounter++; - var subscribeId = 'subscribe:' + this.name + ':' + this.ros.idCounter; - var call = { - op : 'subscribe', - id : subscribeId, - type : this.messageType, - topic : this.name, - compression : this.compression, - throttle_rate : this.throttle_rate - }; - - this.ros.callOnConnection(call); + this.subscribeId = 'subscribe:' + this.name + ':' + (++this.ros.idCounter); + this.ros.callOnConnection({ + op: 'subscribe', + id: this.subscribeId, + type: this.messageType, + topic: this.name, + compression: this.compression, + throttle_rate: this.throttle_rate + }); }; /** @@ -1167,15 +1161,12 @@ Topic.prototype.subscribe = function(callback) { * all subscribe callbacks. */ Topic.prototype.unsubscribe = function() { - this.ros.removeAllListeners([ this.name ]); - this.ros.idCounter++; - var unsubscribeId = 'unsubscribe:' + this.name + ':' + this.ros.idCounter; - var call = { - op : 'unsubscribe', - id : unsubscribeId, - topic : this.name - }; - this.ros.callOnConnection(call); + this.ros.removeAllListeners([this.name]); + this.ros.callOnConnection({ + op: 'unsubscribe', + id: this.subscribeId, + topic: this.name + }); }; /** @@ -1185,17 +1176,15 @@ Topic.prototype.advertise = function() { if (this.isAdvertised) { return; } - this.ros.idCounter++; - this.advertiseId = 'advertise:' + this.name + ':' + this.ros.idCounter; - var call = { - op : 'advertise', - id : this.advertiseId, - type : this.messageType, - topic : this.name, - latch : this.latch, - queue_size : this.queue_size - }; - this.ros.callOnConnection(call); + this.advertiseId = 'advertise:' + this.name + ':' + (++this.ros.idCounter); + this.ros.callOnConnection({ + op: 'advertise', + id: this.advertiseId, + type: this.messageType, + topic: this.name, + latch: this.latch, + queue_size: this.queue_size + }); this.isAdvertised = true; }; @@ -1206,13 +1195,11 @@ Topic.prototype.unadvertise = function() { if (!this.isAdvertised) { return; } - var unadvertiseId = this.advertiseId; - var call = { - op : 'unadvertise', - id : unadvertiseId, - topic : this.name - }; - this.ros.callOnConnection(call); + this.ros.callOnConnection({ + op: 'unadvertise', + id: this.advertiseId, + topic: this.name + }); this.isAdvertised = false; }; @@ -1223,22 +1210,22 @@ Topic.prototype.unadvertise = function() { */ Topic.prototype.publish = function(message) { if (!this.isAdvertised) { - this.advertise(); + this.advertise(); } this.ros.idCounter++; - var publishId = 'publish:' + this.name + ':' + this.ros.idCounter; var call = { - op : 'publish', - id : publishId, - topic : this.name, - msg : message, - latch : this.latch + op: 'publish', + id: 'publish:' + this.name + ':' + this.ros.idCounter, + topic: this.name, + msg: message, + latch: this.latch }; this.ros.callOnConnection(call); }; module.exports = Topic; + },{"./Message":7,"eventemitter2":30}],14:[function(require,module,exports){ /** * @author David Gossow - dgossow@willowgarage.com diff --git a/examples/fibonacci.html b/examples/fibonacci.html index 00962b3b2..f58084219 100644 --- a/examples/fibonacci.html +++ b/examples/fibonacci.html @@ -2,8 +2,8 @@ - - + + - + - + - + - + - +