node-red-contrib-periph-imu 1.3.3 → 1.5.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/README.md CHANGED
@@ -16,9 +16,11 @@ npm install node-red-contrib-periph-imu
16
16
 
17
17
  | Node | Kind | Description |
18
18
  |------|------|-------------|
19
+ | `periph-bno055` | input | Reads the fused absolute orientation of a Bosch BNO055 9-axis sensor over I²C (0x29 with COM3 high, 0x28 with COM3 low). The chip stretches the I²C clock, so the host bus must support clock stretching. Allow up to about one second after deploying for the chip to boot. |
19
20
  | `periph-icm20948` | input | Reads acceleration, angular rate, die temperature and (optionally) the magnetic field from a TDK InvenSense ICM-20948 9-axis MotionTracking device over I²C. The AK09916 magnetometer is read through the chip's own I²C master, so only one I²C address is needed. VDDIO must be 1.71–1.95 V. |
20
21
  | `mpu6050-device` | config | I²C bus and address for a MPU6050 |
21
22
  | `mpu6050` | input | Reads 3-axis acceleration and 3-axis angular rate from an MPU6050 IMU over I²C. |
23
+ | `periph-qmi8658a` | input | Reads acceleration, angular rate and die temperature from a QST QMI8658A 6-axis IMU over I²C (0x6B with SA0 = GND, 0x6A with SA0 = VDDIO) or 4-wire SPI. The three values come from one 14-byte burst, so they belong to the same sample. |
22
24
 
23
25
  ## Links
24
26
 
