virtual_knitting_machine.machine_components.yarn_management.Yarn_Carrier module

Yarn_Carrier representation module for managing individual yarn carriers on knitting machines. This module provides the Yarn_Carrier class which represents a single yarn carrier that can hold yarn, track position, and manage active/hooked states for knitting operations.

class Yarn_Carrier(carrier_id, yarn=None, yarn_properties=None, knit_graph=None)[source]

Bases: object

A class representing an individual yarn carrier on a knitting machine. Yarn carriers hold yarn and can be moved to different positions on the machine, activated for knitting operations, and connected to insertion hooks for yarn manipulation. Each carrier tracks its state including position, active status, and hook connection.

Parameters:
STOPPING_DISTANCE: int = 10
__init__(carrier_id, yarn=None, yarn_properties=None, knit_graph=None)[source]

Initialize a yarn carrier with specified ID and optional yarn configuration.

Parameters:
  • carrier_id (int) – Unique identifier for this yarn carrier.

  • yarn (None | Machine_Knit_Yarn, optional) – Existing machine knit yarn to assign to this carrier. Defaults to None.

  • yarn_properties (Yarn_Properties | None, optional) – Properties for creating new yarn if yarn parameter is None. Defaults to None.

  • knit_graph (Optional[Knit_Graph])

property yarn: Machine_Knit_Yarn

Get the yarn held on this carrier.

Returns:

The yarn held on this carrier.

Return type:

Machine_Knit_Yarn

property position: None | int

Get the needle position that the carrier sits at or None if inactive.

Returns:

The needle position that the carrier sits at or None if the carrier is not active.

Return type:

None | int

direction_to_needle(needle_position)[source]
Parameters:

needle_position (int | Needle) – The position of a needle to move towards.

Returns:

The direction that the carrier will move to reach the given position from its current position.

Return type:

Carriage_Pass_Direction

property last_direction: None | Carriage_Pass_Direction

Returns: Carriage_Pass_Direction | None: The last direction that the carrier was moved in or None if the carrier is inactive.

property conflicting_needle_slot: int | None

Returns: int | None: The needle slot that currently conflicts with the carrier or None if the carrier is not active.

property needle_range: None | tuple[int, int]

Returns: None | tuple[int, int]: The range of positions that a carrier may exist after an ambiguous movement or None if the carrier is inactive.

property is_active: bool

Check if the carrier is currently active (off the grippers).

Returns:

True if carrier is active, False otherwise.

Return type:

bool

property is_hooked: bool

Check if the carrier is connected to the insertion hook.

Returns:

True if connected to inserting hook, False otherwise.

Return type:

bool

bring_in()[source]

Record bring-in operation to activate the carrier without using insertion hook.

Warns:

In_Active_Carrier_Warning – If carrier is already active.

Return type:

None

inhook()[source]

Record inhook operation to bring in carrier using insertion hook.

Return type:

None

releasehook()[source]

Record release hook operation to disconnect carrier from insertion hook.

Return type:

None

out()[source]

Record out operation to deactivate the carrier and move to grippers.

Warns:

Out_Inactive_Carrier_Warning – If carrier is already inactive.

Return type:

None

outhook()[source]

Record outhook operation to cut and remove carrier using insertion hook.

Raises:

Hooked_Carrier_Exception – If carrier is already connected to yarn inserting hook.

Return type:

None

property carrier_id: int

Get the unique identifier of this carrier.

Returns:

ID of carrier, corresponds to order in machine.

Return type:

int

__lt__(other)[source]

Compare if this carrier ID is less than another carrier or integer.

Parameters:

other (int | Yarn_Carrier) – The carrier or integer to compare with.

Returns:

True if this carrier’s ID is less than the other.

Return type:

bool

__eq__(other)[source]

Equality comparison of a carrier to another carrier or object representing a carrier. :type other: int | Yarn_Carrier | Yarn_Carrier_Set | list[int | Yarn_Carrier] :param other: The carrier or object representing a carrier. :type other: int | Yarn_Carrier | Yarn_Carrier_Set | list[int | Yarn_Carrier]

Returns:

True if this carrier is equal to the other. Carrier sets are equal if they only contain this carrier.

Return type:

bool

__hash__()[source]

Return hash value based on carrier ID.

Returns:

Hash value of the carrier ID.

Return type:

int

__str__()[source]

Return string representation of the carrier.

Returns:

String representation showing carrier ID and yarn if different from ID.

Return type:

str

__repr__()[source]

Return string representation of the carrier.

Returns:

String representation of the carrier.

Return type:

str

__int__()[source]

Return integer representation of the carrier.

Returns:

The carrier ID as an integer.

Return type:

int