Skip to content

fposbapi_axis

fposbapi_axis

FPosBAPI axis proxy — represents one axis of a CECC-X controlled gantry.

FPosBAxis delegates all motion commands through a shared FPosBAPIClient socket connection to the CECC-X PLC. It satisfies the Axis structural interface and can be used anywhere a EdconAxis is accepted by Gantry.

Axis index convention (matches CECC-X CoDeSys program default):

  • 1 — X axis
  • 2 — Y axis
  • 3 — Z axis

ROB_POS response field layout assumed by FPosBAxis.get_current_axis_position::

1
msg_id, ROB_POS, x_mm, y_mm, z_mm, 0, NULL, SUCCESS

Position at field index axis_index + 1 (1-based field 2 = X, 3 = Y, 4 = Z).

.. warning:: move issues a SET_PAR 103 (global speed) command immediately before MOVE_AXIS. These two commands are serialised by the shared FPosBAPIClient lock, but they are not atomic — concurrent moves on different axes may interleave their SET_PAR calls. Use Gantry.move_to with a single-axis movement queue (not concurrent) when per-move velocity accuracy matters.

FPosBAxis

FPosBAxis(name: str, index: int, client: FPosBAPIClient)

FPosBAPI-backed representation of a single CECC-X gantry axis.

Wraps MOVE_AXIS, HOME, and ROB_POS FPosBAPI commands behind the same public interface as EdconAxis. All socket communication is performed via the shared client instance which must be owned by the parent Gantry.

Attributes:

Name Type Description
name

Human-readable axis label, e.g. "X".

index

1-based axis number sent to MOV_AXIS (1=X, 2=Y, 3=Z by CECC-X convention).

Initialise the axis proxy.

Parameters:

Name Type Description Default
name str

Human-readable axis label used in log messages and equality checks.

required
index int

1-based axis index for MOVE_AXIS commands. Must match the axis numbering configured in the CECC-X CoDeSys program.

required
client FPosBAPIClient

Shared FPosBAPIClient instance owned by the parent gantry.

required
Source code in src/applied_motion/backends/fposbapi_axis.py
def __init__(self, name: str, index: int, client: FPosBAPIClient) -> None:
    """Initialise the axis proxy.

    Args:
        name: Human-readable axis label used in log messages and equality
            checks.
        index: 1-based axis index for ``MOVE_AXIS`` commands.  Must match
            the axis numbering configured in the CECC-X CoDeSys program.
        client: Shared [`FPosBAPIClient`][applied_motion.backends.fposbapi_client.FPosBAPIClient]
            instance owned by the parent gantry.
    """
    self.name = name
    self.index = index
    self._client = client
    self.min_position: float = -inf
    self.max_position: float = inf
    logger.info("FPosBAxis '%s' (index=%d) created", name, index)

move

move(
    position: float,
    velocity: float,
    timeout: int | None = None,
    **kwargs,
) -> bool

Move this axis to position at velocity.

Sets the global gantry speed (parameter 103) to velocity before issuing the MOVE_AXIS command. The call blocks until the PLC reports SUCCESS.

Parameters:

Name Type Description Default
position float

Target position in mm. Interpreted as absolute by default; pass position_type="relative" in kwargs for a relative displacement.

required
velocity float

Move speed in mm/s. Written to PLC parameter 103 (global speed) before the move.

required
timeout int | None

Optional per-command socket timeout in seconds for the MOVE_AXIS request. None means blocking mode for this request.

None
**kwargs

Optional keyword overrides. Recognised keys:

  • position_type (str): "absolute" (default) or "relative".
{}

Returns:

Type Description
bool

True when both the speed parameter and move commands succeed;

bool

False if the PLC rejects either command.

Raises:

Type Description
~FPosBAPICommunicationError

If a communication or protocol failure occurs.

Source code in src/applied_motion/backends/fposbapi_axis.py
def move(self, position: float, velocity: float, timeout: int | None = None, **kwargs) -> bool:
    """Move this axis to *position* at *velocity*.

    Sets the global gantry speed (parameter 103) to *velocity* before
    issuing the ``MOVE_AXIS`` command.  The call blocks until the PLC
    reports ``SUCCESS``.

    Args:
        position: Target position in mm.  Interpreted as absolute by
            default; pass ``position_type="relative"`` in *kwargs* for a
            relative displacement.
        velocity: Move speed in mm/s.  Written to PLC parameter 103
            (global speed) before the move.
        timeout: Optional per-command socket timeout in seconds for the
            ``MOVE_AXIS`` request.  ``None`` means blocking mode for this
            request.
        **kwargs: Optional keyword overrides.  Recognised keys:

            - ``position_type`` (``str``): ``"absolute"`` (default) or
              ``"relative"``.

    Returns:
        ``True`` when both the speed parameter and move commands succeed;
        ``False`` if the PLC rejects either command.

    Raises:
        ~applied_motion.backends.fposbapi_client.FPosBAPICommunicationError: If a
            communication or protocol failure occurs.
    """
    position_type = kwargs.get("position_type", "absolute")
    rel_flag = 0 if position_type == "absolute" else 1
    logger.debug(
        "FPosBAxis '%s': move position=%s velocity=%s rel_flag=%d",
        self.name,
        position,
        velocity,
        rel_flag,
    )
    if not self._client.try_command("SET_PAR", 103, velocity):
        return False
    result = self._client.try_command("MOVE_AXIS", self.index, rel_flag, position, timeout=timeout)
    if result:
        logger.info(
            "FPosBAxis '%s': move complete (position=%s mm, velocity=%s mm/s)",
            self.name,
            position,
            velocity,
        )
    return result

