New machine configuration based on GCode.js

Discussions around the CAM Add-On of QCAD version 3

Moderator: andrew

New machine configuration based on GCode.js

Postby cmcgrath5035 » Wed Apr 16, 2014 1:34 pm

I have completed the conversion of a hack discussed in a previous "hack help" thread to a 'more proper' implementation.
It is targeted at my ShapeOko machine but obviously rather generic.
My main objectives were to add some identifying information to the GCode file, add basic spindle On/Off management, tweak the GUI parameter selection lists to be more centric to the way I use my machine, and add feedRate to the selectable parameters.
Acknowledgment- This builds on GCode.js and liberally reuses code snippets from other discussions on this forum.
I have run a few tests cases - appears to work as intended.
If you wish to use these on your QCADCAM setup, paste files ShapeOko.js and ShapeOko.ui into qcad-directory/scripts/Cam/CamConfigurations/
Script file : ShapeOko.js
Code: Select all
//cjm April 12, 2014 starting point for ShapeOko.js
//cjm April 15, 2014 ver 0.9
//   Tested with simple washer.dxf, results look good
//   Note
//      GCode.js and ShapeOko.js use units in mm (metric)
//   Implements
//      Date of GCode build in GCode Comment
//      File.dxf used for build included in GCode Comment
//      GUI box to select global feedrate implemented
//         GUI definition in ShapeOko.ui
//      Spindle ON code implemented for first toolDown command
//      Spindle OFF command implemented in writeFooter
//   Needs
//      Remove debug lines
//cjm April 15, 2014 ver 1.0
//      Debug statements commented out

include("GCode.js");   //ShapeOko.js implements a few enhancements/changes to the QCAD GCode.js implementation

function ShapeOko(documentInterface, newDocumentInterface) {
    GCode.call(this, documentInterface, newDocumentInterface);

    // set output unit:
    // cjm Place parameter customizations in here
    // this.unit = RS.Inch;
 
    // use ShapeOko.ui for global options:
    this.globalOptions = "ShapeOko";      //GUI files is ShapeOko.ui
 
}

//cjm Pulled this function from internet
// It builds date string -> 2013/10/04 08:51:32
 function getDateTime() {
    var now     = new Date();
    var year    = now.getFullYear();
    var month   = now.getMonth()+1;
    var day     = now.getDate();
    var hour    = now.getHours();
    var minute  = now.getMinutes();
    var second  = now.getSeconds();
    if(month.toString().length == 1) {
        var month = '0'+month;
    }
    if(day.toString().length == 1) {
        var day = '0'+day;
    }   
    if(hour.toString().length == 1) {
        var hour = '0'+hour;
    }
    if(minute.toString().length == 1) {
        var minute = '0'+minute;
    }
    if(second.toString().length == 1) {
        var second = '0'+second;
    }   
    var dateTime = year+'/'+month+'/'+day+' '+hour+':'+minute+':'+second;   
    return dateTime;

}

ShapeOko.prototype = new GCode();

ShapeOko.prototype.getFileExtensions = function() {
    // set output file extension:
    return ["nc"];  //perhaps make selectable later?
};

ShapeOko.prototype.initGlobalOptionWidget = function(w) {
    switch (w.objectName) {
    case "ZSafety":
// Modify UI list options for ZSafety
        w.addItems(["40", "30", "20", "10", "5"]);
        w.setEditText("5");   //This sets the default value
        break;
    case "ZClear":
        w.addItems(["1", "2", "3"]);
        w.setEditText("2");   //This sets the default value
        break;
    case "ZCutting":
// Modify UI list options for ZCutting
        w.addItems(["-0.1", "-0.2", "-0.3", "-0.4", "-0.5"]);
        w.setEditText("-0.3");   //This sets the default value
        break; 
      case "Feedrate":
        w.addItems(["100", "200", "300", "400", "500"]);
        w.setEditText("200");   //This sets the default value
        break;
    }
};
ShapeOko.prototype.initLayerOptionWidget = function(w) {
    switch (w.objectName) {
    case "ZCutting":
// Modify UI list options for ZCutting by layer
        w.addItems(["default","-0.1", "-0.2", "-0.3", "-0.4", "-0.5"]);
        w.currentText = "default";
        break;
    }
};

ShapeOko.prototype.writeToolUp = function() {
    this.g = GCode.Mode.Rapid;
    this.z = this.getToolUpLevel();
    this.toolPosition = GCode.ToolPosition.Up;
    if (this.feedRateSet!==true) {
        this.writeLine(undefined, "F200");
      this.feedRateSet=true;
    }
    else {
        this.writeLine();
    }
    this.toolIsUp();
};

ShapeOko.prototype.writeToolDown = function() {
  //cjm Called if tool needs to be moved down
  //cjm If called and spindle is Off, Send code to turn spindle ON
    if (this.spindleON!==true) {
        this.writeLine("(Spindle ON)"); //Insert a comment in GCode file
        this.writeLine("M03");      //cjm Turn spindle on
//       debugger;
   this.spindleON=true;
//   qDebug("Spindle On code added by ShapeOko.prototype.writeToolDown");
    };
    //cjm What follows is code from original code GCode.prototype.writeToolDown
    this.g = GCode.Mode.Normal;
    this.z = this.getToolDownLevel();
    this.toolPosition = GCode.ToolPosition.Down;
    this.writeLine();
    this.toolIsDown();
};

