void readFile(String fName) {
    ArrayList<Vec3D> importPts = new ArrayList<Vec3D>();

    File f = new File("");
    try {

      f = new File(p.dataPath(fName));
      p.println(fName);

    } catch (NullPointerException ex) {
      PApplet.println("File: " + " could not be found.");
    }

    String[] strLines = p.loadStrings(f.getAbsolutePath());

    for (int i = 0; i < strLines.length; i++) {
      String clean = strLines[i].substring(1, strLines[i].length() - 1);

      String[] splitToken = clean.split(", ");

      float xx = PApplet.parseFloat(splitToken[0]);
      float yy = PApplet.parseFloat(splitToken[1]);
      float zz = PApplet.parseFloat(splitToken[2]);
      Vec3D ptt = new Vec3D(xx, yy, zz);
      importPts.add(ptt);
    }
    this.populate(importPts);
    p.dotTree.addAll(importPts);
  }
Exemplo n.º 2
0
  public void processSerialData() {
    byte[] inBuf = new byte[20];
    switch (serial.read()) {
      case 'A':
        // wait for all data arrived
        while (serial.available() < 16) {}
        // read all data
        serial.readBytes(inBuf);
        Acc_RAW = (inBuf[1] << 8) + (inBuf[0] & 0xFF);
        Gyro_RAW = (inBuf[3] << 8) + (inBuf[2] & 0xFF);
        // int intbit = 0;
        // intbit = (inBuf[7] << 24) | ((inBuf[6] & 0xFF) << 16) | ((inBuf[5] & 0xFF) << 8) |
        // (inBuf[4] & 0xFF);
        // Angle = Float.intBitsToFloat(intbit);
        int AngleInt = (inBuf[5] << 8) + (inBuf[4] & 0xFF);
        Angle = PApplet.parseFloat(AngleInt) / 10;
        Acc_Angle = (inBuf[7] << 8) + (inBuf[6] & 0xFF);
        Gyro_Rate = (inBuf[9] << 8) + (inBuf[8] & 0xff);
        Drive = (inBuf[11] << 8) + (inBuf[10] & 0xFF);
        statusFlag = (inBuf[13] << 8) + (inBuf[12] & 0xFF);
        int BatLevelInt = (inBuf[15] << 8) + (inBuf[14] & 0xFF);
        Steer = (inBuf[17] << 8) + (inBuf[16] & 0xFF);
        BatLevel = PApplet.parseFloat(BatLevelInt) / 10;
        println(
            "Acc="
                + Acc_RAW
                + "  Gyro="
                + Gyro_RAW
                + "  Angle="
                + Angle
                + "  Acc_Angle="
                + Acc_Angle
                + "  Gyro_Rate="
                + Gyro_Rate
                + "  Drive="
                + Drive
                + "  Status="
                + statusFlag);
        break;

      case 'E':
        // wait for all data arrived
        while (serial.available() < 6) {}
        // read all data
        serial.readBytes(inBuf);
        int P = (inBuf[1] << 8) + (inBuf[0] & 0xFF);
        int I = (inBuf[3] << 8) + (inBuf[2] & 0xFF);
        int D = (inBuf[5] << 8) + (inBuf[4] & 0xFF);
        conf_KP.setValue(P);
        conf_KI.setValue(I);
        conf_KD.setValue(D);
        println("P=" + P + " I=" + I + " D=" + D);
        break;
    }
    serial.clear();
  }
