Skip to content

Commit

Permalink
Add possibility to visualize spindle speed/laser power (#2241)
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler committed Jul 1, 2023
1 parent d2a6e05 commit c4085c4
Show file tree
Hide file tree
Showing 23 changed files with 321 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ This file is part of Universal Gcode Sender (UGS).
* @author wwinder
*
*/
@SuppressWarnings("serial")
public class VisualizerCanvas extends GLCanvas implements GLEventListener, KeyListener, MouseMotionListener, MouseWheelListener {
private static final Logger logger = Logger.getLogger(VisualizerCanvas.class.getName());

private static boolean ortho = true;
private static double orthoRotation = -45;
private static boolean forceOldStyle = false;
private static boolean debugCoordinates = false; // turn on coordinate debug output
final static private DecimalFormat format = new DecimalFormat("####.00");

private static final DecimalFormat format = new DecimalFormat("####.00");

// Machine data
private final Position machineCoord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,7 @@ public static String normalizeCommand(String command, GcodeState state) throws G
}

StringBuilder result = new StringBuilder();

// Don't add the state
//result.append(state.toGcode());

result.append("F").append(state.speed);
result.append("F").append(state.feedRate);
result.append("S").append(state.spindleSpeed);

// Check if we need to add the motion command back in.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class GcodeState {

// group 5
public Code feedMode = G94;
public double speed = 0;
public double feedRate = 0;

// group 6
public boolean isMetric = true;
Expand All @@ -77,7 +77,7 @@ public GcodeState() {
this.plane = Plane.XY;

// TODO: Feed mode
this.speed = 0;
this.feedRate = 0;
this.spindleSpeed = 0;

this.currentPoint = new Position(0, 0, 0, Units.MM);
Expand All @@ -99,7 +99,7 @@ public GcodeState copy() {
ret.isMetric = isMetric;
ret.units = units;

ret.speed = speed;
ret.feedRate = feedRate;
ret.spindleSpeed = spindleSpeed;

ret.offset = offset;
Expand Down Expand Up @@ -131,7 +131,7 @@ public String toAccessoriesCode() {
result.append(coolant.toString());
}

result.append("F").append(this.speed);
result.append("F").append(this.feedRate);

return result.toString();
}
Expand Down Expand Up @@ -164,7 +164,7 @@ public Units getUnits() {
public String toString() {
String pattern = "metric: %b, motionMode: %s, plane: %s, absoluteMode: %b, ijkMode: %b, feed: %f, spindle speed: %f, spindle state: %s, coolant state: %s, point: %s";
return String.format(pattern,
isMetric, currentMotionMode, plane, inAbsoluteMode, inAbsoluteIJKMode, speed, spindleSpeed, spindle, coolant, currentPoint);
isMetric, currentMotionMode, plane, inAbsoluteMode, inAbsoluteIJKMode, feedRate, spindleSpeed, spindle, coolant, currentPoint);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ This file is part of Universal Gcode Sender (UGS).
package com.willwinder.universalgcodesender.gcode.processors;

import com.google.common.collect.Iterables;
import com.willwinder.universalgcodesender.gcode.GcodeParser;
import com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta;
import com.willwinder.universalgcodesender.gcode.GcodePreprocessorUtils;
import com.willwinder.universalgcodesender.gcode.GcodePreprocessorUtils.SplitCommand;
Expand Down Expand Up @@ -103,7 +102,7 @@ public List<String> processCommand(String command, GcodeState state) throws Gcod
if (convertToLines) {
// Tack the speed onto the first line segment in case the arc also
// changed the feed value.
String feed = "F" + arcMeta.point.getSpeed();
String feed = "F" + arcMeta.point.getFeedRate();
for (Position point : points) {
results.add(GcodePreprocessorUtils.generateLineFromPoints(G1, start, point, state.inAbsoluteMode, df) + feed);
start = point;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static List<GcodeParser.GcodeMeta> processCommand(String command, int lin
List<String> fCodes = GcodePreprocessorUtils.parseCodes(args, 'F');
if (!fCodes.isEmpty()) {
try {
state.speed = Double.parseDouble(Iterables.getOnlyElement(fCodes));
state.feedRate = Double.parseDouble(Iterables.getOnlyElement(fCodes));
} catch (IllegalArgumentException e) {
throw new GcodeParserException("Multiple F-codes on one line.");
}
Expand Down Expand Up @@ -155,12 +155,12 @@ public static List<GcodeParser.GcodeMeta> processCommand(String command, int lin
meta.command = command;
// Commands like 'G21' don't return a point segment.
if (meta.point != null) {
meta.point.setSpeed(state.speed);
meta.point.setFeedRate(state.feedRate);
meta.point.setSpindleSpeed(state.spindleSpeed);
}
results.add(meta);
}
}

// Return updated state / command.
if (results.isEmpty() && includeNonMotionStates) {
GcodeParser.GcodeMeta meta = new GcodeParser.GcodeMeta();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
/*
* An optimized LineSegment which only uses the end point with the expectation
* that a collection of points will represent a continuous set of line segments.
*
* Created on Nov 9, 2013
*/

/*
Copyright 2013-2017 Will Winder
Copyright 2013-2023 Will Winder
This file is part of Universal Gcode Sender (UGS).
Expand All @@ -32,11 +25,13 @@ This file is part of Universal Gcode Sender (UGS).
import static com.willwinder.universalgcodesender.model.UnitUtils.Units.MM;

/**
* An optimized LineSegment which only uses the end point with the expectation
* that a collection of points will represent a continuous set of line segments.
*
* @author wwinder
*/
final public class PointSegment {
private double speed;
public final class PointSegment {
private double feedRate;
private Position point;

// Line properties
Expand All @@ -48,6 +43,7 @@ final public class PointSegment {
private boolean isProbe = false;
private int lineNumber;
private ArcProperties arcProperties = null;
private double spindleSpeed = 0;

private class ArcProperties {
public boolean isClockwise;
Expand All @@ -60,7 +56,8 @@ private class ArcProperties {
public PointSegment(PointSegment ps) {
this(ps.point(), ps.getLineNumber());

this.setSpeed(ps.speed);
this.setFeedRate(ps.feedRate);
this.setSpindleSpeed(ps.getSpindleSpeed());
this.setIsArc(ps.isArc);
this.setIsMetric(ps.isMetric);
this.setIsZMovement(ps.isZMovement);
Expand Down Expand Up @@ -111,13 +108,21 @@ public int getLineNumber() {
return lineNumber;
}

public void setSpeed(final double s) {
this.speed = s;
public void setFeedRate(final double s) {
this.feedRate = s;
}

public double getSpeed()
public double getFeedRate()
{
return speed;
return feedRate;
}

public void setSpindleSpeed(double spindleSpeed) {
this.spindleSpeed = spindleSpeed;
}

public double getSpindleSpeed() {
return spindleSpeed;
}

public void setIsZMovement(final boolean isZ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,58 +23,59 @@ This file is part of Universal Gcode Sender (UGS).

package com.willwinder.universalgcodesender.uielements.components;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import java.io.File;

/**
*
* @author wwinder
*/
public class GcodeFileTypeFilter extends FileFilter {
public static JFileChooser getGcodeFileChooser(String startDir) {
//Setup the file filter for gcode files.
GcodeFileTypeFilter filter = new GcodeFileTypeFilter();

// Setup file browser with the last path used.
JFileChooser fileChooser = new JFileChooser(startDir);
JFileChooser fileChooser = new JFileChooser(startDir);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setFileHidingEnabled(true);
fileChooser.addChoosableFileFilter(filter);
fileChooser.setAcceptAllFileFilterUsed(true);
fileChooser.setFileFilter(filter);

return fileChooser;
}


private static String getExtension(File f) {
String ext = null;
String s = f.getName();
int i = s.lastIndexOf('.');

if (i > 0 && i < s.length() - 1) {
ext = s.substring(i + 1).toLowerCase();
}
return ext;
}

@Override
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}

String extension = getExtension(f);
return "cnc".equals(extension) ||
"nc".equals(extension) ||
"gc".equals(extension) ||
"nc".equals(extension) ||
"ngc".equals(extension) ||
"tap".equals(extension) ||
"txt".equals(extension) ||
"gcode".equals(extension);
}

//The description of this filter
@Override
public String getDescription() {
return "G-Code (gcode, nc, txt)";
}

private static String getExtension(File f) {
String ext = null;
String s = f.getName();
int i = s.lastIndexOf('.');

if (i > 0 && i < s.length() - 1) {
ext = s.substring(i+1).toLowerCase();
}
return ext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void clear() {
while (model.getRowCount()>0){
model.removeRow(0);
}
//model.dropData();
this.offset = 0;
this.first = true;
}
Expand Down
Loading

0 comments on commit c4085c4

Please sign in to comment.