Interface 砂3D打印机切片问题 在我的博士论文中,我正在构建一个3D打印机,它是由屯特大学的一个松散的:

Interface 砂3D打印机切片问题 在我的博士论文中,我正在构建一个3D打印机,它是由屯特大学的一个松散的:,interface,arrays,indexing,Interface,Arrays,Indexing,到目前为止,一切都相对顺利。硬件部分花费的时间比预期的要长,但电子设备让我有点害怕。我能成功地点动所有的马达,而且,机械地,所有的东西都能做该做的 然而,现在我在软件方面工作,我感到头疼 Pwder人员编写了一段代码,使用处理来获取.STL文件并将其分层。运行代码后,将打开一个处理GUI,我可以在其中加载模型。该模型加载良好(我使用的是犹他茶壶),并显示它将需要149层 点击“convert”后,程序将获取.STL文件并将其分层,然后编写一个文本文件,然后上传到SD卡。然后,打印机将直接从SD卡

到目前为止,一切都相对顺利。硬件部分花费的时间比预期的要长,但电子设备让我有点害怕。我能成功地点动所有的马达,而且,机械地,所有的东西都能做该做的

然而,现在我在软件方面工作,我感到头疼

Pwder人员编写了一段代码,使用处理来获取.STL文件并将其分层。运行代码后,将打开一个处理GUI,我可以在其中加载模型。该模型加载良好(我使用的是犹他茶壶),并显示它将需要149层

点击“convert”后,程序将获取.STL文件并将其分层,然后编写一个文本文件,然后上传到SD卡。然后,打印机将直接从SD卡打印

但是,当我点击“convert”时,我得到一个“数组索引超出范围”错误。我不太清楚这是什么意思。。谁能启发我

下面可以找到代码以及错误图片

多谢各位