ShapeOko.prototype.writeHeader = function() {
    //cjm add header lines to the GCode file
//  qDebug("ShapeOko.prototype.writeHeader = function() running now"); 
    this.writeLine("(GCode generated by QCADCAM on " + getDateTime() + ")");//Insert a comment in GCode file
    this.writeLine("(GCode generated for File " + this.document.getFileName() + ")");//Insert a comment in GCode file
    this.writeLine("(Spindle ON/OFF actions added by this script)");    //Insert a comment in GCode file
    this.writeRapidZMove(this.getSafetyZLevel());
    this.toolPosition = GCode.ToolPosition.Clear;
    //read in the selected feed rate from GUI
    this.f = this.getFeedrate();
    if(this.f >0){
       this.feedRateSet=true;
//     qDebug("Feedrate greater than 0 has been input, therefore feedRateSet=true");
    };
};

ShapeOko.prototype.writeFooter = function() {
    this.writeToolUp();
    this.writeRapidZMove(this.getSafetyZLevel());
    this.toolPosition = GCode.ToolPosition.Clear;
    this.writeLine("(Spindle OFF) ");   //Insert a comment in GCode file
    this.writeLine("M05");           //cjm Turn off Spindle
    this.spindleON=false;
    this.writeLine("M30");
};

GUI file: ShapeOko.ui
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>GlobalOptions</class>
 <widget class="QScrollArea" name="GlobalOptions">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>503</width>
    <height>387</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>ScrollArea</string>
  </property>
  <property name="widgetResizable">
   <bool>true</bool>
  </property>
  <widget class="QWidget" name="scrollAreaWidgetContents">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>497</width>
     <height>381</height>
    </rect>
   </property>
   <widget class="Line" name="line">
    <property name="geometry">
     <rect>
      <x>333</x>
      <y>109</y>
      <width>160</width>
      <height>16</height>
     </rect>
    </property>
    <property name="orientation">
     <enum>Qt::Horizontal</enum>
    </property>
   </widget>
   <widget class="QLabel" name="label_4">
    <property name="geometry">
     <rect>
      <x>4</x>
      <y>116</y>
      <width>222</width>
      <height>16</height>
     </rect>
    </property>
    <property name="text">
     <string>ShapeOko Target Gcode File Information</string>
    </property>
   </widget>
   <widget class="QComboBox" name="ZClear">
    <property name="geometry">
     <rect>
      <x>168</x>
      <y>30</y>
      <width>71</width>
      <height>22</height>
     </rect>
    </property>
    <property name="editable">
     <bool>true</bool>
    </property>
    <property name="currentIndex">
     <number>-1</number>
    </property>
   </widget>
   <widget class="QLabel" name="label">
    <property name="geometry">
     <rect>
      <x>4</x>
      <y>30</y>
      <width>43</width>
      <height>16</height>
     </rect>
    </property>
    <property name="text">
     <string>Z Clear:</string>
    </property>
   </widget>
   <widget class="QComboBox" name="ZCutting">
    <property name="geometry">
     <rect>
      <x>168</x>
      <y>56</y>
      <width>71</width>
      <height>22</height>
     </rect>
    </property>
    <property name="editable">
     <bool>true</bool>
    </property>
    <property name="currentIndex">
     <number>-1</number>
    </property>
   </widget>
   <widget class="QLabel" name="label_2">
    <property name="geometry">
     <rect>
      <x>4</x>
      <y>56</y>
      <width>52</width>
      <height>16</height>
     </rect>
    </property>
    <property name="text">
     <string>Z Cutting:</string>
    </property>
   </widget>
   <widget class="QComboBox" name="Feedrate">
    <property name="geometry">
     <rect>
      <x>168</x>
      <y>82</y>
      <width>71</width>
      <height>21</height>
     </rect>
    </property>
    <property name="editable">
     <bool>true</bool>
    </property>
   </widget>
   <widget class="QLabel" name="label_5">
    <property name="geometry">
     <rect>
      <x>4</x>
      <y>82</y>
      <width>49</width>
      <height>16</height>
     </rect>
    </property>
    <property name="text">
     <string>Feedrate</string>
    </property>
   </widget>
   <widget class="QComboBox" name="ZSafety">
    <property name="geometry">
     <rect>
      <x>168</x>
      <y>4</y>
      <width>71</width>
      <height>22</height>
     </rect>
    </property>
    <property name="editable">
     <bool>true</bool>
    </property>
   </widget>
   <widget class="QLabel" name="label_3">
    <property name="geometry">
     <rect>
      <x>4</x>
      <y>4</y>
      <width>46</width>
      <height>16</height>
     </rect>
    </property>
    <property name="text">
     <string>Z Safety:</string>
    </property>
   </widget>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>
cmcgrath5035
Active Member
 
Posts: 44
Joined: Thu Oct 13, 2011 7:38 pm

Return to QCAD 3 CAM Add-On

Who is online

Users browsing this forum: No registered users and 1 guest