node-red-contrib-periph-imu 1.0.1 → 1.1.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/examples/mpu6050/demo.json +76 -0
- package/nodes/mpu6050/mpu6050.html +103 -0
- package/nodes/mpu6050/mpu6050.js +49 -0
- package/package.json +4 -2
- package/examples/.gitkeep +0 -0
- package/nodes/.gitkeep +0 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-mpu6050-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "MPU6050 Motion Logger",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Reads 3-axis acceleration and angular rate from an MPU6050 every 100 ms. A function node computes roll and pitch from the accelerometer gravity vector and the gyro magnitude. Demonstrates basic tilt estimation from IMU data. Adjust the gyro and accel full-scale ranges in the device config node to match your application's dynamic range."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "cfg-mpu6050",
|
|
11
|
+
"type": "mpu6050-device",
|
|
12
|
+
"name": "MPU6050",
|
|
13
|
+
"bus": "1",
|
|
14
|
+
"address": "68",
|
|
15
|
+
"gyroFs": "1",
|
|
16
|
+
"accelFs": "1"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"id": "inj-tick",
|
|
20
|
+
"type": "inject",
|
|
21
|
+
"name": "every 100 ms",
|
|
22
|
+
"repeat": "0.1",
|
|
23
|
+
"crontab": "",
|
|
24
|
+
"once": true,
|
|
25
|
+
"onceDelay": 0.1,
|
|
26
|
+
"topic": "",
|
|
27
|
+
"payload": "",
|
|
28
|
+
"payloadType": "date",
|
|
29
|
+
"z": "tab-mpu6050-demo",
|
|
30
|
+
"x": 120,
|
|
31
|
+
"y": 160,
|
|
32
|
+
"wires": [["read-mpu6050"]]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"id": "read-mpu6050",
|
|
36
|
+
"type": "mpu6050",
|
|
37
|
+
"name": "MPU6050",
|
|
38
|
+
"device": "cfg-mpu6050",
|
|
39
|
+
"z": "tab-mpu6050-demo",
|
|
40
|
+
"x": 300,
|
|
41
|
+
"y": 160,
|
|
42
|
+
"wires": [["compute-tilt"]]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"id": "compute-tilt",
|
|
46
|
+
"type": "function",
|
|
47
|
+
"name": "roll/pitch",
|
|
48
|
+
"func": "const p = msg.payload;\nconst roll = Math.atan2(p.ay, p.az) * 180 / Math.PI;\nconst pitch = Math.atan2(-p.ax, Math.sqrt(p.ay*p.ay + p.az*p.az)) * 180 / Math.PI;\nconst gyroMag = Math.sqrt(p.gx*p.gx + p.gy*p.gy + p.gz*p.gz);\nmsg.payload = 'roll=' + roll.toFixed(1) + '° pitch=' + pitch.toFixed(1) + '° |gyro|=' + gyroMag.toFixed(3) + ' rad/s';\nreturn msg;",
|
|
49
|
+
"outputs": 1,
|
|
50
|
+
"noerr": 0,
|
|
51
|
+
"initialize": "",
|
|
52
|
+
"finalize": "",
|
|
53
|
+
"libs": [],
|
|
54
|
+
"z": "tab-mpu6050-demo",
|
|
55
|
+
"x": 480,
|
|
56
|
+
"y": 160,
|
|
57
|
+
"wires": [["dbg-output"]]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": "dbg-output",
|
|
61
|
+
"type": "debug",
|
|
62
|
+
"name": "",
|
|
63
|
+
"active": true,
|
|
64
|
+
"tosidebar": true,
|
|
65
|
+
"console": false,
|
|
66
|
+
"tostatus": true,
|
|
67
|
+
"complete": "payload",
|
|
68
|
+
"targetType": "msg",
|
|
69
|
+
"statusVal": "payload",
|
|
70
|
+
"statusType": "auto",
|
|
71
|
+
"z": "tab-mpu6050-demo",
|
|
72
|
+
"x": 650,
|
|
73
|
+
"y": 160,
|
|
74
|
+
"wires": []
|
|
75
|
+
}
|
|
76
|
+
]
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('mpu6050-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '68', required: true },
|
|
9
|
+
gyroFs: { value: '0', required: true, validate: RED.validators.number() },
|
|
10
|
+
accelFs: { value: '0', required: true, validate: RED.validators.number() }
|
|
11
|
+
},
|
|
12
|
+
label: function() {
|
|
13
|
+
return this.name || ('MPU6050 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script type="text/html" data-template-name="mpu6050-device">
|
|
19
|
+
<div class="form-row">
|
|
20
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
21
|
+
<input type="text" id="node-config-input-name" placeholder="MPU6050">
|
|
22
|
+
</div>
|
|
23
|
+
<div class="form-row">
|
|
24
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
25
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
26
|
+
</div>
|
|
27
|
+
<div class="form-row">
|
|
28
|
+
<label for="node-config-input-address">Address (hex)</label>
|
|
29
|
+
<input type="text" id="node-config-input-address" placeholder="68" style="width:80px"> default: 68 (0x68)
|
|
30
|
+
</div>
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label for="node-config-input-gyroFs">Gyro range</label>
|
|
33
|
+
<select id="node-config-input-gyroFs" style="width:150px">
|
|
34
|
+
<option value="0">±250 dps</option>
|
|
35
|
+
<option value="1">±500 dps</option>
|
|
36
|
+
<option value="2">±1000 dps</option>
|
|
37
|
+
<option value="3">±2000 dps</option>
|
|
38
|
+
</select>
|
|
39
|
+
</div>
|
|
40
|
+
<div class="form-row">
|
|
41
|
+
<label for="node-config-input-accelFs">Accel range</label>
|
|
42
|
+
<select id="node-config-input-accelFs" style="width:150px">
|
|
43
|
+
<option value="0">±2 g</option>
|
|
44
|
+
<option value="1">±4 g</option>
|
|
45
|
+
<option value="2">±8 g</option>
|
|
46
|
+
<option value="3">±16 g</option>
|
|
47
|
+
</select>
|
|
48
|
+
</div>
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<!-- Read node: trigger → measurements -->
|
|
52
|
+
<script type="text/javascript">
|
|
53
|
+
RED.nodes.registerType('mpu6050', {
|
|
54
|
+
category: 'Peripheral',
|
|
55
|
+
color: '#a6bbcf',
|
|
56
|
+
defaults: {
|
|
57
|
+
name: { value: '' },
|
|
58
|
+
device: { value: '', type: 'mpu6050-device', required: true }
|
|
59
|
+
},
|
|
60
|
+
inputs: 1,
|
|
61
|
+
outputs: 1,
|
|
62
|
+
icon: 'font-awesome/fa-compass',
|
|
63
|
+
label: function() { return this.name || 'MPU6050'; },
|
|
64
|
+
paletteLabel: 'MPU6050'
|
|
65
|
+
});
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<script type="text/html" data-template-name="mpu6050">
|
|
69
|
+
<div class="form-row">
|
|
70
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
71
|
+
<input type="text" id="node-input-device">
|
|
72
|
+
</div>
|
|
73
|
+
<div class="form-row">
|
|
74
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
75
|
+
<input type="text" id="node-input-name" placeholder="MPU6050">
|
|
76
|
+
</div>
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<script type="text/html" data-help-name="mpu6050">
|
|
80
|
+
<p>Reads 3-axis acceleration and 3-axis angular rate from an MPU6050 IMU over I²C.</p>
|
|
81
|
+
<p>Any input message triggers a measurement. The device is configured via an <b>mpu6050-device</b> config node.</p>
|
|
82
|
+
|
|
83
|
+
<h3>Output</h3>
|
|
84
|
+
<dl class="message-properties">
|
|
85
|
+
<dt>payload.ax <span class="property-type">number</span></dt>
|
|
86
|
+
<dd>X acceleration in m/s².</dd>
|
|
87
|
+
<dt>payload.ay <span class="property-type">number</span></dt>
|
|
88
|
+
<dd>Y acceleration in m/s².</dd>
|
|
89
|
+
<dt>payload.az <span class="property-type">number</span></dt>
|
|
90
|
+
<dd>Z acceleration in m/s².</dd>
|
|
91
|
+
<dt>payload.gx <span class="property-type">number</span></dt>
|
|
92
|
+
<dd>X angular rate in rad/s.</dd>
|
|
93
|
+
<dt>payload.gy <span class="property-type">number</span></dt>
|
|
94
|
+
<dd>Y angular rate in rad/s.</dd>
|
|
95
|
+
<dt>payload.gz <span class="property-type">number</span></dt>
|
|
96
|
+
<dd>Z angular rate in rad/s.</dd>
|
|
97
|
+
</dl>
|
|
98
|
+
|
|
99
|
+
<h3>Configuration</h3>
|
|
100
|
+
<p>Set the I²C bus number, the chip's 7-bit address (default <code>0x68</code>),
|
|
101
|
+
the gyroscope full-scale range (±250/±500/±1000/±2000 dps), and the accelerometer
|
|
102
|
+
full-scale range (±2/±4/±8/±16 g) in the device config node.</p>
|
|
103
|
+
</script>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CTransport } = require('periph/src/transport/i2c');
|
|
5
|
+
const { MPU6050Full } = require('periph/src/chips/imu/mpu6050');
|
|
6
|
+
|
|
7
|
+
function MPU6050DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const transport = new I2CTransport(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.driver = new MPU6050Full(transport);
|
|
13
|
+
node.transport = transport;
|
|
14
|
+
if (config.gyroFs) node.driver.configureGyro(parseInt(config.gyroFs));
|
|
15
|
+
if (config.accelFs) node.driver.configureAccel(parseInt(config.accelFs));
|
|
16
|
+
} catch (e) {
|
|
17
|
+
node.error('MPU6050 init failed: ' + e.message);
|
|
18
|
+
}
|
|
19
|
+
node.on('close', function() {
|
|
20
|
+
if (node.transport) node.transport.close();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
RED.nodes.registerType('mpu6050-device', MPU6050DeviceNode);
|
|
24
|
+
|
|
25
|
+
function MPU6050ReadNode(config) {
|
|
26
|
+
RED.nodes.createNode(this, config);
|
|
27
|
+
const node = this;
|
|
28
|
+
node.device = RED.nodes.getNode(config.device);
|
|
29
|
+
|
|
30
|
+
node.on('input', function(msg, send, done) {
|
|
31
|
+
if (!node.device || !node.device.driver) {
|
|
32
|
+
node.error('No MPU6050 device configured', msg);
|
|
33
|
+
done();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const d = node.device.driver;
|
|
38
|
+
const [ax, ay, az] = d.accel();
|
|
39
|
+
const [gx, gy, gz] = d.gyro();
|
|
40
|
+
msg.payload = { ax, ay, az, gx, gy, gz };
|
|
41
|
+
send(msg);
|
|
42
|
+
done();
|
|
43
|
+
} catch (e) {
|
|
44
|
+
done(e);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
RED.nodes.registerType('mpu6050', MPU6050ReadNode);
|
|
49
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-imu",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Node-RED nodes for IMU chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"peripheral"
|
|
12
12
|
],
|
|
13
13
|
"node-red": {
|
|
14
|
-
"nodes": {
|
|
14
|
+
"nodes": {
|
|
15
|
+
"mpu6050": "nodes/mpu6050/mpu6050.js"
|
|
16
|
+
}
|
|
15
17
|
},
|
|
16
18
|
"dependencies": {
|
|
17
19
|
"periph": "*"
|
package/examples/.gitkeep
DELETED
|
File without changes
|
package/nodes/.gitkeep
DELETED
|
File without changes
|