nova-control-node 0.0.6 → 0.0.8

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
@@ -139,16 +139,16 @@ Supported commands:
139
139
 
140
140
  | command | description |
141
141
  | --- | --- |
142
- | `home` | send all servos to home positions |
143
- | `shift-to <deg>` | s1 — head forward / back |
144
- | `roll-to <deg>` | s2 — head CW / CCW |
145
- | `pitch-to <deg>` | s3 — head up / down |
146
- | `rotate-to <deg>` | s4 — body Z-axis rotation |
147
- | `lift-to <deg>` | s5 — secondary head axis |
148
- | `move [key val ]` | set multiple servos atomically (e.g. `move shift-to 100 rotate-to 120`) |
142
+ | `home [<within_ms>]` | send all servos to home positions |
143
+ | `shift-to <deg> [<within_ms>]` | s1 — head forward / back |
144
+ | `roll-to <deg> [<within_ms>]` | s2 — head CW / CCW |
145
+ | `pitch-to <deg> [<within_ms>]` | s3 — head up / down |
146
+ | `rotate-to <deg> [<within_ms>]` | s4 — body Z-axis rotation |
147
+ | `lift-to <deg> [<within_ms>]` | s5 — secondary head axis |
148
+ | `move [shift-to <deg>] [roll-to <deg>] [pitch-to <deg>] [rotate-to <deg>] [lift-to <deg>] [within-ms <ms>]` | set multiple servos atomically (e.g. `move shift-to 100 rotate-to 120 within-ms 500`) |
149
149
  | `wait <ms>` | pause for the given number of milliseconds |
150
150
 
151
- Throws a descriptive error containing the line number if an unknown command or invalid argument is encountered.
151
+ Each command is fully awaited before the next begins. Throws a descriptive error containing the line number if an unknown command or invalid argument is encountered.
152
152
 
153
153
  ### Types
154
154
 
@@ -157,65 +157,83 @@ async function u(e, t) {
157
157
  if (r === "" || r.startsWith("#")) continue;
158
158
  let a = r.split(/\s+/), o = a[0].toLowerCase();
159
159
  switch (!0) {
160
- case o === "home":
161
- await e.home();
160
+ case o === "home": {
161
+ let t = a[1] == null ? void 0 : Number(a[1]);
162
+ if (t != null && isNaN(t)) throw Error(`line ${i}: home: within_ms must be a number, got '${a[1]}'`);
163
+ await e.home(t);
162
164
  break;
165
+ }
163
166
  case o === "shift-to": {
164
167
  let t = Number(a[1]);
165
168
  if (isNaN(t)) throw Error(`line ${i}: shift-to requires a numeric angle, got '${a[1]}'`);
166
- await e.shiftHeadTo(t);
169
+ let n = a[2] == null ? void 0 : Number(a[2]);
170
+ if (n != null && isNaN(n)) throw Error(`line ${i}: shift-to: within_ms must be a number, got '${a[2]}'`);
171
+ await e.shiftHeadTo(t, n);
167
172
  break;
168
173
  }
169
174
  case o === "roll-to": {
170
175
  let t = Number(a[1]);
171
176
  if (isNaN(t)) throw Error(`line ${i}: roll-to requires a numeric angle, got '${a[1]}'`);
172
- await e.rollHeadTo(t);
177
+ let n = a[2] == null ? void 0 : Number(a[2]);
178
+ if (n != null && isNaN(n)) throw Error(`line ${i}: roll-to: within_ms must be a number, got '${a[2]}'`);
179
+ await e.rollHeadTo(t, n);
173
180
  break;
174
181
  }
175
182
  case o === "pitch-to": {
176
183
  let t = Number(a[1]);
177
184
  if (isNaN(t)) throw Error(`line ${i}: pitch-to requires a numeric angle, got '${a[1]}'`);
178
- await e.pitchHeadTo(t);
185
+ let n = a[2] == null ? void 0 : Number(a[2]);
186
+ if (n != null && isNaN(n)) throw Error(`line ${i}: pitch-to: within_ms must be a number, got '${a[2]}'`);
187
+ await e.pitchHeadTo(t, n);
179
188
  break;
180
189
  }
181
190
  case o === "rotate-to": {
182
191
  let t = Number(a[1]);
183
192
  if (isNaN(t)) throw Error(`line ${i}: rotate-to requires a numeric angle, got '${a[1]}'`);
184
- await e.rotateBodyTo(t);
193
+ let n = a[2] == null ? void 0 : Number(a[2]);
194
+ if (n != null && isNaN(n)) throw Error(`line ${i}: rotate-to: within_ms must be a number, got '${a[2]}'`);
195
+ await e.rotateBodyTo(t, n);
185
196
  break;
186
197
  }
187
198
  case o === "lift-to": {
188
199
  let t = Number(a[1]);
189
200
  if (isNaN(t)) throw Error(`line ${i}: lift-to requires a numeric angle, got '${a[1]}'`);
190
- await e.liftHeadTo(t);
201
+ let n = a[2] == null ? void 0 : Number(a[2]);
202
+ if (n != null && isNaN(n)) throw Error(`line ${i}: lift-to: within_ms must be a number, got '${a[2]}'`);
203
+ await e.liftHeadTo(t, n);
191
204
  break;
192
205
  }
193
206
  case o === "move": {
194
- let t = {};
207
+ let t = {}, n;
195
208
  for (let e = 1; e < a.length; e += 2) {
196
- let n = a[e].toLowerCase(), r = Number(a[e + 1]);
197
- if (isNaN(r)) throw Error(`line ${i}: '${n}' requires a numeric angle, got '${a[e + 1]}'`);
198
- switch (n) {
209
+ let r = a[e].toLowerCase(), o = Number(a[e + 1]);
210
+ if (r === "within-ms") {
211
+ if (isNaN(o)) throw Error(`line ${i}: within-ms requires a numeric value, got '${a[e + 1]}'`);
212
+ n = o;
213
+ break;
214
+ }
215
+ if (isNaN(o)) throw Error(`line ${i}: '${r}' requires a numeric angle, got '${a[e + 1]}'`);
216
+ switch (r) {
199
217
  case "shift-to":
200
- t.s1 = r;
218
+ t.s1 = o;
201
219
  break;
202
220
  case "roll-to":
203
- t.s2 = r;
221
+ t.s2 = o;
204
222
  break;
205
223
  case "pitch-to":
206
- t.s3 = r;
224
+ t.s3 = o;
207
225
  break;
208
226
  case "rotate-to":
209
- t.s4 = r;
227
+ t.s4 = o;
210
228
  break;
211
229
  case "lift-to":
212
- t.s5 = r;
230
+ t.s5 = o;
213
231
  break;
214
- default: throw Error(`line ${i}: unknown move argument '${n}'`);
232
+ default: throw Error(`line ${i}: unknown move argument '${r}'`);
215
233
  }
216
234
  }
217
235
  if (Object.keys(t).length === 0) throw Error(`line ${i}: move requires at least one servo argument`);
218
- e.State = t, await e.sendServoState();
236
+ await e.moveTo(t, n);
219
237
  break;
220
238
  }
221
239
  case o === "wait": {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nova-control-node",
3
3
  "description": "Control a NOVA DIY Artificial Intelligence Robot by Creoqode from Node.js",
4
- "version": "0.0.6",
4
+ "version": "0.0.8",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "nova",