virtual_knitting_machine.machine_components.carriage_system.Carriage module

A module containing the Carriage class for managing carriage position and movements in virtual knitting machines. This module provides functionality for tracking carriage position, validating movements, and managing transfer operations on knitting machines.

class Carriage_State(*args, **kwargs)[source]

Bases: Relative_to_Needle_Bed[Machine_LoopT], Protocol

Protocol defining readable attributes of carriages.

property last_set_direction: Carriage_Pass_Direction

Returns: Carriage_Pass_Direction: The direction the carriage was last explicitly moved in (i.e., knits, tucks, splits).

classmethod __class_getitem__(params)

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….

__init__(*args, **kwargs)
__int__()
Returns:

The slot number of this position.

Return type:

int

aligned_with_slot(slot)
Parameters:

slot (int | Slotted_Position) – The slot to compare to.

Returns:

True if this is positioned at the same slot, False otherwise.

Return type:

bool

direction_to_slot(slot)
Parameters:

slot (int) – The slot to find a direction towards.

Returns:

The direction of carriage movement from this component to the slot or None if the slots are aligned.

Return type:

Carriage_Pass_Direction | None

handle_violations(response_policy=None, handler=None)

Context manager that catches exceptions and routes them through the violation policy.

Parameters:
  • response_policy (ViolationResponse | Violation, optional) – The ViolationResponse policy for this code block. If given a Violation, the response will be the policy assigned to that violation in the violation policy. Defaults to the response will be the default response of the violation policy.

  • handler (Callable[..., Any], optional) – Optional handler to attempt before falling back to the policy response.

in_pass_direction(slot, direction)
Parameters:
Returns:

True if the given slot is after this slot in the given direction. False otherwise.

Return type:

bool

property knitting_machine: Knitting_Machine_State[Machine_LoopT, Any]

Returns: Knitting_Machine_State: The knitting machine that owns this component.

property last_direction: Carriage_Pass_Direction

Returns: Carriage_Pass_Direction: The last direction the object moved in.

left_of_slot(slot)
Parameters:

slot (int | Slotted_Position) – The slot to compare to.

Returns:

True if this is positioned left of the given slot, False otherwise.

Return type:

bool

property machine_is_all_needle_racked: bool

Returns: bool: True if the knitting machine is racked for all needle knitting.

property machine_racking: int

Returns: int: The racking of the knitting machine.

property machine_specification: Knitting_Machine_Specification[Machine_LoopT]

Returns: Knitting_Machine_Specification[Machine_LoopT]: The machine specification of the machine associated with this component.

property needle_count_of_machine: int

Returns: int: The number of needles on each bed of the knitting machine. Defaults to the bed size in the knitting machine specification.

property position_on_bed: Needle_Bed_Position[Machine_LoopT]

Returns: Needle_Bed_Position: The position of the machine component relative to the needle bed.

right_of_slot(slot)
Parameters:

slot (int | Slotted_Position) – The slot to compare to.

Returns:

True if this is positioned right of the given slot, False otherwise.

Return type:

bool

property rightmost_slot_on_machine: int

Returns: int: The rightmost slot on this knitting machine. Defaults to the standard bed size in the knitting machine specification.

set_response_for(violation, response=None)

Sets the response for the given violation to the given response.

Parameters:
  • violation (Violation) – The violation to set the response for.

  • response (ViolationResponse, optional) – The response to set for the given violation. Defaults to the default response of this policy.

property slot_number: int

The slot number indicates the front-bed alignment of the given needle. For front bed needles this is equivalent to the position. For back bed needles this is dependent on the racking alignment of the beds.

Returns:

The slot number of the given component for the given racking.

Return type:

int

Notes

Racking Calculations: * R = F - B * F = R + B * B = F - R.

property violation_policy: Knitting_Machine_Error_Policy

Returns: Knitting_Machine_Error_Policy: The policy for handling machine state errors.

class Carriage(knitting_machine)[source]

Bases: Carriage_State[Machine_LoopT]

A class for tracking the carriage’s position and managing possible movements on a knitting machine.

The carriage is responsible for moving across the needle bed and performing knitting operations. This class manages position validation, movement direction tracking, and transfer operation states.

