motion-master-client 0.0.315 → 0.0.317

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.
@@ -1693,7 +1693,7 @@ class MotionMasterReqResClient {
1693
1693
  throw new Error('Device parameter values is empty');
1694
1694
  }
1695
1695
  const deviceParameters = deviceParameterValuesStatus.parameterValues.map((value, i) => {
1696
- var _a, _b, _c;
1696
+ var _a, _b, _c, _d, _e;
1697
1697
  const index = (_a = value.index) !== null && _a !== void 0 ? _a : 0;
1698
1698
  const subindex = (_b = value.subindex) !== null && _b !== void 0 ? _b : 0;
1699
1699
  const id = (0, device_parameter_1.makeDeviceParameterId)(device.id, index, subindex);
@@ -1703,7 +1703,13 @@ class MotionMasterReqResClient {
1703
1703
  if (esi) {
1704
1704
  esiExtension = (0, parameter_1.getParameterEsiExtension)(deviceParameter, esi === null || esi === void 0 ? void 0 : esi.value, productCode);
1705
1705
  }
1706
- return Object.assign(Object.assign({}, deviceParameter), esiExtension);
1706
+ const parameterId = (0, parameter_1.makeParameterId)(index, subindex);
1707
+ const plot = {
1708
+ axis: (_d = parameter_1.parameterIdToPlotAxis[parameterId]) !== null && _d !== void 0 ? _d : 'y2',
1709
+ color: (_e = parameter_1.parameterIdToPlotColor[parameterId]) !== null && _e !== void 0 ? _e : (0, util_1.createRandomColor)(100),
1710
+ visible: true,
1711
+ };
1712
+ return Object.assign(Object.assign(Object.assign({}, deviceParameter), esiExtension), { plot: plot });
1707
1713
  });
1708
1714
  const progress = sendProgress ? (_b = (_a = deviceParameterValuesStatus === null || deviceParameterValuesStatus === void 0 ? void 0 : deviceParameterValuesStatus.progress) === null || _a === void 0 ? void 0 : _a.percentage) !== null && _b !== void 0 ? _b : 0 : 100;
1709
1715
  return { parameters: deviceParameters, progress };
@@ -3151,7 +3157,6 @@ class MotionMasterReqResClient {
3151
3157
  // Step 4: Transmit the update file chunk-by-chunk.
3152
3158
  const transmitSoftwareCommand = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.TRANSMIT_SOFTWARE);
3153
3159
  for (let i = 0; i < n; i++) {
3154
- console.log(`Transmitting chunk ${i + 1} of ${n}`);
3155
3160
  const start = i * chunkSize;
3156
3161
  const end = start + chunkSize;
3157
3162
  const fsBufferContent = buffer.slice(start, end);
@@ -3965,6 +3970,140 @@ class MotionMasterReqResClient {
3965
3970
  [deviceRef, 0x2023, 0x04, notchFilter.depth],
3966
3971
  ], requestTimeout);
3967
3972
  }
