@tteja/node-red-dashboard-2-robot-arm 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +142 -0
- package/docs/ARCHITECTURE.md +51 -0
- package/examples/01-inject-demo.json +133 -0
- package/examples/02-controller-to-robot.json +72 -0
- package/examples/03-rosbridge-live.json +54 -0
- package/examples/04-controller-and-ros2.json +72 -0
- package/examples/05-dashboard2.json +143 -0
- package/lib/normalize.js +146 -0
- package/lib/robot-runtime.js +144 -0
- package/lib/rosbridge.js +210 -0
- package/models/ur5e/LICENSE +33 -0
- package/models/ur5e/README.md +15 -0
- package/models/ur5e/joints.json +12 -0
- package/models/ur5e/meshes/base.stl +0 -0
- package/models/ur5e/meshes/forearm.stl +0 -0
- package/models/ur5e/meshes/shoulder.stl +0 -0
- package/models/ur5e/meshes/upperarm.stl +0 -0
- package/models/ur5e/meshes/wrist1.stl +0 -0
- package/models/ur5e/meshes/wrist2.stl +0 -0
- package/models/ur5e/meshes/wrist3.stl +0 -0
- package/models/ur5e/ur5e.urdf +138 -0
- package/models/ur5e-gripper/LICENSE +33 -0
- package/models/ur5e-gripper/README-ur5e.md +15 -0
- package/models/ur5e-gripper/README.md +6 -0
- package/models/ur5e-gripper/joints.json +13 -0
- package/models/ur5e-gripper/meshes/base.stl +0 -0
- package/models/ur5e-gripper/meshes/forearm.stl +0 -0
- package/models/ur5e-gripper/meshes/shoulder.stl +0 -0
- package/models/ur5e-gripper/meshes/upperarm.stl +0 -0
- package/models/ur5e-gripper/meshes/wrist1.stl +0 -0
- package/models/ur5e-gripper/meshes/wrist2.stl +0 -0
- package/models/ur5e-gripper/meshes/wrist3.stl +0 -0
- package/models/ur5e-gripper/ur5e_gripper.urdf +182 -0
- package/nodes/controller.html +76 -0
- package/nodes/controller.js +237 -0
- package/nodes/robot.html +109 -0
- package/nodes/robot.js +347 -0
- package/nodes/ui-robot-arm.html +82 -0
- package/nodes/ui-robot-arm.js +25 -0
- package/nodes/ui-robot-controller.html +81 -0
- package/nodes/ui-robot-controller.js +25 -0
- package/package.json +97 -0
- package/resources/controller.html +64 -0
- package/resources/controller.js +114 -0
- package/resources/pendant.html +66 -0
- package/resources/pendant.js +129 -0
- package/resources/robot-arm-widgets.umd.js +2 -0
- package/resources/viewer.html +54 -0
- package/resources/viewer.js +195 -0
- package/ui/components/UIRobotArm.vue +63 -0
- package/ui/components/UIRobotController.vue +62 -0
- package/ui/index.js +2 -0
package/lib/normalize.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalize joint / pose payloads into a canonical form:
|
|
5
|
+
* { robot, joints: { name: number }, unit: 'rad'|'deg', source, ts }
|
|
6
|
+
*
|
|
7
|
+
* Accepts:
|
|
8
|
+
* - ROS JointState-like: { name: string[], position: number[] }
|
|
9
|
+
* - flat object of joint name → value
|
|
10
|
+
* - msg.payload as array (positional; needs jointNames)
|
|
11
|
+
* - already-canonical { joints, unit, ... }
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const DEFAULT_JOINT_NAMES = [
|
|
15
|
+
'shoulder_pan_joint',
|
|
16
|
+
'shoulder_lift_joint',
|
|
17
|
+
'elbow_joint',
|
|
18
|
+
'wrist_1_joint',
|
|
19
|
+
'wrist_2_joint',
|
|
20
|
+
'wrist_3_joint',
|
|
21
|
+
'finger_joint'
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
function isPlainObject(v) {
|
|
25
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function toNumberMap(obj) {
|
|
29
|
+
const out = {};
|
|
30
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
31
|
+
const n = Number(v);
|
|
32
|
+
if (Number.isFinite(n)) out[k] = n;
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {*} payload - msg.payload or raw object
|
|
39
|
+
* @param {object} [opts]
|
|
40
|
+
* @param {string} [opts.robot]
|
|
41
|
+
* @param {string} [opts.unit] - 'rad' | 'deg'
|
|
42
|
+
* @param {string} [opts.source]
|
|
43
|
+
* @param {string[]} [opts.jointNames] - used when payload is a bare array
|
|
44
|
+
* @returns {{ robot: string, joints: Object.<string,number>, unit: string, source: string, ts: number }}
|
|
45
|
+
*/
|
|
46
|
+
function normalize(payload, opts = {}) {
|
|
47
|
+
const unit = opts.unit === 'deg' ? 'deg' : 'rad';
|
|
48
|
+
const robot = opts.robot || 'robot';
|
|
49
|
+
const source = opts.source || 'unknown';
|
|
50
|
+
const ts = Date.now();
|
|
51
|
+
const jointNames = Array.isArray(opts.jointNames) && opts.jointNames.length
|
|
52
|
+
? opts.jointNames
|
|
53
|
+
: DEFAULT_JOINT_NAMES;
|
|
54
|
+
|
|
55
|
+
let joints = {};
|
|
56
|
+
|
|
57
|
+
if (payload == null) {
|
|
58
|
+
return { robot, joints: {}, unit, source, ts };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Already canonical
|
|
62
|
+
if (isPlainObject(payload) && isPlainObject(payload.joints)) {
|
|
63
|
+
joints = toNumberMap(payload.joints);
|
|
64
|
+
return {
|
|
65
|
+
robot: payload.robot || robot,
|
|
66
|
+
joints,
|
|
67
|
+
unit: payload.unit === 'deg' || payload.unit === 'rad' ? payload.unit : unit,
|
|
68
|
+
source: payload.source || source,
|
|
69
|
+
ts: typeof payload.ts === 'number' ? payload.ts : ts
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ROS JointState-like
|
|
74
|
+
if (
|
|
75
|
+
isPlainObject(payload) &&
|
|
76
|
+
Array.isArray(payload.name) &&
|
|
77
|
+
Array.isArray(payload.position)
|
|
78
|
+
) {
|
|
79
|
+
const n = Math.min(payload.name.length, payload.position.length);
|
|
80
|
+
for (let i = 0; i < n; i++) {
|
|
81
|
+
const name = String(payload.name[i]);
|
|
82
|
+
const val = Number(payload.position[i]);
|
|
83
|
+
if (name && Number.isFinite(val)) joints[name] = val;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
robot: payload.robot || robot,
|
|
87
|
+
joints,
|
|
88
|
+
unit: payload.unit === 'deg' || payload.unit === 'rad' ? payload.unit : unit,
|
|
89
|
+
source: payload.source || source,
|
|
90
|
+
ts
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Bare array → positional joints
|
|
95
|
+
if (Array.isArray(payload)) {
|
|
96
|
+
const n = Math.min(payload.length, jointNames.length);
|
|
97
|
+
for (let i = 0; i < n; i++) {
|
|
98
|
+
const val = Number(payload[i]);
|
|
99
|
+
if (Number.isFinite(val)) joints[jointNames[i]] = val;
|
|
100
|
+
}
|
|
101
|
+
return { robot, joints, unit, source, ts };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Flat object of joint → value (ignore meta keys)
|
|
105
|
+
if (isPlainObject(payload)) {
|
|
106
|
+
const meta = new Set(['robot', 'unit', 'source', 'ts', 'name', 'position', 'velocity', 'effort', 'header']);
|
|
107
|
+
const raw = {};
|
|
108
|
+
for (const [k, v] of Object.entries(payload)) {
|
|
109
|
+
if (meta.has(k)) continue;
|
|
110
|
+
if (typeof v === 'number' || (typeof v === 'string' && v.trim() !== '' && Number.isFinite(Number(v)))) {
|
|
111
|
+
raw[k] = v;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
joints = toNumberMap(raw);
|
|
115
|
+
return {
|
|
116
|
+
robot: payload.robot || robot,
|
|
117
|
+
joints,
|
|
118
|
+
unit: payload.unit === 'deg' || payload.unit === 'rad' ? payload.unit : unit,
|
|
119
|
+
source: payload.source || source,
|
|
120
|
+
ts
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { robot, joints: {}, unit, source, ts };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Convert joints between rad and deg (in place copy).
|
|
129
|
+
*/
|
|
130
|
+
function convertUnit(joints, fromUnit, toUnit) {
|
|
131
|
+
if (fromUnit === toUnit) return { ...joints };
|
|
132
|
+
const factor = fromUnit === 'deg' && toUnit === 'rad' ? Math.PI / 180
|
|
133
|
+
: fromUnit === 'rad' && toUnit === 'deg' ? 180 / Math.PI
|
|
134
|
+
: 1;
|
|
135
|
+
const out = {};
|
|
136
|
+
for (const [k, v] of Object.entries(joints)) {
|
|
137
|
+
out[k] = v * factor;
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
module.exports = {
|
|
143
|
+
normalize,
|
|
144
|
+
convertUnit,
|
|
145
|
+
DEFAULT_JOINT_NAMES
|
|
146
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { normalize, convertUnit } = require('./normalize');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Pure-ish runtime for one robot instance: joint state, priority policy,
|
|
7
|
+
* optional rosbridge publish callback. Used by the Node-RED `robot` node
|
|
8
|
+
* and by automated tests (no RED dependency).
|
|
9
|
+
*/
|
|
10
|
+
class RobotRuntime {
|
|
11
|
+
/**
|
|
12
|
+
* @param {object} opts
|
|
13
|
+
* @param {string} [opts.robotTag]
|
|
14
|
+
* @param {string} [opts.unit] - 'rad' | 'deg'
|
|
15
|
+
* @param {Array<{name:string, home?:number, unit?:string}>} opts.jointsMeta
|
|
16
|
+
* @param {function} [opts.onPublish] - (topic, type, msg) => void
|
|
17
|
+
* @param {string} [opts.publishTopic]
|
|
18
|
+
* @param {function} [opts.getRosbridgeStatus] - () => string
|
|
19
|
+
*/
|
|
20
|
+
constructor(opts = {}) {
|
|
21
|
+
this.robotTag = (opts.robotTag || 'robot').trim() || 'robot';
|
|
22
|
+
this.unit = opts.unit === 'deg' ? 'deg' : 'rad';
|
|
23
|
+
this.jointsMeta = Array.isArray(opts.jointsMeta) ? opts.jointsMeta : [];
|
|
24
|
+
this.jointNames = this.jointsMeta.map((j) => j.name);
|
|
25
|
+
this.onPublish = typeof opts.onPublish === 'function' ? opts.onPublish : null;
|
|
26
|
+
this.publishTopic = (opts.publishTopic || '').trim();
|
|
27
|
+
this.getRosbridgeStatus = typeof opts.getRosbridgeStatus === 'function'
|
|
28
|
+
? opts.getRosbridgeStatus
|
|
29
|
+
: () => 'disabled';
|
|
30
|
+
|
|
31
|
+
this.joints = {};
|
|
32
|
+
for (const j of this.jointsMeta) {
|
|
33
|
+
this.joints[j.name] = typeof j.home === 'number' ? j.home : 0;
|
|
34
|
+
}
|
|
35
|
+
this.source = 'init';
|
|
36
|
+
this.ts = Date.now();
|
|
37
|
+
this.manualArmed = false;
|
|
38
|
+
this.lastPendantTs = 0;
|
|
39
|
+
this.clients = new Set();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getPublicState(extra = {}) {
|
|
43
|
+
return {
|
|
44
|
+
robot: this.robotTag,
|
|
45
|
+
joints: { ...this.joints },
|
|
46
|
+
unit: this.unit,
|
|
47
|
+
source: this.source,
|
|
48
|
+
ts: this.ts,
|
|
49
|
+
rosbridge: this.getRosbridgeStatus(),
|
|
50
|
+
jointNames: this.jointNames.slice(),
|
|
51
|
+
jointsMeta: this.jointsMeta.slice(),
|
|
52
|
+
...extra
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
broadcast() {
|
|
57
|
+
for (const cb of this.clients) {
|
|
58
|
+
try { cb(); } catch (_) { /* ignore */ }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @param {*} payload
|
|
64
|
+
* @param {string} [defaultSource]
|
|
65
|
+
* @returns {{ applied: boolean, out?: object, frozen?: boolean }}
|
|
66
|
+
*/
|
|
67
|
+
applyCommand(payload, defaultSource) {
|
|
68
|
+
const src = (payload && payload.source) || defaultSource || 'input';
|
|
69
|
+
if (src === 'rosbridge' && this.manualArmed && Date.now() - this.lastPendantTs < 2000) {
|
|
70
|
+
return { applied: false };
|
|
71
|
+
}
|
|
72
|
+
if (src === 'pendant' || src === 'controller') {
|
|
73
|
+
this.lastPendantTs = Date.now();
|
|
74
|
+
if (payload && payload.manualArmed != null) {
|
|
75
|
+
this.manualArmed = !!payload.manualArmed;
|
|
76
|
+
} else {
|
|
77
|
+
this.manualArmed = true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (payload && payload.freeze === true) {
|
|
81
|
+
return { applied: false, frozen: true, out: this.getPublicState() };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const norm = normalize(payload, {
|
|
85
|
+
robot: this.robotTag,
|
|
86
|
+
unit: this.unit,
|
|
87
|
+
source: src,
|
|
88
|
+
jointNames: this.jointNames
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
let joints = norm.joints;
|
|
92
|
+
if (norm.unit !== this.unit && Object.keys(joints).length) {
|
|
93
|
+
const angular = {};
|
|
94
|
+
const linear = {};
|
|
95
|
+
for (const [k, v] of Object.entries(joints)) {
|
|
96
|
+
const meta = this.jointsMeta.find((j) => j.name === k);
|
|
97
|
+
if (meta && meta.unit === 'm') linear[k] = v;
|
|
98
|
+
else angular[k] = v;
|
|
99
|
+
}
|
|
100
|
+
joints = { ...convertUnit(angular, norm.unit, this.unit), ...linear };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
Object.assign(this.joints, joints);
|
|
104
|
+
this.source = norm.source;
|
|
105
|
+
this.ts = norm.ts;
|
|
106
|
+
|
|
107
|
+
if (this.joints.finger_joint != null && this.joints.finger_joint_right == null) {
|
|
108
|
+
this.joints.finger_joint_right = this.joints.finger_joint;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
this.broadcast();
|
|
112
|
+
|
|
113
|
+
const out = {
|
|
114
|
+
robot: this.robotTag,
|
|
115
|
+
joints: { ...this.joints },
|
|
116
|
+
unit: this.unit,
|
|
117
|
+
source: this.source,
|
|
118
|
+
ts: this.ts
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
if (this.onPublish && this.publishTopic && this.getRosbridgeStatus() === 'connected') {
|
|
122
|
+
const names = Object.keys(this.joints);
|
|
123
|
+
const positions = names.map((n) => {
|
|
124
|
+
let v = this.joints[n];
|
|
125
|
+
const meta = this.jointsMeta.find((j) => j.name === n);
|
|
126
|
+
const isLinear = meta && meta.unit === 'm';
|
|
127
|
+
if (!isLinear && this.unit === 'deg') {
|
|
128
|
+
v = v * Math.PI / 180;
|
|
129
|
+
}
|
|
130
|
+
return v;
|
|
131
|
+
});
|
|
132
|
+
this.onPublish(this.publishTopic, 'sensor_msgs/JointState', {
|
|
133
|
+
name: names,
|
|
134
|
+
position: positions,
|
|
135
|
+
velocity: [],
|
|
136
|
+
effort: []
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return { applied: true, out };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
module.exports = { RobotRuntime };
|
package/lib/rosbridge.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { EventEmitter } = require('events');
|
|
4
|
+
const WebSocket = require('ws');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Minimal rosbridge WebSocket client for Node-RED robot node.
|
|
8
|
+
* Supports connect, subscribe, advertise, publish, reconnect, and status events.
|
|
9
|
+
*
|
|
10
|
+
* Honest limit: needs a real (or mock) rosbridge endpoint on the configured URL
|
|
11
|
+
* (typically ws://host:9090). This is not a full ROS 2 client.
|
|
12
|
+
*/
|
|
13
|
+
class RosbridgeClient extends EventEmitter {
|
|
14
|
+
/**
|
|
15
|
+
* @param {object} opts
|
|
16
|
+
* @param {string} opts.url - e.g. ws://localhost:9090
|
|
17
|
+
* @param {number} [opts.reconnectMs=3000]
|
|
18
|
+
* @param {function} [opts.WebSocketImpl] - injectable WebSocket (for tests)
|
|
19
|
+
*/
|
|
20
|
+
constructor(opts = {}) {
|
|
21
|
+
super();
|
|
22
|
+
this.url = opts.url || 'ws://localhost:9090';
|
|
23
|
+
this.reconnectMs = opts.reconnectMs != null ? opts.reconnectMs : 3000;
|
|
24
|
+
this._WS = opts.WebSocketImpl || WebSocket;
|
|
25
|
+
this._ws = null;
|
|
26
|
+
this._closed = false;
|
|
27
|
+
this._id = 0;
|
|
28
|
+
this._subs = new Map(); // topic -> { type, cb, id }
|
|
29
|
+
this._ads = new Map(); // topic -> { type, id }
|
|
30
|
+
this._reconnectTimer = null;
|
|
31
|
+
this.status = 'disconnected';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_setStatus(s) {
|
|
35
|
+
this.status = s;
|
|
36
|
+
this.emit('status', s);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
_nextId() {
|
|
40
|
+
this._id += 1;
|
|
41
|
+
return `nra_${this._id}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
connect() {
|
|
45
|
+
this._closed = false;
|
|
46
|
+
if (this._ws && (this._ws.readyState === this._WS.OPEN || this._ws.readyState === this._WS.CONNECTING)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this._clearReconnect();
|
|
50
|
+
this._setStatus('connecting');
|
|
51
|
+
let ws;
|
|
52
|
+
try {
|
|
53
|
+
ws = new this._WS(this.url);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
this._setStatus('error');
|
|
56
|
+
this.emit('error', err);
|
|
57
|
+
this._scheduleReconnect();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
this._ws = ws;
|
|
61
|
+
|
|
62
|
+
ws.on('open', () => {
|
|
63
|
+
this._setStatus('connected');
|
|
64
|
+
for (const [topic, ad] of this._ads.entries()) {
|
|
65
|
+
this._send({
|
|
66
|
+
op: 'advertise',
|
|
67
|
+
id: ad.id,
|
|
68
|
+
topic,
|
|
69
|
+
type: ad.type
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
for (const [topic, sub] of this._subs.entries()) {
|
|
73
|
+
this._send({
|
|
74
|
+
op: 'subscribe',
|
|
75
|
+
id: sub.id,
|
|
76
|
+
topic,
|
|
77
|
+
type: sub.type
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
ws.on('message', (data) => {
|
|
83
|
+
let msg;
|
|
84
|
+
try {
|
|
85
|
+
msg = JSON.parse(data.toString());
|
|
86
|
+
} catch (_) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (msg.op === 'publish' && msg.topic && this._subs.has(msg.topic)) {
|
|
90
|
+
const sub = this._subs.get(msg.topic);
|
|
91
|
+
try {
|
|
92
|
+
sub.cb(msg.msg, msg.topic);
|
|
93
|
+
} catch (err) {
|
|
94
|
+
this.emit('error', err);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
ws.on('close', () => {
|
|
100
|
+
this._ws = null;
|
|
101
|
+
if (!this._closed) {
|
|
102
|
+
this._setStatus('disconnected');
|
|
103
|
+
this._scheduleReconnect();
|
|
104
|
+
} else {
|
|
105
|
+
this._setStatus('closed');
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
ws.on('error', (err) => {
|
|
110
|
+
this.emit('error', err);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
_send(obj) {
|
|
115
|
+
if (this._ws && this._ws.readyState === this._WS.OPEN) {
|
|
116
|
+
this._ws.send(JSON.stringify(obj));
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @param {string} topic
|
|
124
|
+
* @param {string} type - ROS message type e.g. sensor_msgs/JointState
|
|
125
|
+
* @param {function} cb - (msg, topic) => void
|
|
126
|
+
*/
|
|
127
|
+
subscribe(topic, type, cb) {
|
|
128
|
+
const id = this._nextId();
|
|
129
|
+
this._subs.set(topic, { type, cb, id });
|
|
130
|
+
this._send({ op: 'subscribe', id, topic, type });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
unsubscribe(topic) {
|
|
134
|
+
const sub = this._subs.get(topic);
|
|
135
|
+
if (sub) {
|
|
136
|
+
this._send({ op: 'unsubscribe', id: sub.id, topic });
|
|
137
|
+
this._subs.delete(topic);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Advertise a topic before publishing (rosbridge protocol).
|
|
143
|
+
* @param {string} topic
|
|
144
|
+
* @param {string} type
|
|
145
|
+
*/
|
|
146
|
+
advertise(topic, type) {
|
|
147
|
+
const id = this._nextId();
|
|
148
|
+
this._ads.set(topic, { type, id });
|
|
149
|
+
this._send({ op: 'advertise', id, topic, type });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
unadvertise(topic) {
|
|
153
|
+
const ad = this._ads.get(topic);
|
|
154
|
+
if (ad) {
|
|
155
|
+
this._send({ op: 'unadvertise', id: ad.id, topic });
|
|
156
|
+
this._ads.delete(topic);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @param {string} topic
|
|
162
|
+
* @param {string} type
|
|
163
|
+
* @param {object} msg
|
|
164
|
+
*/
|
|
165
|
+
publish(topic, type, msg) {
|
|
166
|
+
if (!this._ads.has(topic)) {
|
|
167
|
+
this.advertise(topic, type);
|
|
168
|
+
}
|
|
169
|
+
this._send({
|
|
170
|
+
op: 'publish',
|
|
171
|
+
topic,
|
|
172
|
+
msg,
|
|
173
|
+
type
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
_scheduleReconnect() {
|
|
178
|
+
if (this._closed || this.reconnectMs <= 0) return;
|
|
179
|
+
this._clearReconnect();
|
|
180
|
+
this._reconnectTimer = setTimeout(() => {
|
|
181
|
+
this._reconnectTimer = null;
|
|
182
|
+
if (!this._closed) this.connect();
|
|
183
|
+
}, this.reconnectMs);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
_clearReconnect() {
|
|
187
|
+
if (this._reconnectTimer) {
|
|
188
|
+
clearTimeout(this._reconnectTimer);
|
|
189
|
+
this._reconnectTimer = null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
close() {
|
|
194
|
+
this._closed = true;
|
|
195
|
+
this._clearReconnect();
|
|
196
|
+
for (const topic of [...this._subs.keys()]) {
|
|
197
|
+
this.unsubscribe(topic);
|
|
198
|
+
}
|
|
199
|
+
for (const topic of [...this._ads.keys()]) {
|
|
200
|
+
this.unadvertise(topic);
|
|
201
|
+
}
|
|
202
|
+
if (this._ws) {
|
|
203
|
+
try { this._ws.close(); } catch (_) { /* ignore */ }
|
|
204
|
+
this._ws = null;
|
|
205
|
+
}
|
|
206
|
+
this._setStatus('closed');
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
module.exports = { RosbridgeClient };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Copyright (c) Universal Robots A/S and contributors.
|
|
2
|
+
Source: UniversalRobots/Universal_Robots_ROS2_Description (rolling)
|
|
3
|
+
meshes/ur5e/collision/*.stl — converted to ASCII STL for GitHub Pages.
|
|
4
|
+
|
|
5
|
+
BSD 3-Clause License
|
|
6
|
+
|
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
|
8
|
+
modification, are permitted provided that the following conditions are met:
|
|
9
|
+
|
|
10
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
11
|
+
list of conditions and the following disclaimer.
|
|
12
|
+
|
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
and/or other materials provided with the distribution.
|
|
16
|
+
|
|
17
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
18
|
+
contributors may be used to endorse or promote products derived from
|
|
19
|
+
this software without specific prior written permission.
|
|
20
|
+
|
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
22
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
23
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
24
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
25
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
26
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
27
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
28
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
29
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
30
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
+
|
|
32
|
+
Note: UR5e meshes are BSD-3-Clause. The separate "Graphical Documentation"
|
|
33
|
+
terms that apply to UR20/UR30/etc. do NOT apply to UR5e.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# UR5e (vendored)
|
|
2
|
+
|
|
3
|
+
Browser-ready URDF + **visual** binary STL meshes for the Electronics Playground 6-DoF arm lab.
|
|
4
|
+
|
|
5
|
+
| Item | Value |
|
|
6
|
+
|------|--------|
|
|
7
|
+
| Model | Universal Robots UR5e |
|
|
8
|
+
| Source | [UniversalRobots/Universal_Robots_ROS2_Description](https://github.com/UniversalRobots/Universal_Robots_ROS2_Description) (rolling) |
|
|
9
|
+
| License | **BSD-3-Clause** (see `LICENSE`) |
|
|
10
|
+
| Meshes | Official **visual** DAE -> binary STL (thousands of tris/link; not collision proxies) |
|
|
11
|
+
| Joints | `shoulder_pan_joint` ... `wrist_3_joint` (same names as ros2_control) |
|
|
12
|
+
|
|
13
|
+
Regenerate locally: `npm run meshes` (needs `pip install trimesh pycollada numpy scipy fast_simplification`).
|
|
14
|
+
|
|
15
|
+
Kinematics match `config/ur5e/default_kinematics.yaml`. Visual offsets match `config/ur5e/visual_parameters.yaml`.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ur5e",
|
|
3
|
+
"urdf": "ur5e.urdf",
|
|
4
|
+
"joints": [
|
|
5
|
+
{ "name": "shoulder_pan_joint", "label": "Base", "min": -6.2832, "max": 6.2832, "home": 0 },
|
|
6
|
+
{ "name": "shoulder_lift_joint", "label": "Shoulder", "min": -6.2832, "max": 6.2832, "home": -1.57 },
|
|
7
|
+
{ "name": "elbow_joint", "label": "Elbow", "min": -3.1416, "max": 3.1416, "home": 1.57 },
|
|
8
|
+
{ "name": "wrist_1_joint", "label": "Wrist 1", "min": -6.2832, "max": 6.2832, "home": -1.57 },
|
|
9
|
+
{ "name": "wrist_2_joint", "label": "Wrist 2", "min": -6.2832, "max": 6.2832, "home": -1.57 },
|
|
10
|
+
{ "name": "wrist_3_joint", "label": "Wrist 3", "min": -6.2832, "max": 6.2832, "home": 0 }
|
|
11
|
+
]
|
|
12
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|