__init__(knitting_machine)[source]

Initialize a new carriage with specified position range and starting direction.

Parameters:

knitting_machine (Knitting_Machine) – The knitting machine this carriage belongs to.

property knitting_machine: Knitting_Machine[Machine_LoopT]

Returns: Knitting_Machine: The knitting machine that owns this carriage.

property position_on_bed: Needle_Bed_Position[Machine_LoopT]

Returns: Needle_Bed_Position: The position of the carriage relative to the needle bed.

property last_set_direction: Carriage_Pass_Direction

Returns: Carriage_Pass_Direction: The direction the carriage was moving prior to the current transfer pass.

move_in_direction(needle, direction)[source]

Move the carriage to the target needle in the specified direction. Updates the last_set_direction to the given direction. :param needle: The needle to move to. :type needle: Needle :param direction: The direction of the movement. :type direction: Carriage_Pass_Direction

move_to_needle(needle)[source]

Move the carriage to the target needle in the inferred direction.

Parameters:

needle (Needle) – The needle to move the carriage to.

Notes

Does not update last_set_direction. Last set direction can be used to infer explicit movements rather than implied directions for drops and xfers.

classmethod __class_getitem__(params)

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….

__int__()
Returns:

The slot number of this position.

Return type:

int

aligned_with_slot(slot)
Parameters:

slot (int | Slotted_Position) – The slot to compare to.

Returns:

True if this is positioned at the same slot, False otherwise.

Return type:

bool

direction_to_slot(slot)
Parameters:

slot (int) – The slot to find a direction towards.

Returns:

The direction of carriage movement from this component to the slot or None if the slots are aligned.

Return type:

Carriage_Pass_Direction | None

handle_violations(response_policy=None, handler=None)

Context manager that catches exceptions and routes them through the violation policy.

Parameters:
  • response_policy (ViolationResponse | Violation, optional) – The ViolationResponse policy for this code block. If given a Violation, the response will be the policy assigned to that violation in the violation policy. Defaults to the response will be the default response of the violation policy.

  • handler (Callable[..., Any], optional) – Optional handler to attempt before falling back to the policy response.

in_pass_direction(slot, direction)
Parameters:
Returns:

True if the given slot is after this slot in the given direction. False otherwise.

Return type:

bool

property last_direction: Carriage_Pass_Direction

Returns: Carriage_Pass_Direction: The last direction the object moved in.

left_of_slot(slot)
Parameters:

slot (int | Slotted_Position) – The slot to compare to.

Returns:

True if this is positioned left of the given slot, False otherwise.

Return type:

bool

property machine_is_all_needle_racked: bool

Returns: bool: True if the knitting machine is racked for all needle knitting.

property machine_racking: int

Returns: int: The racking of the knitting machine.

property machine_specification: Knitting_Machine_Specification[Machine_LoopT]

Returns: Knitting_Machine_Specification[Machine_LoopT]: The machine specification of the machine associated with this component.

property needle_count_of_machine: int

Returns: int: The number of needles on each bed of the knitting machine. Defaults to the bed size in the knitting machine specification.

right_of_slot(slot)
Parameters:

slot (int | Slotted_Position) – The slot to compare to.

Returns:

True if this is positioned right of the given slot, False otherwise.

Return type:

bool

property rightmost_slot_on_machine: int

Returns: int: The rightmost slot on this knitting machine. Defaults to the standard bed size in the knitting machine specification.

set_response_for(violation, response=None)

Sets the response for the given violation to the given response.

Parameters:
  • violation (Violation) – The violation to set the response for.

  • response (ViolationResponse, optional) – The response to set for the given violation. Defaults to the default response of this policy.

property slot_number: int

The slot number indicates the front-bed alignment of the given needle. For front bed needles this is equivalent to the position. For back bed needles this is dependent on the racking alignment of the beds.

Returns:

The slot number of the given component for the given racking.

Return type:

int

Notes

Racking Calculations: * R = F - B * F = R + B * B = F - R.

property violation_policy: Knitting_Machine_Error_Policy

Returns: Knitting_Machine_Error_Policy: The policy for handling machine state errors.