implement printing to ultimaker2go

This commit is contained in:
casperlamboo 2018-01-29 13:59:29 +01:00
parent cd2b0322d8
commit 0c7f08735f
3 changed files with 67 additions and 11 deletions

View File

@ -91,9 +91,10 @@ export function fetchProgress(url, data = {}, onProgress) {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.onload = () => { xhr.onload = () => {
const headers = new Headers(xhr.getAllResponseHeaders()); resolve(new Response(xhr.response));
const { status, statusText, response, responseText, responseURL: url = headers.get('X-Request-URL') } = xhr; // const headers = new Headers(xhr.getAllResponseHeaders() || '');
resolve(new Response(response || responseText, { headers, status, statusText, url })); // const { status, statusText, response, responseText, responseURL: url = headers.get('X-Request-URL') } = xhr;
// resolve(new Response(response || responseText, { headers, status, statusText, url }));
} }
xhr.onerror = () => reject(new TypeError('Network request failed')); xhr.onerror = () => reject(new TypeError('Network request failed'));
xhr.ontimeout = () => reject(new TypeError('Network request failed')); xhr.ontimeout = () => reject(new TypeError('Network request failed'));
@ -108,9 +109,7 @@ export function fetchProgress(url, data = {}, onProgress) {
if (xhr.upload && onProgress) xhr.upload.onprogress = onProgress; if (xhr.upload && onProgress) xhr.upload.onprogress = onProgress;
if (xhr.responseType) xhr.responseType = 'blob'; if (xhr.responseType) xhr.responseType = 'blob';
request.headers.forEach((value, name) => { // request.headers.forEach((value, name) => xhr.setRequestHeader(name, value));
xhr.setRequestHeader(name, value)
});
xhr.send(data.body); xhr.send(data.body);
}); });
@ -223,25 +222,24 @@ export async function slice(target, name, mesh, settings, updateProgress) {
currentStep ++; currentStep ++;
} else { } else {
// upload G-code file to AWS S3 // upload G-code file to AWS S3
const { data: { reservation, id } } = await fetch(`${GCODE_SERVER_URL}/upload`, { method: 'POST' }) const { data: { reservation: { fields, url }, id } } = await fetch(`${GCODE_SERVER_URL}/upload`, { method: 'POST' })
.then(response => response.json()); .then(response => response.json());
const body = new FormData(); const body = new FormData();
const { fields } = reservation;
for (const key in fields) { for (const key in fields) {
body.append(key, fields[key]); body.append(key, fields[key]);
} }
const file = `;${JSON.stringify({ const file = new File([`;${JSON.stringify({
...settings, ...settings,
name: `${name}.gcode`, name: `${name}.gcode`,
printer: { type: settings.printers, title: printerSettings[settings.printer].title }, printer: { type: settings.printers, title: printerSettings[settings.printer].title },
material: { type: settings.material, title: materialSettings[settings.material].title }, material: { type: settings.material, title: materialSettings[settings.material].title },
quality: { type: settings.quality, title: qualitySettings[settings.quality].title } quality: { type: settings.quality, title: qualitySettings[settings.quality].title }
}).trim()}\n${gcode}`; }).trim()}\n${gcode}`], 'doodle.gcode');
body.append('file', file); body.append('file', file);
await fetchProgress(reservation.url, { method: 'POST', body }, (progress) => { await fetchProgress(url, { method: 'POST', body }, progress => {
updateProgress({ updateProgress({
action: 'Uploading', action: 'Uploading',
percentage: (currentStep + progress.loaded / progress.total) / steps percentage: (currentStep + progress.loaded / progress.total) / steps

View File

@ -1,3 +1,30 @@
startCode: |-
M109 S{printingTemp} ;set target temperature
{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature
G21 ;metric values
M107 ;start with the fan off
G28 X0 Y0 ;move X/Y to min endstops
G28 Z0 ;move Z to min endstops
G1 Z15 F9000 ;move the platform down 15mm
G92 E0 ;zero the extruded length
G91 ;relative positioning
G1 F200 E10 ;extrude 10mm of feed stock
G92 E0 ;zero the extruded length again
G92 E0 ;zero the extruded length again
G1 F9000
G90 ;absolute positioning
M117 Printing Doodle...
endcode: |-
M107 ;fan off
G91 ;relative positioning
G1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure
G1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more
G28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way
M84 ;disable axes / steppers
G90 ;absolute positioning
M104 S0
{if heatedBed}M140 S0
M117 Done
dimensions: dimensions:
x: 200 x: 200
y: 200 y: 200

View File

@ -300,6 +300,37 @@ ultimaker2_plus:
y: 223 y: 223
z: 305 z: 305
ultimaker2go: ultimaker2go:
startCode: |-
M10000
M10000
M10001 X8 Y28 SDoodle3D heat up...
M109 S{temperature} ;set target temperature
{if heatedBed}M190 S{bedTemperature} ;set target bed temperature
G21 ;metric values
G90 ;absolute positioning
M107 ;start with the fan off
G28 ; home to endstops
G1 Z15 F9000 ;move the platform down 15mm
G92 E0 ;zero the extruded length
G1 F200 E10 ;extrude 10mm of feed stock
G92 E0 ;zero the extruded length again
G1 F9000
M10000
M10000
M10001 X8 Y28 SDoodle3D printing...
endCode: |-
M10000
M10000
M10001 X20 Y28 SDoodle3D done!
M107 ;fan off
G91 ;relative positioning
G1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure
G1 Z+5.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more
G28 ;home the printer
M84 ;disable axes / steppers
G90 ;absolute positioning
M104 S0
{if heatedBed}M140 S0
title: Ultimaker 2 Go title: Ultimaker 2 Go
heatedBed: false heatedBed: false
filamentThickness: 2.85 filamentThickness: 2.85