Skip to content

edcon_axis

edcon_axis

Modbus TCP axis backend — direct per-drive edcon/CMMT connection.

EdconAxis is the original Festo gantry axis implementation. It connects directly to an individual CMMT servo/stepper drive via Modbus TCP using the festo-edcon library, and exposes a millimetre-based public API that satisfies Axis.

This backend is appropriate when each drive is individually addressable on the network and Gantry manages concurrency in Python.

For coordinated multi-axis motion managed by a CECC-X PLC using the Festo Easy Positioning API, use FPosBAxis with the FPosBAPI backend instead.

EdconAxis

EdconAxis(
    name: str,
    ip: str,
    run_referencing: bool = False,
    max_position: float = inf,
    min_position: float = -inf,
)

Bases: MotionHandler

Modbus TCP axis: direct festo-edcon MotionHandler connection to one drive.

Wraps low-level Modbus communication and position/velocity unit conversion behind a millimetre-based public API. All position values accepted and returned by the public methods use millimetres (mm) as their unit.

Attributes:

Name Type Description
name

Human-readable label for this axis (e.g. "X").

ip

IPv4 address of the drive's Modbus TCP endpoint.

com

Active ComModbus connection.

max_speed float

Maximum achievable speed in drive velocity units.

max_position float

Maximum achievable position in mm.

min_position float

Minimum achievable position in mm.

Initialise the axis and establish a Modbus connection.

Creates the ComModbus connection, initialises the parent MotionHandler, reads the software-limit PNUs, and optionally triggers homing.

Parameters:

Name Type Description Default
name str

Human-readable axis label used in log messages and equality checks. Axis labels are unique within a gantry.

required
ip str

IPv4 address of the Festo drive's Modbus TCP interface.

required
run_referencing bool

When True, perform a homing (referencing) sequence during construction. Defaults to False.

False
max_position float

Optional max position limitation, if the drive is restricted more than the internal SW limit position check. This avoids an issue where traversing toward the actual endstop is interrupted because the interia of the motion causes the drive to overshoot the limit position, throwing an error and interrupting the power stage on state.

inf
min_position float

Optional min position limitation, if the drive is restricted more than the internal SW limit position check. This avoids an issue where traversing toward the actual endstop is interrupted because the interia of the motion causes the drive to overshoot the limit position, throwing an error and interrupting the power stage on state.

-inf
Source code in src/applied_motion/backends/edcon_axis.py
def __init__(
    self,
    name: str,
    ip: str,
    run_referencing: bool = False,
    max_position: float = inf,
    min_position: float = -inf,
) -> None:
    """Initialise the axis and establish a Modbus connection.

    Creates the `ComModbus` connection,
    initialises the parent `MotionHandler`,
    reads the software-limit PNUs, and optionally triggers homing.

    Args:
        name: Human-readable axis label used in log messages and equality
            checks.  Axis labels are unique within a gantry.
        ip: IPv4 address of the Festo drive's Modbus TCP interface.
        run_referencing: When ``True``, perform a homing (referencing)
            sequence during construction.  Defaults to ``False``.
        max_position: Optional max position limitation, if the drive is restricted
            more than the internal SW limit position check. This avoids an issue where
            traversing toward the actual endstop is interrupted because the interia of
            the motion causes the drive to overshoot the limit position, throwing an error
            and interrupting the power stage on state.
        min_position: Optional min position limitation, if the drive is restricted
            more than the internal SW limit position check. This avoids an issue where
            traversing toward the actual endstop is interrupted because the interia of
            the motion causes the drive to overshoot the limit position, throwing an error
            and interrupting the power stage on state.
    """
    self.name = name
    self.ip = ip
    self.com = ComModbus(self.ip)
    super().__init__(self.com)
    self.acknowledge_faults()

    self.acknowledge_faults()
    # self.home()
    logger.info("Axis '%s': initialized", self.name)
    self.configure_software_limit_switch(True)
    logger.info("Axis '%s': software limit switch configured", self.name)

    self._neg_sw_limit: int = self.com.read_pnu(834)
    self._pos_sw_limit: int = self.com.read_pnu(835)

    self._min_vel: int = self.com.read_pnu(11212)
    self._max_vel: int = self.com.read_pnu(11213)
    self._pos_scale_exp: int = self.com.read_pnu(11724)
    self._vel_scale_exp: int = self.com.read_pnu(11725)
    self.input_pos_unit = {"distance": {"unit": "m", "power": 1, "power_of_ten": -3}}
    self.input_vel_unit = {
        "distance": {"unit": "m", "power": 1, "power_of_ten": -3},
        "time": {"unit": "s", "power": -1, "power_of_ten": 1},
    }
    self.max_position = -1 + min(
        max_position,
        self._valid_position(self._pos_sw_limit, self.input_pos_unit, invert=True),
    )  # TODO: Fix overshooting following error in drive control
    self.min_position = 1 + max(
        min_position,
        self._valid_position(self._neg_sw_limit, self.input_pos_unit, invert=True),
    )  # TODO: Fix overshooting following error in drive control
    self.max_velocity = self._valid_velocity(
        self._max_vel, self.input_vel_unit, invert=True
    )  # TODO: Get these from config, compare with SW limits and take most restrictive superset
    self.min_velocity = self._valid_velocity(
        self._min_vel, self.input_vel_unit, invert=True
    )  # TODO: Get these from config, compare with SW limits and take most restrictive superset

    logger.info(
        "Axis '%s': SW limits loaded — neg=%s, pos=%s (drive units)",
        self.name,
        self._neg_sw_limit,
        self._pos_sw_limit,
    )
    logger.info(
        "Axis '%s': SW limits loaded — neg=%s, pos=%s (standard units)",
        self.name,
        self.min_position,
        self.max_position,
    )

    if self.fault_present():
        logger.warning("Axis '%s': fault present on init", self.name)
    logger.debug("Axis '%s' fault string: %s", self.name, self.fault_string())
    logger.debug("Axis '%s' current fault code: %s", self.name, self.current_fault_code())
    self.acknowledge_faults()
    self.enable_powerstage()

    if run_referencing:
        logger.info("Axis '%s': referencing requested during initialization", self.name)
        self.home()

