stoner_measurement.plugins.monitor.motor_controller.MotorAngleMonitorPlugin

class stoner_measurement.plugins.monitor.motor_controller.MotorAngleMonitorPlugin(parent=None)[source]

Bases: MonitorPlugin

Monitor motor position and motion state without commanding movement.

Use this passive monitor when other sequence plugins need access to the current motor angle or motion status but should not change the motor target. On connection it opens the application’s preferred motor controller when necessary and starts the standard one-second monitor timer. Disconnecting stops this plugin’s timer while leaving the shared motor-controller engine available to scan, sweep, and set-position plugins.

The configuration page selects which quantities appear in the sequence value catalogue: Angle and Target Angle in degrees, Angular Rate in degrees per second, and the unitless Moving, At Target, and Stable flags. Boolean states are published as 1.0 or 0.0; unavailable position or motion readings are reported as NaN.

By default each read uses the latest state cached by the shared engine, avoiding an extra instrument transaction. Enable Force fresh controller poll when every monitor read must query the hardware directly. Fresh polling improves immediacy but increases communication traffic and may reduce the rate available to other controller operations.

This plugin is a leaf sequence step. A direct sequence execution performs one synchronous read(), while its timer can continue to update last_reading during an active measurement lifecycle. It never sets velocity, acceleration, direction, or target position.

The General tab sets the instance name and comment. Measurement selection and polling options are on Settings.

Variables:
  • report_angle (bool) – Publish the measured angle in degrees.

  • report_target_angle (bool) – Publish the active target angle in degrees.

  • report_moving (bool) – Publish whether the motor is currently moving.

  • report_angular_rate (bool) – Publish the measured angular rate in degrees per second.

  • report_at_target (bool) – Publish the engine’s at-target state.

  • report_stability (bool) – Publish the engine’s stable-state indication.

  • force_fresh_poll (bool) – Query the controller during every read instead of using cached engine state.

  • instance_name (str) – Inherited Python identifier for this instance in the Script tab and QtConsole.

  • comment (str) – Inherited optional note displayed beside this step.

  • sequence_engine (SequenceEngine | None) – Inherited owning engine and its live namespace; None while detached.

  • last_reading (dict[str, float]) – Inherited read-only access to the latest cached readings.

  • monitor_interval (int) – Inherited timer polling interval in milliseconds; initially 1000.

Keyword Parameters:

parent (QObject | None) – Optional Qt parent object.

Examples

With an instance named motor_angle_monitor in the sequence, use the QtConsole to inspect or edit it before running. Substitute your instance name if different; result data reflects completed steps:

motor_angle_monitor.force_fresh_poll = False
motor_angle_monitor.last_reading
angle() → float[source]

Return the latest measured motor angle in degrees.

angular_rate() → float[source]

Return the estimated angular rate in degrees per second.

at_target() → float[source]

Return 1.0 when the engine reports at-target, else 0.0.

config_widget(parent: QWidget | None = None) → QWidget[source]

Return a QWidget for configuring this plugin.

The default implementation returns a simple label. Override this method to provide a richer configuration interface. This method is called by the default config_tabs() implementation to supply the single tab widget.

Keyword Parameters:

parent (QWidget | None) – Optional Qt parent widget.

Returns:

The configuration widget for this plugin.

Return type:

(QWidget)

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.trace import DummyPlugin
>>> plugin = DummyPlugin()
>>> widget = plugin.config_widget()
>>> widget is not None
True
configure() → None[source]

No-op — the engine is configured by dedicated state-control plugins.

connect() → None[source]

Ensure a motor controller is connected and start monitoring.

property controller_features: frozenset[str]

Return controller feature flags required by this plugin.

declared_outputs() → PluginOutputs[source]

Declare configured outputs and their physical units together.

disconnect() → None[source]

Stop monitoring while leaving the shared engine running.

moving() → float[source]

Return 1.0 while moving, 0.0 when idle, or NaN if unknown.

property name: str

Unique human-readable name for this plugin.

property quantity_names: list[str]

Ordered list of quantity identifiers returned by read().

Returns:

Names matching the keys in the dict returned by read().

Return type:

(list[str])

read(*, force_poll: bool = False) → dict[str, float][source]

Perform a single synchronous hardware read and return the results.

Subclasses implement acquisition only. The base class wraps overrides to cache a copy and emit data_available once after a successful outermost read. Direct, timer and generated calls share this behaviour. Failed reads propagate without replacing the last successful reading; the polling callback additionally emits read_error.

Returns:

Mapping of quantity name to measured value.

Return type:

(dict[str, float])

Raises:

Exception – Any hardware communication error; callers should handle exceptions appropriately.

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor import MonitorPlugin
>>> class _ConstMonitor(MonitorPlugin):
...     @property
...     def name(self): return "Const"
...     @property
...     def quantity_names(self): return ["x"]
...     @property
...     def units(self): return {"x": "au"}
...     def read(self): return {"x": 42.0}
>>> m = _ConstMonitor()
>>> m.read()
{'x': 42.0}
stable() → float[source]

Return 1.0 when the engine reports stable, else 0.0.

target_angle() → float[source]

Return the current target angle in degrees, if known.

to_json() → dict[str, object][source]

Serialise this plugin’s configuration to a JSON-compatible dict.

The returned dict contains at minimum:

  • "type" — the plugin sub-type tag (e.g. "trace", "state").

  • "class" — the fully qualified class path "module:ClassName" used by from_json() to reconstruct the exact subclass.

  • "instance_name" — the current instance_name.

Subclasses should call super().to_json() and then add their own configuration keys to the returned dict.

Returns:

A JSON-serialisable dictionary representing this plugin’s current configuration.

Return type:

(dict[str, Any])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.trace import DummyPlugin
>>> plugin = DummyPlugin()
>>> d = plugin.to_json()
>>> d["type"]
'trace'
>>> d["instance_name"]
'dummy'
>>> "class" in d
True
property units: dict[str, str]

Mapping of quantity name to physical unit string.

Returns:

E.g. {"temperature": "K", "pressure": "Pa"}.

Return type:

(dict[str, str])