Exemplo n.º 3
0
  // \u30c7\u30fc\u30bf\u3092\u30ea\u30b9\u30c8\u306b\u683c\u7d0d\u3057\u3066\u53d6\u5f97
  public ArrayList<dotObj> getDataList(String[] lines, int targetChannel) {

    ArrayList<dotObj> retList = new ArrayList<dotObj>();

    // \u5168\u30c7\u30fc\u30bf\u3092\u53c2\u7167\u3057\u3066\u5fc5\u8981\u306a\u60c5\u5831\u3092\u53d6\u308a\u51fa\u3059
    int index = 0;
    for (int i = 0; i < lines.length; i++) {
      // ','\u3067\u533a\u5207\u308a\u914d\u5217\u306b\u683c\u7d0d
      String data[] = split(lines[i], ',');
      // channel, date, valuse
      // \u306e\u9806\u3067\u30c7\u30fc\u30bf\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b
      int channel = PApplet.parseInt(data[0]); // \u30c1\u30e3\u30f3\u30cd\u30eb
      String timeStamp = data[1]; // \u65e5\u4ed8
      float val = PApplet.parseFloat(data[2]); // \u5024

      if (channel == targetChannel) {
        // println("channel: " + channel);
        // println("date   : " + timeStamp);
        // println("val    : " + val);

        // \u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30bb\u30c3\u30c8\u3057\u3001\u914d\u5217\u306b\u683c\u7d0d
        float m = map(val, -0.5f, 0.5f, height / 4, height);
        dotObj theObj = new dotObj(index * width / 70, m, 0);
        theObj.channel = channel;
        theObj.timeStamp = timeStamp;
        theObj.val = val;
        retList.add(theObj);

        index++;
      }
    }

    return retList;
  }
Exemplo n.º 4
0
/*      */   public float getFloat(String name, float defaultValue)
/*      */   {
/*  984 */     String value = getString(name);
/*  985 */     if (value == null) {
/*  986 */       return defaultValue;
/*      */     }
/*  988 */     return PApplet.parseFloat(value, defaultValue);
/*      */   }
Exemplo n.º 5
0
 /**
  * Construct an FloatList from an iterable pile of objects. For instance, a float array, an array
  * of strings, who knows). Un-parseable or null values will be set to NaN.
  *
  * @nowebref
  */
 public FloatList(Iterable<Object> iter) {
   this(10);
   for (Object o : iter) {
     if (o == null) {
       append(Float.NaN);
     } else if (o instanceof Number) {
       append(((Number) o).floatValue());
     } else {
       append(PApplet.parseFloat(o.toString().trim()));
     }
   }
   crop();
 }
Exemplo n.º 6
0
  public FloatHash(PApplet parent, String filename) {
    String[] lines = parent.loadStrings(filename);
    keys = new String[lines.length];
    values = new float[lines.length];

    //    boolean csv = (lines[0].indexOf('\t') == -1);

    for (int i = 0; i < lines.length; i++) {
      //      String[] pieces = csv ? Table.splitLineCSV(lines[i]) : PApplet.split(lines[i], '\t');
      String[] pieces = PApplet.split(lines[i], '\t');
      if (pieces.length == 2) {
        keys[count] = pieces[0];
        values[count] = PApplet.parseFloat(pieces[1]);
        count++;
      }
    }
  }
Exemplo n.º 7
0
  /**
   * Construct an FloatList from a random pile of objects. Un-parseable or null values will be set
   * to NaN.
   */
  public FloatList(Object... items) {
    // nuts, no good way to pass missingValue to this fn (varargs must be last)
    final float missingValue = Float.NaN;

    count = items.length;
    data = new float[count];
    int index = 0;
    for (Object o : items) {
      float value = missingValue;
      if (o != null) {
        if (o instanceof Number) {
          value = ((Number) o).floatValue();
        } else {
          value = PApplet.parseFloat(o.toString().trim(), missingValue);
        }
      }
      data[index++] = value;
    }
  }
 public void draw() {
   lights();
   background(255);
   noStroke();
   fill(200);
   translate(-width / 2, 0);
   t += 0.001f;
   int offset = 10;
   float shapeSize = 5.0f;
   for (int i = 1; i < 10; i++) {
     // ellipse(noise(t+i*offset*0.01)*width, sin(float(frameCount + i*offset)/100)*height/2,
     // shapeSize*i, shapeSize*i);
     float x = noise(t + i * offset * 0.01f) * width;
     float y = sin(PApplet.parseFloat(frameCount + i * offset) / 100) * height / 2;
     pushMatrix();
     translate(x, y);
     sphere(shapeSize * i);
     popMatrix();
   }
 }
