virtual_knitting_machine.machine_components.needle_bed_position module
Module containing the Needle_Bed_Position class
- class Needle_Bed_Position(knitting_machine, parking_position=Right_Side, stopping_distance=10)[source]
Bases:
Slotted_Position[Machine_LoopT]A class used to keep track of the position of machine components (i.e., carriers, carriage) relative to the needle beds.
- property knitting_machine: Knitting_Machine_State[Machine_LoopT, Any]
Returns: Knitting_Machine_State: The knitting machine that owns this component.
- property position_on_bed: Needle_Specification | Side_of_Needle_Bed
Returns: Needle_Specification | Side_of_Needle_Bed: The needle that the object is positioned relative to or the side of the needle bed it is parked on when inactive.
- property current_bed_side: Side_of_Needle_Bed | None
Returns: Side_of_Needle_Bed | None: The current bedside position or None if positioned relative to a needle.
- property parking_position: Side_of_Needle_Bed
Returns: Side_of_Needle_Bed: The side of the needle bed that the machine component is parked at when it is not active.
- property parked_slot: int
Returns: int: The slot number of the position when it is parked off the needle bed.
- property parked_direction: Carriage_Pass_Direction
Returns: Carriage_Pass_Direction: The direction of movement from a parked position.
- property needle: Needle_Specification | None
Returns: Needle_Specification | None: The needle that this component is positioned relative to or None if the components is parked off the needle bed.
- property slot_number: int
- Returns:
The slot number of the needle of this position or the slot number of the needle bed.
- Return type:
Notes
When parked on the left side of the bed the slot is -1. When parked on the right side of the bed the slot 1 greater than the needle count of the machine.
- property last_direction: Carriage_Pass_Direction
Returns: Carriage_Pass_Direction: The last direction the object moved in.
- property reverse_of_last_direction: Carriage_Pass_Direction
Get the reverse of the last direction the carriage moved in.
- Returns:
The opposite direction of the last carriage movement.
- Return type:
- property on_bed: bool
Returns: bool: True if the machine component is position relative to a needle on the bed. False otherwise.
- property between_needles: tuple[Needle_Specification | None, Needle_Specification | None]
Returns: tuple[Needle_Specification | None, Needle_Specification | None]: The needles to the left and right of the position. None values imply the edge of the needle beds.
- property conflicting_needle_slot: int | None
Returns: int | None: The slot that currently conflicts with this position or None if the carrier is not active.
- property slot_range: tuple[int, int]
Returns: tuple[int, int]: The range of positions that a component may exist after an ambiguous movement with a stopping distance.
- set_position(needle, direction=None)[source]
Sets the position based on the given needle and current racking of the machine state.
- Parameters:
needle (Needle_Specification) – The new needle position that the carrier will move to or None if the carrier is moved off the needle bed.
direction (Carriage_Pass_Direction | None, optional) – The specific direction to set the carriage pass direction to. Defaults to inferring from the needle position and current state.
- update_from_position(other_position)[source]
Updates this position to match the given position. :param other_position: The position to match the needle bed. :type other_position: Needle_Bed_Position
- __lt__(other)[source]
- Parameters:
other (Slotted_Position | int) – The slot, needle, or position to compare to.
- Returns:
True if the slot of this position is to the left of the other position, False otherwise.
- Return type:
- 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]): ….
- 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:
- 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:
slot (int | Slotted_Position) – The slot following this slot in a carriage pass movement.
direction (Carriage_Pass_Direction) – The direction to test.
- Returns:
True if the given slot is after this slot in the given direction. False otherwise.
- Return type:
- 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:
- property machine_is_all_needle_racked: bool
Returns: bool: True if the knitting machine is racked for all needle knitting.
- 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:
- 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 violation_policy: Knitting_Machine_Error_Policy
Returns: Knitting_Machine_Error_Policy: The policy for handling machine state errors.
- class Relative_to_Needle_Bed(*args, **kwargs)[source]
Bases:
Slotted_Position[Machine_LoopT],ProtocolProtocol for Machine components which move relative to the needle bed such as the Carriage and carriers.
- property position_on_bed: Needle_Bed_Position[Machine_LoopT]
Returns: Needle_Bed_Position: The position of the machine component relative to the needle bed.
- 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:
Notes
Racking Calculations: * R = F - B * F = R + B * B = F - R.
- property last_direction: Carriage_Pass_Direction
Returns: Carriage_Pass_Direction: The last direction the object moved in.
- 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)
- 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:
- 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:
slot (int | Slotted_Position) – The slot following this slot in a carriage pass movement.
direction (Carriage_Pass_Direction) – The direction to test.
- Returns:
True if the given slot is after this slot in the given direction. False otherwise.
- Return type:
- property knitting_machine: Knitting_Machine_State[Machine_LoopT, Any]
Returns: Knitting_Machine_State: The knitting machine that owns this component.
- 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:
- property machine_is_all_needle_racked: bool
Returns: bool: True if the knitting machine is racked for all needle knitting.
- 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:
- 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 violation_policy: Knitting_Machine_Error_Policy
Returns: Knitting_Machine_Error_Policy: The policy for handling machine state errors.