From b48792d3b39203902b9c53a84a1c364442e558de Mon Sep 17 00:00:00 2001 From: Jetty 840 Date: Mon, 20 Feb 2012 01:52:06 -0700 Subject: [PATCH] Added acceleration MCode support to go with https://github.com/jetty840/G3Firmware MCodes: 201, 203, 204, 205, 206, 207, 208, 209, 215 --- src/replicatorg/app/GCodeEnumeration.java | 20 +++- src/replicatorg/app/GCodeParser.java | 76 +++++++++++++ src/replicatorg/drivers/Driver.java | 21 ++++ .../drivers/DriverBaseImplementation.java | 32 ++++++ src/replicatorg/drivers/VirtualPrinter.java | 54 ++++++++- .../commands/SetAccelerationControl.java | 17 +++ .../drivers/commands/SetAdvanceK.java | 17 +++ .../drivers/commands/SetAdvancedSettings.java | 20 ++++ .../drivers/commands/SetAxisStepsPerMM.java | 20 ++++ .../commands/SetDefaultAcceleration.java | 18 +++ .../commands/SetExtruderStepsPerMM.java | 17 +++ .../drivers/commands/SetFilamentDiameter.java | 17 +++ .../drivers/commands/SetMaxAcceleration.java | 20 ++++ .../drivers/commands/SetMaxFeedRate.java | 20 ++++ .../drivers/gen3/Makerbot4GDriver.java | 104 ++++++++++++++++++ .../drivers/gen3/MotherboardCommandCode.java | 12 +- 16 files changed, 477 insertions(+), 8 deletions(-) create mode 100644 src/replicatorg/drivers/commands/SetAccelerationControl.java create mode 100644 src/replicatorg/drivers/commands/SetAdvanceK.java create mode 100644 src/replicatorg/drivers/commands/SetAdvancedSettings.java create mode 100644 src/replicatorg/drivers/commands/SetAxisStepsPerMM.java create mode 100644 src/replicatorg/drivers/commands/SetDefaultAcceleration.java create mode 100644 src/replicatorg/drivers/commands/SetExtruderStepsPerMM.java create mode 100644 src/replicatorg/drivers/commands/SetFilamentDiameter.java create mode 100644 src/replicatorg/drivers/commands/SetMaxAcceleration.java create mode 100644 src/replicatorg/drivers/commands/SetMaxFeedRate.java diff --git a/src/replicatorg/app/GCodeEnumeration.java b/src/replicatorg/app/GCodeEnumeration.java index c15bdf46c..df72af897 100644 --- a/src/replicatorg/app/GCodeEnumeration.java +++ b/src/replicatorg/app/GCodeEnumeration.java @@ -70,17 +70,25 @@ public enum GCodeEnumeration { M141("M", 141, "Set Chamber Temperature (Ignored)"), M142("M", 142, "Set Chamber Holding Pressure (Ignored)"), M200("M", 200, "Reset driver"), - M300("M", 300, "Set Servo 1 Position"), - M301("M", 301, "Set Servo 2 Position"), - M310("M", 310, "Start data capture"), - M311("M", 311, "Stop data capture"), - M312("M", 312, "Log a note to the data capture store"), + M201("M", 201, "Set max acceleration"), + M203("M", 203, "Set max feedrate"), + M204("M", 204, "Set default acceleration"), + M205("M", 205, "Set Advanced Settings"), + M206("M", 206, "Set Filament Diameter"), + M207("M", 207, "Set Advance K"), + M208("M", 208, "Set Extruder Steps:mm"), + M209("M", 209, "Set Acceleration Control"), M210("M", 210, "Mood Light Set RGB Color"), M211("M", 211, "Mood Light Set HSB Color"), M212("M", 212, "Mood Light Play Script"), M213("M", 213, "Set Buzzer Repetitions"), M214("M", 214, "Buzz"), - + M215("M", 215, "Set Axis Steps Per:mm"), + M300("M", 300, "Set Servo 1 Position"), + M301("M", 301, "Set Servo 2 Position"), + M310("M", 310, "Start data capture"), + M311("M", 311, "Stop data capture"), + M312("M", 312, "Log a note to the data capture store"), G0("G", 0, "Rapid Positioning"), G1("G", 1, "Coordinated Motion"), G2("G", 2, "Clockwise Arc"), diff --git a/src/replicatorg/app/GCodeParser.java b/src/replicatorg/app/GCodeParser.java index e64dfca93..352bb2049 100644 --- a/src/replicatorg/app/GCodeParser.java +++ b/src/replicatorg/app/GCodeParser.java @@ -660,6 +660,72 @@ else if (gcode.hasCode('R')) commands.add(new replicatorg.drivers.commands.DataCaptureNote(gcode.getComment())); break; + case M201: //Set max acceleration + { + double x = gcode.getCodeValue('X'); + double y = gcode.getCodeValue('Y'); + double z = gcode.getCodeValue('Z'); + double a = gcode.getCodeValue('A'); + commands.add(new replicatorg.drivers.commands.SetMaxAcceleration(x,y,z,a)); + } + break; + + case M203: //Set max feedrate + { + double x = gcode.getCodeValue('X'); + double y = gcode.getCodeValue('Y'); + double z = gcode.getCodeValue('Z'); + double a = gcode.getCodeValue('A'); + commands.add(new replicatorg.drivers.commands.SetMaxFeedRate(x,y,z,a)); + } + break; + + case M204: //Set default acceleration + { + double s = gcode.getCodeValue('S'); + double t = gcode.getCodeValue('K'); + commands.add(new replicatorg.drivers.commands.SetDefaultAcceleration(s,t)); + } + break; + + case M205: //Set Advanced Settings + { + double s = (double)gcode.getCodeValue('S') / 10.0; + double t = (double)gcode.getCodeValue('K') / 10.0; + double x = (double)gcode.getCodeValue('X') / 10.0; + double z = (double)gcode.getCodeValue('Z') / 10.0; + commands.add(new replicatorg.drivers.commands.SetAdvancedSettings(s,t,x,z)); + } + break; + + case M206: //Set Filament Diameter + { + double s = (double)gcode.getCodeValue('S') / 100.0; + commands.add(new replicatorg.drivers.commands.SetFilamentDiameter(s)); + } + break; + + case M207: //Set Advance K + { + double s = (double)gcode.getCodeValue('S') / 100000.0; + commands.add(new replicatorg.drivers.commands.SetAdvanceK(s)); + } + break; + + case M208: //Set Extruder Steps:mm + { + double a = gcode.getCodeValue('A') / 10.0; + commands.add(new replicatorg.drivers.commands.SetExtruderStepsPerMM(a)); + } + break; + + case M209: //Set Acceleration Control + { + double s = gcode.getCodeValue('S'); + commands.add(new replicatorg.drivers.commands.SetAccelerationControl(s)); + } + break; + case M210: // Mood Light Set RGB Color double fadeSpeed = (int)gcode.getCodeValue('S'); if ( fadeSpeed == -1 ) fadeSpeed = 8; //The default @@ -737,6 +803,16 @@ else if (( repeats < 1 ) || ( repeats > 255)) else commands.add(new replicatorg.drivers.commands.Buzz(buzzes, duration, repeats)); break; + case M215: //Set Axis Steps Per:mm + { + double x = (double)gcode.getCodeValue('X') / 10000.0; + double y = (double)gcode.getCodeValue('Y') / 10000.0; + double z = (double)gcode.getCodeValue('Z') / 10000.0; + double a = (double)gcode.getCodeValue('A') / 10000.0; + commands.add(new replicatorg.drivers.commands.SetAxisStepsPerMM(x,y,z,a)); + } + break; + default: throw new GCodeException("Unknown M code: M" + (int) gcode.getCodeValue('M')); } diff --git a/src/replicatorg/drivers/Driver.java b/src/replicatorg/drivers/Driver.java index 35ea45b8b..0f297c248 100644 --- a/src/replicatorg/drivers/Driver.java +++ b/src/replicatorg/drivers/Driver.java @@ -236,6 +236,27 @@ public interface Driver { public void buzz(int buzzes, int duration, int repeats) throws RetryException; + /** + * Acceleration Methods + */ + public void setMaxAcceleration(double x, double y, double z, double a) throws RetryException; + + public void setMaxFeedRate(double x, double y, double z, double a) throws RetryException; + + public void setDefaultAcceleration(double s, double t) throws RetryException; + + public void setAdvancedSettings(double s, double t, double x, double z) throws RetryException; + + public void setFilamentDiameter(double s) throws RetryException; + + public void setAdvanceK(double s) throws RetryException; + + public void setExtruderStepsPerMM(double a) throws RetryException; + + public void setAccelerationControl(double s) throws RetryException; + + public void setAxisStepsPerMM(double x, double y, double z, double a) throws RetryException; + /** * Home the given set of axes at the given feedrate. If the feedrate is <=0, run at * maximum feedrate for the appropriate axes. diff --git a/src/replicatorg/drivers/DriverBaseImplementation.java b/src/replicatorg/drivers/DriverBaseImplementation.java index 1ed944e69..c1a0e3b6b 100644 --- a/src/replicatorg/drivers/DriverBaseImplementation.java +++ b/src/replicatorg/drivers/DriverBaseImplementation.java @@ -433,6 +433,38 @@ public void setBuzzerRepetitions(int repeats) throws RetryException { public void buzz(int buzzes, int duration, int repeats) throws RetryException { } + /*************************************************************************** + * Acceleration interface functions + * @throws RetryException + **************************************************************************/ + + public void setMaxAcceleration(double x, double y, double z, double a) throws RetryException { + } + + public void setMaxFeedRate(double x, double y, double z, double a) throws RetryException { + } + + public void setDefaultAcceleration(double s, double t) throws RetryException { + } + + public void setAdvancedSettings(double s, double t, double x, double z) throws RetryException { + } + + public void setFilamentDiameter(double s) throws RetryException { + } + + public void setAdvanceK(double s) throws RetryException { + } + + public void setExtruderStepsPerMM(double a) throws RetryException { + } + + public void setAccelerationControl(double s) throws RetryException { + } + + public void setAxisStepsPerMM(double x, double y, double z, double a) throws RetryException { + } + /*************************************************************************** * pause function * @throws RetryException diff --git a/src/replicatorg/drivers/VirtualPrinter.java b/src/replicatorg/drivers/VirtualPrinter.java index a72143df2..f64d8c5a4 100644 --- a/src/replicatorg/drivers/VirtualPrinter.java +++ b/src/replicatorg/drivers/VirtualPrinter.java @@ -285,10 +285,62 @@ public void buzz(int buzzes, int duration, int repeats) } @Override - public void homeAxes(EnumSet axes, boolean positive, double feedrate) + public void setMaxAcceleration(double x, double y, double z, double a) throws RetryException { // TODO Auto-generated method stub + } + + @Override + public void setMaxFeedRate(double x, double y, double z, double a) + throws RetryException { + // TODO Auto-generated method stub + } + + @Override + public void setDefaultAcceleration(double s, double t) + throws RetryException { + // TODO Auto-generated method stub + } + @Override + public void setAdvancedSettings(double s, double t, double x, double z) + throws RetryException { + // TODO Auto-generated method stub + } + + @Override + public void setFilamentDiameter(double s) + throws RetryException { + // TODO Auto-generated method stub + } + + @Override + public void setAdvanceK(double s) + throws RetryException { + // TODO Auto-generated method stub + } + + @Override + public void setExtruderStepsPerMM(double a) + throws RetryException { + // TODO Auto-generated method stub + } + + @Override + public void setAccelerationControl(double s) + throws RetryException { + // TODO Auto-generated method stub + } + + @Override + public void setAxisStepsPerMM(double x, double y, double z, double a) + throws RetryException { + // TODO Auto-generated method stub + } + + @Override + public void homeAxes(EnumSet axes, boolean positive, double feedrate) { + // TODO Auto-generated method stub } @Override diff --git a/src/replicatorg/drivers/commands/SetAccelerationControl.java b/src/replicatorg/drivers/commands/SetAccelerationControl.java new file mode 100644 index 000000000..ec15e225a --- /dev/null +++ b/src/replicatorg/drivers/commands/SetAccelerationControl.java @@ -0,0 +1,17 @@ +package replicatorg.drivers.commands; + +import replicatorg.drivers.Driver; +import replicatorg.drivers.RetryException; + +public class SetAccelerationControl implements DriverCommand { + + double s; + + public SetAccelerationControl(double s) { + this.s = s; + } + @Override + public void run(Driver driver) throws RetryException { + driver.setAccelerationControl(s); + } +} diff --git a/src/replicatorg/drivers/commands/SetAdvanceK.java b/src/replicatorg/drivers/commands/SetAdvanceK.java new file mode 100644 index 000000000..b79fc547d --- /dev/null +++ b/src/replicatorg/drivers/commands/SetAdvanceK.java @@ -0,0 +1,17 @@ +package replicatorg.drivers.commands; + +import replicatorg.drivers.Driver; +import replicatorg.drivers.RetryException; + +public class SetAdvanceK implements DriverCommand { + + double s; + + public SetAdvanceK(double s) { + this.s = s; + } + @Override + public void run(Driver driver) throws RetryException { + driver.setAdvanceK(s); + } +} diff --git a/src/replicatorg/drivers/commands/SetAdvancedSettings.java b/src/replicatorg/drivers/commands/SetAdvancedSettings.java new file mode 100644 index 000000000..547fd2d1e --- /dev/null +++ b/src/replicatorg/drivers/commands/SetAdvancedSettings.java @@ -0,0 +1,20 @@ +package replicatorg.drivers.commands; + +import replicatorg.drivers.Driver; +import replicatorg.drivers.RetryException; + +public class SetAdvancedSettings implements DriverCommand { + + double s, t, x, z; + + public SetAdvancedSettings(double s, double t, double x, double z) { + this.s = s; + this.t = t; + this.x = x; + this.z = z; + } + @Override + public void run(Driver driver) throws RetryException { + driver.setAdvancedSettings(s,t,x,z); + } +} diff --git a/src/replicatorg/drivers/commands/SetAxisStepsPerMM.java b/src/replicatorg/drivers/commands/SetAxisStepsPerMM.java new file mode 100644 index 000000000..293669f24 --- /dev/null +++ b/src/replicatorg/drivers/commands/SetAxisStepsPerMM.java @@ -0,0 +1,20 @@ +package replicatorg.drivers.commands; + +import replicatorg.drivers.Driver; +import replicatorg.drivers.RetryException; + +public class SetAxisStepsPerMM implements DriverCommand { + + double x, y, z, a; + + public SetAxisStepsPerMM(double x, double y, double z, double a) { + this.x = x; + this.y = y; + this.z = z; + this.a = a; + } + @Override + public void run(Driver driver) throws RetryException { + driver.setAxisStepsPerMM(x,y,z,a); + } +} diff --git a/src/replicatorg/drivers/commands/SetDefaultAcceleration.java b/src/replicatorg/drivers/commands/SetDefaultAcceleration.java new file mode 100644 index 000000000..c3f8face6 --- /dev/null +++ b/src/replicatorg/drivers/commands/SetDefaultAcceleration.java @@ -0,0 +1,18 @@ +package replicatorg.drivers.commands; + +import replicatorg.drivers.Driver; +import replicatorg.drivers.RetryException; + +public class SetDefaultAcceleration implements DriverCommand { + + double s, t; + + public SetDefaultAcceleration(double s, double t) { + this.s = s; + this.t = t; + } + @Override + public void run(Driver driver) throws RetryException { + driver.setDefaultAcceleration(s, t); + } +} diff --git a/src/replicatorg/drivers/commands/SetExtruderStepsPerMM.java b/src/replicatorg/drivers/commands/SetExtruderStepsPerMM.java new file mode 100644 index 000000000..69a18b6c8 --- /dev/null +++ b/src/replicatorg/drivers/commands/SetExtruderStepsPerMM.java @@ -0,0 +1,17 @@ +package replicatorg.drivers.commands; + +import replicatorg.drivers.Driver; +import replicatorg.drivers.RetryException; + +public class SetExtruderStepsPerMM implements DriverCommand { + + double a; + + public SetExtruderStepsPerMM(double a) { + this.a = a; + } + @Override + public void run(Driver driver) throws RetryException { + driver.setExtruderStepsPerMM(a); + } +} diff --git a/src/replicatorg/drivers/commands/SetFilamentDiameter.java b/src/replicatorg/drivers/commands/SetFilamentDiameter.java new file mode 100644 index 000000000..492fd4968 --- /dev/null +++ b/src/replicatorg/drivers/commands/SetFilamentDiameter.java @@ -0,0 +1,17 @@ +package replicatorg.drivers.commands; + +import replicatorg.drivers.Driver; +import replicatorg.drivers.RetryException; + +public class SetFilamentDiameter implements DriverCommand { + + double s; + + public SetFilamentDiameter(double s) { + this.s = s; + } + @Override + public void run(Driver driver) throws RetryException { + driver.setFilamentDiameter(s); + } +} diff --git a/src/replicatorg/drivers/commands/SetMaxAcceleration.java b/src/replicatorg/drivers/commands/SetMaxAcceleration.java new file mode 100644 index 000000000..2a558d3b1 --- /dev/null +++ b/src/replicatorg/drivers/commands/SetMaxAcceleration.java @@ -0,0 +1,20 @@ +package replicatorg.drivers.commands; + +import replicatorg.drivers.Driver; +import replicatorg.drivers.RetryException; + +public class SetMaxAcceleration implements DriverCommand { + + double x,y,z,a; + + public SetMaxAcceleration(double x, double y, double z, double a) { + this.x = x; + this.y = y; + this.z = z; + this.a = a; + } + @Override + public void run(Driver driver) throws RetryException { + driver.setMaxAcceleration(x,y,z,a); + } +} diff --git a/src/replicatorg/drivers/commands/SetMaxFeedRate.java b/src/replicatorg/drivers/commands/SetMaxFeedRate.java new file mode 100644 index 000000000..0bf9ffbc4 --- /dev/null +++ b/src/replicatorg/drivers/commands/SetMaxFeedRate.java @@ -0,0 +1,20 @@ +package replicatorg.drivers.commands; + +import replicatorg.drivers.Driver; +import replicatorg.drivers.RetryException; + +public class SetMaxFeedRate implements DriverCommand { + + double x,y,z,a; + + public SetMaxFeedRate(double x, double y, double z, double a) { + this.x = x; + this.y = y; + this.z = z; + this.a = a; + } + @Override + public void run(Driver driver) throws RetryException { + driver.setMaxFeedRate(x,y,z,a); + } +} diff --git a/src/replicatorg/drivers/gen3/Makerbot4GDriver.java b/src/replicatorg/drivers/gen3/Makerbot4GDriver.java index a95cb5fe7..9c378fd40 100644 --- a/src/replicatorg/drivers/gen3/Makerbot4GDriver.java +++ b/src/replicatorg/drivers/gen3/Makerbot4GDriver.java @@ -302,4 +302,108 @@ public void buzz(int buzzes, int duration, int repeats) throws RetryException { runCommand(pb.getPacket()); } + + public void setMaxAcceleration(double x, double y, double z, double a) throws RetryException { + PacketBuilder pb = new PacketBuilder(MotherboardCommandCode.SET_MAX_ACCEL.getCode()); + + pb.add32((int)x); + pb.add32((int)y); + pb.add32((int)z); + pb.add32((int)a); + + Base.logger.log(Level.FINE,"SetMaxAcceleration (" + x + " " + y + " " + z + " " + a + ")" ); + + runCommand(pb.getPacket()); + } + + public void setMaxFeedRate(double x, double y, double z, double a) throws RetryException { + PacketBuilder pb = new PacketBuilder(MotherboardCommandCode.SET_MAX_FEEDRATE.getCode()); + + pb.add32((int)x); + pb.add32((int)y); + pb.add32((int)z); + pb.add32((int)a); + + Base.logger.log(Level.FINE,"SetMaxFeedRate (" + x + " " + y + " " + z + " " + a + ")" ); + + runCommand(pb.getPacket()); + } + + public void setDefaultAcceleration(double s, double t) throws RetryException { + PacketBuilder pb = new PacketBuilder(MotherboardCommandCode.SET_DEFAULT_ACCEL.getCode()); + + pb.add32((int)s); + pb.add32((int)t); + + Base.logger.log(Level.FINE,"SetDefaultAcceleration (" + s + " " + t + ")" ); + + runCommand(pb.getPacket()); + } + + public void setAdvancedSettings(double s, double t, double x, double z) throws RetryException { + PacketBuilder pb = new PacketBuilder(MotherboardCommandCode.SET_ADVANCED_ACCEL.getCode()); + + pb.add32((int)(s*10.0)); + pb.add32((int)(t*10.0)); + pb.add32((int)(x*10.0)); + pb.add32((int)(z*10.0)); + + Base.logger.log(Level.FINE,"SetAdvancedSettings (" + s + " " + t + " " + x + " " + z + ")" ); + + runCommand(pb.getPacket()); + } + + public void setFilamentDiameter(double s) throws RetryException { + PacketBuilder pb = new PacketBuilder(MotherboardCommandCode.SET_FILAMENT_DIA.getCode()); + + pb.add32((int)(s * 100.0)); + + Base.logger.log(Level.FINE,"SetFilamentDiameter (" + s + ")" ); + + runCommand(pb.getPacket()); + } + + public void setAdvanceK(double s) throws RetryException { + PacketBuilder pb = new PacketBuilder(MotherboardCommandCode.SET_ADVANCE_K.getCode()); + + pb.add32((int)(s * 100000.0)); + + Base.logger.log(Level.FINE,"SetAdvanceK (" + s + ")" ); + + runCommand(pb.getPacket()); + } + + public void setExtruderStepsPerMM(double a) throws RetryException { + PacketBuilder pb = new PacketBuilder(MotherboardCommandCode.SET_EXTRUDER_STEPSMM.getCode()); + + pb.add32((int)(a * 10.0)); + + Base.logger.log(Level.FINE,"SetExtruderStepsPerMM (" + a + ")" ); + + runCommand(pb.getPacket()); + } + + public void setAccelerationControl(double s) throws RetryException { + PacketBuilder pb = new PacketBuilder(MotherboardCommandCode.SET_ACCELERATION.getCode()); + + if (( s == 0 ) || ( s == 1 ) || ( s == 3 )) pb.add8((int)s); + else pb.add8(0); + + Base.logger.log(Level.FINE,"SetAccelerationControl (" + s + ")" ); + + runCommand(pb.getPacket()); + } + + public void setAxisStepsPerMM(double x, double y, double z, double a) throws RetryException { + PacketBuilder pb = new PacketBuilder(MotherboardCommandCode.SET_AXIS_STEPS_MM.getCode()); + + pb.add32((long)(x * 100000.0)); + pb.add32((long)(y * 100000.0)); + pb.add32((long)(z * 100000.0)); + pb.add32((long)(a * 100000.0)); + + Base.logger.log(Level.FINE,"SetAxisStepsPerMM (" + x + " " + y + " " + z + " " + a + ")" ); + + runCommand(pb.getPacket()); + } } diff --git a/src/replicatorg/drivers/gen3/MotherboardCommandCode.java b/src/replicatorg/drivers/gen3/MotherboardCommandCode.java index 86bb68585..b45bd60eb 100644 --- a/src/replicatorg/drivers/gen3/MotherboardCommandCode.java +++ b/src/replicatorg/drivers/gen3/MotherboardCommandCode.java @@ -51,11 +51,21 @@ public enum MotherboardCommandCode { STORE_HOME_POSITIONS(143), RECALL_HOME_POSITIONS(144), + SET_MAX_ACCEL(201), + SET_MAX_FEEDRATE(203), + SET_DEFAULT_ACCEL(204), + SET_ADVANCED_ACCEL(205), + SET_FILAMENT_DIA(206), + SET_ADVANCE_K(207), + SET_EXTRUDER_STEPSMM(208), + SET_ACCELERATION(209), MOOD_LIGHT_SET_RGB(210), MOOD_LIGHT_SET_HSB(211), MOOD_LIGHT_PLAY_SCRIPT(212), BUZZER_REPEATS(213), - BUZZER_BUZZ(214); + BUZZER_BUZZ(214), + SET_AXIS_STEPS_MM(215); + private int code; private MotherboardCommandCode(int code) {