max_speed property

max_speed: float

Return largest allowed speed magnitude for this axis in mm/s.

This derives from configured signed velocity bounds and returns absolute maximum magnitude, independent of direction.

Returns:

Type Description
float

Maximum absolute velocity limit in mm/s.

home

home() -> bool

Home the axis by running a referencing task.

Acknowledges any faults, enables the power stage, and then executes a blocking referencing task to establish the axis zero point.

Source code in src/applied_motion/backends/edcon_axis.py
def home(self) -> bool:
    """Home the axis by running a referencing task.

    Acknowledges any faults, enables the power stage, and then
    executes a blocking referencing task to establish the axis zero
    point.
    """
    logger.info("Axis '%s': starting homing sequence", self.name)
    self.acknowledge_faults()
    self.enable_powerstage()
    res = self.referencing_task(nonblocking=False)

    logger.info("Axis '%s': homing result=%s", self.name, res)
    logger.info("Axis '%s': homing complete", self.name)
    return res

is_homed

is_homed() -> bool

Checks whether drive has been homed and has a valid frame of reference.

Thin wrapper for interface consistency around MotionHandler.referenced().

Source code in src/applied_motion/backends/edcon_axis.py
def is_homed(self) -> bool:
    """Checks whether drive has been homed and has a valid frame of reference.

    Thin wrapper for interface consistency around `MotionHandler.referenced()`.

    """
    return self.referenced()

current_position

current_position()

Transparent wrapper around MotionHandler.current_position.

TODO: is this necessary?

Returns the raw position value in the drive's internal unit system (drive units, whose scale is determined by PNU 11724 and varies by firmware/configuration — typically 0.001 mm per unit). Use get_current_axis_position when you need the position in a consistent, human-readable unit (mm).

Source code in src/applied_motion/backends/edcon_axis.py
def current_position(self):
    """Transparent wrapper around ``MotionHandler.current_position``.

    # TODO: is this necessary?

    Returns the raw position value in the drive's **internal unit system**
    (drive units, whose scale is determined by PNU 11724 and varies by
    firmware/configuration — typically 0.001 mm per unit).  Use
    [`get_current_axis_position`][applied_motion.backends.edcon_axis.EdconAxis.get_current_axis_position] when you need the position in a
    consistent, human-readable unit (mm).
    """
    logger.warning(
        "Axis '%s': current_position() returns a raw drive-unit value — "
        "unit depends on drive configuration (PNU 11724). "
        "Call get_current_axis_position() for a consistent mm value.",
        self.name,
    )
    return super().current_position()

get_current_axis_position

get_current_axis_position() -> float

Return the current axis position in the library's canonical output unit (mm).

Reads the raw drive-unit position from MotionHandler.current_position, then converts it to mm via _valid_position with invert=True. The drive's own PNU-reported position-unit scale is used for the conversion, so the result is always consistent regardless of how the drive was configured.

Internal methods (_check_overshoot, unit converters) continue to use super().current_position() directly so their drive-unit arithmetic is unaffected.

Source code in src/applied_motion/backends/edcon_axis.py
def get_current_axis_position(self) -> float:
    """Return the current axis position in the library's canonical output unit (mm).

    Reads the raw drive-unit position from ``MotionHandler.current_position``,
    then converts it to mm via `_valid_position` with ``invert=True``.
    The drive's own PNU-reported position-unit scale is used for the
    conversion, so the result is always consistent regardless of how the
    drive was configured.

    Internal methods (`_check_overshoot`, unit converters) continue to
    use ``super().current_position()`` directly so their drive-unit arithmetic
    is unaffected.
    """
    _mm_unit = {"distance": {"unit": "m", "power": 1, "power_of_ten": -3}}
    return self._valid_position(super().current_position(), _mm_unit, invert=True)

move

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

Move the axis to a specified position with a given velocity.

Parameters:

Name Type Description Default
position int | float