Exemplo n.º 9
0
 /** @param defaultValue the default value of the attribute */
 public float getFloatContent(float defaultValue) {
   return PApplet.parseFloat(node.getTextContent(), defaultValue);
 }
Exemplo n.º 10
0
  public void setup() {
    size(1200, 800, OPENGL);
    smooth();
    cam = new PeasyCam(this, 500);
    gfx = new ToxiclibsSupport(this);
    float range = maxX - minX;
    myHolder = new holder(this);
    dotTree = new dotTree(new Vec3D(minX, minY, minZ), range * 5, this);
    obsTree = new ObstacleTree(new Vec3D(minX, minY, minZ), range * 5, this);
    tTree = new terrainTree(new Vec3D(minX, minY, minZ), range * 5, this);

    PP = new ProgPoints(this);
    PP.readFile(dataPath(fName));

    ArrayList<Vec3D> importPts = new ArrayList<Vec3D>();
    File f = new File("");
    try {
      f = new File(dataPath(fNameDest));
    } catch (NullPointerException ex) {
      PApplet.println("File: " + " could not be found.");
    }
    String[] strLines = loadStrings(f.getAbsolutePath());

    for (int i = 0; i < strLines.length; i++) {
      String clean = strLines[i].substring(1, strLines[i].length() - 1);
      String[] splitToken = clean.split(", ");
      float xx = PApplet.parseFloat(splitToken[0]);
      float yy = PApplet.parseFloat(splitToken[1]);
      float zz = PApplet.parseFloat(splitToken[2]);
      Vec3D ptt = new Vec3D(xx, yy, zz);
      importPts.add(ptt);
    }

    for (int i = 0; i < importPts.size(); i++) {
      if (i < importPts.size() - 1) {
        start.add(importPts.get(i));
        end.add(importPts.get(i + 1));
      } else {
        start.add(importPts.get(i));
        end.add(importPts.get(0));
      }
    }

    aMesh =
        (TriangleMesh)
            new STLReader().loadBinary(dataPath("final_obs.stl"), STLReader.TRIANGLEMESH);

    allVertx.addAll(aMesh.getVertices());
    obsTree.addAll(allVertx);
    allVertx.clear();

    importMesh =
        (TriangleMesh)
            new STLReader().loadBinary(dataPath("final_srf.stl"), STLReader.TRIANGLEMESH);
    allVertx.addAll(importMesh.getVertices());
    tTree.addAll(allVertx);
    terrain = importMesh;
    moved = importMesh.getTranslated(new Vec3D(0, 0, 36));

    for (int i = 0; i < 150; i++) {
      int groupId = (int) (random(0, start.size()));
      float test = random(0, 1);
      myHolder.addAgent(new Agent(i, groupId, test, this));
    }
  }
