Skip to content

Commit

Permalink
- output settings into gcode
Browse files Browse the repository at this point in the history
  • Loading branch information
cemonds committed Feb 15, 2016
1 parent 71a4e35 commit 82c340e
Show file tree
Hide file tree
Showing 5 changed files with 119,202 additions and 23,751 deletions.
41 changes: 31 additions & 10 deletions Software/Tools/gcodeviewer/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
$scope.gcode = "";
$scope.maxX = 1;
$scope.maxY = 1;
$scope.minX = 0;
$scope.minY = 0;
$scope.layers = [];
$scope.currentLayer = 0;
$scope.zoom = 1;
Expand All @@ -35,8 +37,12 @@
vertical: true
};
$scope.$watch("zoom", function(newZoomLevel) {
$scope.positionXOptions.ceil = $scope.maxX-($scope.maxX/newZoomLevel);
$scope.positionYOptions.ceil = $scope.maxY-($scope.maxY/newZoomLevel);
var xSize = $scope.maxX - $scope.minX;
var ySize = $scope.maxY - $scope.minY;
$scope.positionXOptions.ceil = xSize-(xSize/newZoomLevel);
$scope.positionYOptions.ceil = ySize-(ySize/newZoomLevel);
$scope.position.x = $scope.positionXOptions.ceil/2;
$scope.position.y = $scope.positionYOptions.ceil/2;
});
$scope.loadGCode = function() {
if (window.File && window.FileReader && window.FileList && window.Blob) {
Expand All @@ -50,10 +56,13 @@
var lineFinished = true;
var maxY = 1;
var maxX = 1;
var minY = 0;
var minX = 0;
var yPosition = 0;
var xPosition = 0;
var lineOpen = false;
var layer = -1;
var lineSpacings = [];
for(var i=0, len=lines.length; i < len; i++) {
line = lines[i];
if(line.indexOf("G01 Z") == 0) {
Expand All @@ -64,12 +73,16 @@
// adjust Y position
var remainingString = line.substring(5);
var yDistance = Number(remainingString);
lineSpacings.unshift(yDistance);
yPosition += yDistance;
if(yPosition > maxY) {
maxY = yPosition;
}
if(yPosition < minY) {
minY = yPosition;
}
xPosition = 0;
} else if(line.indexOf("G05 D0") == 0) {
} else if(line.indexOf("G06 E") == 0) {
if(lineFinished) {
console.error("Error in line "+i+": line finished without started");
} else {
Expand All @@ -96,10 +109,16 @@
if(xPosition > maxX) {
maxX = xPosition;
}
if(xPosition < minX) {
minX = xPosition;
}
}
}
$scope.maxX = maxX;
$scope.maxY = maxY;
$scope.lineWidth = lineSpacings[Math.round(lineSpacings.length/2)]/2.5;
$scope.maxX = maxX+20;
$scope.maxY = maxY+20;
$scope.minX = minX-20;
$scope.minY = minY-20;
$scope.layer = $scope.layers[0];
$scope.zoom = 1;
$scope.position.x = 0;
Expand Down Expand Up @@ -137,12 +156,14 @@
<body ng-app="gcodeViewApp">
<div ng-controller="GCodeController">
<div class="viewer" style="float:left;">
<svg ng-attr-width="{{ 800 }}" ng-attr-height="{{ 800 * (maxY/maxX) }}" ng-attr-view_box="{{ position.x }} {{ position.y }} {{ maxX / zoom }} {{ maxY / zoom }}">
<line ng-attr-x1="{{ line.x1 }}" ng-attr-y1="{{ line.y }}" ng-attr-x2="{{ line.x2 }}" ng-attr-y2="{{ line.y }}" style="stroke:rgb(255,0,0);stroke-width:2" ng-repeat="line in layer"/>
</svg>
<div style="position:relative;">
<rzslider style="height: 100%; position: absolute; right: 0px; margin-right: -20px;" rz-slider-model="position.y" rz-slider-options="positionYOptions"></rzslider>
<rzslider style="width: 20%; right: 20px; bottom: 20px; position: absolute;" rz-slider-model="zoom" rz-slider-options="zoomOptions"></rzslider>
<svg style="display: inline-block;" ng-attr-width="{{ 800 }}" ng-attr-height="{{ 800 * (maxY/maxX) }}" ng-attr-view_box="{{ position.x+minX }} {{ position.y+minY }} {{ (maxX-minX) / zoom }} {{ (maxY-minY) / zoom }}">
<line ng-attr-x1="{{ line.x1 }}" ng-attr-y1="{{ line.y }}" ng-attr-x2="{{ line.x2 }}" ng-attr-y2="{{ line.y }}" style="stroke:rgb(255,0,0);stroke-width:{{ lineWidth }};" ng-repeat="line in layer"/>
</svg>
</div>
<rzslider rz-slider-model="position.x" rz-slider-options="positionXOptions"></rzslider>
<rzslider rz-slider-model="position.y" rz-slider-options="positionYOptions"></rzslider>
<rzslider rz-slider-model="zoom" rz-slider-options="zoomOptions"></rzslider>
</div>
<div class="gcode" style="float:right;">
<pre ng-bind="gcode" style="max-height: 15em; overflow-y: scroll;"></pre>
Expand Down
45 changes: 31 additions & 14 deletions Software/Tools/grslicer/grslicer/gcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,27 @@ def __init__(self, fs, verbose=True):
self.buffer_count = 0
self.buffer = ""

def move(self, x=None, y=None, z=None, e=None, f=None):
self.command_position('G01', x, y, z, e, f)
def move(self, x=None, y=None, z=None):
self.command_position('G01', x, y, z)

def command_position(self, command, x=None, y=None, z=None, e=None, f=None):
def command_position(self, command, x=None, y=None, z=None):
self.write(command)
if y is not None:
self.write(' Y{:d}'.format(y))
self.write(' Y{:d}'.format(self._scale_number(y)))
if z is not None:
self.write(' Z{:d}'.format(z))
self.write(' Z{:d}'.format(self._scale_number(z)))
self.nl()

def machine_command(self, command):
self.write(command)
self.nl()

def line_command(self, distance):
self.write('G05 D{:d}'.format(distance))
self.write('G05 D{:d}'.format(self._scale_number(distance)))
self.nl()

def expose_command(self, exposingCycles):
self.write('G06 E{:d}'.format(exposingCycles))
self.nl()

# def parameter(self, axis, value, precision):
Expand Down Expand Up @@ -385,6 +389,9 @@ def finalize(self):
if self.buffer:
self.fs.write(self.buffer)

def _scale_number(self, number):
return long(1000*number)


class ScanlineGCoder(object):
def __init__(self, model, settings, gcode_file):
Expand All @@ -400,6 +407,8 @@ def __init__(self, model, settings, gcode_file):
self.height = 0
self.y = 0

self._model_center = model.get_center()

@progress_log('Write layers to G-Code')
def encode(self, progress):

Expand Down Expand Up @@ -431,7 +440,7 @@ def encode_end_block(self):

def encode_layer(self, layer, layer_seq_nr):

self.coder.move(z=long(100*(layer.height-self.height)))
self.coder.move(z=layer.height-self.height)

self.height = layer.height

Expand All @@ -441,17 +450,25 @@ def encode_layer(self, layer, layer_seq_nr):
self.coder.machine_command('M19')

for line in layer.lines:
y_distance = line[0][1] - self.y
self.coder.move(y=long(y_distance*100))
y_distance = self._centered_y(line[0][1]) - self.y
self.coder.move(y=y_distance)

x = 0
for point in line:
x_distance = point[0] - x
self.coder.line_command(long(x_distance*100))
x = point[0]
self.coder.line_command(0)
self.y = line[0][1]
x_distance = self._centered_x(point[0]) - x
self.coder.line_command(x_distance)
x = self._centered_x(point[0])
self.coder.expose_command(self.s.exposingCycles)
self.y = self._centered_y(line[0][1])

self.coder.comment('Disable laser')
self.coder.machine_command('M20')

def _centered_x(self, x_position):
return x_position - self._model_center[0]

def _centered_y(self, y_position):
return y_position - self._model_center[1]

def _centered_z(self, z_position):
return z_position - self._model_center[2]
7 changes: 7 additions & 0 deletions Software/Tools/grslicer/grslicer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ def __str__(self):
def __repr__(self):
return self.__str__()

def get_center(self):
bounding_box = self.aabb
center_x = bounding_box.max[0]-bounding_box.min[0]
center_y = bounding_box.max[1]-bounding_box.min[1]
center_z = bounding_box.max[2]-bounding_box.min[2]
return [center_x, center_y, center_z]


class Layer(object):
__slots__ = ['model', 'height', 'seq_nr', 'islands', 'skirts', 'lines']
Expand Down
2 changes: 1 addition & 1 deletion Software/Tools/grslicer/grslicer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def um(v):
),
('Scanline',
[
RangeSettingFloat('scanlineSpacing', 'Scanline distance', default=0.1, low=0.01, high=1, step=0.01,
RangeSettingFloat('scanlineSpacing', 'Scanline distance', default=0.1, low=0.001, high=1, step=0.001,
description='Spacing between the individual scanlines', arg='scanline_spacing'),
RangeSettingInt('exposingCycles', 'Exposing cycles', default=10, low=1, high=100, step=1,
description='Number of exposing cycles for each line', arg='scanline_cycles'),
Expand Down
Loading

0 comments on commit 82c340e

Please sign in to comment.