home

home() -> bool

Issue the HOME command, homing all axes together.

The FPosBAPI HOME command references every axis simultaneously — there is no per-axis home. Calling this method on any individual proxy triggers a full multi-axis homing sequence.

.. note:: Gantry.home sends a single HOME command at the gantry level and does not call this method on each proxy individually, avoiding duplicate HOME requests.

Returns:

Type Description
bool

True when the PLC reports the HOME command succeeded; False

bool

if the PLC rejects it.

Raises:

Type Description
~FPosBAPICommunicationError

If a communication or protocol failure occurs.

Source code in src/applied_motion/backends/fposbapi_axis.py
def home(self) -> bool:
    """Issue the ``HOME`` command, homing all axes together.

    The FPosBAPI ``HOME`` command references every axis simultaneously —
    there is no per-axis home.  Calling this method on any individual
    proxy triggers a full multi-axis homing sequence.

    .. note::
        [`Gantry.home`][applied_motion.applied_motion.Gantry.home] sends a single
        ``HOME`` command at the gantry level and does not call this method
        on each proxy individually, avoiding duplicate ``HOME`` requests.

    Returns:
        ``True`` when the PLC reports the HOME command succeeded; ``False``
        if the PLC rejects it.

    Raises:
        ~applied_motion.backends.fposbapi_client.FPosBAPICommunicationError: If a
            communication or protocol failure occurs.
    """
    logger.info("FPosBAxis '%s': issuing HOME command (homes all axes)", self.name)
    return self._client.try_command("HOME", timeout=None)

get_current_axis_position

get_current_axis_position() -> float

Return this axis's current position in mm via ROB_POS.

Sends ROB_POS and extracts this axis's coordinate from the response. Assumes the response layout::

1
msg_id, ROB_POS, x_mm, y_mm, z_mm, 0, NULL, SUCCESS

where the position field for axis n is at fields[n + 1] (1-based field numbering after stripping the leading msg_id and ROB_POS label fields).

Returns:

Type Description
float

Current axis position in mm.

Raises:

Type Description
RuntimeError

If the response cannot be parsed.

~FPosBAPIClientError

If the PLC returns an error response.

Source code in src/applied_motion/backends/fposbapi_axis.py
def get_current_axis_position(self) -> float:
    """Return this axis's current position in mm via ``ROB_POS``.

    Sends ``ROB_POS`` and extracts this axis's coordinate from the
    response.  Assumes the response layout::

        msg_id, ROB_POS, x_mm, y_mm, z_mm, 0, NULL, SUCCESS

    where the position field for axis *n* is at ``fields[n + 1]``
    (1-based field numbering after stripping the leading ``msg_id``
    and ``ROB_POS`` label fields).

    Returns:
        Current axis position in mm.

    Raises:
        RuntimeError: If the response cannot be parsed.
        ~applied_motion.backends.fposbapi_client.FPosBAPIClientError: If the
            PLC returns an error response.
    """
    response = self._client.send_command("ROB_POS")
    fields = [
        f.strip() for f in response[-1].split(",")
    ]  # TODO: Make this a function in the client that is passed in here
    # fields[0] = msg_id, fields[1] = "ROB_POS", fields[2] = X, fields[3] = Y, fields[4] = Z
    position_field_index = self.index + 1
    try:
        value = float(fields[position_field_index])
    except (IndexError, ValueError) as exc:
        logger.exception(
            "FPosBAxis '%s': cannot parse ROB_POS response — %s",
            self.name,
            response,
        )
        raise RuntimeError(
            f"Failed to parse ROB_POS position for axis '{self.name}' "
            f"(field index {position_field_index}): {response!r}"
        ) from exc
    logger.debug("FPosBAxis '%s': current position = %s mm", self.name, value)
    return value

is_homed

is_homed() -> bool

Return whether the gantry has been homed via IS_HOME.

Sends IS_HOME and interprets the response field that follows the echoed command name. The PLC returns 1 when homing is complete and 0 when it is not.

Returns:

Type Description
bool

True if the PLC reports the gantry is homed; False

bool

otherwise.

Raises:

Type Description
~FPosBAPIClientError

If the PLC returns an error response.

RuntimeError

If the response cannot be parsed.

