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(knitting_machine, right_needle_position, left_needle_position=0)[source]
Bases:
object
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.
- knitting_machine
The Knitting machine this carriage belongs to.
- Type:
- Parameters:
knitting_machine (
Knitting_Machine
)right_needle_position (
int
)left_needle_position (
int
)
- __init__(knitting_machine, right_needle_position, left_needle_position=0)[source]
Initialize a new carriage with specified position range and starting direction.
- Parameters:
knitting_machine (Knitting_Machine) – The knitting machine this carriage belongs to.
right_needle_position (int) – The rightmost needle position the carriage can reach.
left_needle_position (int, optional) – The leftmost needle position the carriage can reach. Defaults to 0.
- Raises:
AssertionError – If left_needle_position is not less than right_needle_position.
- property transferring: bool
Check if carriage is currently running transfers.
- Returns:
True if carriage is currently running transfers, False otherwise.
- Return type:
- property current_needle_position: int
Get the front bed aligned position of the carriage at this time.
- Returns:
The current needle position of the carriage.
- Return type:
- 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 last_direction: Carriage_Pass_Direction
Get the last direction the carriage moved in.
- Returns:
The last direction the carriage moved in.
- Return type:
- property on_left_side: bool
Check if carriage is positioned on the very left side of the machine.
- Returns:
True if positioned on very left side of machine, False otherwise.
- Return type:
- property on_right_side: bool
Check if carriage is positioned on the very right side of the machine.
- Returns:
True if positioned on very right side of machine, False otherwise.
- Return type:
- possible_directions()[source]
Get list of possible directions the carriage can move from this position.
- Returns:
List of possible directions the carriage can move from this position.
- Return type:
- Raises:
AssertionError – If no directions are available (should never happen with valid carriage range).
- left_of(needle_position)[source]
Check if the current carriage position is to the left of the given needle position.
- right_of(needle_position)[source]
Check if the current carriage position is to the right of the given needle position.
- on_position(needle_position)[source]
Check if the carriage position is exactly on the given needle position.
- direction_to(needle_position)[source]
Get the direction needed to move from current position to given needle position.
- Parameters:
needle_position (int) – Needle position to target the direction towards.
- Returns:
Direction to move from current position to given needle_position or None if on given position.
- Return type:
Carriage_Pass_Direction | None
- move(direction, end_position)[source]
Update current needle position based on given target and direction with validation.
- Parameters:
direction (Carriage_Pass_Direction) – Direction to move the carriage in.
end_position (int) – The position to move the carriage to.
- Warns:
Carriage_Off_Edge_Warning – If the target needle is off the edge of the bed, will update the current needle to the edge.
- Return type: