session
session
Gantry commissioning and motion session — position recording and jogging.
This module is backend-agnostic. It does not depend on prompt_toolkit
or rich and can be imported and tested without the teach extra
installed, as long as applied_motion.cli (the package guard)
is not triggered first.
The MotionSession class deliberately avoids calling any private
attributes of Gantry.
PLC-specific actions (TEACH_POS, TEACH_TRAY) are delegated to the
caller via the on_capture hook, keeping this class backend-agnostic and
independently unit-testable.
OnCaptureHook
module-attribute
Type alias for the optional capture hook.
Signature: on_capture(label: str, position: dict[str, float]) -> None
Called after every successful MotionSession.capture with the
position label and the recorded position dict. Typical uses:
- Send
TEACH_POS/TEACH_TRAYto the CECC-X PLC viaFPosBAPIClient. - Emit an event to a higher-level orchestration layer.
- Write a running log to a remote database.
MotionSession
Records gantry positions interactively or programmatically.
Provides step-jog and position capture on top of a connected
Gantry. Captured positions are kept
in positions and can be persisted to and from JSON via
save / load.
This class has no knowledge of the gantry backend (Modbus vs FPosBAPI)
and no dependency on prompt_toolkit or rich. Backend-specific
post-capture actions (e.g. sending TEACH_POS to the PLC) are
performed by the caller through the on_capture hook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gantry
|
Gantry
|
Connected and homed |
required |
on_capture
|
OnCaptureHook | None
|
Optional hook called immediately after each successful
|
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
dict[str, dict[str, float]]
|
Example::
1 2 3 4 5 6 7 8 9 | |
Source code in src/applied_motion/cli/session.py
jog
jog(
axis_name: str,
direction: str,
step_mm: float,
velocity: float = 10.0,
timeout: int = 15,
) -> dict[str, float]
Step-move one axis by step_mm in direction.
Reads the current axis position, computes an absolute target, and
dispatches a single-axis move via
Gantry.move_to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis_name
|
str
|
Name of the axis to jog (must be a key in
|
required |
direction
|
str
|
|
required |
step_mm
|
float
|
Distance to step in millimetres. Must be positive. |
required |
velocity
|
float
|
Jog speed in mm/s. Defaults to |
10.0
|
timeout
|
int
|
Maximum seconds to wait for the move to complete.
When exceeded the axis backend issues a stop command and
the move is abandoned. Defaults to |
15
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Full gantry location dict after the move completes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If direction is not |
KeyError
|
If axis_name is not registered with the gantry. |
Source code in src/applied_motion/cli/session.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
capture
Record the current gantry position under label.
Calls Gantry.get_location, stores
the result in positions, then invokes on_capture if one
was provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Unique name for this position (e.g. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
The recorded position dict |
Source code in src/applied_motion/cli/session.py
save
Write all captured positions to a JSON file.
The output format is a plain JSON object mapping label →
{axis_name: position_mm}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Destination file path. Parent directories must exist. |
required |
Source code in src/applied_motion/cli/session.py
load
Merge positions from a JSON file into positions.
Existing labels are overwritten by entries from path; labels absent in path are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Source JSON file previously written by |
required |
Raises:
| Type | Description |
|---|---|
OSError
|
If path cannot be opened. |
ValueError
|
If the file contains invalid JSON. |