Printer

Printer

Basic properties, settings and functions for the physical printer like speeds, dimensions, extrusion. Uses a function passed in to send messages (strings of G Code), usually a websockets one.

Constructor

new Printer(_messageSendFunc)

Source:
Version:
  • 0.8
License:
  • Copyright 2018 Evan Raskob Licensed under the GNU Affero 3.0 License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.gnu.org/licenses/gpl-3.0.en.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Create new instance, passing a function for sending messages

Example

Log GCode to console:

let printer = new Printer(msg => console.log(msg));
Parameters:
Name Type Default Description
_messageSendFunc function null

function to pass in that will send messages to the server/physical printer

Members

boundaryMode

Source:

What to do when movement or extrusion commands are out of machine bounds. Can be clip (keep printing inside edges), bounce (bounce off edges), stop

cx

Source:

Get the center horizontal (x) position on the bed

cy

Source:

Get the center vertical (y) position on the bed,

send :function

Source:

the function (Websockets or other) that this object will use to send gcode to the printer

Type:
  • function

time

Source:

readonly total movetime

Methods

_extrude(moveVector, leftToMove) → {Boolean}

Source:

Tail-recursive extrusion function. Don't call this directly. Uses fext See extrudeto()

Parameters:
Name Type Description
moveVector Vector
leftToMove Number
Returns:

false when done

Type
Boolean

angle(ang, radians) → {Printer}

Source:

Set the direction of movement for the next operation.

Parameters:
Name Type Default Description
ang float

Angle of movement (in xy plane)

radians Boolean false

use radians or not

Returns:

Reference to this object for chaining

Type
Printer

circle(r, segs)

Source:

Extrude a circle starting at the current point on the curve

Parameters:
Name Type Default Description
r any

radius

segs any 10

segments (more means more perfect circle)

clipToPrinterBounds(position:) → {object}

Source:

clip object's x,y,z properties to printer bounds and return it

Parameters:
Name Type Description
position: object

object with x,y,z properties clip

Returns:

position clipped object

Type
object

d2r(angle) → {float}

Source:

Degrees to radians conversion.

Parameters:
Name Type Description
angle float

in degrees

Returns:

angle in radians

Type
float

dist(d) → {Printer}

Source:

Shortcut to distance()

Parameters:
Name Type Description
d float

distance to move next time

Returns:

reference to this object for chaining

Type
Printer

distance(d) → {Printer}

Source:

Set the distance of movement for the next operation.

Parameters:
Name Type Description
d float

distance to move next time

Returns:

reference to this object for chaining

Type
Printer

elev(_elev) → {Printer}

Source:
See:
  • elevation

Shortcut for elevation.

Parameters:
Name Type Description
_elev any

elevation

Returns:

reference to this object for chaining

Type
Printer

elevation(angle, radians) → {Printer}

Source:

Set the direction of movement for the next operation. TODO: This doesn't work with other commands. Need to implement roll, pitch, yaw?

Parameters:
Name Type Default Description
angle float

elevation angle (in z direction, in degrees) for next movement

radians Boolean false

use radians or not

Returns:

reference to this object for chaining

Type
Printer

extrude(params) → {Printer}

Source:

Extrude plastic from the printer head, relative to the current print head position, within printer bounds

Parameters:
Name Type Description
params Object

Parameters dictionary containing either x,y,z keys or direction/angle (radians) keys and retract setting (true/false).

Returns:

reference to this object for chaining

Type
Printer

extrudeto(params) → {Printer}

Source:

Extrude plastic from the printer head to specific coordinates, within printer bounds

Parameters:
Name Type Description
params Object

Parameters dictionary containing either x,y,z keys or direction/angle (radians) keys and retract setting (true/false). Optional bounce (Boolean) key if movement should bounce off sides.

Returns:

reference to this object for chaining

Type
Printer

fan(speed) → {Printer}

Source:

Set fan speed.

Parameters:
Name Type Default Description
speed float 100

is the speed from 0-100

Returns:

reference to this object for chaining

Type
Printer

fill(w, h, lh) → {Printer}