3973
+ /**
3974
+ * Deletes all HRD data files (`hr_data0.bin` to `hr_data4.bin`) from the device.
3975
+ *
3976
+ * The operation attempts to remove each file sequentially, regardless of whether
3977
+ * it exists or not. Missing files do not cause the sequence to stop or fail.
3978
+ *
3979
+ * @param deviceRef - Reference to the target device.
3980
+ * @returns An observable that completes once all delete operations have finished.
3981
+ */
3982
+ removeAllHrdFiles(deviceRef) {
3983
+ const filenames = Array.from({ length: 5 }, (_, i) => `hr_data${i}.bin`);
3984
+ // Attempt to delete all HRD files regardless of whether they exist
3985
+ return (0, rxjs_1.from)(filenames).pipe((0, operators_1.concatMap)((filename) => this.deleteFile(deviceRef, filename)), (0, operators_1.toArray)(), (0, operators_1.map)(() => void 0));
3986
+ }
3987
+ /**
3988
+ * Reads a sequence of HRD files (`hr_data0.bin` to `hr_data4.bin`) from a device,
3989
+ * combines their contents into a single `Uint8Array`, and returns it as an Observable.
3990
+ *
3991
+ * Each file is read sequentially. If a file is missing or its content is `null`/`undefined`,
3992
+ * it is treated as an empty `Uint8Array`, so the sequence continues without errors.
3993
+ *
3994
+ * @param deviceRef - Reference to the device from which the files are read.
3995
+ * @returns An `Observable<Uint8Array>` that emits a single `Uint8Array` containing
3996
+ * the combined contents of all read files.
3997
+ */
3998
+ readAllHrdFiles(deviceRef) {
3999
+ const readFileObservable = (filename) => (0, rxjs_1.from)(this.getFile(deviceRef, filename)).pipe((0, operators_1.map)((content) => {
4000
+ if (content) {
4001
+ return Array.isArray(content) ? new Uint8Array(content) : content;
4002
+ }
4003
+ else {
4004
+ return new Uint8Array();
4005
+ }
4006
+ }));
4007
+ const filenames = Array.from({ length: 5 }, (_, i) => `hr_data${i}.bin`);
4008
+ return (0, rxjs_1.from)(filenames).pipe((0, operators_1.concatMap)((filename) => readFileObservable(filename)), (0, operators_1.toArray)(), (0, operators_1.map)((arrays) => {
4009
+ const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
4010
+ const combined = new Uint8Array(totalLength);
4011
+ let offset = 0;
4012
+ for (const arr of arrays) {
4013
+ combined.set(arr, offset);
4014
+ offset += arr.length;
4015
+ }
4016
+ return combined;
4017
+ }));
4018
+ }
4019
+ /**
4020
+ * Runs HRD streaming on the device.
4021
+ *
4022
+ * The procedure performs the following steps:
4023
+ * 1. Configures HRD streaming with the specified data index and duration.
4024
+ * 2. Starts the streaming process.
4025
+ * 3. Reads and combines all HRD files once streaming completes.
4026
+ *
4027
+ * @param deviceRef - Device to stream from.
4028
+ * @param dataIndex - Index of the HRD streaming data (default is 0).
4029
+ * @param duration - Streaming duration in milliseconds (default is 1000).
4030
+ * @returns Observable that emits a combined `Uint8Array` containing all HRD file data.
4031
+ */
4032
+ runHrdStreaming(deviceRef, dataIndex = 0, duration = 1000) {
4033
+ return (0, rxjs_1.concat)(
4034
+ // Removing all HRD files upfront is unnecessary, as the firmware automatically handles this when configuring the stream.
4035
+ // defer(() => this.removeAllHrdFiles(deviceRef)),
4036
+ (0, rxjs_1.defer)(() => this.runHrdStreamingOsCommand(deviceRef, os_command_1.HrdStreamingOsCommandAction.CONFIGURE_STREAM, dataIndex, duration, 10000)), (0, rxjs_1.defer)(() => this.runHrdStreamingOsCommand(deviceRef, os_command_1.HrdStreamingOsCommandAction.START_STREAM, 0, 0, duration + 10000))).pipe((0, operators_1.last)(), (0, operators_1.mergeMap)(() => this.readAllHrdFiles(deviceRef)), (0, operators_1.map)((combinedData) => (0, os_command_1.parseHrdBuffer)(combinedData)));
4037
+ }
4038
+ /**
4039
+ * Executes a chirp signal on the drive for system identification purposes.
4040
+ *
4041
+ * This method sends a sequence of system identification commands to the drive, configuring
4042
+ * the necessary parameters and optionally starting HRD streaming if requested.
4043
+ *
4044
+ * Key points:
4045
+ * - By executing the chirp signal on the drive, the firmware provides a very clean signal
4046
+ * to the motion controller without communication jitter.
4047
+ * - The sine profile is used for system identification purposes.
4048
+ * - This profile is not available as a standard Motion Profile type (0x6086).
4049
+ *
4050
+ * Requirements for the drive to correctly follow the trajectory:
4051
+ * - The drive must have the correct commutation offset angle configured.
4052
+ * - The encoder for the selected control method must be functional.
4053
+ * - The controller must be tuned appropriately.
4054
+ *
4055
+ * Limitations:
4056
+ * - The statusword cannot report the status of the profiler for this sine profile type.
4057
+ * It does not differentiate between different motion profile types.
4058
+ * - If any parameter is out of range or the start frequency is greater than the target
4059
+ * frequency, the drive will report an "Invalid Parameter" error.
4060
+ * - If the start and target frequencies are equal, the output wave frequency will be constant (static sine).
4061
+ *
4062
+ * Implementation notes:
4063
+ * - The generated chirp signal is added to the control loop as an additional demanded torque,
4064
+ * just after the notch filter.
4065
+ * - This allows system identification in CST, CSV, or CSP modes (or other profile modes).
4066
+ *
4067
+ * @param deviceRef - Reference to the target device.
4068
+ * @param options - Configuration options for the chirp signal, including:
4069
+ * - `modesOfOperation` (optional): Modes of operation to configure before starting.
4070
+ * - `startFrequency`: Frequency at which the chirp begins.
4071
+ * - `targetFrequency`: Frequency at which the chirp ends.
4072
+ * - `targetAmplitude`: Amplitude of the chirp signal.
4073
+ * - `transitionTime`: Time for frequency/amplitude transition.
4074
+ * - `signalType`: Type of signal to generate.
4075
+ * - `startProcedure`: If set to `WAIT_FOR_HRD_STREAMING_TO_START`, the OS command for executing
4076
+ * the chirp signal will wait for HRD streaming to start before running the chirp.
4077
+ *
4078
+ * @returns An observable that completes after the chirp signal sequence is finished.
4079
+ * If `startProcedure` is set to `WAIT_FOR_HRD_STREAMING_TO_START`, HRD streaming
4080
+ * will also be executed.
4081
+ */
4082
+ runChirpSignal(deviceRef, options) {
4083
+ const observables = [
4084
+ options.modesOfOperation !== undefined
4085
+ ? (0, rxjs_1.defer)(() => this.setModesOfOperation(deviceRef, options.modesOfOperation))
4086
+ : rxjs_1.EMPTY,
4087
+ (0, rxjs_1.defer)(() => this.transitionToCia402State(deviceRef, cia402_1.Cia402State.OPERATION_ENABLED)),
4088
+ (0, rxjs_1.defer)(() => this.runSystemIdentificationOsCommand(deviceRef, 0, options.startFrequency, 10000)),
4089
+ (0, rxjs_1.defer)(() => this.runSystemIdentificationOsCommand(deviceRef, 1, options.targetFrequency, 10000)),
4090
+ (0, rxjs_1.defer)(() => this.runSystemIdentificationOsCommand(deviceRef, 2, options.targetAmplitude, 10000)),
4091
+ (0, rxjs_1.defer)(() => this.runSystemIdentificationOsCommand(deviceRef, 3, options.transitionTime, 10000)),
4092
+ (0, rxjs_1.defer)(() => this.runSystemIdentificationOsCommand(deviceRef, 4, options.signalType, 10000)),
4093
+ // Rising edge to start the chirp signal
4094
+ (0, rxjs_1.defer)(() => this.runSystemIdentificationOsCommand(deviceRef, 5, 0, 10000)),
4095
+ (0, rxjs_1.defer)(() => this.runSystemIdentificationOsCommand(deviceRef, 5, options.startProcedure, 10000)),
4096
+ ];
4097
+ return (0, rxjs_1.concat)(...observables).pipe((0, operators_1.last)(), (0, operators_1.mergeMap)(() => {
4098
+ if (options.startProcedure === os_command_1.SystemIdentificationOsCommandStartProcedure.WAIT_FOR_HRD_STREAMING_TO_START) {
4099
+ // 6693 ms is the maximum duration for 5 files, each containing 8032 bytes
4100
+ return this.runHrdStreaming(deviceRef, os_command_1.HrdStreamingOsCommandDataIndex.SYSTEM_IDENTIFICATION_DATA, 6693);
4101
+ }
4102
+ else {
4103
+ return rxjs_1.EMPTY;
4104
+ }
4105
+ }));
4106
+ }
3968
4107
  }
3969
4108
  exports.MotionMasterReqResClient = MotionMasterReqResClient;
3970
4109
  /**