ops.calibration.manager — Runs the calibration procedure

This module contains the CalibrationManager class, which is responsible for calibrating the production system.

To start the calibration procedure, it is sufficient to create a calibration manager instance and call its startCalibration() method. The ProductionSystem that is to be calibrated and a list of heating currents that are to be used are passed to the constructor.

The calibration manager sends a CalibrationStarted event when the procedure is started, and a CalibrationOver event when it terminates. The production system is locked for the duration of the procedure.

The calibration procedure itself consists of a number of calibration stages. During the first stage, the system’s heater is moved to its foremost position. Subsequent stages are heating stages, which each use one of the heating currents that are passed to the calibration manager’s constructor. At the end of each heating stage, when the temperature sensor voltage has become reasonably stable, the user needs to take a temperature measurement. When a measurement is needed, the calibration manager sends a TemperatureRequested event.

The client is responsible for ensuring that some GUI component (most likely a TemperatureEntryHandler) is listening for these events, asks the user to take a measurement, and reports the result using the callback function that is sent along with the event. When a measurement has been reported, a TemperatureRequestOver event is sent.

The data that is collected during calibration is automatically added to the CalibrationData object of the production system that is being calibrated. If the object already has data for a given heating current, they are replaced with the new data gathered for that current, but data for heating currents that are not used during the ongoing calibration are retained, so that the calibration of a system can be refined with subsequent calibration procedures.

The calibration data object uses the data to fit a number of estimation functions, which are used to estimate the heating temperature that corresponds to a given temperature sensor voltage, and the heating current that results in the heating temperature reaching, but not exceeding, a given target temperature. About twelve heating currents should be used during calibration so that these functions can be properly fitted.

If a reasonable number of heating stages are used, the calibration procedure may take several hours. The calibration manager provides a number of methods (most notably getExtendedProgress()) that estimate the procedure’s progress and remaining duration, so that the user can receive some feedback about the state of the procure while it is running. The classes in the gui.calibration.progress module can be used to present this information to the user.

The calibration procedure may end prematurely if it is aborted by a client, or if the production system’s safe mode is triggered. The data that have already been collected are used nevertheless.

The CalibrationManager Class

class ops.calibration.manager.CalibrationManager(system, currents)

Creates a new instance of this class, using the arguments to set system and currents. currents is sorted first, and duplicate heating currents are removed.

Heating currents in currents that exceed the system‘s maxHeatingCurrent are skipped during calibration. In that case, the calibration procedure’s exit status will be STATUS_INVALID_CURRENT.

CalibrationManager.system
The ProductionSystem that is being calibrated. Immutable.
CalibrationManager.currents
A sorted tuple of the heating currents for which measurements are to be taken, in mA. Immutable.
CalibrationManager.startCalibration()
Starts the calibration procedure. Instances cannot be reused for a second calibration procedure, so this method may only be called once on any given object.
CalibrationManager.abortCalibration()
Aborts the calibration procedure. The data that have already been collected are still used.

Parameters

CalibrationManager.precision
The greatest difference between the estimated heating temperature and and the estimated final heating temperature that is small enough for a temperature measurement to be requested, in °C. This is a class attribute, but it can be set on an instance to override the default value.
CalibrationManager.tickInterval
The interval in which the instance records temperature sensor voltages, in milliseconds. This is a class attribute, but it can be set on an instance before startCalibration() is called to override the default value.

Progress Information

CalibrationManager.isRunning
Indicates whether the calibration procedure is running. It starts running as soon as startCalibration() is called, and terminates when a client calls abortCalibration(), the production system’s safe mode is triggered, or a temperature measurement for the last valid heating current is reported. Read-only.
CalibrationManager.state
The state the calibration procedure is in. Must be one of STATE_NOT_YET_STARTED, STATE_MOVING_HEATER, STATE_HEATING, STATE_WAITING_FOR_TEMPERATURE, and STATE_DONE. Read-only.
CalibrationManager.hasMoreHeatingStages
Indicates whether there will be another heating stage after the current one (if any) is finished. This will be False if all heating currents in currents have been used, or if the next current in currents exceeds the system‘s maxHeatingCurrent. Read-only.
CalibrationManager.heatingStageIndex
The index of the ongoing heating stage, or -1 if the procedure hasn’t yet reached the first heating stage. In heating stage n, the heating current currents[n] is used. Read-only.
CalibrationManager.heatingStageCount
The number of heating stages the calibration procedure will have if it isn’t terminated prematurely. May be less than len(currents), since some currents in currents may exceed the system‘s maxHeatingCurrent. Read-only.
CalibrationManager.remainingHeatingStageCount
The number of heating stages left after the ongoing one (if any) is finished. May be less than len(currents) - heatingStageIndex - 1, since some currents in currents may exceed the system‘s maxHeatingCurrent. Read-only.
CalibrationManager.getProgress()
Estimates what fraction of the time required to finish the ongoing calibration stage has already passed. The estimate returned is in the range [0.0, 1.0]. If the calibration procedure’s state is STATE_NOT_YET_STARTED or STATE_DONE, 0.0 and 1.0 are returned, respectively.
CalibrationManager.getExtendedProgress()

Returns a named tuple with the following attributes:

  • stageProgress, the estimated progress of the ongoing calibration stage, as a number in the range [0.0, 1.0] (equal to the return value of getProgress());
  • stageTimeLeft, the estimated amount of time remaining until the ongoing calibration stage is finished, in seconds, or None if no estimation is possible;
  • totalProgress, the estimated progress of the calibration procedure as a whole, as a number in the range [0.0, 1.0];
  • totalTimeLeft, the estimated amount of time remaining until the calibration procedure as a whole is finished, in seconds, or None if no estimation is possible.

If the calibration procedure’s state is STATE_NOT_YET_STARTED or STATE_DONE, the tuples (0.0, None, 0.0, None) and (1.0, None, 1.0, None) are returned, respectively.

Calibration States

ops.calibration.manager.STATE_NOT_YET_STARTED
Indicates that the calibration procedure has not yet started.
ops.calibration.manager.STATE_MOVING_HEATER
Indicates that the calibration manager is waiting for the heater to reach its foremost position.
ops.calibration.manager.STATE_HEATING
Indicates that the calibration manager is waiting for the heating temperature to get sufficiently close to its final value for a measurement to be taken.
ops.calibration.manager.STATE_WAITING_FOR_TEMPERATURE
Indicates that the calibration manager is waiting for the user to take a temperature measurement.
ops.calibration.manager.STATE_DONE
Indicates that the calibration procedure has ended.

Status Codes

ops.calibration.manager.STATUS_ABORTED
Indicates that the calibration procedure was aborted by the user.
ops.calibration.manager.STATUS_SAFE_MODE_TRIGGERED
Indicates that the calibration procedure was terminated when the ProductionSystem‘s safe mode was triggered.
ops.calibration.manager.STATUS_INVALID_CURRENT
Indicates that the calibration procedure was terminated because the next heating current would exceed the ProductionSystem‘s maxHeatingCurrent.
ops.calibration.manager.STATUS_FINISHED
Indicates that the calibration procedure sucessfully aquired temperatures for all passed heating currents.