Skip to content
This repository has been archived by the owner on Jan 29, 2018. It is now read-only.

Commit

Permalink
Oops turned on offset in one of those last commits. Thats for LW2 (;
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter van der Walt committed Mar 25, 2016
1 parent 8bde9a5 commit 2a04780
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 34 deletions.
28 changes: 11 additions & 17 deletions i/dxf/gcode/three2gcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,29 +165,23 @@ console.log('RapidSpeed', rapidSpeed);
isAtClearanceHeight = true;
}
console.log('Input Path', subj_paths);
subj_path2 = getInflatedPath(subj_paths, 2);
subj_path2 = getInflatedPath(subj_paths, 5);
console.log('Output Path', subj_path2);

//var mesh = createClipperPathsAsMesh(subj_path2, 0xff0000, 0.2, subj_path2);
var millpath = createClipperPathsAsLines(subj_path2);
millpath.translateX(laserxmax /2 * -1);
millpath.translateY(laserymax /2 * -1);
scene.add(millpath);
// var mesh = createClipperPathsAsMesh(subj_path2, 0xff0000, 0.2, subj_path2);
// tool_offset = createClipperPathsAsLines(subj_path2);
// tool_offset.translateX(laserxmax /2 * -1);
// tool_offset.translateY(laserymax /2 * -1);
// tool_offset.name = 'Mill Path';
//scene.add(tool_offset); // Plasma Mode! W.I.P



}
});

console.log("generated gcode. length:", g.length);
// subj_paths = ClipperLib.Clipper.SimplifyPolygons(subj_paths, ClipperLib.PolyFillType.pftEvenOdd);
// console.log('Subj Path', subj_paths);
// //console.log("gcode:", g);
// $('#' + this.id + " .gcode").val(g).prop('disabled', false);
// $('#' + this.id + " .btn-sendgcodetows").prop('disabled', false);
// $('#' + this.id + " .regenerate").addClass('hidden');
// $('#' + this.id + " .gcode-size-span").removeClass('hidden');
// $('#' + this.id + " .gcode-size").text(parseInt(g.length / 1024) + "KB");
//

isGcodeInRegeneratingState = false;

// Remove DXF Preview
Expand Down Expand Up @@ -249,8 +243,8 @@ var scale = 10000;

material = new THREE.LineBasicMaterial({ linewidth: 1, color: color, transparent: true });

millpath = new THREE.Line(geometry, material);
return millpath;
millgeom = new THREE.Line(geometry, material);
return millgeom;

};

Expand Down
6 changes: 3 additions & 3 deletions i/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ <h3 class="panel-title"> <a data-toggle="collapse" data-target="#machinepanel"

<!-- Digital Position Readout -->
<div id="mPosition" >
<div id="mX" style="background-color: #ffffff; text-align: left; padding-left: 15px; margin-bottom: 3px; font-size: 20px; width: 100%; border: 1px solid #aaa; font-weight: bold;">X: 0.000</div>
<div id="mY" style="background-color: #ffffff; text-align: left; padding-left: 15px; margin-bottom: 3px; font-size: 20px; width: 100%; border: 1px solid #aaa; font-weight: bold;">Y: 0.000</div>
<div id="mZ" style="background-color: #ffffff; text-align: left; padding-left: 15px; margin-bottom: 3px; font-size: 20px; width: 100%; border: 1px solid #aaa; font-weight: bold;">Z: 0.000</div>
<div id="mX" style="background-color: #ffffff; text-align: left; padding-left: 15px; margin-bottom: 3px; font-size: 16px; width: 100%; border: 1px solid #aaa; font-weight: bold;">X: 0.000</div>
<div id="mY" style="background-color: #ffffff; text-align: left; padding-left: 15px; margin-bottom: 3px; font-size: 16px; width: 100%; border: 1px solid #aaa; font-weight: bold;">Y: 0.000</div>
<div id="mZ" style="background-color: #ffffff; text-align: left; padding-left: 15px; margin-bottom: 3px; font-size: 16px; width: 100%; border: 1px solid #aaa; font-weight: bold;">Z: 0.000</div>
</div>

<!-- Temperature Guages (Hidden unless in 3D printer mode) -->
Expand Down
15 changes: 15 additions & 0 deletions i/js/jog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