Target position in millimetres (mm). Converted internally to drive units before the motion command is issued.

required
velocity int | float

Move velocity in mm/s. Converted internally to drive units.

required
timeout int | None

Optional time limit in seconds for the move. When provided, the motion is launched in a background thread and a stop command is issued if the thread has not finished by the deadline. When None (default), the call blocks until motion completes.

None
**kwargs

Optional keyword overrides. Recognised keys:

  • position_type (str): "absolute" for an absolute target position or "relative" for a relative displacement. When omitted the move is treated as absolute.
{}

Returns:

Type Description
bool

True if the motion task succeeded, False otherwise.

Source code in src/applied_motion/backends/edcon_axis.py
def move(self, position: int | float, velocity: int | float, timeout: int | None = None, **kwargs) -> bool:
    """Move the axis to a specified position with a given velocity.

    Args:
        position: Target position in millimetres (mm).  Converted internally
            to drive units before the motion command is issued.
        velocity: Move velocity in mm/s.  Converted internally to drive units.
        timeout: Optional time limit in seconds for the move.  When provided,
            the motion is launched in a background thread and a stop command
            is issued if the thread has not finished by the deadline.  When
            ``None`` (default), the call blocks until motion completes.
        **kwargs: Optional keyword overrides.  Recognised keys:

            - ``position_type`` (``str``): ``"absolute"`` for an absolute
              target position or ``"relative"`` for a relative displacement.
              When omitted the move is treated as **absolute**.

    Returns:
        ``True`` if the motion task succeeded, ``False`` otherwise.
    """
    # TODO: check valid move parameters against internal set values
    # e.g. Position limit, velocity limit, acceleration limit, etc.
    # if not valid, raise exception
    pos_type = kwargs.get("position_type", "absolute")
    logger.debug(
        "Axis '%s': entering move — raw position=%s  raw velocity=%s raw timeout=%s raw position_type=%s",
        self.name,
        position,
        velocity,
        timeout,
        pos_type,
    )
    positioning_type = pos_type == "absolute"

    clamped_position = self._clamped_target(position, positioning_type)
    logger.debug("Axis '%s': processing move — clamped_position=%s", self.name, clamped_position)
    try:
        validated_position = int(self._valid_position(clamped_position, self.input_pos_unit))
    except Exception:
        logger.exception("Axis '%s': failed to validate position", self.name)
        validated_position = -5  # TODO: This seems bad and wrong

    try:
        validated_velocity = int(self._valid_velocity(velocity, self.input_vel_unit))
    except Exception:
        logger.exception("Axis '%s': failed to validate velocity", self.name)
        validated_velocity = 5  # TODO: This seems bad and wrong
    logger.debug(
        "Axis '%s': processing move — validated_position=%s  validated_velocity=%s",
        self.name,
        validated_position,
        validated_velocity,
    )
    # self.configure_continuous_update(True) # continous update so that new position tasks can be started while still in motion
    #
    # TODO: Check faults and abort if critical fault encountered

    # self.acknowledge_faults()

    logger.debug(
        "Axis '%s': fault_string=%s  fault_code=%s", self.name, self.fault_string(), self.current_fault_code()
    )
    validated_position = self._check_overshoot(validated_position, absolute=positioning_type)
    logger.debug(
        "Axis '%s': clamped_position=%s  validated_velocity=%s", self.name, validated_position, validated_velocity
    )
    # Skip if already at target (absolute) or zero delta (relative).
    at_target = (
        abs(validated_position - int(super().current_position())) == 0
        if positioning_type
        else abs(validated_position) == 0
    )
    if at_target:
        logger.info("Axis '%s': already at target drive position %s, skipping move", self.name, validated_position)
        return True
    result: bool = False
    # TODO: Check powerstage enabled, attempt enable if not
    # TODO:
    # TODO: Check for CRITICAL error stages,
    # TODO: ack faults,
    # TODO: then move.
    # TODO: Incorporate jog mode into this function?
    self.acknowledge_faults()
    self.enable_powerstage()
    if timeout is None:
        result = self.position_task(
            validated_position,
            validated_velocity,
            absolute=positioning_type,
            nonblocking=False,
        )
    else:
        _result_box: list[bool] = []
        move_thread = Thread(
            target=lambda: _result_box.append(
                self.position_task(
                    validated_position,
                    validated_velocity,
                    absolute=positioning_type,
                    nonblocking=False,
                )
            )
        )
        move_thread.start()
        move_thread.join(timeout=timeout)
        if move_thread.is_alive():
            logger.warning("Axis '%s': move timed out after %ss — sending stop motion task", self.name, timeout)
            self.stop_motion_task()
            # Wait for the thread to actually exit before returning; 50 ms is not enough.
            move_thread.join(timeout=timeout)
            if move_thread.is_alive():
                logger.error(
                    f"Axis '%s': position_task thread still alive {timeout}s after stop command", self.name
                )
        else:
            result = _result_box[0] if _result_box else False  # TODO: AllTrue?

    logger.info("Axis '%s': motion task complete, result=%s", self.name, result)
    return result