node-red-contrib-periph-imu 1.3.3 → 1.4.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
@@ -19,6 +19,7 @@ npm install node-red-contrib-periph-imu
19
19
  | `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
20
  | `mpu6050-device` | config | I²C bus and address for a MPU6050 |
21
21
  | `mpu6050` | input | Reads 3-axis acceleration and 3-axis angular rate from an MPU6050 IMU over I²C. |
22
+ | `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
23
 
23
24
  ## Links
24
25
 
@@ -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,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.4.0",
4
4
  "description": "Node-RED nodes for IMU chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -15,7 +15,8 @@
15
15
  "icm20948": "nodes/icm20948/icm20948.js",
16
16
  "mpu6050": "nodes/mpu6050/mpu6050.js",
17
17
  "mpu9250": "nodes/mpu9250/mpu9250.js",
18
- "mpu9255": "nodes/mpu9255/mpu9255.js"
18
+ "mpu9255": "nodes/mpu9255/mpu9255.js",
19
+ "qmi8658a": "nodes/qmi8658a/qmi8658a.js"
19
20
  }
20
21
  },
21
22
  "dependencies": {