node-red-contrib-periph-imu 1.3.2 → 1.3.3

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,6 +16,7 @@ npm install node-red-contrib-periph-imu
16
16
 
17
17
  | Node | Kind | Description |
18
18
  |------|------|-------------|
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. |
19
20
  | `mpu6050-device` | config | I²C bus and address for a MPU6050 |
20
21
  | `mpu6050` | input | Reads 3-axis acceleration and 3-axis angular rate from an MPU6050 IMU over I²C. |
21
22
 
@@ -0,0 +1,87 @@
1
+ [
2
+ {
3
+ "id": "icm20948-tab",
4
+ "type": "tab",
5
+ "label": "ICM-20948 compass",
6
+ "disabled": false,
7
+ "info": "Reads an ICM-20948 every 100 ms and computes roll, pitch and a tilt-compensated heading from the acceleration and magnetic field — a 9-axis compass. The magnetometer frame is rotated 180° about X relative to the accelerometer frame, so (mx, -my, -mz) is used before tilt compensation."
8
+ },
9
+ {
10
+ "id": "icm20948-inject",
11
+ "type": "inject",
12
+ "z": "icm20948-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
+ "icm20948-node"
30
+ ]
31
+ ]
32
+ },
33
+ {
34
+ "id": "icm20948-node",
35
+ "type": "periph-icm20948",
36
+ "z": "icm20948-tab",
37
+ "name": "ICM-20948",
38
+ "bus": "1",
39
+ "address": "0x68",
40
+ "accelRange": "1",
41
+ "gyroRange": "1",
42
+ "mag": true,
43
+ "x": 400,
44
+ "y": 160,
45
+ "wires": [
46
+ [
47
+ "icm20948-compass"
48
+ ]
49
+ ]
50
+ },
51
+ {
52
+ "id": "icm20948-compass",
53
+ "type": "function",
54
+ "z": "icm20948-tab",
55
+ "name": "Roll, pitch, tilt-compensated heading",
56
+ "func": "const { accel, gyro, mag } = msg.payload;\nconst roll = Math.atan2(accel.y, accel.z);\nconst pitch = Math.atan2(-accel.x, Math.sqrt(accel.y * accel.y + accel.z * accel.z));\n// map the magnetometer frame into the accelerometer frame\nconst bx = mag.x, by = -mag.y, bz = -mag.z;\nconst xh = bx * Math.cos(pitch) + bz * Math.sin(pitch);\nconst yh = bx * Math.sin(roll) * Math.sin(pitch) + by * Math.cos(roll) - bz * Math.sin(roll) * Math.cos(pitch);\nconst heading = (Math.atan2(-yh, xh) * 180 / Math.PI + 360) % 360;\nmsg.payload = {\n roll: roll * 180 / Math.PI,\n pitch: pitch * 180 / Math.PI,\n heading,\n gyroMagnitude: Math.sqrt(gyro.x * gyro.x + gyro.y * gyro.y + gyro.z * gyro.z)\n};\nreturn msg;",
57
+ "outputs": 1,
58
+ "noerr": 0,
59
+ "initialize": "",
60
+ "finalize": "",
61
+ "libs": [],
62
+ "x": 690,
63
+ "y": 160,
64
+ "wires": [
65
+ [
66
+ "icm20948-debug"
67
+ ]
68
+ ]
69
+ },
70
+ {
71
+ "id": "icm20948-debug",
72
+ "type": "debug",
73
+ "z": "icm20948-tab",
74
+ "name": "Compass",
75
+ "active": true,
76
+ "tosidebar": true,
77
+ "console": false,
78
+ "tostatus": false,
79
+ "complete": "payload",
80
+ "targetType": "msg",
81
+ "statusVal": "",
82
+ "statusType": "auto",
83
+ "x": 940,
84
+ "y": 160,
85
+ "wires": []
86
+ }
87
+ ]
@@ -0,0 +1,88 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-icm20948', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x68', required: true },
9
+ accelRange: { value: '0', required: true, validate: RED.validators.number() },
10
+ gyroRange: { value: '0', required: true, validate: RED.validators.number() },
11
+ mag: { value: true }
12
+ },
13
+ inputs: 1,
14
+ outputs: 1,
15
+ icon: 'bridge.svg',
16
+ label: function() {
17
+ return this.name || ('ICM-20948 @ ' + this.address + ' (bus ' + this.bus + ')');
18
+ }
19
+ });
20
+ </script>
21
+
22
+ <script type="text/html" data-template-name="periph-icm20948">
23
+ <div class="form-row">
24
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
25
+ <input type="text" id="node-input-name" placeholder="ICM-20948">
26
+ </div>
27
+ <div class="form-row">
28
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
29
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
30
+ </div>
31
+ <div class="form-row">
32
+ <label for="node-input-address"><i class="fa fa-microchip"></i> I²C address</label>
33
+ <select id="node-input-address" style="width:160px">
34
+ <option value="0x68" selected>0x68 (AD0 = GND)</option>
35
+ <option value="0x69">0x69 (AD0 = VDDIO)</option>
36
+ </select>
37
+ </div>
38
+ <div class="form-row">
39
+ <label for="node-input-accelRange"><i class="fa fa-cog"></i> Accelerometer range</label>
40
+ <select id="node-input-accelRange" style="width:120px">
41
+ <option value="0" selected>±2 g</option>
42
+ <option value="1">±4 g</option>
43
+ <option value="2">±8 g</option>
44
+ <option value="3">±16 g</option>
45
+ </select>
46
+ </div>
47
+ <div class="form-row">
48
+ <label for="node-input-gyroRange"><i class="fa fa-cog"></i> Gyroscope range</label>
49
+ <select id="node-input-gyroRange" style="width:120px">
50
+ <option value="0" selected>±250 dps</option>
51
+ <option value="1">±500 dps</option>
52
+ <option value="2">±1000 dps</option>
53
+ <option value="3">±2000 dps</option>
54
+ </select>
55
+ </div>
56
+ <div class="form-row">
57
+ <label for="node-input-mag"><i class="fa fa-magnet"></i> Magnetometer</label>
58
+ <input type="checkbox" id="node-input-mag" style="width:auto">
59
+ </div>
60
+ </script>
61
+
62
+ <script type="text/html" data-help-name="periph-icm20948">
63
+ <p>Reads acceleration, angular rate, die temperature and (optionally) the magnetic field from a TDK InvenSense
64
+ ICM-20948 9-axis MotionTracking device over I²C. The AK09916 magnetometer is read through the chip's own
65
+ I²C master, so only one I²C address is needed. VDDIO must be 1.71–1.95 V.</p>
66
+ <h3>Inputs</h3>
67
+ <dl class="message-properties">
68
+ <dt>payload <span class="property-type">any</span></dt>
69
+ <dd>Any incoming message triggers one coherent measurement.</dd>
70
+ </dl>
71
+ <h3>Outputs</h3>
72
+ <dl class="message-properties">
73
+ <dt>payload.accel <span class="property-type">object</span></dt>
74
+ <dd><code>{ x, y, z }</code> acceleration in m/s².</dd>
75
+ <dt>payload.gyro <span class="property-type">object</span></dt>
76
+ <dd><code>{ x, y, z }</code> angular rate in rad/s.</dd>
77
+ <dt>payload.mag <span class="property-type">object</span></dt>
78
+ <dd><code>{ x, y, z }</code> magnetic field in µT, as the chip reports it. Present only when the magnetometer
79
+ is enabled. The magnetometer frame is rotated 180° about X relative to the accelerometer frame; map it with
80
+ <code>(mx, -my, -mz)</code> before tilt compensation.</dd>
81
+ <dt>payload.temperature <span class="property-type">number</span></dt>
82
+ <dd>Die temperature in °C.</dd>
83
+ </dl>
84
+ <h3>Configuration</h3>
85
+ <p>I²C bus number, I²C address (<code>0x68</code> with AD0 = GND, <code>0x69</code> with AD0 = VDDIO),
86
+ accelerometer range (±2/±4/±8/±16 g), gyroscope range (±250/±500/±1000/±2000 dps) and whether to enable the
87
+ magnetometer.</p>
88
+ </script>
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { ICM20948Full } = require('periph/src/chips/imu/icm20948');
6
+
7
+ function ICM20948Node(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const address = parseInt(config.address, 16) || 0x68;
12
+ const connection = new I2CConnection(parseInt(config.bus), address);
13
+ node.connection = connection;
14
+ node.driver = new ICM20948Full(connection);
15
+ // The driver initialises itself asynchronously; configure it once ready.
16
+ node.ready = (async () => {
17
+ await node.driver.init();
18
+ await node.driver.configureAccel(parseInt(config.accelRange) || 0);
19
+ await node.driver.configureGyro(parseInt(config.gyroRange) || 0);
20
+ if (config.mag) await node.driver.enableMag();
21
+ })();
22
+ node.ready.catch((e) => {
23
+ node.error('ICM20948 init failed: ' + e.message);
24
+ });
25
+ } catch (e) {
26
+ node.error('ICM20948 init failed: ' + e.message);
27
+ }
28
+
29
+ node.on('input', async function(msg, send, done) {
30
+ if (!node.driver) {
31
+ node.error('ICM20948 not initialised', msg);
32
+ done();
33
+ return;
34
+ }
35
+ try {
36
+ await node.ready;
37
+ const [accel, gyro, temperature] = await node.driver.readAll();
38
+ const payload = {
39
+ accel: { x: accel[0], y: accel[1], z: accel[2] },
40
+ gyro: { x: gyro[0], y: gyro[1], z: gyro[2] },
41
+ temperature,
42
+ };
43
+ if (config.mag) {
44
+ const [x, y, z] = await node.driver.mag();
45
+ payload.mag = { x, y, z };
46
+ }
47
+ msg.payload = payload;
48
+ send(msg);
49
+ done();
50
+ } catch (e) {
51
+ done(e);
52
+ }
53
+ });
54
+
55
+ node.on('close', function() {
56
+ if (node.connection) node.connection.close();
57
+ });
58
+ }
59
+ RED.nodes.registerType('periph-icm20948', ICM20948Node);
60
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-imu",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Node-RED nodes for IMU chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -12,6 +12,7 @@
12
12
  ],
13
13
  "node-red": {
14
14
  "nodes": {
15
+ "icm20948": "nodes/icm20948/icm20948.js",
15
16
  "mpu6050": "nodes/mpu6050/mpu6050.js",
16
17
  "mpu9250": "nodes/mpu9250/mpu9250.js",
17
18
  "mpu9255": "nodes/mpu9255/mpu9255.js"