motion-master-client 0.0.426 → 0.0.428
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/package.json +2 -1
- package/src/lib/circulo.d.ts +195 -7
- package/src/lib/circulo.js +337 -8
- package/src/lib/circulo.js.map +1 -1
- package/src/lib/motion-master-req-res-client.d.ts +19 -6
- package/src/lib/motion-master-req-res-client.js +43 -8
- package/src/lib/motion-master-req-res-client.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motion-master-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.428",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "A library and CLI program used for communicating with Motion Master.",
|
|
6
6
|
"dependencies": {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"ws": "^8.13.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
+
"util": "0.12.5",
|
|
27
28
|
"tslib": "2.5.3"
|
|
28
29
|
},
|
|
29
30
|
"main": "./src/index.js",
|
package/src/lib/circulo.d.ts
CHANGED
|
@@ -101,6 +101,169 @@ export interface CirculoIntegratedEncoderStatusRegister {
|
|
|
101
101
|
* while `ENAC` (register 0x05, bit 7) is 1; the report gives the raw value either way.
|
|
102
102
|
*/
|
|
103
103
|
export declare const circuloIntegratedEncoderAmplitudeControlRegisters: CirculoIntegratedEncoderStatusRegister[];
|
|
104
|
+
/** The version of the calibration history file this client reads. */
|
|
105
|
+
export declare const circuloIntegratedEncoderCalibrationHistoryVersion = 1;
|
|
106
|
+
/**
|
|
107
|
+
* The name of the calibration history file Motion Master 5.8.10 and later write to the drive at the end of every
|
|
108
|
+
* Circulo encoder calibration run, e.g. `circulo_integrated_encoder_1_calib.json`.
|
|
109
|
+
*/
|
|
110
|
+
export declare function circuloIntegratedEncoderCalibrationHistoryFileName(encoderOrdinal: number): string;
|
|
111
|
+
/** The adjustment values of one track, one element per analysed iteration. */
|
|
112
|
+
export interface CirculoIntegratedEncoderCalibrationTrackAdjustments {
|
|
113
|
+
voss: number[];
|
|
114
|
+
vosc: number[];
|
|
115
|
+
ph: number[];
|
|
116
|
+
phr: number[];
|
|
117
|
+
gx: number[];
|
|
118
|
+
}
|
|
119
|
+
/** The quality of a calibration run, taken from its validation iteration. */
|
|
120
|
+
export interface CirculoIntegratedEncoderCalibrationQuality {
|
|
121
|
+
/**
|
|
122
|
+
* The quality percentage OBLAC showed. Absent when the validation curve was not sent to the client.
|
|
123
|
+
*/
|
|
124
|
+
percentage?: number;
|
|
125
|
+
/** The max permissible phase error of the measured ring, in encoder increments. */
|
|
126
|
+
maxPermissiblePhaseError: number;
|
|
127
|
+
/** The lower phase margin, in percent. */
|
|
128
|
+
lowerPhaseMargin: number;
|
|
129
|
+
/** The upper phase margin, in percent. */
|
|
130
|
+
upperPhaseMargin: number;
|
|
131
|
+
/** `EXCELLENT`, `MARGINAL` or `UNSAFE`, from the phase margins. */
|
|
132
|
+
verdict: string;
|
|
133
|
+
/** The residual offset errors of both tracks after the analysis, in LSB. */
|
|
134
|
+
residualOffsetError: {
|
|
135
|
+
masterSine: number;
|
|
136
|
+
masterCosine: number;
|
|
137
|
+
noniusSine: number;
|
|
138
|
+
noniusCosine: number;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/** How a calibration run ended. */
|
|
142
|
+
export interface CirculoIntegratedEncoderCalibrationOutcome {
|
|
143
|
+
success: boolean;
|
|
144
|
+
errorCode: number;
|
|
145
|
+
error: string;
|
|
146
|
+
/** The detailed cause, e.g. the phase an aborted run stopped in, or the library's reject message. Empty on success. */
|
|
147
|
+
reason: string;
|
|
148
|
+
eepromWritten: boolean;
|
|
149
|
+
}
|
|
150
|
+
/** One calibration run as Motion Master records it in the calibration history file. */
|
|
151
|
+
export interface CirculoIntegratedEncoderCalibrationRun {
|
|
152
|
+
/** When the run ended, as an ISO 8601 UTC time. */
|
|
153
|
+
time: string;
|
|
154
|
+
motionMasterVersion: string;
|
|
155
|
+
/** Absent when Motion Master could not read it. */
|
|
156
|
+
firmwareVersion?: string;
|
|
157
|
+
calibrationLibraryVersion: string;
|
|
158
|
+
/** `HARD_REV` of the chip. Absent when Motion Master could not read it. */
|
|
159
|
+
hardwareRevision?: number;
|
|
160
|
+
encoderOrdinal: number;
|
|
161
|
+
encoderType: string;
|
|
162
|
+
externalEncoderType: number;
|
|
163
|
+
measurementOnly: boolean;
|
|
164
|
+
healthMonitoringRequested: boolean;
|
|
165
|
+
/** Whether health monitoring was on after the run. Absent when Motion Master could not read it. */
|
|
166
|
+
healthMonitoringActive?: boolean;
|
|
167
|
+
outcome: CirculoIntegratedEncoderCalibrationOutcome;
|
|
168
|
+
/** The number of started iterations. The adjustment arrays can be shorter. */
|
|
169
|
+
iterations: number;
|
|
170
|
+
iterationAdjustments: {
|
|
171
|
+
master: CirculoIntegratedEncoderCalibrationTrackAdjustments;
|
|
172
|
+
nonius: CirculoIntegratedEncoderCalibrationTrackAdjustments;
|
|
173
|
+
};
|
|
174
|
+
/** Absent when the run did not reach the validation iteration. */
|
|
175
|
+
quality?: CirculoIntegratedEncoderCalibrationQuality;
|
|
176
|
+
/**
|
|
177
|
+
* The key configuration registers after the run, in the order of
|
|
178
|
+
* {@link circuloIntegratedEncoderKeyConfigurationRegisterAddresses}. Present only for successful runs.
|
|
179
|
+
*/
|
|
180
|
+
keyConfigurationRegisters?: number[];
|
|
181
|
+
/** The raw values of registers 0x2B and 0x2F after the run. Present only for successful runs. */
|
|
182
|
+
amplitudeControlGain?: {
|
|
183
|
+
master: number;
|
|
184
|
+
nonius: number;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** The calibration history file of one encoder: the last runs, newest first. */
|
|
188
|
+
export interface CirculoIntegratedEncoderCalibrationHistory {
|
|
189
|
+
version: typeof circuloIntegratedEncoderCalibrationHistoryVersion;
|
|
190
|
+
runs: CirculoIntegratedEncoderCalibrationRun[];
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Parses the calibration history file Motion Master writes to the drive, see
|
|
194
|
+
* {@link circuloIntegratedEncoderCalibrationHistoryFileName}.
|
|
195
|
+
*
|
|
196
|
+
* It refuses a file it does not understand instead of guessing: one that is not JSON, one with a version other
|
|
197
|
+
* than {@link circuloIntegratedEncoderCalibrationHistoryVersion}, and one with a required field missing or of the
|
|
198
|
+
* wrong type. The optional fields may be absent. Fields it does not know are kept.
|
|
199
|
+
*
|
|
200
|
+
* @param text - The content of the file.
|
|
201
|
+
* @returns The history, its runs newest first as stored.
|
|
202
|
+
* @throws Error that says what is wrong with the file.
|
|
203
|
+
*/
|
|
204
|
+
export declare function parseCirculoIntegratedEncoderCalibrationHistory(text: string): CirculoIntegratedEncoderCalibrationHistory;
|
|
205
|
+
/**
|
|
206
|
+
* Finds the latest full calibration: the newest successful run that was not measurement only.
|
|
207
|
+
*
|
|
208
|
+
* @param runs - The runs, newest first, as the calibration history file stores them.
|
|
209
|
+
* @returns The index of that run in `runs`, or -1 when there is none.
|
|
210
|
+
*/
|
|
211
|
+
export declare function findLatestFullCirculoIntegratedEncoderCalibrationIndex(runs: CirculoIntegratedEncoderCalibrationRun[]): number;
|
|
212
|
+
/** A key configuration register whose value differs from the one a calibration stored. */
|
|
213
|
+
export interface CirculoIntegratedEncoderChangedRegister {
|
|
214
|
+
ram: number;
|
|
215
|
+
eeprom: number;
|
|
216
|
+
/** The value the calibration stored. */
|
|
217
|
+
calibrated: number;
|
|
218
|
+
/** The value read now. */
|
|
219
|
+
now: number;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Compares the key configuration registers a calibration stored with the ones read now.
|
|
223
|
+
*
|
|
224
|
+
* @param calibrated - The values the calibration stored, in the order of
|
|
225
|
+
* {@link circuloIntegratedEncoderKeyConfigurationRegisters}.
|
|
226
|
+
* @param now - The values read now, in the same order.
|
|
227
|
+
* @returns Every register that differs, in that order. Empty when the chip still holds what the calibration wrote.
|
|
228
|
+
* @throws Error when either list does not hold a value for every register.
|
|
229
|
+
*/
|
|
230
|
+
export declare function compareCirculoIntegratedEncoderRegistersWithCalibration(calibrated: number[], now: number[]): CirculoIntegratedEncoderChangedRegister[];
|
|
231
|
+
/**
|
|
232
|
+
* The calibration history file as read from the drive: stored, missing (calibrated with a Motion Master older than
|
|
233
|
+
* 5.8.10, or not calibrated at all), or unreadable, with the reason.
|
|
234
|
+
*/
|
|
235
|
+
export type CirculoIntegratedEncoderCalibrationHistoryReadResult = {
|
|
236
|
+
state: 'stored';
|
|
237
|
+
history: CirculoIntegratedEncoderCalibrationHistory;
|
|
238
|
+
} | {
|
|
239
|
+
state: 'missing';
|
|
240
|
+
} | {
|
|
241
|
+
state: 'unreadable';
|
|
242
|
+
message: string;
|
|
243
|
+
};
|
|
244
|
+
/** The calibration history in an encoder report. */
|
|
245
|
+
export type CirculoIntegratedEncoderReportCalibrationHistory = {
|
|
246
|
+
state: 'stored';
|
|
247
|
+
fileName: string;
|
|
248
|
+
/** The runs, newest first. */
|
|
249
|
+
runs: CirculoIntegratedEncoderCalibrationRun[];
|
|
250
|
+
/** The index in `runs` of the latest full calibration, or null when there is none. */
|
|
251
|
+
latestFullCalibrationIndex: number | null;
|
|
252
|
+
/**
|
|
253
|
+
* The key configuration registers that differ from the ones the latest full calibration stored, or null when
|
|
254
|
+
* there is no full calibration to compare with.
|
|
255
|
+
*/
|
|
256
|
+
registersChangedSinceCalibration: CirculoIntegratedEncoderChangedRegister[] | null;
|
|
257
|
+
} | {
|
|
258
|
+
state: 'missing';
|
|
259
|
+
fileName: string;
|
|
260
|
+
} | {
|
|
261
|
+
state: 'unreadable';
|
|
262
|
+
fileName: string;
|
|
263
|
+
message: string;
|
|
264
|
+
} | {
|
|
265
|
+
state: 'notRead';
|
|
266
|
+
};
|
|
104
267
|
/** A key configuration register with the raw value read from it and the raw values of its fields. */
|
|
105
268
|
export interface CirculoIntegratedEncoderReportRegister {
|
|
106
269
|
ram: number;
|
|
@@ -116,7 +279,7 @@ export interface CirculoIntegratedEncoderReportStatusRegister {
|
|
|
116
279
|
fields: IcMuRegisterFieldValue[];
|
|
117
280
|
}
|
|
118
281
|
/** The version of {@link CirculoIntegratedEncoderReport}. It changes when the shape changes. */
|
|
119
|
-
export declare const circuloIntegratedEncoderReportSchemaVersion =
|
|
282
|
+
export declare const circuloIntegratedEncoderReportSchemaVersion = 3;
|
|
120
283
|
/**
|
|
121
284
|
* The registers of a Circulo integrated encoder as read: the data behind both the JSON and the text report.
|
|
122
285
|
*
|
|
@@ -151,6 +314,11 @@ export interface CirculoIntegratedEncoderReport {
|
|
|
151
314
|
amplitudeControlRegisters: CirculoIntegratedEncoderReportStatusRegister[];
|
|
152
315
|
/** Every key configuration register in the order of {@link circuloIntegratedEncoderKeyConfigurationRegisters}. */
|
|
153
316
|
registers: CirculoIntegratedEncoderReportRegister[];
|
|
317
|
+
/**
|
|
318
|
+
* The calibration history Motion Master stored on the drive, with the latest full calibration and the registers
|
|
319
|
+
* that changed since it.
|
|
320
|
+
*/
|
|
321
|
+
calibrationHistory: CirculoIntegratedEncoderReportCalibrationHistory;
|
|
154
322
|
}
|
|
155
323
|
/**
|
|
156
324
|
* Whether health monitoring is on. Health monitoring is Synapticon's name for reporting the iC-MU's
|
|
@@ -184,11 +352,13 @@ export interface CirculoIntegratedEncoderReportInfo {
|
|
|
184
352
|
* The values of {@link circuloIntegratedEncoderAmplitudeControlRegisters}, in their order, when they were read.
|
|
185
353
|
*/
|
|
186
354
|
amplitudeControlValues?: number[];
|
|
355
|
+
/** The calibration history file of the encoder, when it was read. */
|
|
356
|
+
calibrationHistory?: CirculoIntegratedEncoderCalibrationHistoryReadResult;
|
|
187
357
|
}
|
|
188
358
|
/**
|
|
189
|
-
* Builds the report of a Circulo integrated encoder from its registers: the
|
|
190
|
-
* the Nonius track offset table, the amplitude control gain and every
|
|
191
|
-
* values of its fields. Nothing is decoded with a datasheet.
|
|
359
|
+
* Builds the report of a Circulo integrated encoder from its registers: the calibration history stored on the
|
|
360
|
+
* drive, the chip revision, health monitoring, the Nonius track offset table, the amplitude control gain and every
|
|
361
|
+
* key configuration register with the raw values of its fields. Nothing is decoded with a datasheet.
|
|
192
362
|
*
|
|
193
363
|
* Serialize it with `JSON.stringify` for programs, or render it with
|
|
194
364
|
* {@link formatCirculoIntegratedEncoderReport} for people.
|
|
@@ -207,12 +377,30 @@ export declare function buildCirculoIntegratedEncoderReport(values: number[], in
|
|
|
207
377
|
export declare function circuloIntegratedEncoderReportFileName(report: Pick<CirculoIntegratedEncoderReport, 'encoderOrdinal' | 'deviceSerialNumber' | 'readAt'>, format: 'json' | 'txt'): string;
|
|
208
378
|
/** The chip line of the text report, e.g. `HARD_REV: 0x11 = iC-MU150 rev 1`. */
|
|
209
379
|
export declare function formatIcMuChip(chip: IcMuPart | null): string;
|
|
380
|
+
/** The mode of a calibration run: `calibration` or `measurement only`. */
|
|
381
|
+
export declare function formatCirculoIntegratedEncoderCalibrationMode(run: CirculoIntegratedEncoderCalibrationRun): string;
|
|
382
|
+
/** The outcome of a calibration run: `success`, or the error code and the error, e.g. `error 52: ...`. */
|
|
383
|
+
export declare function formatCirculoIntegratedEncoderCalibrationOutcome(outcome: CirculoIntegratedEncoderCalibrationOutcome): string;
|
|
384
|
+
/**
|
|
385
|
+
* A percentage of a calibration run, e.g. `60 %`, or `-` when it is absent. Null counts as absent, since `?.` in an
|
|
386
|
+
* Angular template gives null.
|
|
387
|
+
*/
|
|
388
|
+
export declare function formatCirculoIntegratedEncoderCalibrationPercentage(value: number | null | undefined): string;
|
|
389
|
+
/** Whether health monitoring was on after a calibration run: `ON`, `OFF`, or `-` when it was not read. */
|
|
390
|
+
export declare function formatCirculoIntegratedEncoderCalibrationHealthMonitoring(active: boolean | null | undefined): string;
|
|
391
|
+
/** Why a report has no calibration history to show: the file is missing or could not be read. */
|
|
392
|
+
export declare function formatCirculoIntegratedEncoderCalibrationHistoryUnavailable(history: Extract<CirculoIntegratedEncoderReportCalibrationHistory, {
|
|
393
|
+
state: 'missing' | 'unreadable';
|
|
394
|
+
}>): string;
|
|
210
395
|
/**
|
|
211
396
|
* Renders a report as plain text for people. It computes nothing: every value comes from the report, raw.
|
|
212
397
|
*
|
|
213
|
-
* It opens with the device and the chip revision, then
|
|
214
|
-
*
|
|
215
|
-
*
|
|
398
|
+
* It opens with the device and the chip revision, then the calibration history stored on the drive (the latest full
|
|
399
|
+
* calibration, every stored run, the registers changed since that calibration, and every detail each run stored:
|
|
400
|
+
* versions, `HARD_REV`, amplitude control gain, registers and the iteration lines), whether health monitoring is
|
|
401
|
+
* on, the Nonius track offset table, the amplitude control gain, and every key configuration register with its RAM
|
|
402
|
+
* and EEPROM address and its value, and below it every field with its name, its slice, its value and its
|
|
403
|
+
* description.
|
|
216
404
|
* Registers the encoder calibration writes are marked with `*`.
|
|
217
405
|
*
|
|
218
406
|
* @returns The report, lines separated by `\n` and ending with a newline.
|
package/src/lib/circulo.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// https://github.com/synapticon/somanet_software/blob/32edf5ef572ea7d840aabe4a26e0f3d31f05caab/sw_applications/app_motion_drive/test/pytest/somanet_icmu_helpers.py
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.computeCirculoEncoderCalibrationProgressResult = exports.computeCirculoEncoderCalibrationResult = exports.getCirculoEncoderMaxPermissiblePhaseError = exports.circulo9MaxPermissiblePhaseError = exports.circulo7MaxPermissiblePhaseError = exports.CirculoExternalEncoderType = exports.getCirculoEncoderCalibrationMaxValuePercentageLabel = exports.getCirculoEncoderCalibrationMaxValuePercentageColor = exports.CirculoIntegratedEncoderIcpvlCommands = exports.CirculoIntegratedEncoderIcmuCommands = exports.CirculoIntegratedEncoderEepromParameters = exports.CirculoIntegratedEncoderIcpvlParameters = exports.CirculoIntegratedEncoderIcmuParameters = exports.circuloIntegratedEncoderI2CDeviceIdOptions = exports.CirculoIntegratedEncoderI2CDeviceId = exports.formatCirculoIntegratedEncoderReport = exports.formatIcMuChip = exports.circuloIntegratedEncoderReportFileName = exports.buildCirculoIntegratedEncoderReport = exports.decodeCirculoIntegratedEncoderKeyConfigurationRegisters = exports.isCirculoIntegratedEncoderHealthMonitoringActive = exports.circuloIntegratedEncoderReportSchemaVersion = exports.circuloIntegratedEncoderAmplitudeControlRegisters = exports.decodeIcMuHardRev = exports.icMuHardRevRegister = exports.circuloIntegratedEncoderKeyConfigurationRegisterAddresses = exports.circuloIntegratedEncoderKeyConfigurationRegisters = void 0;
|
|
4
|
+
exports.computeCirculoEncoderCalibrationProgressResult = exports.computeCirculoEncoderCalibrationResult = exports.getCirculoEncoderMaxPermissiblePhaseError = exports.circulo9MaxPermissiblePhaseError = exports.circulo7MaxPermissiblePhaseError = exports.CirculoExternalEncoderType = exports.getCirculoEncoderCalibrationMaxValuePercentageLabel = exports.getCirculoEncoderCalibrationMaxValuePercentageColor = exports.CirculoIntegratedEncoderIcpvlCommands = exports.CirculoIntegratedEncoderIcmuCommands = exports.CirculoIntegratedEncoderEepromParameters = exports.CirculoIntegratedEncoderIcpvlParameters = exports.CirculoIntegratedEncoderIcmuParameters = exports.circuloIntegratedEncoderI2CDeviceIdOptions = exports.CirculoIntegratedEncoderI2CDeviceId = exports.formatCirculoIntegratedEncoderReport = exports.formatCirculoIntegratedEncoderCalibrationHistoryUnavailable = exports.formatCirculoIntegratedEncoderCalibrationHealthMonitoring = exports.formatCirculoIntegratedEncoderCalibrationPercentage = exports.formatCirculoIntegratedEncoderCalibrationOutcome = exports.formatCirculoIntegratedEncoderCalibrationMode = exports.formatIcMuChip = exports.circuloIntegratedEncoderReportFileName = exports.buildCirculoIntegratedEncoderReport = exports.decodeCirculoIntegratedEncoderKeyConfigurationRegisters = exports.isCirculoIntegratedEncoderHealthMonitoringActive = exports.circuloIntegratedEncoderReportSchemaVersion = exports.compareCirculoIntegratedEncoderRegistersWithCalibration = exports.findLatestFullCirculoIntegratedEncoderCalibrationIndex = exports.parseCirculoIntegratedEncoderCalibrationHistory = exports.circuloIntegratedEncoderCalibrationHistoryFileName = exports.circuloIntegratedEncoderCalibrationHistoryVersion = exports.circuloIntegratedEncoderAmplitudeControlRegisters = exports.decodeIcMuHardRev = exports.icMuHardRevRegister = exports.circuloIntegratedEncoderKeyConfigurationRegisterAddresses = exports.circuloIntegratedEncoderKeyConfigurationRegisters = void 0;
|
|
5
5
|
const product_1 = require("./product");
|
|
6
6
|
/** A field of a register, with the datasheet's own slice of the field computed from its width. */
|
|
7
7
|
function icMuField(name, msb, lsb, description, bits) {
|
|
@@ -167,8 +167,157 @@ exports.circuloIntegratedEncoderAmplitudeControlRegisters = [
|
|
|
167
167
|
],
|
|
168
168
|
},
|
|
169
169
|
];
|
|
170
|
+
/** The version of the calibration history file this client reads. */
|
|
171
|
+
exports.circuloIntegratedEncoderCalibrationHistoryVersion = 1;
|
|
172
|
+
/**
|
|
173
|
+
* The name of the calibration history file Motion Master 5.8.10 and later write to the drive at the end of every
|
|
174
|
+
* Circulo encoder calibration run, e.g. `circulo_integrated_encoder_1_calib.json`.
|
|
175
|
+
*/
|
|
176
|
+
function circuloIntegratedEncoderCalibrationHistoryFileName(encoderOrdinal) {
|
|
177
|
+
return `circulo_integrated_encoder_${encoderOrdinal}_calib.json`;
|
|
178
|
+
}
|
|
179
|
+
exports.circuloIntegratedEncoderCalibrationHistoryFileName = circuloIntegratedEncoderCalibrationHistoryFileName;
|
|
180
|
+
function malformed(path, expected) {
|
|
181
|
+
throw new Error(`Malformed calibration history: ${path} is not ${expected}.`);
|
|
182
|
+
}
|
|
183
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
184
|
+
const checkString = (value, path) => typeof value === 'string' || malformed(path, 'a string');
|
|
185
|
+
const checkBoolean = (value, path) => typeof value === 'boolean' || malformed(path, 'a boolean');
|
|
186
|
+
const checkNumber = (value, path) => (typeof value === 'number' && Number.isFinite(value)) || malformed(path, 'a number');
|
|
187
|
+
const checkInteger = (value, path) => Number.isInteger(value) || malformed(path, 'an integer');
|
|
188
|
+
const checkIntegerArray = (length) => (value, path) => {
|
|
189
|
+
if (!Array.isArray(value) || (length !== undefined && value.length !== length)) {
|
|
190
|
+
malformed(path, length === undefined ? 'an array' : `an array of ${length} values`);
|
|
191
|
+
}
|
|
192
|
+
value.forEach((item, i) => checkInteger(item, `${path}[${i}]`));
|
|
193
|
+
};
|
|
194
|
+
/** Checks an object against its fields; a field whose name ends with `?` may be absent. Extra fields are kept. */
|
|
195
|
+
const checkObject = (fields) => (value, path) => {
|
|
196
|
+
if (!isRecord(value)) {
|
|
197
|
+
malformed(path, 'an object');
|
|
198
|
+
}
|
|
199
|
+
for (const [key, check] of Object.entries(fields)) {
|
|
200
|
+
const optional = key.endsWith('?');
|
|
201
|
+
const name = optional ? key.slice(0, -1) : key;
|
|
202
|
+
if (value[name] === undefined) {
|
|
203
|
+
if (!optional) {
|
|
204
|
+
throw new Error(`Malformed calibration history: ${path}.${name} is missing.`);
|
|
205
|
+
}
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
check(value[name], `${path}.${name}`);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
const checkTrackAdjustments = checkObject({
|
|
212
|
+
voss: checkIntegerArray(),
|
|
213
|
+
vosc: checkIntegerArray(),
|
|
214
|
+
ph: checkIntegerArray(),
|
|
215
|
+
phr: checkIntegerArray(),
|
|
216
|
+
gx: checkIntegerArray(),
|
|
217
|
+
});
|
|
218
|
+
const checkCalibrationRun = checkObject({
|
|
219
|
+
time: checkString,
|
|
220
|
+
motionMasterVersion: checkString,
|
|
221
|
+
'firmwareVersion?': checkString,
|
|
222
|
+
calibrationLibraryVersion: checkString,
|
|
223
|
+
'hardwareRevision?': checkInteger,
|
|
224
|
+
encoderOrdinal: checkInteger,
|
|
225
|
+
encoderType: checkString,
|
|
226
|
+
externalEncoderType: checkInteger,
|
|
227
|
+
measurementOnly: checkBoolean,
|
|
228
|
+
healthMonitoringRequested: checkBoolean,
|
|
229
|
+
'healthMonitoringActive?': checkBoolean,
|
|
230
|
+
outcome: checkObject({
|
|
231
|
+
success: checkBoolean,
|
|
232
|
+
errorCode: checkInteger,
|
|
233
|
+
error: checkString,
|
|
234
|
+
reason: checkString,
|
|
235
|
+
eepromWritten: checkBoolean,
|
|
236
|
+
}),
|
|
237
|
+
iterations: checkInteger,
|
|
238
|
+
iterationAdjustments: checkObject({ master: checkTrackAdjustments, nonius: checkTrackAdjustments }),
|
|
239
|
+
'quality?': checkObject({
|
|
240
|
+
'percentage?': checkNumber,
|
|
241
|
+
maxPermissiblePhaseError: checkNumber,
|
|
242
|
+
lowerPhaseMargin: checkNumber,
|
|
243
|
+
upperPhaseMargin: checkNumber,
|
|
244
|
+
verdict: checkString,
|
|
245
|
+
residualOffsetError: checkObject({
|
|
246
|
+
masterSine: checkNumber,
|
|
247
|
+
masterCosine: checkNumber,
|
|
248
|
+
noniusSine: checkNumber,
|
|
249
|
+
noniusCosine: checkNumber,
|
|
250
|
+
}),
|
|
251
|
+
}),
|
|
252
|
+
'keyConfigurationRegisters?': checkIntegerArray(exports.circuloIntegratedEncoderKeyConfigurationRegisters.length),
|
|
253
|
+
'amplitudeControlGain?': checkObject({ master: checkInteger, nonius: checkInteger }),
|
|
254
|
+
});
|
|
255
|
+
/**
|
|
256
|
+
* Parses the calibration history file Motion Master writes to the drive, see
|
|
257
|
+
* {@link circuloIntegratedEncoderCalibrationHistoryFileName}.
|
|
258
|
+
*
|
|
259
|
+
* It refuses a file it does not understand instead of guessing: one that is not JSON, one with a version other
|
|
260
|
+
* than {@link circuloIntegratedEncoderCalibrationHistoryVersion}, and one with a required field missing or of the
|
|
261
|
+
* wrong type. The optional fields may be absent. Fields it does not know are kept.
|
|
262
|
+
*
|
|
263
|
+
* @param text - The content of the file.
|
|
264
|
+
* @returns The history, its runs newest first as stored.
|
|
265
|
+
* @throws Error that says what is wrong with the file.
|
|
266
|
+
*/
|
|
267
|
+
function parseCirculoIntegratedEncoderCalibrationHistory(text) {
|
|
268
|
+
let data;
|
|
269
|
+
try {
|
|
270
|
+
data = JSON.parse(text);
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
throw new Error(`Malformed calibration history: not JSON (${err instanceof Error ? err.message : String(err)}).`);
|
|
274
|
+
}
|
|
275
|
+
if (!isRecord(data)) {
|
|
276
|
+
malformed('the file', 'an object');
|
|
277
|
+
}
|
|
278
|
+
if (data['version'] !== exports.circuloIntegratedEncoderCalibrationHistoryVersion) {
|
|
279
|
+
throw new Error(`Unknown calibration history version ${JSON.stringify(data['version'])}. This client reads version ` +
|
|
280
|
+
`${exports.circuloIntegratedEncoderCalibrationHistoryVersion}.`);
|
|
281
|
+
}
|
|
282
|
+
const runs = data['runs'];
|
|
283
|
+
if (!Array.isArray(runs)) {
|
|
284
|
+
malformed('runs', 'an array');
|
|
285
|
+
}
|
|
286
|
+
runs.forEach((run, i) => checkCalibrationRun(run, `runs[${i}]`));
|
|
287
|
+
return data;
|
|
288
|
+
}
|
|
289
|
+
exports.parseCirculoIntegratedEncoderCalibrationHistory = parseCirculoIntegratedEncoderCalibrationHistory;
|
|
290
|
+
/**
|
|
291
|
+
* Finds the latest full calibration: the newest successful run that was not measurement only.
|
|
292
|
+
*
|
|
293
|
+
* @param runs - The runs, newest first, as the calibration history file stores them.
|
|
294
|
+
* @returns The index of that run in `runs`, or -1 when there is none.
|
|
295
|
+
*/
|
|
296
|
+
function findLatestFullCirculoIntegratedEncoderCalibrationIndex(runs) {
|
|
297
|
+
return runs.findIndex((run) => run.outcome.success && !run.measurementOnly);
|
|
298
|
+
}
|
|
299
|
+
exports.findLatestFullCirculoIntegratedEncoderCalibrationIndex = findLatestFullCirculoIntegratedEncoderCalibrationIndex;
|
|
300
|
+
/**
|
|
301
|
+
* Compares the key configuration registers a calibration stored with the ones read now.
|
|
302
|
+
*
|
|
303
|
+
* @param calibrated - The values the calibration stored, in the order of
|
|
304
|
+
* {@link circuloIntegratedEncoderKeyConfigurationRegisters}.
|
|
305
|
+
* @param now - The values read now, in the same order.
|
|
306
|
+
* @returns Every register that differs, in that order. Empty when the chip still holds what the calibration wrote.
|
|
307
|
+
* @throws Error when either list does not hold a value for every register.
|
|
308
|
+
*/
|
|
309
|
+
function compareCirculoIntegratedEncoderRegistersWithCalibration(calibrated, now) {
|
|
310
|
+
const registers = exports.circuloIntegratedEncoderKeyConfigurationRegisters;
|
|
311
|
+
if (calibrated.length !== registers.length || now.length !== registers.length) {
|
|
312
|
+
throw new Error(`Expected ${registers.length} register values on both sides, got ${calibrated.length} and ${now.length}.`);
|
|
313
|
+
}
|
|
314
|
+
return registers
|
|
315
|
+
.map(({ ram, eeprom }, i) => ({ ram, eeprom, calibrated: calibrated[i] & 0xff, now: now[i] & 0xff }))
|
|
316
|
+
.filter((register) => register.calibrated !== register.now);
|
|
317
|
+
}
|
|
318
|
+
exports.compareCirculoIntegratedEncoderRegistersWithCalibration = compareCirculoIntegratedEncoderRegistersWithCalibration;
|
|
170
319
|
/** The version of {@link CirculoIntegratedEncoderReport}. It changes when the shape changes. */
|
|
171
|
-
exports.circuloIntegratedEncoderReportSchemaVersion =
|
|
320
|
+
exports.circuloIntegratedEncoderReportSchemaVersion = 3;
|
|
172
321
|
function hex(value, digits = 2) {
|
|
173
322
|
return `0x${value.toString(16).toUpperCase().padStart(digits, '0')}`;
|
|
174
323
|
}
|
|
@@ -207,10 +356,32 @@ function decodeCirculoIntegratedEncoderKeyConfigurationRegisters(values) {
|
|
|
207
356
|
return registers.map((register, i) => fieldValues(register.fields, values[i]));
|
|
208
357
|
}
|
|
209
358
|
exports.decodeCirculoIntegratedEncoderKeyConfigurationRegisters = decodeCirculoIntegratedEncoderKeyConfigurationRegisters;
|
|
359
|
+
/** The calibration history of a report, with the latest full calibration and the registers changed since it. */
|
|
360
|
+
function reportCalibrationHistory(values, encoderOrdinal, read) {
|
|
361
|
+
if (!read) {
|
|
362
|
+
return { state: 'notRead' };
|
|
363
|
+
}
|
|
364
|
+
const fileName = circuloIntegratedEncoderCalibrationHistoryFileName(encoderOrdinal);
|
|
365
|
+
if (read.state !== 'stored') {
|
|
366
|
+
return Object.assign(Object.assign({}, read), { fileName });
|
|
367
|
+
}
|
|
368
|
+
const { runs } = read.history;
|
|
369
|
+
const index = findLatestFullCirculoIntegratedEncoderCalibrationIndex(runs);
|
|
370
|
+
const calibrated = index === -1 ? undefined : runs[index].keyConfigurationRegisters;
|
|
371
|
+
return {
|
|
372
|
+
state: 'stored',
|
|
373
|
+
fileName,
|
|
374
|
+
runs,
|
|
375
|
+
latestFullCalibrationIndex: index === -1 ? null : index,
|
|
376
|
+
registersChangedSinceCalibration: calibrated
|
|
377
|
+
? compareCirculoIntegratedEncoderRegistersWithCalibration(calibrated, values)
|
|
378
|
+
: null,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
210
381
|
/**
|
|
211
|
-
* Builds the report of a Circulo integrated encoder from its registers: the
|
|
212
|
-
* the Nonius track offset table, the amplitude control gain and every
|
|
213
|
-
* values of its fields. Nothing is decoded with a datasheet.
|
|
382
|
+
* Builds the report of a Circulo integrated encoder from its registers: the calibration history stored on the
|
|
383
|
+
* drive, the chip revision, health monitoring, the Nonius track offset table, the amplitude control gain and every
|
|
384
|
+
* key configuration register with the raw values of its fields. Nothing is decoded with a datasheet.
|
|
214
385
|
*
|
|
215
386
|
* Serialize it with `JSON.stringify` for programs, or render it with
|
|
216
387
|
* {@link formatCirculoIntegratedEncoderReport} for people.
|
|
@@ -257,6 +428,7 @@ function buildCirculoIntegratedEncoderReport(values, info) {
|
|
|
257
428
|
value: values[i] & 0xff,
|
|
258
429
|
fields: decoded[i],
|
|
259
430
|
})),
|
|
431
|
+
calibrationHistory: reportCalibrationHistory(values, info.encoderOrdinal, info.calibrationHistory),
|
|
260
432
|
};
|
|
261
433
|
}
|
|
262
434
|
exports.buildCirculoIntegratedEncoderReport = buildCirculoIntegratedEncoderReport;
|
|
@@ -286,6 +458,158 @@ function formatIcMuChip(chip) {
|
|
|
286
458
|
return `${hex(chip.hardRev)} = ${(_a = chip.name) !== null && _a !== void 0 ? _a : 'unknown iC-MU chip'} rev ${chip.revision}`;
|
|
287
459
|
}
|
|
288
460
|
exports.formatIcMuChip = formatIcMuChip;
|
|
461
|
+
/** The text the report and the Console page show for an absent value. */
|
|
462
|
+
const absent = '-';
|
|
463
|
+
/** The mode of a calibration run: `calibration` or `measurement only`. */
|
|
464
|
+
function formatCirculoIntegratedEncoderCalibrationMode(run) {
|
|
465
|
+
return run.measurementOnly ? 'measurement only' : 'calibration';
|
|
466
|
+
}
|
|
467
|
+
exports.formatCirculoIntegratedEncoderCalibrationMode = formatCirculoIntegratedEncoderCalibrationMode;
|
|
468
|
+
/** The outcome of a calibration run: `success`, or the error code and the error, e.g. `error 52: ...`. */
|
|
469
|
+
function formatCirculoIntegratedEncoderCalibrationOutcome(outcome) {
|
|
470
|
+
if (outcome.success) {
|
|
471
|
+
return 'success';
|
|
472
|
+
}
|
|
473
|
+
return `error ${outcome.errorCode}${outcome.error ? `: ${outcome.error}` : ''}`;
|
|
474
|
+
}
|
|
475
|
+
exports.formatCirculoIntegratedEncoderCalibrationOutcome = formatCirculoIntegratedEncoderCalibrationOutcome;
|
|
476
|
+
/**
|
|
477
|
+
* A percentage of a calibration run, e.g. `60 %`, or `-` when it is absent. Null counts as absent, since `?.` in an
|
|
478
|
+
* Angular template gives null.
|
|
479
|
+
*/
|
|
480
|
+
function formatCirculoIntegratedEncoderCalibrationPercentage(value) {
|
|
481
|
+
return value === undefined || value === null ? absent : `${value} %`;
|
|
482
|
+
}
|
|
483
|
+
exports.formatCirculoIntegratedEncoderCalibrationPercentage = formatCirculoIntegratedEncoderCalibrationPercentage;
|
|
484
|
+
/** Whether health monitoring was on after a calibration run: `ON`, `OFF`, or `-` when it was not read. */
|
|
485
|
+
function formatCirculoIntegratedEncoderCalibrationHealthMonitoring(active) {
|
|
486
|
+
return active === undefined || active === null ? absent : active ? 'ON' : 'OFF';
|
|
487
|
+
}
|
|
488
|
+
exports.formatCirculoIntegratedEncoderCalibrationHealthMonitoring = formatCirculoIntegratedEncoderCalibrationHealthMonitoring;
|
|
489
|
+
/** Why a report has no calibration history to show: the file is missing or could not be read. */
|
|
490
|
+
function formatCirculoIntegratedEncoderCalibrationHistoryUnavailable(history) {
|
|
491
|
+
if (history.state === 'missing') {
|
|
492
|
+
return ('No calibration history is stored on the drive. The encoder was calibrated with a Motion Master older than ' +
|
|
493
|
+
'5.8.10, or not calibrated at all.');
|
|
494
|
+
}
|
|
495
|
+
return `The calibration history in ${history.fileName} could not be read: ${history.message}`;
|
|
496
|
+
}
|
|
497
|
+
exports.formatCirculoIntegratedEncoderCalibrationHistoryUnavailable = formatCirculoIntegratedEncoderCalibrationHistoryUnavailable;
|
|
498
|
+
/** Lines of a table whose columns are as wide as their widest cell. Trailing blanks are trimmed. */
|
|
499
|
+
function columnLines(rows) {
|
|
500
|
+
const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
|
|
501
|
+
return rows.map((row) => row
|
|
502
|
+
.map((cell, column) => (column === row.length - 1 ? cell : cell.padEnd(widths[column] + 2)))
|
|
503
|
+
.join('')
|
|
504
|
+
.trimEnd());
|
|
505
|
+
}
|
|
506
|
+
/** The lines of the CALIBRATION HISTORY section of the text report. */
|
|
507
|
+
function calibrationHistoryLines(history) {
|
|
508
|
+
const lines = ['CALIBRATION HISTORY'];
|
|
509
|
+
switch (history.state) {
|
|
510
|
+
case 'notRead':
|
|
511
|
+
return [...lines, 'Not read.'];
|
|
512
|
+
case 'missing':
|
|
513
|
+
case 'unreadable':
|
|
514
|
+
return [...lines, formatCirculoIntegratedEncoderCalibrationHistoryUnavailable(history)];
|
|
515
|
+
}
|
|
516
|
+
const { runs, latestFullCalibrationIndex, registersChangedSinceCalibration } = history;
|
|
517
|
+
lines.push(`${runs.length} ${runs.length === 1 ? 'run' : 'runs'} stored in ${history.fileName}.`, '');
|
|
518
|
+
const latest = latestFullCalibrationIndex === null ? undefined : runs[latestFullCalibrationIndex];
|
|
519
|
+
if (!latest) {
|
|
520
|
+
lines.push('Latest full calibration: none stored.');
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
const quality = latest.quality;
|
|
524
|
+
lines.push(`Latest full calibration: ${latest.time}`, ` Quality: ${formatCirculoIntegratedEncoderCalibrationPercentage(quality === null || quality === void 0 ? void 0 : quality.percentage)}`, ` Lower phase margin: ${formatCirculoIntegratedEncoderCalibrationPercentage(quality === null || quality === void 0 ? void 0 : quality.lowerPhaseMargin)}`, ` Upper phase margin: ${formatCirculoIntegratedEncoderCalibrationPercentage(quality === null || quality === void 0 ? void 0 : quality.upperPhaseMargin)}`, ` Verdict: ${(quality === null || quality === void 0 ? void 0 : quality.verdict) || absent}`, ` Health monitoring: ${formatCirculoIntegratedEncoderCalibrationHealthMonitoring(latest.healthMonitoringActive)} (requested: ${latest.healthMonitoringRequested ? 'yes' : 'no'})`);
|
|
525
|
+
}
|
|
526
|
+
lines.push('', 'All stored runs, newest first:', ...columnLines([
|
|
527
|
+
['TIME', 'MODE', 'QUALITY', 'LOWER MARGIN', 'UPPER MARGIN', 'HEALTH MONITORING', 'OUTCOME', 'REASON'],
|
|
528
|
+
...runs.map((run) => {
|
|
529
|
+
var _a, _b, _c;
|
|
530
|
+
return [
|
|
531
|
+
run.time,
|
|
532
|
+
formatCirculoIntegratedEncoderCalibrationMode(run),
|
|
533
|
+
formatCirculoIntegratedEncoderCalibrationPercentage((_a = run.quality) === null || _a === void 0 ? void 0 : _a.percentage),
|
|
534
|
+
formatCirculoIntegratedEncoderCalibrationPercentage((_b = run.quality) === null || _b === void 0 ? void 0 : _b.lowerPhaseMargin),
|
|
535
|
+
formatCirculoIntegratedEncoderCalibrationPercentage((_c = run.quality) === null || _c === void 0 ? void 0 : _c.upperPhaseMargin),
|
|
536
|
+
formatCirculoIntegratedEncoderCalibrationHealthMonitoring(run.healthMonitoringActive),
|
|
537
|
+
formatCirculoIntegratedEncoderCalibrationOutcome(run.outcome),
|
|
538
|
+
run.outcome.reason || absent,
|
|
539
|
+
];
|
|
540
|
+
}),
|
|
541
|
+
]), '', 'Registers changed since the latest full calibration:');
|
|
542
|
+
if (registersChangedSinceCalibration === null) {
|
|
543
|
+
lines.push(latest
|
|
544
|
+
? 'Not compared: the latest full calibration stored no registers.'
|
|
545
|
+
: 'Not compared: no full calibration is stored.');
|
|
546
|
+
}
|
|
547
|
+
else if (registersChangedSinceCalibration.length === 0) {
|
|
548
|
+
lines.push('None. The chip still holds what the latest full calibration wrote.');
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
lines.push(...columnLines([
|
|
552
|
+
['RAM', 'EEPROM', 'CALIBRATED', 'NOW'],
|
|
553
|
+
...registersChangedSinceCalibration.map((r) => [hex(r.ram), hex(r.eeprom), hex(r.calibrated), hex(r.now)]),
|
|
554
|
+
]));
|
|
555
|
+
}
|
|
556
|
+
if (runs.length > 0) {
|
|
557
|
+
lines.push('', 'Details of every stored run, newest first:');
|
|
558
|
+
runs.forEach((run, i) => lines.push('', ...calibrationRunDetailLines(run, i, runs.length)));
|
|
559
|
+
}
|
|
560
|
+
return lines;
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* The iteration lines of a run, in the order and format Motion Master logs them to system-log.txt, e.g.
|
|
564
|
+
* `VOSS_N: -67 -7 -7 -6`. Empty when the run stopped before the first analysed iteration.
|
|
565
|
+
*/
|
|
566
|
+
function calibrationIterationLines(run) {
|
|
567
|
+
const fields = ['voss', 'vosc', 'ph', 'phr', 'gx'];
|
|
568
|
+
const tracks = [
|
|
569
|
+
['M', run.iterationAdjustments.master],
|
|
570
|
+
['N', run.iterationAdjustments.nonius],
|
|
571
|
+
];
|
|
572
|
+
if (tracks.every(([, track]) => fields.every((field) => track[field].length === 0))) {
|
|
573
|
+
return [];
|
|
574
|
+
}
|
|
575
|
+
return tracks.flatMap(([suffix, track]) => fields.map((field) => `${field.toUpperCase()}_${suffix}: ${track[field].length ? track[field].join(' ') : absent}`));
|
|
576
|
+
}
|
|
577
|
+
/** The stored amplitude control gain of one track, raw with its fields, e.g. `0x12 (ACGAIN_M 2, AFGAIN_M 2)`. */
|
|
578
|
+
function formatStoredAmplitudeControlGain(value, register) {
|
|
579
|
+
const fields = fieldValues(register.fields, value).map((field) => `${field.name} ${field.value}`);
|
|
580
|
+
return `${hex(value & 0xff)} (${fields.join(', ')})`;
|
|
581
|
+
}
|
|
582
|
+
/** The lines that give everything a stored run holds, for diagnosing it offline. */
|
|
583
|
+
function calibrationRunDetailLines(run, index, count) {
|
|
584
|
+
var _a;
|
|
585
|
+
const { outcome, quality } = run;
|
|
586
|
+
const [masterGain, noniusGain] = exports.circuloIntegratedEncoderAmplitudeControlRegisters;
|
|
587
|
+
const lines = [
|
|
588
|
+
`Run ${index + 1} of ${count}: ${run.time}, ${formatCirculoIntegratedEncoderCalibrationMode(run)}, ${formatCirculoIntegratedEncoderCalibrationOutcome(outcome)}`,
|
|
589
|
+
` Reason: ${outcome.reason || absent}`,
|
|
590
|
+
` EEPROM written: ${outcome.eepromWritten ? 'yes' : 'no'}`,
|
|
591
|
+
` Motion Master: ${run.motionMasterVersion}`,
|
|
592
|
+
` Firmware: ${(_a = run.firmwareVersion) !== null && _a !== void 0 ? _a : absent}`,
|
|
593
|
+
` Calibration library: ${run.calibrationLibraryVersion}`,
|
|
594
|
+
` HARD_REV: ${run.hardwareRevision === undefined ? absent : formatIcMuChip(decodeIcMuHardRev(run.hardwareRevision))}`,
|
|
595
|
+
` Encoder: ordinal ${run.encoderOrdinal}, type ${run.encoderType}, external encoder type ${run.externalEncoderType}`,
|
|
596
|
+
` Health monitoring: ${formatCirculoIntegratedEncoderCalibrationHealthMonitoring(run.healthMonitoringActive)} (requested: ${run.healthMonitoringRequested ? 'yes' : 'no'})`,
|
|
597
|
+
];
|
|
598
|
+
if (quality) {
|
|
599
|
+
const residual = quality.residualOffsetError;
|
|
600
|
+
lines.push(` Quality: ${formatCirculoIntegratedEncoderCalibrationPercentage(quality.percentage)}, verdict ${quality.verdict || absent}`, ` Phase margin: lower ${formatCirculoIntegratedEncoderCalibrationPercentage(quality.lowerPhaseMargin)}, upper ${formatCirculoIntegratedEncoderCalibrationPercentage(quality.upperPhaseMargin)}`, ` Max permissible phase error: ${quality.maxPermissiblePhaseError}`, ` Residual offset error (LSB): master sine ${residual.masterSine}, master cosine ${residual.masterCosine}, ` +
|
|
601
|
+
`Nonius sine ${residual.noniusSine}, Nonius cosine ${residual.noniusCosine}`);
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
lines.push(' Quality: - (the run did not reach the validation iteration)');
|
|
605
|
+
}
|
|
606
|
+
lines.push(` Amplitude control gain: ${run.amplitudeControlGain
|
|
607
|
+
? `master ${formatStoredAmplitudeControlGain(run.amplitudeControlGain.master, masterGain)}, Nonius ${formatStoredAmplitudeControlGain(run.amplitudeControlGain.nonius, noniusGain)}`
|
|
608
|
+
: absent}`, ` Key configuration registers: ${run.keyConfigurationRegisters ? run.keyConfigurationRegisters.map((v) => hex(v).slice(2)).join(' ') : absent}`);
|
|
609
|
+
const iterationLines = calibrationIterationLines(run);
|
|
610
|
+
lines.push(iterationLines.length ? ` Iterations: ${run.iterations}` : ` Iterations: ${run.iterations}, none analysed`, ...iterationLines.map((line) => ` ${line}`));
|
|
611
|
+
return lines;
|
|
612
|
+
}
|
|
289
613
|
/** The table header and lines of registers with their fields, the first columns given per register. */
|
|
290
614
|
function registerTableLines(heading, registers) {
|
|
291
615
|
const lines = [
|
|
@@ -309,9 +633,12 @@ function registerTableLines(heading, registers) {
|
|
|
309
633
|
/**
|
|
310
634
|
* Renders a report as plain text for people. It computes nothing: every value comes from the report, raw.
|
|
311
635
|
*
|
|
312
|
-
* It opens with the device and the chip revision, then
|
|
313
|
-
*
|
|
314
|
-
*
|
|
636
|
+
* It opens with the device and the chip revision, then the calibration history stored on the drive (the latest full
|
|
637
|
+
* calibration, every stored run, the registers changed since that calibration, and every detail each run stored:
|
|
638
|
+
* versions, `HARD_REV`, amplitude control gain, registers and the iteration lines), whether health monitoring is
|
|
639
|
+
* on, the Nonius track offset table, the amplitude control gain, and every key configuration register with its RAM
|
|
640
|
+
* and EEPROM address and its value, and below it every field with its name, its slice, its value and its
|
|
641
|
+
* description.
|
|
315
642
|
* Registers the encoder calibration writes are marked with `*`.
|
|
316
643
|
*
|
|
317
644
|
* @returns The report, lines separated by `\n` and ending with a newline.
|
|
@@ -326,6 +653,8 @@ function formatCirculoIntegratedEncoderReport(report) {
|
|
|
326
653
|
`HARD_REV: ${formatIcMuChip(report.chip)}`,
|
|
327
654
|
'All values are raw, as read from the encoder.',
|
|
328
655
|
'',
|
|
656
|
+
...calibrationHistoryLines(report.calibrationHistory),
|
|
657
|
+
'',
|
|
329
658
|
`HEALTH MONITORING: ${healthMonitoring.active ? 'ON' : 'OFF'} (CFGEW = ${hex(healthMonitoring.cfgew)}, bit 6 = ${healthMonitoring.active ? 0 : 1})`,
|
|
330
659
|
'',
|
|
331
660
|
'NONIUS TRACK OFFSET TABLE',
|