Source:

Fills an area based on layerHeight (as thickness of each line)

Parameters:
Name Type Description
w float

width of the area in mm

h float

height of the area in mm

lh float

the layerheight (or gap, if larger)

Returns:

reference to this object for chaining

Type
Printer

fillDirection(w, h, gap, retract)

Source:

Fill a rectagular area.

Parameters:
Name Type Default Description
w Number

width

h Number

height

gap Number

gap between fills

retract Boolean true

retract when finished

fwretract(state) → {Printer}

Source:

Set firmware retraction on or off (for after every move).

Parameters:
Name Type Description
state Boolean

True if on, false if off

Returns:

this printer object for chaining

Type
Printer

go(extruding, retract) → {Printer}

Source:

Perform current operations (extrusion) based on direction/elevation/distance.

Parameters:
Name Type Default Description
extruding Boolean false

Whether to extrude whilst moving (true if yes, false if not)

retract Boolean true

Whether to retract at end (usually true). Set to 0 if executing a few moves in a row

Returns:

reference to this object for chaining

Type
Printer

lh(height) → {Printer}

Source:

Set layer height safely and easily

Parameters:
Name Type Description
height float

layer height in mm

Returns:

Reference to this object for chaining

Type
Printer

m2s(note, axis) → {float}

Source:

Calculate the tool speed in mm/s based on midi note

Parameters:
Name Type Description
note float

midi note

axis string

axis (x,y,z,e) of movement

Returns:

tool speed in mm/s

Type
float

midi2speed(note, axis) → {float}

Source:
Parameters:
Name Type Description
note number

as midi note

axis string

of movement: x,y,z

Returns:

speed in mm/s

Type
float

move(params) → {Printer}

Source:

Relative movement.

Parameters:
Name Type Description
params any

Can be specified as x,y,z,e or dist (distance), angle (xy plane), elev (z dir). All in mm.

Returns:

reference to this object for chaining

Type
Printer

moveto(params) → {Printer}

Source:

Absolute movement.

Parameters:
Name Type Description
params any

Can be specified as x,y,z,e. All in mm.

Returns:

reference to this object for chaining

Type
Printer

note(note, time, axes) → {Printer}

Source:

Convert MIDI notes and duration into direction and angle for future movement. Low notes below 10 are treated a pauses.

Example
Play MIDI note 41 for 400ms on the x & y axes
    lp.note(41, 400, "xy").go();
Parameters:
Name Type Default Description
note float 40

as midi note

time float 200

in ms

axes string x

move direction as x,y,z (default "x")

Returns:

reference to this object for chaining

Type
Printer

pause() → {Printer}

Source:

Temporarily pause the printer: move the head up, turn off fan & temp

Returns:

reference to this object for chaining

Type
Printer

printPaths(paths, settings) → {Printer}

Source:

Print paths

Parameters:
Name Type Description
paths Array

List of paths (lists of coordinates in x,y) to print

settings Object

Settings for the scaling, etc. of this object. useaspect means respect aspect ratio (width/height). A width or height of 0 means to use the original paths' width/height.

Returns:

reference to this object for chaining

Type
Printer

r2d(angle) → {float}

Source:

Radians to degrees conversion.

Parameters:
Name Type Description
angle float

in radians

Returns:

angle in degrees

Type
float

rect(w, h) → {Printer}

Source:

Extrude a rectangle with the current point as its centre

Parameters:
Name Type Description
w any

width

h any

height

Returns:

reference to this object for chaining

Type
Printer

resume(temp) → {Printer}

Source:

Resume the printer printing: turn on fan & temp

Parameters:
Name Type Default Description
temp float 190

target temp

Returns:

reference to this object for chaining

Type
Printer

retract(len, speed) → {Printer}

Source:

Immediately perform a "retract" which is a shortcut for just moving the filament back up at a speed. Sets the internal retract variables to those passed in.

Example
Custom retraction:
lp.extrude({x:40,y:80, retract:false}).retract(6,30);
// next move, will unretract that amount too

