K-code consists of a set of low level instructions which can be passed to the Kniterate digital knitting machine, fully describing any set of operations it can undertake. The name and the language itself are inspired by G-code, although the similarities in the commands may not be immediately obvious since many concepts do not carry easily between machining and knitting.

K-code is a fully functional language but it is constantly being refined. This means the information below may be updated, although the logic will remain the same.

The basic structure is that there are some commands which cause an instant action (e.g. move the roller [‘ROL:(+/-)x’], move the rack [‘RCK:(+/-)x’], knit [‘KNIT], (re)home [‘HOME’]), and there are some commands which update variables which determine how the machine behaves (e.g. change the speed [‘SPE:x’], change the yarn carrier [‘YARx’], change which needles are selected on the front bed when moving right [‘KFR:x...y...z’]). These commands in the second group can be given in any order and their associated variables persist until they are updated. Generally, commands ending in a colon are followed by numbers. In the case of needle selection commands this is a string of 0s and 1s the same length as the number of needles in the bed. In the case of selecting a yarn carrier this is a single integer from 0-6, and in the case of adjusting the knitting speed this is an integer from 0-999. Repetition is possible via the ‘FOR:’ and ‘END’ commands; other structural commands should be included in future updates.

An example of a simple program for a machine with 20 needles on each bed:

        // Setup

        HOME

        RCK:+0

        SPE:250

        STI:04

        //

        // Knit 10 rows chequerboard

        FOR:5

        // first repeated row

        YAR1

        KRR:00000000000000000000

        KFR:00001010101010100000

        KRL:00000101010101010000

        KFL:00000000000000000000

        KNIT

        ROL:+100

        YAR2

        KRR:00000000000000000000

        KFR:00000101010101010000

        KRL:00001010101010100000

        KFL:00000000000000000000

        KNIT

        ROL:+100

        // second repeated row

        YAR1

        KNIT

        ROL:+100

        YAR2

        KRR:00000000000000000000

        KFR:00001010101010100000

        KRL:00000101010101010000

        KFL:00000000000000000000

        KNIT

        ROL:+50

        END

        //

        // Shaping double reduction at edges

        RCK:+4

        SPE:150

        STI:00

        KRR:00000000000001000000

        KFR:00000000000000010000

        KRL:00000000000010000000

        KFL:00000000000000100000

        TRNF

        KRR:00000100000000000000

        KFR:00000001000000000000

        KRL:00001000000000000000

        KFL:00000010000000000000

        TRNR

        RCK:-4

        KRR:00000010000000000000

        KFR:00001000000000000000

        KRL:00000001000000000000

        KFL:00000100000000000000

        TRNF

        KRR:00000000000000100000

        KFR:00000000000010000000

        KRL:00000000000000010000

        KFL:00000000000001000000

        TRNR

        ROL:+50

        //

        // Knitting

        RCK:+0

        SPE:250

        STI:04

        YAR1

        KRR:00000000000000000000

        KFR:00000011111111000000

        KRL:00000011111111000000

        KFL:00000000000000000000

        // Row 21

        KNIT

        ROL:+100

        // Row 22

        KNIT

        ROL:+100

        // Row 23

        KNIT

        ROL:+100

        

This will create a  tube with a reduced top:

------OOOOOOOO------

------OOOOOOOO------

------OOOOOOOO------

----OOOOOOOOOOOO----

----OOOOOOOOOOOO----

----OOOOOOOOOOOO----

----OOOOOOOOOOOO----

----OOOOOOOOOOOO----

----OOOOOOOOOOOO----

----OOOOOOOOOOOO----

----OOOOOOOOOOOO----

----OOOOOOOOOOOO----

----OOOOOOOOOOOO----

K-code was designed to be readable and writable by a human, but a balance has been struck between the simplicity and power of the language and the complexity of the interpreter within Kniterate. We have designed a low-level protocol which is unlikely to need updating, and allows all future changes to be absorbed by the slicer and design interface, rather than requiring users to update firmware when new features are implemented. As a result, writing a complete garment by hand is possible but tedious (as Gerard can testify!), and it is intended that the only people who would need to do this are ‘power users’ who are exploring new capabilities of the machine.

Supported Commands

Code Flow Commands

// xxx

xxx is a comment and will be ignored by the machine.

BREAK

Pause the machine at this point until the user resumes.

FOR:x

y

z

END

Loop over commands y and z in sequence x times.

Instantaneous Commands

HOME

The machine (re)homes. This must be done at least once at the start of a program.

KNIT

The machine will knit one cycle moving right and then left, returning to the home position. It will select the needles indicated by 1s in the KFR, KFL, KRR and KRL arrays as it is moving.

TRNF

Transfer. The carriage will transfer from front to rear, selecting needles indicated by 1s in the KFR, KFL, KRR and KRL arrays as it is moving. Transferring and receiving needles must be selected.

TRNR

As above but the carriage will transfer from the rear to the front.

TCKF

Tuck. The front carriage enters tuck mode and it will tuck with selected needles. The rear carriage is in knitting mode and will behave as normal for a knitting cycle.

TCKR

As above but the rear carriage tucks and the front carriage knits.

SPLF

Split. Similar to TRNF except that the transferring donor needle on the front bed also knits.

SPLR

As above, but the transferring donor needle on the rear bed knits.

RCK:(+/-)x

Rack. The rear needle bed will move x/2 pitch lengths. x may be between -8 (move to left) and +8 (move to right).  

ROL:(+/-)xxx

Takedown roller. Specifies the number of steps the takedown rollers turn in one direction. Ranging from ROL:-999 to ROL:+999. Negative numbers push the garment up and reduce tension, positive steps pull the piece down.

Variable Update Commands

SPE:xxx

Specifies the maximum speed the carriage moves at (xxx mm/s).

STI:xx

Specifies the stitch density. Ranging from 00 to 16, with 16 being the largest loop the cams can create.

YARx

Specifies the number of yarn carrier. 0-6. 0 drops stitches since no yarn carrier is selected.

Selection Array Commands

KRR:xxx...

Knitted/selected by the rear carriage when moving right.

KFR:xxx...

Knitted/selected by the front carriage when moving right.

KRL:xxx...

Knitted/selected by the rear carriage when moving left.

KFL:xxx...

Knitted/selected by the front carriage when moving left.

Code example to create the sample below

sample_k-code.jpg