Exemplo n.º 11
0
  public void draw() {
    background(0);
    // Strings composition
    textFont(createFont("Arial bold", 24));
    fill(c_red);
    stroke(255);
    text("OpenWheels GUI V1.0", 20, 30);
    textSize(16);
    // textAlign(CENTER);
    fill(c_azure);
    text("Acc_RAW:  " + Acc_RAW, 150, 65);
    AccSlider.setValue(Acc_RAW);
    text("Gyro_RAW: " + Gyro_RAW, 150, 90);
    GyroSlider.setValue(Gyro_RAW);
    text("Acc_Angle:  " + Acc_Angle + "\u00b0", 150, 115);
    text("Gyro_Rate: " + Gyro_Rate + "\u00b0/sec", 150, 140);
    text("Drive: " + Drive, 150, 165);
    text("Steer: " + Steer, 150, 190);
    text("BatLevel: " + nf(BatLevel, 1, 1) + "V", 150, 215);
    text("Status: " + statusFlag, 150, 240);
    graphGauge();
    graphGrid();

    // call the function that plot the angular of acc, with few screen settings
    graphRoll(PApplet.parseFloat(Acc_Angle), VideoBuffer2, c_red); // xPos, YPos, YSpan
    // call the function that plot the estimate angular, with few screen settings
    graphRoll(Angle, VideoBuffer1, c_yellow); // xPos, YPos, YSpan

    // call arduino for data every timePolling [msec]
    int timePolling = 50; // 50msec=20Hz
    time1 = millis();
    if (init_com == 1) {
      while (serial.available() > 0) processSerialData();
      if ((time1 - time2) > timePolling) {
        if (requestPID == true) {
          serial.write('E');
          requestPID = false;
        } else if (writePID == true) {
          int P = PApplet.parseInt(conf_KP.value());
          int I = PApplet.parseInt(conf_KI.value());
          int D = PApplet.parseInt(conf_KD.value());
          char data[] = {0, 0, 0, 0, 0};
          data[0] = 'W';
          data[1] = PApplet.parseChar(P);
          data[2] = PApplet.parseChar(I);
          data[3] = PApplet.parseChar(D);
          data[4] = ' ';
          String str = new String(data);
          serial.write(str);
          println(str);
          // println(" P=" + P + " I=" + I + " D=" + D);
          writePID = false;
        }
        // else if (RUN==true ) {serial.write('A');}
        else {
          serial.write('A');
        }
        time2 = time1;
      }
    }
  }
Exemplo n.º 12
0
  public void setup() {
    minim = new Minim(this);
    size(winWidth, winHeight, OPENGL);
    background(bGround);
    sm = new SceneManager(minim);
    rulesChecker = new RulesChecker();

    controlP5 = new ControlP5(this);
    // ruleChoiceList = controlP5.addDropdownList("ruleChoiceList",850,100,100,100);
    // customize(ruleChoiceList);
    selectedRule = 0;
    selectedCamera = 0;
    gl = ((PGraphicsOpenGL) g).gl;

    picker = new Picker(this);
    oscP5 = new OscP5(this, port);
    // TODO(sanjeet): Change the address
    interfaceAddr = new NetAddress("127.0.0.1", port);

    noStroke();
    lines = loadStrings("fileFriedrich.txt"); // Hardcoded input file name
    String[] tokens = split(lines[0], " ");
    if (tokens.length != 1) {
      println("Incorrect file format for number of cameras");
      return;
    }
    int numOfCams = PApplet.parseInt(tokens[0]);
    for (int i = 1; i < numOfCams + 1; i++) {

      tokens = split(lines[i], " ");
      float[] matrix = new float[16];
      for (int j = 0; j < tokens.length; j++) {
        matrix[j] = PApplet.parseFloat(tokens[j]);
      }

      cameras.add(new Cam(FloatBuffer.wrap(matrix))); // add all the cameras
    }

    tokens = split(lines[1 + numOfCams], " ");
    if (tokens.length != 1) {
      println("Incorrect file format for number of characters");
      return;
    }
    int numOfChars = PApplet.parseInt(tokens[0]);
    for (int i = 2 + numOfCams; i < lines.length; i++) {
      tokens = split(lines[i], " ");
      float[] matrix = new float[16];
      for (int j = 0; j < tokens.length; j++) {
        matrix[j] = PApplet.parseFloat(tokens[j]);
      }

      characters.add(new Character(FloatBuffer.wrap(matrix))); // add all the characters
    }

    characters.get(0).col = color(255, 255, 0);
    characters.get(1).col = color(255, 0, 255);

    timeline = new Timeline(sm);
    // add initial tick to the begining of the timeline
    timeline.addTick(cameras.get(0));

    debug = new Debug(controlP5);

    // title, start, end, initVal, xpos, ypos, width, height
    // controlP5.addSlider("Timeline", 0,120,0,100,winHeight-50,winWidth-200,30);

  }