node-red-contrib-periph-motor 1.3.2 → 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 +5 -0
- package/examples/drv2605/demo.json +162 -0
- package/examples/tmc2130/demo.json +114 -0
- package/examples/tmc2208/demo.json +151 -0
- package/examples/tmc2209/demo.json +151 -0
- package/examples/tmc5160/demo.json +26 -0
- package/nodes/drv2605/drv2605.html +79 -0
- package/nodes/drv2605/drv2605.js +79 -0
- package/nodes/tmc2130/tmc2130.html +116 -0
- package/nodes/tmc2130/tmc2130.js +106 -0
- package/nodes/tmc2208/tmc2208.html +92 -0
- package/nodes/tmc2208/tmc2208.js +106 -0
- package/nodes/tmc2209/tmc2209.html +106 -0
- package/nodes/tmc2209/tmc2209.js +119 -0
- package/nodes/tmc5160/tmc5160.html +95 -0
- package/nodes/tmc5160/tmc5160.js +136 -0
- package/package.json +7 -2
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-drv2605', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
actuator: { value: 'erm', required: true },
|
|
9
|
+
library: { value: 'A', required: true }
|
|
10
|
+
},
|
|
11
|
+
inputs: 1,
|
|
12
|
+
outputs: 1,
|
|
13
|
+
icon: 'font-awesome/fa-cog',
|
|
14
|
+
label: function() { return this.name || 'DRV2605'; },
|
|
15
|
+
paletteLabel: 'DRV2605'
|
|
16
|
+
});
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script type="text/html" data-template-name="periph-drv2605">
|
|
20
|
+
<div class="form-row">
|
|
21
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
22
|
+
<input type="text" id="node-input-name" placeholder="DRV2605">
|
|
23
|
+
</div>
|
|
24
|
+
<div class="form-row">
|
|
25
|
+
<label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
26
|
+
<input type="number" id="node-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
27
|
+
</div>
|
|
28
|
+
<div class="form-row">
|
|
29
|
+
<label for="node-input-actuator"><i class="fa fa-bolt"></i> Actuator</label>
|
|
30
|
+
<select id="node-input-actuator" style="width:120px">
|
|
31
|
+
<option value="erm">ERM</option>
|
|
32
|
+
<option value="lra">LRA</option>
|
|
33
|
+
</select>
|
|
34
|
+
</div>
|
|
35
|
+
<div class="form-row">
|
|
36
|
+
<label for="node-input-library"><i class="fa fa-book"></i> Library</label>
|
|
37
|
+
<select id="node-input-library" style="width:120px">
|
|
38
|
+
<option value="A">A (ERM)</option>
|
|
39
|
+
<option value="B">B (ERM)</option>
|
|
40
|
+
<option value="C">C (ERM)</option>
|
|
41
|
+
<option value="D">D (ERM)</option>
|
|
42
|
+
<option value="E">E (ERM)</option>
|
|
43
|
+
<option value="LRA">LRA</option>
|
|
44
|
+
</select>
|
|
45
|
+
</div>
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<script type="text/html" data-help-name="periph-drv2605">
|
|
49
|
+
<p>Plays haptic effects on an ERM or LRA vibration motor through a DRV2605 haptic driver over I²C (fixed address 0x5A). The EN pin must be high.</p>
|
|
50
|
+
|
|
51
|
+
<h3>Inputs</h3>
|
|
52
|
+
<dl class="message-properties">
|
|
53
|
+
<dt>payload.effect <span class="property-type">number</span></dt>
|
|
54
|
+
<dd>Plays one ROM effect (1–123). A bare number <code>msg.payload</code> does the same.</dd>
|
|
55
|
+
<dt>payload.sequence <span class="property-type">array</span></dt>
|
|
56
|
+
<dd>Plays up to 8 steps: a number is a ROM effect, <code>["wait", ms]</code> is a delay of 0–1270 ms (10 ms steps), e.g. <code>[1, ["wait", 100], 10]</code>.</dd>
|
|
57
|
+
<dt>payload.rtp <span class="property-type">number</span></dt>
|
|
58
|
+
<dd>Real-time amplitude 0.0–1.0; stays on until stopped.</dd>
|
|
59
|
+
<dt>payload.stop <span class="property-type">boolean</span></dt>
|
|
60
|
+
<dd><code>true</code> stops playback (also leaves real-time playback).</dd>
|
|
61
|
+
<dt>payload.status <span class="property-type">boolean</span></dt>
|
|
62
|
+
<dd><code>true</code> reads the chip status. Note this clears the latched diagnostic and over-temperature flags.</dd>
|
|
63
|
+
</dl>
|
|
64
|
+
|
|
65
|
+
<h3>Outputs</h3>
|
|
66
|
+
<dl class="message-properties">
|
|
67
|
+
<dt>payload.ok <span class="property-type">boolean</span></dt>
|
|
68
|
+
<dd><code>true</code> after an effect, sequence, rtp or stop command.</dd>
|
|
69
|
+
<dt>payload.device_id <span class="property-type">number</span></dt>
|
|
70
|
+
<dd>DEVICE_ID (3 for the DRV2605) — status replies only.</dd>
|
|
71
|
+
<dt>payload.over_temp / over_current <span class="property-type">boolean</span></dt>
|
|
72
|
+
<dd>Latched overtemperature / overcurrent flags — status replies only.</dd>
|
|
73
|
+
<dt>payload.supply_voltage <span class="property-type">number</span></dt>
|
|
74
|
+
<dd>Supply voltage in V; only valid while an effect is playing — status replies only.</dd>
|
|
75
|
+
</dl>
|
|
76
|
+
|
|
77
|
+
<h3>Configuration</h3>
|
|
78
|
+
<p>Set the Linux I²C bus number, the actuator type (ERM or LRA) and the ROM library (A–E for an ERM, LRA for an LRA). The I²C address is fixed at 0x5A. Playback is stopped when the node is closed.</p>
|
|
79
|
+
</script>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { DRV2605Full } = require('periph/src/chips/motor/drv2605');
|
|
6
|
+
|
|
7
|
+
const LIBRARIES = { A: 1, B: 2, C: 3, D: 4, E: 5, LRA: 6 };
|
|
8
|
+
|
|
9
|
+
function DRV2605Node(config) {
|
|
10
|
+
RED.nodes.createNode(this, config);
|
|
11
|
+
const node = this;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const lra = config.actuator === 'lra';
|
|
15
|
+
const connection = new I2CConnection(parseInt(config.bus, 10), DRV2605Full.I2C_ADDRESS);
|
|
16
|
+
node.driver = new DRV2605Full(connection, lra);
|
|
17
|
+
node.connection = connection;
|
|
18
|
+
node.ready = node.driver.init()
|
|
19
|
+
.then(() => node.driver.setLibrary(LIBRARIES[config.library] || (lra ? 6 : 1)))
|
|
20
|
+
.catch((e) => { node.driver = null; node.error('DRV2605 init failed: ' + e.message); });
|
|
21
|
+
} catch (e) {
|
|
22
|
+
node.error('DRV2605 init failed: ' + e.message);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
node.on('input', async function(msg, send, done) {
|
|
26
|
+
await node.ready;
|
|
27
|
+
if (!node.driver) { done(); return; }
|
|
28
|
+
try {
|
|
29
|
+
const p = msg.payload;
|
|
30
|
+
if (typeof p === 'number') {
|
|
31
|
+
await node.driver.playEffect(p);
|
|
32
|
+
msg.payload = { ok: true };
|
|
33
|
+
} else if (p && typeof p === 'object') {
|
|
34
|
+
if (typeof p.effect === 'number') {
|
|
35
|
+
await node.driver.playEffect(p.effect);
|
|
36
|
+
msg.payload = { ok: true };
|
|
37
|
+
} else if (Array.isArray(p.sequence)) {
|
|
38
|
+
await node.driver.playSequence(p.sequence);
|
|
39
|
+
msg.payload = { ok: true };
|
|
40
|
+
} else if (typeof p.rtp === 'number') {
|
|
41
|
+
await node.driver.rtpLevel(p.rtp);
|
|
42
|
+
msg.payload = { ok: true };
|
|
43
|
+
} else if (p.stop === true) {
|
|
44
|
+
await node.driver.stop();
|
|
45
|
+
msg.payload = { ok: true };
|
|
46
|
+
} else if (p.status === true) {
|
|
47
|
+
const device_id = await node.driver.readDeviceId();
|
|
48
|
+
const st = await node.driver.readStatus();
|
|
49
|
+
const supply_voltage = await node.driver.readSupplyVoltage();
|
|
50
|
+
msg.payload = { device_id, over_temp: st.overTemp, over_current: st.overCurrent, supply_voltage };
|
|
51
|
+
} else {
|
|
52
|
+
done(); return;
|
|
53
|
+
}
|
|
54
|
+
send(msg);
|
|
55
|
+
done();
|
|
56
|
+
return;
|
|
57
|
+
} else {
|
|
58
|
+
done(); return;
|
|
59
|
+
}
|
|
60
|
+
send(msg);
|
|
61
|
+
done();
|
|
62
|
+
} catch (e) {
|
|
63
|
+
done(e);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
node.on('close', async function(removed, done) {
|
|
68
|
+
try {
|
|
69
|
+
if (node.driver) await node.driver.stop();
|
|
70
|
+
if (node.connection) await node.connection.close();
|
|
71
|
+
} catch (e) {
|
|
72
|
+
// bus may already be gone; nothing more to do on close
|
|
73
|
+
} finally {
|
|
74
|
+
done();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
RED.nodes.registerType('periph-drv2605', DRV2605Node);
|
|
79
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-tmc2130', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '0', required: true, validate: RED.validators.number() },
|
|
8
|
+
device: { value: '0', required: true, validate: RED.validators.number() },
|
|
9
|
+
speedHz: { value: '1000000', validate: RED.validators.number() },
|
|
10
|
+
stepGpio: { value: '0:27', required: true },
|
|
11
|
+
dirGpio: { value: '0:22', required: true },
|
|
12
|
+
enGpio: { value: '' },
|
|
13
|
+
rsense: { value: '0.11', required: true, validate: RED.validators.number() },
|
|
14
|
+
current: { value: '0.5', validate: RED.validators.number() },
|
|
15
|
+
microsteps: { value: '16' },
|
|
16
|
+
speed: { value: '200', validate: RED.validators.number() }
|
|
17
|
+
},
|
|
18
|
+
inputs: 1,
|
|
19
|
+
outputs: 1,
|
|
20
|
+
icon: 'font-awesome/fa-cog',
|
|
21
|
+
label: function() { return this.name || 'TMC2130'; },
|
|
22
|
+
paletteLabel: 'TMC2130'
|
|
23
|
+
});
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<script type="text/html" data-template-name="periph-tmc2130">
|
|
27
|
+
<div class="form-row">
|
|
28
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
29
|
+
<input type="text" id="node-input-name" placeholder="TMC2130">
|
|
30
|
+
</div>
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label for="node-input-bus"><i class="fa fa-plug"></i> SPI bus</label>
|
|
33
|
+
<input type="number" id="node-input-bus" min="0" style="width:100px">
|
|
34
|
+
</div>
|
|
35
|
+
<div class="form-row">
|
|
36
|
+
<label for="node-input-device"><i class="fa fa-plug"></i> SPI device (CS)</label>
|
|
37
|
+
<input type="number" id="node-input-device" min="0" style="width:100px">
|
|
38
|
+
</div>
|
|
39
|
+
<div class="form-row">
|
|
40
|
+
<label for="node-input-speedHz"><i class="fa fa-tachometer"></i> SPI clock (Hz)</label>
|
|
41
|
+
<input type="number" id="node-input-speedHz" min="100000" max="4000000" style="width:120px">
|
|
42
|
+
</div>
|
|
43
|
+
<div class="form-row">
|
|
44
|
+
<label for="node-input-stepGpio"><i class="fa fa-microchip"></i> STEP GPIO</label>
|
|
45
|
+
<input type="text" id="node-input-stepGpio" placeholder="e.g. 0:27" style="width:140px">
|
|
46
|
+
</div>
|
|
47
|
+
<div class="form-row">
|
|
48
|
+
<label for="node-input-dirGpio"><i class="fa fa-microchip"></i> DIR GPIO</label>
|
|
49
|
+
<input type="text" id="node-input-dirGpio" placeholder="e.g. 0:22" style="width:140px">
|
|
50
|
+
</div>
|
|
51
|
+
<div class="form-row">
|
|
52
|
+
<label for="node-input-enGpio"><i class="fa fa-microchip"></i> ENN GPIO (optional)</label>
|
|
53
|
+
<input type="text" id="node-input-enGpio" placeholder="not wired, e.g. 0:17" style="width:140px">
|
|
54
|
+
</div>
|
|
55
|
+
<div class="form-row">
|
|
56
|
+
<label for="node-input-rsense"><i class="fa fa-bolt"></i> Sense resistor (Ω)</label>
|
|
57
|
+
<input type="number" id="node-input-rsense" min="0.01" step="0.01" style="width:100px">
|
|
58
|
+
</div>
|
|
59
|
+
<div class="form-row">
|
|
60
|
+
<label for="node-input-current"><i class="fa fa-bolt"></i> Default current (A RMS)</label>
|
|
61
|
+
<input type="number" id="node-input-current" min="0" max="1.4" step="0.05" style="width:100px">
|
|
62
|
+
</div>
|
|
63
|
+
<div class="form-row">
|
|
64
|
+
<label for="node-input-microsteps"><i class="fa fa-th"></i> Default microsteps</label>
|
|
65
|
+
<select id="node-input-microsteps" style="width:100px">
|
|
66
|
+
<option value="1">1</option><option value="2">2</option><option value="4">4</option>
|
|
67
|
+
<option value="8">8</option><option value="16">16</option><option value="32">32</option>
|
|
68
|
+
<option value="64">64</option><option value="128">128</option><option value="256">256</option>
|
|
69
|
+
</select>
|
|
70
|
+
</div>
|
|
71
|
+
<div class="form-row">
|
|
72
|
+
<label for="node-input-speed"><i class="fa fa-forward"></i> Default speed (full steps/s)</label>
|
|
73
|
+
<input type="number" id="node-input-speed" min="1" style="width:100px">
|
|
74
|
+
</div>
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<script type="text/html" data-help-name="periph-tmc2130">
|
|
78
|
+
<p>Drives a two-phase bipolar stepper motor through a Trinamic TMC2130 over SPI (Mode 3). The chip has no internal step generator, so the node pulses the STEP and DIR GPIOs; moves are blocking.</p>
|
|
79
|
+
|
|
80
|
+
<h3>Inputs</h3>
|
|
81
|
+
<dl class="message-properties">
|
|
82
|
+
<dt>payload.move <span class="property-type">number</span></dt>
|
|
83
|
+
<dd>Full steps to move; negative = reverse. Blocks until finished.</dd>
|
|
84
|
+
<dt>payload.speed <span class="property-type">number</span></dt>
|
|
85
|
+
<dd>Speed in full steps per second for <code>move</code>; defaults to the configured speed.</dd>
|
|
86
|
+
<dt>payload.current <span class="property-type">number</span></dt>
|
|
87
|
+
<dd>Run current in A RMS (at most 1.4); hold current becomes one third of it.</dd>
|
|
88
|
+
<dt>payload.microsteps <span class="property-type">number</span></dt>
|
|
89
|
+
<dd>Microstep resolution: 1, 2, 4, 8, 16, 32, 64, 128 or 256.</dd>
|
|
90
|
+
<dt>payload.stall_threshold <span class="property-type">number</span></dt>
|
|
91
|
+
<dd>StallGuard2 threshold <code>sgt</code> −64…63; lower is more sensitive.</dd>
|
|
92
|
+
<dt>payload.spreadcycle <span class="property-type">boolean</span></dt>
|
|
93
|
+
<dd><code>true</code> selects SpreadCycle only (needed for StallGuard2), <code>false</code> StealthChop.</dd>
|
|
94
|
+
<dt>payload.enable <span class="property-type">boolean</span></dt>
|
|
95
|
+
<dd><code>true</code> switches the power stage on, <code>false</code> off (the motor freewheels).</dd>
|
|
96
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
97
|
+
<dd>Any other message polls the driver status.</dd>
|
|
98
|
+
</dl>
|
|
99
|
+
|
|
100
|
+
<h3>Outputs</h3>
|
|
101
|
+
<dl class="message-properties">
|
|
102
|
+
<dt>payload.standstill <span class="property-type">boolean</span></dt>
|
|
103
|
+
<dd>The motor is at standstill.</dd>
|
|
104
|
+
<dt>payload.fault <span class="property-type">number</span></dt>
|
|
105
|
+
<dd>Fault bitmask: 1 over-temperature pre-warning, 2 over-temperature, 4 short to GND, 16 open load (informative only); <code>0</code> = none.</dd>
|
|
106
|
+
<dt>payload.cs_actual <span class="property-type">number</span></dt>
|
|
107
|
+
<dd>Actual current scale 0–31.</dd>
|
|
108
|
+
<dt>payload.sg_result <span class="property-type">number</span></dt>
|
|
109
|
+
<dd>StallGuard2 result 0–1023 (0 = highest load).</dd>
|
|
110
|
+
<dt>payload.tstep, stallguard, otpw, ot</dt>
|
|
111
|
+
<dd>Status polls only: time between microsteps, stall flag, over-temperature pre-warning and shutdown flags.</dd>
|
|
112
|
+
</dl>
|
|
113
|
+
|
|
114
|
+
<h3>Configuration</h3>
|
|
115
|
+
<p>Connect the chip to the SPI bus (SPI_MODE pin high, SCK idles high) and set the bus and device numbers (<code>/dev/spidevB.D</code>). STEP and DIR GPIOs are given as <code>chip:line</code> (e.g. <code>0:27</code>, needs the <code>opengpio</code> package); the optional ENN GPIO drives the enable pin, otherwise the node switches the power stage through the chopper (<code>TOFF</code>). Set the external sense resistor value (0.11 Ω on common boards) and the default current, microsteps and speed applied at start. The driver is disabled when the node is closed.</p>
|
|
116
|
+
</script>
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { SPIConnection } = require('periph/src/connection/spi');
|
|
5
|
+
const { TMC2130Full } = require('periph/src/chips/motor/tmc2130');
|
|
6
|
+
|
|
7
|
+
function gpioOut(spec) {
|
|
8
|
+
// "<chip>:<line>", e.g. "0:17" -- gpiod chip number and line offset
|
|
9
|
+
const [chip, line] = String(spec).split(':').map((v) => parseInt(v, 10));
|
|
10
|
+
const { Default } = require('opengpio');
|
|
11
|
+
const { GpioOutputPin } = require('periph/src/connection/output_pin');
|
|
12
|
+
return new GpioOutputPin(Default.output({ chip, line }));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function TMC2130Node(config) {
|
|
16
|
+
RED.nodes.createNode(this, config);
|
|
17
|
+
const node = this;
|
|
18
|
+
node.ready = false;
|
|
19
|
+
node.speed = parseFloat(config.speed) || 200;
|
|
20
|
+
|
|
21
|
+
(async () => {
|
|
22
|
+
try {
|
|
23
|
+
const connection = new SPIConnection(parseInt(config.bus, 10) || 0, parseInt(config.device, 10) || 0, {
|
|
24
|
+
mode: 3,
|
|
25
|
+
maxSpeedHz: parseInt(config.speedHz, 10) || 1000000,
|
|
26
|
+
});
|
|
27
|
+
node.connection = connection;
|
|
28
|
+
node.driver = new TMC2130Full(connection, gpioOut(config.stepGpio), gpioOut(config.dirGpio), {
|
|
29
|
+
rSenseOhm: parseFloat(config.rsense) || 0.11,
|
|
30
|
+
enPin: config.enGpio ? gpioOut(config.enGpio) : null,
|
|
31
|
+
});
|
|
32
|
+
await node.driver.init();
|
|
33
|
+
const current = parseFloat(config.current);
|
|
34
|
+
if (current > 0) await node.driver.setCurrent(current);
|
|
35
|
+
const microsteps = parseInt(config.microsteps, 10);
|
|
36
|
+
if (microsteps > 0) await node.driver.setMicrosteps(microsteps);
|
|
37
|
+
node.ready = true;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
node.error('TMC2130 init failed: ' + e.message);
|
|
40
|
+
}
|
|
41
|
+
})();
|
|
42
|
+
|
|
43
|
+
async function snapshot() {
|
|
44
|
+
const status = await node.driver.readStatus();
|
|
45
|
+
return {
|
|
46
|
+
standstill: status.stst,
|
|
47
|
+
fault: await node.driver.readFault(),
|
|
48
|
+
cs_actual: status.cs_actual,
|
|
49
|
+
sg_result: status.sg_result,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
node.on('input', async function(msg, send, done) {
|
|
54
|
+
if (!node.driver || !node.ready) { done(); return; }
|
|
55
|
+
try {
|
|
56
|
+
const p = msg.payload;
|
|
57
|
+
let handled = false;
|
|
58
|
+
if (p && typeof p === 'object') {
|
|
59
|
+
if (typeof p.microsteps === 'number') { await node.driver.setMicrosteps(p.microsteps); handled = true; }
|
|
60
|
+
if (typeof p.current === 'number') { await node.driver.setCurrent(p.current); handled = true; }
|
|
61
|
+
if (typeof p.stall_threshold === 'number') { await node.driver.setStallThreshold(p.stall_threshold); handled = true; }
|
|
62
|
+
if (typeof p.spreadcycle === 'boolean') { await node.driver.setChopperMode(p.spreadcycle); handled = true; }
|
|
63
|
+
if (typeof p.enable === 'boolean') {
|
|
64
|
+
if (p.enable) await node.driver.enable(); else await node.driver.disable();
|
|
65
|
+
handled = true;
|
|
66
|
+
}
|
|
67
|
+
if (typeof p.move === 'number') {
|
|
68
|
+
await node.driver.move(p.move, typeof p.speed === 'number' ? p.speed : node.speed);
|
|
69
|
+
handled = true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (handled) {
|
|
73
|
+
msg.payload = await snapshot();
|
|
74
|
+
} else {
|
|
75
|
+
const status = await node.driver.readStatus();
|
|
76
|
+
msg.payload = {
|
|
77
|
+
standstill: status.stst,
|
|
78
|
+
fault: await node.driver.readFault(),
|
|
79
|
+
cs_actual: status.cs_actual,
|
|
80
|
+
sg_result: status.sg_result,
|
|
81
|
+
tstep: await node.driver.readTstep(),
|
|
82
|
+
stallguard: status.stallguard,
|
|
83
|
+
otpw: status.otpw,
|
|
84
|
+
ot: status.ot,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
send(msg);
|
|
88
|
+
done();
|
|
89
|
+
} catch (e) {
|
|
90
|
+
done(e);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
node.on('close', async function(removed, done) {
|
|
95
|
+
try {
|
|
96
|
+
if (node.driver && node.ready) await node.driver.disable();
|
|
97
|
+
if (node.connection) await node.connection.close();
|
|
98
|
+
} catch (e) {
|
|
99
|
+
// bus may already be gone; nothing more to do on close
|
|
100
|
+
} finally {
|
|
101
|
+
done();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
RED.nodes.registerType('periph-tmc2130', TMC2130Node);
|
|
106
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-tmc2208', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
port: { value: '/dev/ttyS0', required: true },
|
|
8
|
+
baudrate: { value: '115200', required: true, validate: RED.validators.number() },
|
|
9
|
+
rsense: { value: '0.11', required: true, validate: RED.validators.number() },
|
|
10
|
+
current: { value: '0.5', validate: RED.validators.number() },
|
|
11
|
+
microsteps: { value: '16' },
|
|
12
|
+
enGpio: { value: '' }
|
|
13
|
+
},
|
|
14
|
+
inputs: 1,
|
|
15
|
+
outputs: 1,
|
|
16
|
+
icon: 'font-awesome/fa-cog',
|
|
17
|
+
label: function() { return this.name || 'TMC2208'; },
|
|
18
|
+
paletteLabel: 'TMC2208'
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script type="text/html" data-template-name="periph-tmc2208">
|
|
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="TMC2208">
|
|
26
|
+
</div>
|
|
27
|
+
<div class="form-row">
|
|
28
|
+
<label for="node-input-port"><i class="fa fa-plug"></i> Serial port</label>
|
|
29
|
+
<input type="text" id="node-input-port" placeholder="/dev/ttyS0">
|
|
30
|
+
</div>
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label for="node-input-baudrate"><i class="fa fa-tachometer"></i> Baud rate</label>
|
|
33
|
+
<input type="number" id="node-input-baudrate" min="9000" style="width:100px">
|
|
34
|
+
</div>
|
|
35
|
+
<div class="form-row">
|
|
36
|
+
<label for="node-input-rsense"><i class="fa fa-bolt"></i> Sense resistor (Ω)</label>
|
|
37
|
+
<input type="number" id="node-input-rsense" min="0.01" step="0.01" style="width:100px">
|
|
38
|
+
</div>
|
|
39
|
+
<div class="form-row">
|
|
40
|
+
<label for="node-input-current"><i class="fa fa-bolt"></i> Default current (A RMS)</label>
|
|
41
|
+
<input type="number" id="node-input-current" min="0" max="1.2" step="0.05" style="width:100px">
|
|
42
|
+
</div>
|
|
43
|
+
<div class="form-row">
|
|
44
|
+
<label for="node-input-microsteps"><i class="fa fa-th"></i> Default microsteps</label>
|
|
45
|
+
<select id="node-input-microsteps" style="width:100px">
|
|
46
|
+
<option value="1">1</option><option value="2">2</option><option value="4">4</option>
|
|
47
|
+
<option value="8">8</option><option value="16">16</option><option value="32">32</option>
|
|
48
|
+
<option value="64">64</option><option value="128">128</option><option value="256">256</option>
|
|
49
|
+
</select>
|
|
50
|
+
</div>
|
|
51
|
+
<div class="form-row">
|
|
52
|
+
<label for="node-input-enGpio"><i class="fa fa-microchip"></i> ENN GPIO (optional)</label>
|
|
53
|
+
<input type="text" id="node-input-enGpio" placeholder="not wired, e.g. 0:17" style="width:140px">
|
|
54
|
+
</div>
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<script type="text/html" data-help-name="periph-tmc2208">
|
|
58
|
+
<p>Drives a two-phase bipolar stepper motor through a Trinamic TMC2202 / TMC2208 / TMC2224 over its single-wire UART. The chip's internal step generator moves the motor, so no STEP pulses are needed.</p>
|
|
59
|
+
|
|
60
|
+
<h3>Inputs</h3>
|
|
61
|
+
<dl class="message-properties">
|
|
62
|
+
<dt>payload.speed <span class="property-type">number</span></dt>
|
|
63
|
+
<dd>Full steps per second at the configured microstepping; negative = reverse, <code>0</code> stops.</dd>
|
|
64
|
+
<dt>payload.current <span class="property-type">number</span></dt>
|
|
65
|
+
<dd>Run current in A RMS (at most 1.2); hold current becomes one third of it.</dd>
|
|
66
|
+
<dt>payload.microsteps <span class="property-type">number</span></dt>
|
|
67
|
+
<dd>Microstep resolution: 1, 2, 4, 8, 16, 32, 64, 128 or 256.</dd>
|
|
68
|
+
<dt>payload.enable <span class="property-type">boolean</span></dt>
|
|
69
|
+
<dd><code>true</code> switches the power stage on, <code>false</code> off (the motor freewheels).</dd>
|
|
70
|
+
<dt>payload.stop <span class="property-type">boolean</span></dt>
|
|
71
|
+
<dd><code>true</code> stops the internal step generator.</dd>
|
|
72
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
73
|
+
<dd>Any other message polls the driver status.</dd>
|
|
74
|
+
</dl>
|
|
75
|
+
|
|
76
|
+
<h3>Outputs</h3>
|
|
77
|
+
<dl class="message-properties">
|
|
78
|
+
<dt>payload.speed <span class="property-type">number</span></dt>
|
|
79
|
+
<dd>Echo of the commanded speed (command messages only).</dd>
|
|
80
|
+
<dt>payload.standstill <span class="property-type">boolean</span></dt>
|
|
81
|
+
<dd>The motor is at standstill.</dd>
|
|
82
|
+
<dt>payload.fault <span class="property-type">number</span></dt>
|
|
83
|
+
<dd>Fault bitmask: 1 over-temperature pre-warning, 2 over-temperature, 4 short to GND, 8 short to supply, 16 open load; <code>0</code> = none.</dd>
|
|
84
|
+
<dt>payload.cs_actual <span class="property-type">number</span></dt>
|
|
85
|
+
<dd>Actual current scale 0–31.</dd>
|
|
86
|
+
<dt>payload.stealth, tstep, temperature_flags</dt>
|
|
87
|
+
<dd>Status polls only: StealthChop active, time between microsteps, temperature comparator bits (t120…t157 as bits 0–3).</dd>
|
|
88
|
+
</dl>
|
|
89
|
+
|
|
90
|
+
<h3>Configuration</h3>
|
|
91
|
+
<p>Wire MCU TX through a 1 kΩ resistor to PDN_UART and MCU RX directly to PDN_UART. Set the serial port and baud rate (9 kBd and up; the chip auto-detects it), the external sense resistor value (0.11 Ω on common boards), and the default run current and microsteps applied at start. The optional ENN GPIO field (<code>chip:line</code>, e.g. <code>0:17</code>, needs the <code>opengpio</code> package) drives the ENN pin; without it the node switches the power stage through the chopper (<code>TOFF</code>). The motor is stopped and the driver disabled when the node is closed.</p>
|
|
92
|
+
</script>
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { UARTConnection } = require('periph/src/connection/uart');
|
|
5
|
+
const { TMC2208Full } = require('periph/src/chips/motor/tmc2208');
|
|
6
|
+
|
|
7
|
+
function TMC2208Node(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
node.ready = false;
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
try {
|
|
14
|
+
const connection = new UARTConnection(config.port, {
|
|
15
|
+
baudRate: parseInt(config.baudrate, 10) || 115200,
|
|
16
|
+
timeoutMs: 100,
|
|
17
|
+
});
|
|
18
|
+
await connection.open();
|
|
19
|
+
node.connection = connection;
|
|
20
|
+
let enPin = null;
|
|
21
|
+
if (config.enGpio) {
|
|
22
|
+
// "<chip>:<line>", e.g. "0:17" -- gpiod chip number and line offset
|
|
23
|
+
const [chip, line] = String(config.enGpio).split(':').map((v) => parseInt(v, 10));
|
|
24
|
+
const { Default } = require('opengpio');
|
|
25
|
+
const { GpioOutputPin } = require('periph/src/connection/output_pin');
|
|
26
|
+
enPin = new GpioOutputPin(Default.output({ chip, line }));
|
|
27
|
+
}
|
|
28
|
+
node.enPin = enPin;
|
|
29
|
+
node.driver = new TMC2208Full(connection, {
|
|
30
|
+
rSenseOhm: parseFloat(config.rsense) || 0.11,
|
|
31
|
+
enPin,
|
|
32
|
+
});
|
|
33
|
+
await node.driver.init();
|
|
34
|
+
const current = parseFloat(config.current);
|
|
35
|
+
if (current > 0) await node.driver.setCurrent(current);
|
|
36
|
+
const microsteps = parseInt(config.microsteps, 10);
|
|
37
|
+
if (microsteps > 0) await node.driver.setMicrosteps(microsteps);
|
|
38
|
+
node.ready = true;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
node.error('TMC2208 init failed: ' + e.message);
|
|
41
|
+
}
|
|
42
|
+
})();
|
|
43
|
+
|
|
44
|
+
async function snapshot(extra) {
|
|
45
|
+
const status = await node.driver.readStatus();
|
|
46
|
+
const fault = await node.driver.readFault();
|
|
47
|
+
return Object.assign({
|
|
48
|
+
standstill: status.stst,
|
|
49
|
+
stealth: status.stealth,
|
|
50
|
+
fault,
|
|
51
|
+
cs_actual: status.cs_actual,
|
|
52
|
+
}, extra);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
node.on('input', async function(msg, send, done) {
|
|
56
|
+
if (!node.driver || !node.ready) { done(); return; }
|
|
57
|
+
try {
|
|
58
|
+
const p = msg.payload;
|
|
59
|
+
let handled = false;
|
|
60
|
+
let extra = {};
|
|
61
|
+
if (p && typeof p === 'object') {
|
|
62
|
+
if (typeof p.microsteps === 'number') { await node.driver.setMicrosteps(p.microsteps); handled = true; }
|
|
63
|
+
if (typeof p.current === 'number') { await node.driver.setCurrent(p.current); handled = true; }
|
|
64
|
+
if (typeof p.enable === 'boolean') {
|
|
65
|
+
if (p.enable) await node.driver.enable(); else await node.driver.disable();
|
|
66
|
+
handled = true;
|
|
67
|
+
}
|
|
68
|
+
if (p.stop === true) { await node.driver.stop(); extra.speed = 0; handled = true; }
|
|
69
|
+
if (typeof p.speed === 'number') { await node.driver.run(p.speed); extra.speed = p.speed; handled = true; }
|
|
70
|
+
}
|
|
71
|
+
if (handled) {
|
|
72
|
+
msg.payload = await snapshot(extra);
|
|
73
|
+
} else {
|
|
74
|
+
const status = await node.driver.readStatus();
|
|
75
|
+
msg.payload = {
|
|
76
|
+
standstill: status.stst,
|
|
77
|
+
stealth: status.stealth,
|
|
78
|
+
fault: await node.driver.readFault(),
|
|
79
|
+
cs_actual: status.cs_actual,
|
|
80
|
+
tstep: await node.driver.readTstep(),
|
|
81
|
+
temperature_flags: await node.driver.readTemperatureFlags(),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
send(msg);
|
|
85
|
+
done();
|
|
86
|
+
} catch (e) {
|
|
87
|
+
done(e);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
node.on('close', async function(removed, done) {
|
|
92
|
+
try {
|
|
93
|
+
if (node.driver && node.ready) {
|
|
94
|
+
await node.driver.stop();
|
|
95
|
+
await node.driver.disable();
|
|
96
|
+
}
|
|
97
|
+
if (node.connection) await node.connection.close();
|
|
98
|
+
} catch (e) {
|
|
99
|
+
// port may already be gone; nothing more to do on close
|
|
100
|
+
} finally {
|
|
101
|
+
done();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
RED.nodes.registerType('periph-tmc2208', TMC2208Node);
|
|
106
|
+
};
|