// or extrude an angle/distance and then force retract
lp.firmwareRetract = false; // turn off automatic retraction in firmware
lp.angle(45).dist(50).go(1).retract(6,30);

// retract again with same settings
lp.angle(45).dist(50).go(1).retract();
Parameters:
Name Type Description
len Number

Length of filament to retract. Set to 0 to use current setting (or leave out)

speed Number

(optional) Speed of retraction. Will be clipped to max filament feed speed for printer model.

Returns:

reference to this object for chaining

Type
Printer

run(strings) → {Printer}

Source:

Run a set of commands specified in a grammar (experimental.)

Parameters:
Name Type Description
strings String

commands to run - M(move),E(extrude),L(left turn),R(right turn)

Returns:

Reference to this object for chaining

Type
Printer

sendExtrusionGCode(speed, retract)

Source:

Send movement update GCode to printer based on current position (this.x,y,z).

Parameters:
Name Type Default Description
speed Int

print speed in mm/s

retract boolean true

if true (default) add GCode for retraction/unretraction. Will use either hardware or software retraction if set in Printer object

sendFirmwareRetractSettings() → {Printer}

Source:

Send the current retract settings to the printer (useful when updating the retraction settings locally)

Returns:

reference to this object for chaining

Type
Printer

sendQueued() → {Printer}

Source:

Send all the queued command messages via the send function (probably websockets)

Returns:

reference to this object for chaining

Type
Printer

speed(val) → {Printer}

Source:

Set the overall speed of the extrusion in mm/s

Parameters:
Name Type Description
val float

Speed for the extrusion in mm/s

Returns:

reference to this object for chaining

Type
Printer

speedScale() → {object}

Source:

Convenience function for getting speed scales for midi notes from printer model.

Returns:

x,y,z speed scales

Type
object

start(temp) → {Printer}

Source:

Performs a quick startup by resetting the axes and moving the head to printing position (layerheight).

Parameters:
Name Type Default Description
temp float 190

is the temperature to start warming up to

Returns:

reference to this object for chaining

Type
Printer

temp(temp) → {Printer}

Source:

Set temperature, don't block other operation. to printing position (layerheight).

Parameters:
Name Type Default Description
temp float 190

is the temperature to start warming up to

Returns:

reference to this object for chaining

Type
Printer

thick(val) → {Printer}

Source:

Set the extrusion thickness (in mm)

Parameters:
Name Type Description
val float

thickness of the extruded line in mm

Returns:

reference to this object for chaining

Type
Printer

turn(angle, radians) → {Printer}

Source:

Turn (clockwise positive, CCW negative)

Example
Turn 45 degrees twice (so 90 total) and extrude 40 mm in that direction:
lp.turn(45).turn(45).distance(40).go(1);
Parameters:
Name Type Default Description
angle Number

in degrees by default

radians Boolean false

use radians if true

Returns:

reference to this object for chaining

Type
Printer

unretract(len, speed) → {Printer}

Source:

Immediately perform an "unretract" which is a shortcut for just extruding the filament out at a speed. Sets the internal retract variables to those passed in.

Example
Custom unretraction:
lp.extrude({x:40,y:80, retract:false}).retract(6,30);
lp.unretract();

// next move, will unretract that amount too

// or extrude an angle/distance and then force retract
lp.firmwareRetract = false; // turn off automatic retraction in firmware
lp.angle(45).dist(50).go(1).retract(6,30);
lp.unretract(8,30); // extract a little more to get it going
Parameters:
Name Type Description
len Number

Length of filament to unretract. Set to 0 to use current setting (or leave out)

speed Number

(optional) Speed of unretraction. Will be clipped to max filament feed speed for printer model.

Returns:

reference to this object for chaining

Type
Printer

up(d) → {Printer}

Source:

Move up quickly! (in mm)

Parameters:
Name Type Description
d Number

distance in mm to move up

Returns:

Reference to this object for chaining

Type
Printer

wait(ms) → {Printer}

Source:

Causes the printer to wait for a number of milliseconds

Parameters:
Name Type Description
ms float

to wait

Returns:

reference to this object for chaining

Type
Printer