//将切片STL的图形输出转换为可打印的二进制格式。
//字节由Arduino固件读取
PrintWriter输出,outputUpper;
int loc;
int-LTR=0;
int-lowernozzles=8;
int=4;
内部喷嘴=下部喷嘴+上部喷嘴;
int printXcoordinate=120+280;//左边缘120
int printYcoordinate=30+190;//上缘30
int printWidth=120;//图像总宽度650
int printHeight=120;//总图像高度480
int layer_size=打印宽度*打印高度/喷嘴*2;
void模型(){
//为打印机创建配置文件,为方便起见,后面加逗号
output=createWriter(“PWDR/PWDRCONF.TXT”);output.print(打印宽度+”、“+打印高度/喷嘴+”、“+最大切片+”、“+墨水饱和度+”、”;
output.flush();
output.close();
int指数=0;
字节[]打印数据=新字节[图层大小*2];
//Y方向12个喷嘴的步骤
用于(int y=打印坐标;y<打印坐标+打印高度;y=y+喷嘴){
//设置一个变量以了解我们何时移动RTL的LTR
LTR++;
//向X方向移动
用于(int x=0;x=1000){
字符串DEST_FILE=“PWDR/PWDR”+sliceNumber+“.DAT”;
文件数据文件=草图文件(DEST_文件);
if(dataFile.exists()){
dataFile.delete();
}
saveBytes(DEST_FILE,print_data);//saveBytes直接导致Windows下的错误
}
数字++;
println(切片编号);
}

发生的情况是打印数据小于索引(例如,如果索引为123,但打印数据只有122个元素)

打印数据的大小为图层大小*2或打印宽度*打印高度/喷嘴*4或4800

索引的最大大小为打印高度/喷嘴*2*打印宽度或20*120或2400


这似乎没什么问题,所以我可能错过了一些东西,它似乎将数据放在元素4800中,这很奇怪。我建议使用一组打印语句来获取打印数据的大小和索引。

感谢您的反馈。我明白了这是什么意思,但我不确定如何修复它。我的编程技能非常糟糕,我更喜欢h硬件方面。仅此而已;我不确定这里出了什么问题。实际的代码看起来是正确的,我看不到任何方法可以使索引达到4800。语言可能有点奇怪,但逻辑似乎很好。
    // Convert the graphical output of the sliced STL into a printable         binary format. 
    // The bytes are read by the Arduino firmware

    PrintWriter output, outputUpper;

    int loc;
    int LTR = 0;
    int lowernozzles = 8;
    int uppernozzles = 4;
    int nozzles = lowernozzles+uppernozzles;

    int printXcoordinate = 120+280;  // Left margin 120
    int printYcoordinate = 30+190;  // Top margin 30
    int printWidth = 120;        // Total image width 650
    int printHeight = 120;      // Total image height 480

    int layer_size = printWidth * printHeight/nozzles * 2;

    void convertModel() {

      // Create config file for the printer, trailing comma for convenience  
      output = createWriter("PWDR/PWDRCONF.TXT");        output.print(printWidth+","+printHeight/nozzles+","+maxSlices+","+inkSaturation+ ",");
      output.flush();
      output.close();

      int index = 0;
      byte[] print_data = new byte[layer_size * 2];

      // Steps of 12 nozzles in Y direction
      for (int y = printYcoordinate; y < printYcoordinate+printHeight;  y=y+nozzles ) {
        // Set a variable to know wheter we're moving LTR of RTL
        LTR++;  
        // Step in X direction  
        for (int x = 0; x < printWidth; x++) {

          // Clear the temp strings
          String[] LowerStr = {""};
          String LowerStr2 = "";
          String[] UpperStr = {""};
          String UpperStr2 = "";

          // For every step in Y direction, sample the 12 nozzles
          for ( int i=0; i<nozzles; i++) {
            // Calculate the location in the pixel array, use total window  width!
            // Use the LTR to determine the direction

            if (LTR % 2 == 1){
              loc = printXcoordinate + printWidth - x + (y+i) * width;
            } else {
              loc = printXcoordinate + x + (y+i) * width;
            }

            if (brightness(pixels[loc]) < 100) {

              // Write a zero when the pixel is white (or should be white, as the preview is inverted)
              if (i<uppernozzles) {
                UpperStr = append(UpperStr, "0");
              } else {
                LowerStr = append(LowerStr, "0");
              }
            } else {
              // Write a one when the pixel is black     
              if (i<uppernozzles) {
                UpperStr = append(UpperStr, "1");                  
              } else {
                LowerStr = append(LowerStr, "1");
              }
            }
          } 

          LowerStr2 = join(LowerStr, "");
          print_data[index] = byte(unbinary(LowerStr2));
          index++;

          UpperStr2 = join(UpperStr, "");
          print_data[index] = byte(unbinary(UpperStr2));
          index++;
        }
      }

      if (sliceNumber >= 1 && sliceNumber < 10){
        String DEST_FILE = "PWDR/PWDR000"+sliceNumber+".DAT";
        File dataFile = sketchFile(DEST_FILE);
        if (dataFile.exists()){
          dataFile.delete();
        }
        saveBytes(DEST_FILE, print_data); // Savebytes directly causes bug  under Windows
      } else if (sliceNumber >= 10 && sliceNumber < 100){
        String DEST_FILE = "PWDR/PWDR00"+sliceNumber+".DAT";
        File dataFile = sketchFile(DEST_FILE);
        if (dataFile.exists()){
          dataFile.delete();
        }
        saveBytes(DEST_FILE, print_data); // Savebytes directly causes bug   under Windows
      } else if (sliceNumber >= 100 && sliceNumber < 1000){
        String DEST_FILE = "PWDR/PWDR0"+sliceNumber+".DAT";
        File dataFile = sketchFile(DEST_FILE);
        if (dataFile.exists()){
          dataFile.delete();
        }
        saveBytes(DEST_FILE, print_data); // Savebytes directly causes bug  under Windows
      } else if (sliceNumber >= 1000) {
        String DEST_FILE = "PWDR/PWDR"+sliceNumber+".DAT";
        File dataFile = sketchFile(DEST_FILE);
        if (dataFile.exists()){
          dataFile.delete();
        }
        saveBytes(DEST_FILE, print_data); // Savebytes directly causes bug  under Windows
      }

      sliceNumber++;
      println(sliceNumber);
    }