function initJog() {

$('#xp').on('click', function() {
var dist = $('#jogstp').val()
console.log('Jog Distance', dist);
sendGcode('G91\nG0 X'+ +'\nG90') {
};






}
24 changes: 22 additions & 2 deletions i/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ $(document).ready(function() {

// List serial Ports
socket.on('ports', function (data) {
//console.log('ports event',data);
console.log('ports event',data);
$('#choosePort').html('<option val="no">Select a serial port</option>');
for (var i=0; i<data.length; i++) {
$('#choosePort').append('<option value="'+i+'">'+data[i].comName+': '+data[i].manufacturer+'</option>');
Expand Down Expand Up @@ -1407,17 +1407,26 @@ $(document).ready(function() {
document.getElementById('gcodepreview').value = '';
openGCodeFromText();
var r = new FileReader();
console.log('Reader', r)
r.readAsText(odxf.files[0]);
r.onload = function(e) {
fileName = fileInputDXF.value.replace("C:\\fakepath\\", "");

// Remove the UI elements from last run
if (typeof(dxfObject) !== 'undefined') {
scene.remove(dxfObject);
};

if (typeof(showDxf) !== 'undefined') {
scene.remove(showDxf);
};

if (typeof(tool_offset) !== 'undefined') {
scene.remove(tool_offset);
toolPath = null;
};


dxfObject = new THREE.Group();

row = [];
Expand Down Expand Up @@ -1510,8 +1519,8 @@ $(document).ready(function() {
dxfThickness = $('#thickness').val()

g += generateGcodeCallback(window["dxfEntity" + c], cutSpeed[c], pwr[c], rapidSpeed)
}

}
document.getElementById('fileName').value = fileName;
$('#mainStatus').html('Status: <b>'+fileName+' </b> loaded ...');
if (boundingBox) {
Expand Down Expand Up @@ -2026,6 +2035,17 @@ osvg.addEventListener('change', function(e) {
cylinder.position.z = (parseInt(posArray[6],10) + 20);
});

socket.on('posStatusT', function(data) {
var data2 = JSON.parse(data);
console.log('TinyG Status: ' + data);
$('#mX').html('X: '+data2.sr.posx);
$('#mY').html('Y: '+data2.sr.posy);
$('#mZ').html('Z: '+data2.sr.posz);
cylinder.position.x = (parseInt(data2.sr.posx) - (laserxmax /2));
cylinder.position.y = (parseInt(data2.sr.posy) - (laserymax /2));
cylinder.position.z = (parseInt(data2.sr.posz) + 20);
});

// Handle position feedback data from the machine: Smoothie
// Position [data = ok C: X:190.000 Y:10.000 Z:1.000 A:190.000 B:10.000 C:1.000 E:0.000 ]
socket.on('posStatusS', function(data) {
Expand Down
77 changes: 65 additions & 12 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ http.get('http://127.0.0.1:8080', function(res) {
// 2 second timeout on this socket
socket.setTimeout(2000);
socket.on('timeout', function() {
this.abort();
//this.abort();
});
}).on('error', function(e) {
console.error(
Expand Down Expand Up @@ -174,6 +174,7 @@ serialport.list(function (err, ports) {
sp[i].handle.write("?\n"); // Lets check if its LasaurGrbl?
sp[i].handle.write("M115\n"); // Lets check if its Marlin?
sp[i].handle.write("version\n"); // Lets check if its Smoothieware?
sp[i].handle.write("$fb\n"); // Lets check if its TinyG

// line from serial port
sp[i].handle.on("data", function (data) {
Expand Down Expand Up @@ -217,6 +218,22 @@ function emitToPortSockets(port, evt, obj) {
function serialData(data, port) {
// new line of data terminated with \n
//console.log('Port '+port+' got newline from serial: '+data);
if (data.match(/^\{/)) {

jsondata = JSON.parse(data);
//console.log('Got JSON response: ' + jsondata);

if (jsondata.r) {
sendFirstQ(port);

// ok is green
emitToPortSockets(port, 'serialRead', {c:0,l:data});

// remove first
sp[port].lastSerialWrite.shift();
};
};



// Try to determine Firmware in use and set up queryloop
Expand Down Expand Up @@ -316,6 +333,32 @@ function serialData(data, port) {
sp[port].firmware = firmware;
}

if (data.indexOf('firmware build') != -1 ) { // found a TinyG
// setInterval(function() {
// sp[port].handle.write("M114\n"); //for Smoothieware
// }, 1000);
//data = data.replace(/:/g,',');
//data = data.replace(/ /g,',');
data = data.replace( /(?!\s+$)\s+/g, "," );
//console.log('Data' + data);
var firmwareVersion = data.split(',');
var tinyGVersion = 'TinyG '+firmwareVersion[3];
var firmware = tinyGVersion;
console.log(chalk.green('INFO:'), chalk.yellow(' Found device: '),
chalk.yellow(sp[port].manufacturer),
chalk.blue(sp[port].port),
chalk.yellow('Firmware Detected:'),
chalk.blue(firmware),
chalk.yellow(' Port ID No: '),
chalk.blue(port)
);
sp[port].firmware = firmware;
// INIT COMMANDS
sp[port].handle.write("{sv:2}\n"); //for Smoothieware


}

// End of Queryloop

// handle M105
Expand Down Expand Up @@ -346,6 +389,13 @@ function serialData(data, port) {
return;
}

// handle Always On Feedback (TinyG)
if (data.indexOf('pos') != -1 || data.indexOf('ok pos') != -1) {
emitToPortSockets(port, 'posStatusT', data);
sp[port].lastSerialReadLine = data;
return;
}

if (sp[port].firmware) {
if (sp[port].firmware.indexOf('Lasaur') == 0) {
if (data.indexOf('N') !=-1 || data.indexOf('E') !=-1 || data.indexOf('U') !=-1 || data.indexOf('B') !=-1 || data.indexOf('B') !=-1 || data.indexOf('T') !=-1 || data.indexOf('P') !=-1 || data.indexOf('L') !=-1 || data.indexOf('R') !=-1 || data.indexOf('D') !=-1 || data.indexOf('C') !=-1 || data.indexOf('V') !=-1 ) {
Expand Down Expand Up @@ -398,10 +448,8 @@ function serialData(data, port) {

data = ConvChar(data);



if (data.indexOf('ok') == 0 || data == "") { // data == "" relates to supporting LaserSaur - monitor if it causes bugs on other firmwares. Refer to https://groups.google.com/forum/#!topic/lasersaur/_6wTYNJgGyI

if (data.indexOf('ok') == 0 || data.indexOf('{"qr":32}') == 0 || data == "" ) { // data == "" relates to supporting LaserSaur - monitor if it causes bugs on other firmwares. Refer to https://groups.google.com/forum/#!topic/lasersaur/_6wTYNJgGyI
console.log('Got OK');
// run another line from the q
sendFirstQ(port);

Expand Down Expand Up @@ -488,12 +536,12 @@ function serialData(data, port) {
else {
// other is grey
emitToPortSockets(port, 'serialRead', {c:2,l:data});
console.log(chalk.yellow('WARN:'),
chalk.gray('Ignored:'), chalk.yellow(' Port'),

chalk.blue(sp[port].port),
chalk.yellow('said: '),
chalk.blue(data));
// console.log(chalk.yellow('WARN:'),
// chalk.gray('Ignored:'), chalk.yellow(' Port'),
//
// chalk.blue(sp[port].port),
// chalk.yellow('said: '),
// chalk.blue(data));
}

if (sp[port].q.length == 0) {
Expand All @@ -509,6 +557,7 @@ function serialData(data, port) {
var currentSocketPort = {};

function sendFirstQ(port) {
console.log('Queue Length: ' + sp[port].q.length);
if (sp[port].q.length < 1) {
// nothing to send
return;
Expand All @@ -532,6 +581,7 @@ function sendFirstQ(port) {
sp[port].sockets[i].emit('serialRead', {c:3,l:'SEND: '+t});
}
sp[port].handle.write(t+"\n");
console.log('Sent' + t);
sp[port].lastSerialWrite.push(t);
}

Expand Down Expand Up @@ -706,11 +756,12 @@ io.sockets.on('connection', function (socket) {

// lines fromweb ui
socket.on('gcodeLine', function (data) {
console.log(chalk.yellow('Command Sent from Console'));
console.log(chalk.yellow('Command Sent from Console: '));
if (typeof currentSocketPort[socket.id] != 'undefined') {
// valid serial port, safe to send
// split newlines
var nl = data.line.split("\n");
console.log('Line: '+ nl);
// add to queue
sp[currentSocketPort[socket.id]].q = sp[currentSocketPort[socket.id]].q.concat(nl);
// add to qCurrentMax
Expand All @@ -720,10 +771,12 @@ io.sockets.on('connection', function (socket) {
// Debug for Issue #70 https://github.com/openhardwarecoza/LaserWeb/issues/70

sendFirstQ(currentSocketPort[socket.id]);
console.log(chalk.yellow('first command'));

if (sp[currentSocketPort[socket.id]].firmware.indexOf('Lasaur') === 0) {
if (nl[0] === '~' && nl.length > 1) {
sendFirstQ(currentSocketPort[socket.id]);

}
}
}
Expand Down

0 comments on commit 2a04780

Please sign in to comment.