Source code in src/applied_motion/backends/fposbapi_axis.py
def is_homed(self) -> bool:
    """Return whether the gantry has been homed via ``IS_HOME``.

    Sends ``IS_HOME`` and interprets the response field that follows the
    echoed command name.  The PLC returns ``1`` when homing is complete
    and ``0`` when it is not.

    Returns:
        ``True`` if the PLC reports the gantry is homed; ``False``
        otherwise.

    Raises:
        ~applied_motion.backends.fposbapi_client.FPosBAPIClientError: If the
            PLC returns an error response.
        RuntimeError: If the response cannot be parsed.
    """
    response = self._client.send_command("IS_HOME")
    fields = [f.strip() for f in response[-1].split(",")]
    # fields: msg_id, IS_HOME, value, ERR_ID, ERR_TYPE, SUCCESS
    try:
        homed = bool(int(fields[2]))
    except (IndexError, ValueError) as exc:
        raise RuntimeError(f"Failed to parse IS_HOME response for axis '{self.name}': {response!r}") from exc
    logger.debug("FPosBAxis '%s': is_homed=%s", self.name, homed)
    return homed

stopped

stopped() -> bool

Return True; FPosBAPI moves are blocking so motion is always complete on return.

move blocks until the PLC emits a SUCCESS response, meaning by the time Python regains control the axis has stopped. This method always returns True to satisfy the Axis interface.

Returns:

Type Description
bool

Always True.

Source code in src/applied_motion/backends/fposbapi_axis.py
def stopped(self) -> bool:
    """Return ``True``; FPosBAPI moves are blocking so motion is always complete on return.

    [`move`][applied_motion.backends.fposbapi_axis.FPosBAxis.move] blocks until the PLC emits a ``SUCCESS`` response,
    meaning by the time Python regains control the axis has stopped.
    This method always returns ``True`` to satisfy the
    [`Axis`][applied_motion.backends.axis_protocol.Axis] interface.

    Returns:
        Always ``True``.
    """
    return True

acknowledge_faults

acknowledge_faults()

Clear errors.

Source code in src/applied_motion/backends/fposbapi_axis.py
def acknowledge_faults(self):
    """Clear errors."""
    pass

enable_powerstage

enable_powerstage()

Turn on torque to motor controlling this axis.

Source code in src/applied_motion/backends/fposbapi_axis.py
def enable_powerstage(self):
    """Turn on torque to motor controlling this axis."""
    # TODO: Implement this functionality using corresponding FPosBAPI command
    pass

disable_powerstage

disable_powerstage()

Turn off torque to motor controlling this axis.

Source code in src/applied_motion/backends/fposbapi_axis.py
def disable_powerstage(self):
    """Turn off torque to motor controlling this axis."""
    # TODO: Implement this functionality using corresponding FPosBAPI command
    pass

current_position

current_position()

Return current position.

Source code in src/applied_motion/backends/fposbapi_axis.py
def current_position(self):
    """Return current position."""
    # TODO: Implement this functionality using corresponding FPosBAPI command
    pass

current_velocity

current_velocity()

Return current velocity.

Source code in src/applied_motion/backends/fposbapi_axis.py
def current_velocity(self):
    """Return current velocity."""
    pass

jog_task

jog_task(
    jog_positive: bool = True,
    jog_negative: bool = False,
    incremental: bool = False,
    duration: float = 0.0,
) -> bool

Jog axis.

Source code in src/applied_motion/backends/fposbapi_axis.py
def jog_task(
    self,
    jog_positive: bool = True,
    jog_negative: bool = False,
    incremental: bool = False,
    duration: float = 0.0,
) -> bool:
    """Jog axis."""
    # TODO: Implement this functionality using corresponding FPosBAPI command
    return True

ready_for_motion

ready_for_motion() -> bool

Return whether the gantry drives are enabled via IS_ENBL.

Sends IS_ENBL and interprets the response. The PLC returns 1 when drives are enabled and ready to accept motion commands, 0 when they are disabled.

Returns:

Type Description
bool

True if the PLC reports drives are enabled; False

bool

otherwise.

Raises:

Type Description
~FPosBAPIClientError

If the PLC returns an error response.

RuntimeError

If the response cannot be parsed.

Source code in src/applied_motion/backends/fposbapi_axis.py
def ready_for_motion(self) -> bool:
    """Return whether the gantry drives are enabled via ``IS_ENBL``.

    Sends ``IS_ENBL`` and interprets the response.  The PLC returns
    ``1`` when drives are enabled and ready to accept motion commands,
    ``0`` when they are disabled.

    Returns:
        ``True`` if the PLC reports drives are enabled; ``False``
        otherwise.

    Raises:
        ~applied_motion.backends.fposbapi_client.FPosBAPIClientError: If the
            PLC returns an error response.
        RuntimeError: If the response cannot be parsed.
    """
    response = self._client.send_command("IS_ENBL")
    fields = [f.strip() for f in response[-1].split(",")]
    # fields: msg_id, IS_ENBL, value, ERR_ID, ERR_TYPE, SUCCESS
    try:
        enabled = bool(int(fields[2]))
    except (IndexError, ValueError) as exc:
        raise RuntimeError(f"Failed to parse IS_ENBL response for axis '{self.name}': {response!r}") from exc
    logger.debug("FPosBAxis '%s': ready_for_motion=%s", self.name, enabled)
    return enabled