@@ -0,0 +1,85 @@
1
+ [
2
+ {
3
+ "id": "bno055-tab",
4
+ "type": "tab",
5
+ "label": "BNO055 orientation",
6
+ "disabled": false,
7
+ "info": "Reads the fused orientation of a BNO055 every 100 ms and formats heading, roll and pitch (rad) together with the calibration status. Demonstrates the absolute-orientation output; move the board in a figure eight until the calibration values reach 3."
8
+ },
9
+ {
10
+ "id": "bno055-inject",
11
+ "type": "inject",
12
+ "z": "bno055-tab",
13
+ "name": "100 ms timer",
14
+ "props": [
15
+ {
16
+ "p": "payload"
17
+ }
18
+ ],
19
+ "repeat": "0.1",
20
+ "crontab": "",
21
+ "once": false,
22
+ "onceDelay": 0.1,
23
+ "topic": "",
24
+ "payloadType": "date",
25
+ "x": 170,
26
+ "y": 160,
27
+ "wires": [
28
+ [
29
+ "bno055-node"
30
+ ]
31
+ ]
32
+ },
33
+ {
34
+ "id": "bno055-node",
35
+ "type": "periph-bno055",
36
+ "z": "bno055-tab",
37
+ "name": "BNO055",
38
+ "bus": "1",
39
+ "address": "0x29",
40
+ "mode": "12",
41
+ "x": 400,
42
+ "y": 160,
43
+ "wires": [
44
+ [
45
+ "bno055-format"
46
+ ]
47
+ ]
48
+ },
49
+ {
50
+ "id": "bno055-format",
51
+ "type": "function",
52
+ "z": "bno055-tab",
53
+ "name": "Format orientation",
54
+ "func": "const p = msg.payload;\nconst c = p.calibration;\nmsg.payload = 'heading ' + p.heading.toFixed(2) + ' rad, roll ' + p.roll.toFixed(2) + ', pitch ' + p.pitch.toFixed(2) +\n ' (cal sys ' + c.sys + ' gyr ' + c.gyr + ' acc ' + c.acc + ' mag ' + c.mag + ')';\nreturn msg;",
55
+ "outputs": 1,
56
+ "noerr": 0,
57
+ "initialize": "",
58
+ "finalize": "",
59
+ "libs": [],
60
+ "x": 650,
61
+ "y": 160,
62
+ "wires": [
63
+ [
64
+ "bno055-debug"
65
+ ]
66
+ ]
67
+ },
68
+ {
69
+ "id": "bno055-debug",
70
+ "type": "debug",
71
+ "z": "bno055-tab",
72
+ "name": "Orientation",
73
+ "active": true,
74
+ "tosidebar": true,
75
+ "console": false,
76
+ "tostatus": false,
77
+ "complete": "payload",
78
+ "targetType": "msg",
79
+ "statusVal": "",
80
+ "statusType": "auto",
81
+ "x": 890,
82
+ "y": 160,
83
+ "wires": []
84
+ }
85
+ ]
@@ -0,0 +1,89 @@
1
+ [
2
+ {
3
+ "id": "qmi8658a-tab",
4
+ "type": "tab",
5
+ "label": "QMI8658A tilt estimator",
6
+ "disabled": false,
7
+ "info": "Reads a QMI8658A every 100 ms and estimates roll and pitch with a complementary filter: the gyro rate is integrated for the fast response and the accelerometer gravity vector (roll/pitch from atan2) corrects the slow drift. Demonstrates 6-DOF tilt estimation. The function node keeps its state in the node context, so the first message after deploy starts from the accelerometer-only angles."
8
+ },
9
+ {
10
+ "id": "qmi8658a-inject",
11
+ "type": "inject",
12
+ "z": "qmi8658a-tab",
13
+ "name": "100 ms timer",
14
+ "props": [
15
+ {
16
+ "p": "payload"
17
+ }
18
+ ],
19
+ "repeat": "0.1",
20
+ "crontab": "",
21
+ "once": false,
22
+ "onceDelay": 0.1,
23
+ "topic": "",
24
+ "payloadType": "date",
25
+ "x": 170,
26
+ "y": 160,
27
+ "wires": [
28
+ [
29
+ "qmi8658a-node"
30
+ ]
31
+ ]
32
+ },
33
+ {
34
+ "id": "qmi8658a-node",
35
+ "type": "periph-qmi8658a",
36
+ "z": "qmi8658a-tab",
37
+ "name": "QMI8658A",
38
+ "transport": "i2c",
39
+ "bus": "1",
40
+ "device": "0",
41
+ "address": "0x6B",
42
+ "accelRange": "1",
43
+ "gyroRange": "4",
44
+ "odr": "5",
45
+ "x": 400,
46
+ "y": 160,
47
+ "wires": [
48
+ [
49
+ "qmi8658a-tilt"
50
+ ]
51
+ ]
52
+ },
53
+ {
54
+ "id": "qmi8658a-tilt",
55
+ "type": "function",
56
+ "z": "qmi8658a-tab",
57
+ "name": "Complementary-filter roll/pitch",
58
+ "func": "const { accel, gyro, temperature } = msg.payload;\nconst now = Date.now();\nconst last = context.get('t') || now;\nconst dt = Math.min(0.5, (now - last) / 1000);\ncontext.set('t', now);\nconst D = 180 / Math.PI;\n// accelerometer-only angles (degrees)\nconst accRoll = Math.atan2(accel.y, accel.z) * D;\nconst accPitch = Math.atan2(-accel.x, Math.sqrt(accel.y * accel.y + accel.z * accel.z)) * D;\nlet roll = context.get('roll');\nlet pitch = context.get('pitch');\nif (roll === undefined) { roll = accRoll; pitch = accPitch; }\nconst alpha = 0.98;\nroll = alpha * (roll + gyro.x * D * dt) + (1 - alpha) * accRoll;\npitch = alpha * (pitch + gyro.y * D * dt) + (1 - alpha) * accPitch;\ncontext.set('roll', roll);\ncontext.set('pitch', pitch);\nmsg.payload = { roll, pitch, temperature };\nreturn msg;",
59
+ "outputs": 1,
60
+ "noerr": 0,
61
+ "initialize": "",
62
+ "finalize": "",
63
+ "libs": [],
64
+ "x": 700,
65
+ "y": 160,
66
+ "wires": [
67
+ [
68
+ "qmi8658a-debug"
69
+ ]
70
+ ]
71
+ },
72
+ {
73
+ "id": "qmi8658a-debug",
74
+ "type": "debug",
75
+ "z": "qmi8658a-tab",
76
+ "name": "Tilt",
77
+ "active": true,
78
+ "tosidebar": true,
79
+ "console": false,
80
+ "tostatus": false,
81
+ "complete": "payload",
82
+ "targetType": "msg",
83
+ "statusVal": "",
84
+ "statusType": "auto",
85
+ "x": 930,
86
+ "y": 160,
87
+ "wires": []
88
+ }
89
+ ]
@@ -0,0 +1,71 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-bno055', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x29' },
9
+ mode: { value: '12', required: true, validate: RED.validators.number() }
10
+ },
11
+ inputs: 1,
12
+ outputs: 1,
13
+ icon: 'bridge.svg',
14
+ label: function() {
15
+ return this.name || ('BNO055 @ ' + this.address + ' (bus ' + this.bus + ')');
16
+ }
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="periph-bno055">
21
+ <div class="form-row">
22
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
23
+ <input type="text" id="node-input-name" placeholder="BNO055">
24
+ </div>
25
+ <div class="form-row">
26
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
27
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
28
+ </div>
29
+ <div class="form-row">
30
+ <label for="node-input-address"><i class="fa fa-microchip"></i> I²C address</label>
31
+ <select id="node-input-address" style="width:160px">
32
+ <option value="0x29" selected>0x29 (COM3 = high)</option>
33
+ <option value="0x28">0x28 (COM3 = low)</option>
34
+ </select>
35
+ </div>
36
+ <div class="form-row">
37
+ <label for="node-input-mode"><i class="fa fa-cog"></i> Operation mode</label>
38
+ <select id="node-input-mode" style="width:260px">
39
+ <option value="12" selected>NDOF (9-DOF absolute orientation)</option>
40
+ <option value="11">NDOF, fast magnetometer calibration off</option>
41
+ <option value="8">IMU (relative orientation)</option>
42
+ <option value="9">COMPASS</option>
43
+ <option value="10">M4G</option>
44
+ </select>
45
+ </div>
46
+ </script>
47
+
48
+ <script type="text/html" data-help-name="periph-bno055">
49
+ <p>Reads the fused absolute orientation of a Bosch BNO055 9-axis sensor over I²C (0x29 with COM3 high,
50
+ 0x28 with COM3 low). The chip stretches the I²C clock, so the host bus must support clock stretching.
51
+ Allow up to about one second after deploying for the chip to boot.</p>
52
+ <h3>Inputs</h3>
53
+ <dl class="message-properties">
54
+ <dt>payload <span class="property-type">any</span></dt>
55
+ <dd>Any incoming message triggers one measurement.</dd>
56
+ </dl>
57
+ <h3>Outputs</h3>
58
+ <dl class="message-properties">
59
+ <dt>payload.heading <span class="property-type">number</span></dt>
60
+ <dd>Heading in rad (0 … 2π).</dd>
61
+ <dt>payload.roll <span class="property-type">number</span></dt>
62
+ <dd>Roll in rad.</dd>
63
+ <dt>payload.pitch <span class="property-type">number</span></dt>
64
+ <dd>Pitch in rad.</dd>
65
+ <dt>payload.calibration <span class="property-type">object</span></dt>
66
+ <dd><code>{ sys, gyr, acc, mag }</code>, each 0 (uncalibrated) … 3 (fully calibrated). Absolute heading is
67
+ only accurate once the magnetometer and system values reach 3.</dd>
68
+ </dl>
69
+ <h3>Configuration</h3>
70
+ <p>I²C bus number, I²C address and the operation mode (default NDOF, 100 Hz absolute orientation).</p>
71
+ </script>
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { BNO055Full } = require('periph/src/chips/imu/bno055');
6
+
7
+ function BNO055Node(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const address = parseInt(config.address, 16) || 0x29;
12
+ const connection = new I2CConnection(parseInt(config.bus), address);
13
+ node.connection = connection;
14
+ node.driver = new BNO055Full(connection);
15
+ // The driver initialises itself asynchronously (it waits for the chip to boot).
16
+ node.ready = (async () => {
17
+ await node.driver.init();
18
+ const mode = parseInt(config.mode);
19
+ if (!Number.isNaN(mode) && mode !== 12) await node.driver.setMode(mode);
20
+ })();
21
+ node.ready.catch((e) => {
22
+ node.error('BNO055 init failed: ' + e.message);
23
+ });
24
+ } catch (e) {
25
+ node.error('BNO055 init failed: ' + e.message);
26
+ }
27
+
28
+ node.on('input', async function(msg, send, done) {
29
+ if (!node.driver) {
30
+ node.error('BNO055 not initialised', msg);
31
+ done();
32
+ return;
33
+ }
34
+ try {
35
+ await node.ready;
36
+ const [heading, roll, pitch] = await node.driver.euler();
37
+ const [sys, gyr, acc, mag] = await node.driver.calibrationStatus();
38
+ msg.payload = { heading, roll, pitch, calibration: { sys, gyr, acc, mag } };
39
+ send(msg);
40
+ done();
41
+ } catch (e) {
42
+ done(e);
43
+ }
44
+ });
45
+
46
+ node.on('close', function() {
47
+ if (node.connection) node.connection.close();
48
+ });
49
+ }
50
+ RED.nodes.registerType('periph-bno055', BNO055Node);
51
+ };
@@ -0,0 +1,119 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-qmi8658a', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ transport: { value: 'i2c', required: true },
8
+ bus: { value: '1', required: true, validate: RED.validators.number() },
9
+ device: { value: '0' },
10
+ address: { value: '0x6B' },
11
+ accelRange: { value: '0', required: true, validate: RED.validators.number() },
12
+ gyroRange: { value: '4', required: true, validate: RED.validators.number() },
13
+ odr: { value: '5', required: true, validate: RED.validators.number() }
14
+ },
15
+ inputs: 1,
16
+ outputs: 1,
17
+ icon: 'bridge.svg',
18
+ label: function() {
19
+ return this.name || ('QMI8658A ' + (this.transport === 'spi' ? 'SPI ' + this.bus + '.' + this.device
20
+ : '@ ' + this.address + ' (bus ' + this.bus + ')'));
21
+ },
22
+ oneditprepare: function() {
23
+ function toggle() {
24
+ var spi = $('#node-input-transport').val() === 'spi';
25
+ $('.qmi-i2c').toggle(!spi);
26
+ $('.qmi-spi').toggle(spi);
27
+ }
28
+ $('#node-input-transport').on('change', toggle);
29
+ toggle();
30
+ }
31
+ });
32
+ </script>
33
+
34
+ <script type="text/html" data-template-name="periph-qmi8658a">
35
+ <div class="form-row">
36
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
37
+ <input type="text" id="node-input-name" placeholder="QMI8658A">
38
+ </div>
39
+ <div class="form-row">
40
+ <label for="node-input-transport"><i class="fa fa-exchange"></i> Transport</label>
41
+ <select id="node-input-transport" style="width:120px">
42
+ <option value="i2c" selected>I²C</option>
43
+ <option value="spi">SPI</option>
44
+ </select>
45
+ </div>
46
+ <div class="form-row">
47
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> Bus</label>
48
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N or /dev/spidevN.M)
49
+ </div>
50
+ <div class="form-row qmi-spi">
51
+ <label for="node-input-device"><i class="fa fa-microchip"></i> SPI device</label>
52
+ <input type="number" id="node-input-device" min="0" style="width:80px"> &nbsp;(chip select N in /dev/spidevB.N)
53
+ </div>
54
+ <div class="form-row qmi-i2c">
55
+ <label for="node-input-address"><i class="fa fa-microchip"></i> I²C address</label>
56
+ <select id="node-input-address" style="width:160px">
57
+ <option value="0x6B" selected>0x6B (SA0 = GND)</option>
58
+ <option value="0x6A">0x6A (SA0 = VDDIO)</option>
59
+ </select>
60
+ </div>
61
+ <div class="form-row">
62
+ <label for="node-input-accelRange"><i class="fa fa-cog"></i> Accelerometer range</label>
63
+ <select id="node-input-accelRange" style="width:120px">
64
+ <option value="0" selected>±2 g</option>
65
+ <option value="1">±4 g</option>
66
+ <option value="2">±8 g</option>
67
+ <option value="3">±16 g</option>
68
+ </select>
69
+ </div>
70
+ <div class="form-row">
71
+ <label for="node-input-gyroRange"><i class="fa fa-cog"></i> Gyroscope range</label>
72
+ <select id="node-input-gyroRange" style="width:120px">
73
+ <option value="0">±16 dps</option>
74
+ <option value="1">±32 dps</option>
75
+ <option value="2">±64 dps</option>
76
+ <option value="3">±128 dps</option>
77
+ <option value="4" selected>±256 dps</option>
78
+ <option value="5">±512 dps</option>
79
+ <option value="6">±1024 dps</option>
80
+ <option value="7">±2048 dps</option>
81
+ </select>
82
+ </div>
83
+ <div class="form-row">
84
+ <label for="node-input-odr"><i class="fa fa-clock-o"></i> Output data rate</label>
85
+ <select id="node-input-odr" style="width:120px">
86
+ <option value="8">28 Hz</option>
87
+ <option value="7">56 Hz</option>
88
+ <option value="6">112 Hz</option>
89
+ <option value="5" selected>224 Hz</option>
90
+ <option value="4">448 Hz</option>
91
+ <option value="3">897 Hz</option>
92
+ </select>
93
+ </div>
94
+ </script>
95
+
96
+ <script type="text/html" data-help-name="periph-qmi8658a">
97
+ <p>Reads acceleration, angular rate and die temperature from a QST QMI8658A 6-axis IMU over I²C (0x6B with
98
+ SA0 = GND, 0x6A with SA0 = VDDIO) or 4-wire SPI. The three values come from one 14-byte burst, so they belong
99
+ to the same sample.</p>
100
+ <h3>Inputs</h3>
101
+ <dl class="message-properties">
102
+ <dt>payload <span class="property-type">any</span></dt>
103
+ <dd>Any incoming message triggers one coherent measurement.</dd>
104
+ </dl>
105
+ <h3>Outputs</h3>
106
+ <dl class="message-properties">
107
+ <dt>payload.accel <span class="property-type">object</span></dt>
108
+ <dd><code>{ x, y, z }</code> acceleration in m/s².</dd>
109
+ <dt>payload.gyro <span class="property-type">object</span></dt>
110
+ <dd><code>{ x, y, z }</code> angular rate in rad/s.</dd>
111
+ <dt>payload.temperature <span class="property-type">number</span></dt>
112
+ <dd>Die temperature in °C (refreshed at 8 Hz).</dd>
113
+ </dl>
114
+ <h3>Configuration</h3>
115
+ <p>Transport (I²C or SPI), the I²C bus number or SPI bus and chip select, the I²C address, the accelerometer
116
+ range (±2/±4/±8/±16 g), the gyroscope range (±16 … ±2048 dps) and the output data rate (28 … 897 Hz, shared by
117
+ both sensors). Allow ≈165 ms after deploying before the first message — the gyroscope needs that long to
118
+ turn on.</p>
119
+ </script>
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { SPIConnection } = require('periph/src/connection/spi');
6
+ const { QMI8658AFull } = require('periph/src/chips/imu/qmi8658a');
7
+
8
+ function QMI8658ANode(config) {
9
+ RED.nodes.createNode(this, config);
10
+ const node = this;
11
+ try {
12
+ let connection;
13
+ if (config.transport === 'spi') {
14
+ // 4-wire SPI mode 3, read bit 0x80, no multi-byte bit (burst needs CTRL1.ADDR_AI, set by the driver).
15
+ connection = new SPIConnection(parseInt(config.bus), parseInt(config.device) || 0,
16
+ { mode: 3, readBit: 0x80, multiByteBit: null, maxSpeedHz: 10000000 });
17
+ } else {
18
+ const address = parseInt(config.address, 16) || 0x6B;
19
+ connection = new I2CConnection(parseInt(config.bus), address);
20
+ }
21
+ node.connection = connection;
22
+ node.driver = new QMI8658AFull(connection);
23
+ // The driver initialises itself asynchronously; configure it once ready.
24
+ node.ready = (async () => {
25
+ await node.driver.init();
26
+ const odr = parseInt(config.odr);
27
+ const code = Number.isNaN(odr) ? 5 : odr;
28
+ await node.driver.configureAccel(parseInt(config.accelRange) || 0, code);
29
+ await node.driver.configureGyro(Number.isNaN(parseInt(config.gyroRange)) ? 4 : parseInt(config.gyroRange), code);
30
+ await new Promise((r) => setTimeout(r, 165));
31
+ })();
32
+ node.ready.catch((e) => {
33
+ node.error('QMI8658A init failed: ' + e.message);
34
+ });
35
+ } catch (e) {
36
+ node.error('QMI8658A init failed: ' + e.message);
37
+ }
38
+
39
+ node.on('input', async function(msg, send, done) {
40
+ if (!node.driver) {
41
+ node.error('QMI8658A not initialised', msg);
42
+ done();
43
+ return;
44
+ }
45
+ try {
46
+ await node.ready;
47
+ const [accel, gyro, temperature] = await node.driver.readAll();
48
+ msg.payload = {
49
+ accel: { x: accel[0], y: accel[1], z: accel[2] },
50
+ gyro: { x: gyro[0], y: gyro[1], z: gyro[2] },
51
+ temperature,
52
+ };
53
+ send(msg);
54
+ done();
55
+ } catch (e) {
56
+ done(e);
57
+ }
58
+ });
59
+
60
+ node.on('close', function() {
61
+ if (node.connection) node.connection.close();
62
+ });
63
+ }
64
+ RED.nodes.registerType('periph-qmi8658a', QMI8658ANode);
65
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-imu",
3
- "version": "1.3.3",
3
+ "version": "1.5.0",
4
4
  "description": "Node-RED nodes for IMU chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -12,10 +12,12 @@
12
12
  ],
13
13
  "node-red": {
14
14
  "nodes": {
15
+ "bno055": "nodes/bno055/bno055.js",
15
16
  "icm20948": "nodes/icm20948/icm20948.js",
16
17
  "mpu6050": "nodes/mpu6050/mpu6050.js",
17
18
  "mpu9250": "nodes/mpu9250/mpu9250.js",
18
- "mpu9255": "nodes/mpu9255/mpu9255.js"
19
+ "mpu9255": "nodes/mpu9255/mpu9255.js",
20
+ "qmi8658a": "nodes/qmi8658a/qmi8658a.js"
19
21
  }
20
22
  },
21
23
  "dependencies": {