motion-master-client 0.0.424 → 0.0.426

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.
@@ -2343,16 +2343,26 @@ class MotionMasterReqResClient {
2343
2343
  * To indicate that the new set-point is valid and should be executed, you need to trigger a rising edge of the new set-point bit in the controlword.
2344
2344
  * This rising edge serves as a signal to the device that a new set-point is being provided.
2345
2345
  *
2346
- * Once the device receives the rising edge of the new set-point bit, it will set the set-point acknowledge bit in the statusword to 1.
2347
- * This indicates that the device has acknowledged the new set-point and will execute the corresponding action, such as moving to the specified position.
2346
+ * Once the device receives the rising edge of the new set-point bit, it sets the set-point acknowledge bit in the statusword to 1.
2347
+ * This indicates that the device has taken the new set-point and executes it, for example by moving to the target position.
2348
2348
  *
2349
- * Afterwards, the device will signal its ability to accept new set-points by setting the set-point acknowledge bit back to 0 in the statusword.
2350
- * This signifies that the device is ready to receive and process additional set-points.
2349
+ * The new set-point bit is written together with the change set immediately bit (5) and the relative bit (6).
2350
+ * The relative bit is set when `relative` is true and cleared otherwise. When it is set, the device adds the target position (0x607A)
2351
+ * to the position selected by the position option code (0x60F2) instead of using it as an absolute position.
2352
+ * The device reads the relative bit from firmware v5.6.0 on; older firmware treats every target as absolute.
2353
+ *
2354
+ * After the device acknowledges the set-point, the new set-point bit and the relative bit are cleared. The running set-point is not affected,
2355
+ * because the device reads both bits only at the rising edge of the new set-point bit. The device then clears the set-point acknowledge bit.
2356
+ * Clearing the relative bit keeps it from turning a later set-point into a relative one, including set-points applied by other software.
2351
2357
  *
2352
2358
  * It's important to note that the device won't wait for the previous set-point to finish before executing a new set-point.
2353
2359
  * If you want to initiate a new set-point while the previous one is still being executed, you need to generate another rising edge of the new set-point bit in the controlword.
2360
+ *
2361
+ * @param deviceRef - Reference to the target device.
2362
+ * @param setPointAckTimeout - Time, in milliseconds, to wait for the set-point acknowledge bit to change (default: 2000).
2363
+ * @param relative - Whether the target position is relative (default: false).
2354
2364
  */
2355
- applySetPoint(deviceRef, setPointAckTimeout = 2000) {
2365
+ applySetPoint(deviceRef, setPointAckTimeout = 2000, relative = false) {
2356
2366
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
2357
2367
  let controlword = yield this.upload(deviceRef, 0x6040, 0);
2358
2368
  if ((controlword & 0x0010) > 0) {
@@ -2361,11 +2371,19 @@ class MotionMasterReqResClient {
2361
2371
  // Wait for the device to drop set-point acknowledge so the next set produces a real rising edge.
2362
2372
  yield this.waitForSetPointAcknowledge(deviceRef, false, setPointAckTimeout);
2363
2373
  }
2364
- controlword = controlword | 0x0010 | 0x0020; // set new set-point and change set immediately bits to 1
2374
+ // Set the new set-point and change set immediately bits, and set or clear the relative bit.
2375
+ controlword = (controlword & 0xffbf) | 0x0010 | 0x0020 | (relative ? 0x0040 : 0);
2365
2376
  yield this.download(deviceRef, 0x6040, 0, controlword);
2366
2377
  // Wait for the device to acknowledge the new set-point. Until it does, the target reached bit
2367
2378
  // (0x6041 bit 10) still reflects the previous set-point, so callers polling it would latch a stale value.
2368
2379
  yield this.waitForSetPointAcknowledge(deviceRef, true, setPointAckTimeout);
2380
+ // Clear the new set-point and relative bits, so that the next set-point gets a real rising edge
2381
+ // and is not made relative by a leftover relative bit.
2382
+ controlword = controlword & 0xffaf;
2383
+ yield this.download(deviceRef, 0x6040, 0, controlword);
2384
+ // Wait for the device to see the cleared bit, so that a set-point applied right after this one
2385
+ // cannot land in the same cycle and lose its rising edge.
2386
+ yield this.waitForSetPointAcknowledge(deviceRef, false, setPointAckTimeout);
2369
2387
  });
2370
2388
  }
2371
2389
  waitForSetPointAcknowledge(deviceRef, expected, timeoutMs) {
@@ -4385,15 +4403,85 @@ class MotionMasterReqResClient {
4385
4403
  * It sends a series of commands to the device to read the registers and returns the responses as an array.
4386
4404
  * It was added as part of a fix for the EEPROM issue in Circulo integrated encoders.
4387
4405
  *
4406
+ * A register read completes on the drive within a few tens of milliseconds, so the response is polled every
4407
+ * 50 ms rather than at the 1000 ms default for OS commands. The first poll usually comes before the read has
4408
+ * completed; at 1000 ms each of those reads then waits a full second, and the 33 registers take about 30 s
4409
+ * instead of 1 to 2 s (measured on a Circulo 7 Safe Motion).
4410
+ *
4411
+ * The registers are read through the encoder configured in 0x2110 (encoder 1) or 0x2112 (encoder 2). When its
4412
+ * sensor port (subindex 1) is 0, no encoder is configured: no OS command is sent, and the observable fails at
4413
+ * once. Otherwise the firmware times out each read after 5 s and then refuses further OS commands.
4414
+ *
4388
4415
  * @param deviceRef - The reference to the device to which the command will be sent.
4389
4416
  * @param encoderOrdinal - The ordinal number of the encoder.
4390
4417
  * @param commandTimeout - The timeout in milliseconds for the command to complete.
4418
+ * @param responsePollingInterval - How often, in milliseconds, the response of each register read is polled.
4391
4419
  * @returns An observable that emits an array of `EncoderRegisterCommunicationOsCommandResponse` objects.
4420
+ * @throws Error when the encoder is not configured.
4392
4421
  */
4393
- readCirculoIntegratedEncoderKeyConfigurationRegisters(deviceRef, encoderOrdinal, commandTimeout = 5000) {
4422
+ readCirculoIntegratedEncoderKeyConfigurationRegisters(deviceRef, encoderOrdinal, commandTimeout = 5000, responsePollingInterval = 50) {
4394
4423
  const registerAddresses = circulo_1.circuloIntegratedEncoderKeyConfigurationRegisterAddresses.map((addr) => addr.ram);
4395
- const defferedOsCommands = registerAddresses.map((registerAddress) => (0, rxjs_1.defer)(() => this.runEncoderRegisterCommunicationOsCommand(deviceRef, encoderOrdinal, 0, 0, registerAddress, undefined, commandTimeout).pipe((0, operators_1.last)())));
4396
- return (0, rxjs_1.concat)(...defferedOsCommands).pipe((0, operators_1.toArray)());
4424
+ const defferedOsCommands = registerAddresses.map((registerAddress) => (0, rxjs_1.defer)(() => this.runEncoderRegisterCommunicationOsCommand(deviceRef, encoderOrdinal, 0, 0, registerAddress, undefined, commandTimeout, responsePollingInterval).pipe((0, operators_1.last)())));
4425
+ const configurationIndex = { 1: 0x2110, 2: 0x2112 }[encoderOrdinal];
4426
+ if (configurationIndex === undefined) {
4427
+ return (0, rxjs_1.concat)(...defferedOsCommands).pipe((0, operators_1.toArray)());
4428
+ }
4429
+ return (0, rxjs_1.defer)(() => this.upload(deviceRef, configurationIndex, 1)).pipe((0, operators_1.mergeMap)((sensorPort) => {
4430
+ if (sensorPort === 0) {
4431
+ const index = `0x${configurationIndex.toString(16).toUpperCase()}`;
4432
+ return (0, rxjs_1.throwError)(() => new Error(`Encoder ${encoderOrdinal} is not configured: its sensor port (${index}:01) is 0. Configure the ` +
4433
+ 'integrated encoder before reading its registers.'));
4434
+ }
4435
+ return (0, rxjs_1.concat)(...defferedOsCommands).pipe((0, operators_1.toArray)());
4436
+ }));
4437
+ }
4438
+ /**
4439
+ * Reads the key configuration registers of a Circulo integrated encoder, `HARD_REV` (register 0x74) and the
4440
+ * amplitude control gain (registers 0x2B and 0x2F), and builds its report: the chip revision, health monitoring,
4441
+ * the Nonius track offset table and every register with the raw values of its fields. See
4442
+ * {@link buildCirculoIntegratedEncoderReport}.
4443
+ *
4444
+ * The device serial number is resolved alongside; when it can't be, the report says it is unknown.
4445
+ *
4446
+ * @param deviceRef - The reference to the device.
4447
+ * @param encoderOrdinal - The ordinal number of the encoder, 1 or 2.
4448
+ * @param commandTimeout - The timeout in milliseconds for each register read.
4449
+ * @param responsePollingInterval - How often, in milliseconds, the response of each register read is polled.
4450
+ * @returns An observable that emits the report and completes.
4451
+ * @throws Error when a register read returns no value, so the report never shows a value it didn't read.
4452
+ */
4453
+ getCirculoIntegratedEncoderReport(deviceRef, encoderOrdinal, commandTimeout = 5000, responsePollingInterval = 50) {
4454
+ const valueOf = (response, ram) => {
4455
+ if (response.registerValue === undefined) {
4456
+ const reason = [response.request, response.errorCode, response.errorName, response.errorDescription]
4457
+ .filter((part) => part !== undefined && part !== '')
4458
+ .join(', ');
4459
+ throw new Error(`Register 0x${ram.toString(16).padStart(2, '0')} returned no value (${reason}).`);
4460
+ }
4461
+ return response.registerValue;
4462
+ };
4463
+ const readRegister = (ram) => (0, rxjs_1.defer)(() => this.runEncoderRegisterCommunicationOsCommand(deviceRef, encoderOrdinal, 0, 0, ram, undefined, commandTimeout, responsePollingInterval).pipe((0, operators_1.last)()));
4464
+ const extraRegisters = [
4465
+ circulo_1.icMuHardRevRegister,
4466
+ ...circulo_1.circuloIntegratedEncoderAmplitudeControlRegisters.map((r) => r.ram),
4467
+ ];
4468
+ const deviceSerialNumber$ = this.resolveDevice(deviceRef).pipe((0, operators_1.map)((device) => device.id), (0, operators_1.catchError)(() => (0, rxjs_1.of)(undefined)));
4469
+ // The OS command channel runs one command at a time, so HARD_REV and the amplitude control registers are read
4470
+ // after the key configuration registers, not alongside.
4471
+ return (0, rxjs_1.forkJoin)([
4472
+ (0, rxjs_1.concat)(this.readCirculoIntegratedEncoderKeyConfigurationRegisters(deviceRef, encoderOrdinal, commandTimeout, responsePollingInterval), (0, rxjs_1.concat)(...extraRegisters.map(readRegister)).pipe((0, operators_1.toArray)())).pipe((0, operators_1.toArray)()),
4473
+ deviceSerialNumber$,
4474
+ ]).pipe((0, operators_1.map)(([[responses, extraResponses], deviceSerialNumber]) => {
4475
+ const values = responses.map((response, i) => valueOf(response, circulo_1.circuloIntegratedEncoderKeyConfigurationRegisterAddresses[i].ram));
4476
+ const [hardRev, ...amplitudeControlValues] = extraResponses.map((response, i) => valueOf(response, extraRegisters[i]));
4477
+ return (0, circulo_1.buildCirculoIntegratedEncoderReport)(values, {
4478
+ encoderOrdinal,
4479
+ deviceSerialNumber,
4480
+ readAt: new Date(),
4481
+ hardRev,
4482
+ amplitudeControlValues,
4483
+ });
4484
+ }));
4397
4485
  }
4398
4486
  /**
4399
4487
  * Writes the integrated encoder configuration to a binary file on the device.
@@ -5043,7 +5131,9 @@ class MotionMasterReqResClient {
5043
5131
  },
5044
5132
  commutationOffsetMeasurement: {
5045
5133
  execute: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
5046
- measurementMethod === 2 ? yield this.engageBrake(deviceRef, brakeEngageWaitMs) : yield this.releaseBrake(deviceRef, brakeReleaseWaitMs);
5134
+ measurementMethod === 2
5135
+ ? yield this.engageBrake(deviceRef, brakeEngageWaitMs)
5136
+ : yield this.releaseBrake(deviceRef, brakeReleaseWaitMs);
5047
5137
  return yield (0, rxjs_1.lastValueFrom)(this.runCommutationOffsetMeasurementOsCommand(deviceRef));
5048
5138
  }),
5049
5139
  valueKey: 'commutationAngleOffset',