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:

Knitting_Machine

Parameters:
__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:

bool

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:

int

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:

Carriage_Pass_Direction

property last_direction: Carriage_Pass_Direction

Get the last direction the carriage moved in.

Returns:

The last direction the carriage moved in.

Return type:

Carriage_Pass_Direction

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:

bool

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:

bool

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:

list[Carriage_Pass_Direction]

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.

Parameters:

needle_position (int) – Position to compare to.

Returns:

True if the current carriage position is to the left of the given needle_position, False otherwise.

Return type:

bool

right_of(needle_position)[source]

Check if the current carriage position is to the right of the given needle position.

Parameters:

needle_position (int) – Position to compare to.

Returns:

True if the current carriage position is to the right of the given needle_position, False otherwise.

Return type:

bool

on_position(needle_position)[source]

Check if the carriage position is exactly on the given needle position.

Parameters:

needle_position (int) – Position to compare to.

Returns:

True if this carriage position is on the given needle_position, False otherwise.

Return type:

bool

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:

None

move_to(end_position)[source]

Move the carriage, regardless of current position, to end position.

Parameters:

end_position (int) – New position of carriage.

Return type:

None

move_in_reverse_direction(end_position)[source]

Move in reverse of last direction to given end position.

Parameters:

end_position (int) – Position to move to.

Return type:

None

move_in_current_direction(end_position)[source]

Move in the current direction to given end position.

Parameters:

end_position (int) – Position to move to.

Return type:

None