public void draw(int[] pixels) {

    frameCount++;

    parent.println("draw!");

    String data = "";

    data += "task.animation.set(leds, 50, ";

    if (isLoggedIn) { // && serverIsReady){

      for (int i = 0; i < pixels.length; i++) {
        String value = Integer.toHexString(pixels[i]);
        value = value.substring(2, value.length());
        data += "#" + value + ",";
      }
      data = data.substring(0, data.length() - 1);
      data += ")\n";

      parent.println(data);
      lumoClient.write(data);

      serverIsReady = false;
    }
  }
Example #2
0
  /*
  	Perform Simulation
  */
  public void simulate(float dt) {
    // Accelerate angular speed
    float requiredSpeed = targetAngularSpeed - angularSpeed;
    float angularAccel = requiredSpeed / dt;
    angularAccel = PApplet.constrain(angularAccel, -maxAngularAccel, maxAngularAccel);

    // Limit Angular speed
    angularSpeed += angularAccel * dt;
    angularSpeed = PApplet.constrain(angularSpeed, -maxAngularSpeed, maxAngularSpeed);

    // Orientation Simulation
    orientation += angularSpeed * dt;

    // Position simulation
    PVector worldRequiredSpeed = targetSpeed.get();
    worldRequiredSpeed.rotate(orientation);
    worldRequiredSpeed.sub(speed);

    // PVector worldRequiredSpeed = worldTargetSpeed.get();
    float dSpeed = worldRequiredSpeed.mag();
    float dAcell = dSpeed / dt;
    float dForce = Math.min(dAcell * getMass(), motorForce);

    worldRequiredSpeed.normalize();
    worldRequiredSpeed.mult(dForce);
    force.add(worldRequiredSpeed);

    super.simulate(dt);
  }
  // \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;
  }
Example #4
0
 public void callOriginal() {
   camPos =
       new PVector(
           p.width * 0.5f, p.height * 0.5f, (p.height * 0.5f) / p.tan(p.PI * 30.0f / 180.0f));
   camCenter = new PVector(p.width * 0.5f, p.height * 0.5f, 0f);
   p.camera(camPos.x, camPos.y, camPos.z, camCenter.x, camCenter.y, camCenter.z, 0f, 1f, 0f);
 }
Example #5
0
  public void WRITE() {
    if (writeEnable == false) return;

    myPort.write("h");

    myPort.write(PApplet.parseInt(PitchP.value() * 100));
    myPort.write(PApplet.parseInt(RollP.value() * 100));
    myPort.write(PApplet.parseInt(YawP.value() * 100));

    myPort.write(PApplet.parseInt(PitchD.value() * 100));
    myPort.write(PApplet.parseInt(RollD.value() * 100));
    myPort.write(PApplet.parseInt(YawD.value() * 100));

    myPort.write(PApplet.parseInt(PitchPWR.value()));
    myPort.write(PApplet.parseInt(RollPWR.value()));
    myPort.write(PApplet.parseInt(YawPWR.value()));

    myPort.write(RCcontrol);
    myPort.write(YawRCon);

    myPort.write(PApplet.parseInt(RollCal.value() * 10 + 100));
    // println (RollCal.value());
    // println (int (RollCal.value()*10+100));

    readStatus = "Write OK";
  }
Example #6
0
  public void draw(PApplet canvas, float scale) {
    PVector orient = PVector.fromAngle(orientation);
    orient.mult(scale * getRadius());
    float x = (float) position.x * scale;
    float y = (float) position.y * scale;
    float diameter = getRadius() * 2 * scale;

    canvas.fill(teamColor);
    canvas.stroke(0);
    canvas.ellipse(x, y, diameter, diameter);
    canvas.line(x, y, x + (float) orient.x, y + (float) orient.y);

    // Delegate Decoration to Robot
    float heading = orient.heading();
    float drawScale = 100f / scale * getRadius();

    canvas.translate(x, y);
    canvas.rotate(heading);
    canvas.scale(drawScale);
    // TODO: How to resolve scale, so that teams don't have to mind it also...
    decorateRobot(canvas);
    canvas.scale(1f / drawScale);
    canvas.rotate(-heading);
    canvas.translate(-x, -y);
  }
Example #7
0
  /**
   * Constructor.
   *
   * @param inpParApp Parent PApplet.
   * @param inpResNbr Resolution of the sphere.
   * @param inpModelRadiusNbr Radius of the sphere.
   * @param inpExtDatFilePathTxt Path to an external data file for manipulating the sphere.
   */
  public Sphere(
      PApplet inpParApp, float inpResNbr, float inpModelRadiusNbr, String inpExtDatFilePathTxt) {
    _parApp = inpParApp;
    _resNbr = inpResNbr;
    _modelRadiusNbr = inpModelRadiusNbr;

    _latitudeLnCnt = (int) (180 / _resNbr);
    _longitudeLnCnt = (int) (360 / _resNbr);

    // The number of vertices is the number of longitudinal lines multiplied by the number of
    // latitudinal lines minus 1, plus 2 vertices for the poles.
    int vertexCnt = _longitudeLnCnt * (_latitudeLnCnt - 1) + 2;
    _latitudeDegs = new float[vertexCnt];
    _longitudeDegs = new float[vertexCnt];
    _radiusLenNbrs = new float[vertexCnt];

    // createVertices(0);
    crteVertices();

    FROM_CLR_NBR = _parApp.color(144, 29, 31);
    TO_CLR_NBR = _parApp.color(215, 180, 15);

    _loadFilePathTxt = inpExtDatFilePathTxt;

    loadExtData();
  }
Example #8
0
  public void initXMLObject() {

    numProfiles = xmlFeed.getChildCount();
    println("NUM PROFILES: " + numProfiles);
    for (int i = 0; i < numProfiles; i++) {
      XMLElement profile = xmlFeed.getChild(i);
      /// *
      try {
        headerList.add(profile.getChild(0).getContent());
        nameList.add(profile.getChild(1).getContent());
        blurbList.add(profile.getChild(2).getContent());
        // videoPathList.add(profile.getChild(3).getContent());
        thePopUp.videoPath.add(profile.getChild(3).getContent());
        latList.add(profile.getChild(4).getContent());
        longList.add(profile.getChild(5).getContent());

        pApp.println("Title= " + profile.getChild(0).getContent());
        pApp.println("Name= " + profile.getChild(1).getContent());
        pApp.println("Blurb= " + profile.getChild(2).getContent());
        // pApp.println("video = " +  profile.getChild(3).getContent());
        pApp.println("Address = " + profile.getChild(4).getContent());
        // pApp.println("long = " + profile.getChild(5).getContent());
        // pApp.println(" ");
        pApp.println(" ");
      } catch (Exception e) {
        println("XML init error: " + e);
      }
    }
    /// now that the popup video array has data, init the video
    thePopUp.initVideo();
    /// convert the lat and long string to floats
    initLocations();
  }
Example #9
0
  /**
   * Set the Quaternion from a (supposedly correct) 3x3 rotation matrix.
   *
   * <p>The matrix is expressed in European format: its three columns are the images by the rotation
   * of the three vectors of an orthogonal basis.
   *
   * <p>{@link #fromRotatedBasis(PVector, PVector, PVector)} sets a Quaternion from the three axis
   * of a rotated frame. It actually fills the three columns of a matrix with these rotated basis
   * vectors and calls this method.
   *
   * @param m the 3*3 matrix of float values
   */
  public final void fromRotationMatrix(float m[][]) {
    // Compute one plus the trace of the matrix
    float onePlusTrace = 1.0f + m[0][0] + m[1][1] + m[2][2];

    if (onePlusTrace > 1E-5f) {
      // Direct computation
      float s = PApplet.sqrt(onePlusTrace) * 2.0f;
      this.x = (m[2][1] - m[1][2]) / s;
      this.y = (m[0][2] - m[2][0]) / s;
      this.z = (m[1][0] - m[0][1]) / s;
      this.w = 0.25f * s;
    } else {
      // Computation depends on major diagonal term
      if ((m[0][0] > m[1][1]) & (m[0][0] > m[2][2])) {
        float s = PApplet.sqrt(1.0f + m[0][0] - m[1][1] - m[2][2]) * 2.0f;
        this.x = 0.25f * s;
        this.y = (m[0][1] + m[1][0]) / s;
        this.z = (m[0][2] + m[2][0]) / s;
        this.w = (m[1][2] - m[2][1]) / s;
      } else if (m[1][1] > m[2][2]) {
        float s = PApplet.sqrt(1.0f + m[1][1] - m[0][0] - m[2][2]) * 2.0f;
        this.x = (m[0][1] + m[1][0]) / s;
        this.y = 0.25f * s;
        this.z = (m[1][2] + m[2][1]) / s;
        this.w = (m[0][2] - m[2][0]) / s;
      } else {
        float s = PApplet.sqrt(1.0f + m[2][2] - m[0][0] - m[1][1]) * 2.0f;
        this.x = (m[0][2] + m[2][0]) / s;
        this.y = (m[1][2] + m[2][1]) / s;
        this.z = 0.25f * s;
        this.w = (m[0][1] - m[1][0]) / s;
      }
    }
    normalize();
  }
Example #10
0
  public void sendDataString(int addressH, int addressL, String data) {
    if (DEBUG) System.out.println("executing sendString");
    String cmdString = data;
    int[] myCommand = new int[2];
    myCommand[0] = TRANSMIT_REQUEST; // frame identifier
    myCommand[1] = 0x01; // frame type

    // break up the address and append the bytes of it:
    byte thisByte = 0;
    // get each byte from the 4-byte int:
    for (int b = 3; b > -1; b--) {
      thisByte = (byte) (addressH >> (8 * b));
      myCommand = parent.append(myCommand, thisByte);
    }
    // same for addressL:
    for (int b = 3; b > -1; b--) {
      thisByte = (byte) (addressL >> (8 * b));
      myCommand = parent.append(myCommand, thisByte);
    }
    // 16-bit address:
    myCommand = parent.append(myCommand, 0xFF);
    myCommand = parent.append(myCommand, 0xFE);

    myCommand = parent.append(myCommand, 0x00); // broadcast radius
    myCommand = parent.append(myCommand, 0x00); // options
    // append the cmdString to the array
    for (int i = 0; i < cmdString.length(); i++) {
      myCommand = parent.append(myCommand, (int) (cmdString.charAt(i)));
    }
    sendPacket(myCommand);
  }
 // A function to rotate a vector
 public void rotateVector(PVector v, float theta) {
   float m = v.mag();
   float a = v.heading2D();
   a += theta;
   v.x = m * PApplet.cos(a);
   v.y = m * PApplet.sin(a);
 }
Example #12
0
  public int[] getPacket(byte[] someFileArray) {
    boolean gotAPacket = false; // whether the first byte was 0x7E
    int packetLength = -1; // length of the dataArray
    int[] thisdataArray = null; // the dataArray to return
    int checksum = -1; // the checksum as received
    int localChecksum = -1; // the chacksum as we calculate it

    if (DEBUG) System.out.println("fileIndex: " + fileIndex);
    if (DEBUG) System.out.println("file length: " + fileArray.length);

    // make sure you have a 0x7E and at least three bytes
    if (getNextByte() == 0x7E && fileArray.length > 2) {
      gotAPacket = true;
    }

    // if the header byte is good, try the rest:
    if (gotAPacket) {
      // read two bytes
      if (bytesAvailable() >= 2) {
        int lengthMSB = getNextByte(); // high byte for length of packet
        int lengthLSB = getNextByte(); // low byte for length of packet

        // convert to length value
        packetLength = (lengthLSB + (lengthMSB << 8));
        if (DEBUG) System.out.println("length: " + packetLength);
      }
      // read bytes until you've reached the length
      if (bytesAvailable() >= packetLength && packetLength > 0) {
        // make an array to hold the data frame:
        thisdataArray = new int[packetLength];

        // read all the bytes except the last one into the dataArray array:
        for (int thisByte = 0; thisByte < packetLength; thisByte++) {
          thisdataArray[thisByte] = getNextByte();
          if (DEBUG) System.out.print(parent.hex(thisdataArray[thisByte], 2) + " ");
        }

        if (bytesAvailable() >= 1) {
          // get the checksum:
          checksum = getNextByte();
        }
        // calculate the checksum of the received dataArray:

        localChecksum = checkSum(thisdataArray);
        // if they're not the same, we have bad data:
        if (localChecksum != checksum) {
          if (DEBUG) System.out.println("bad checksum. Local: " + parent.hex(localChecksum % 256));
          if (DEBUG) System.out.println("  remote: " + parent.hex(checksum));
          // if the checksums don't add up, clear the dataArray array:
          thisdataArray = null;
        }
      }
    }
    // makes a nice printing for debugging:
    if (DEBUG) System.out.println();

    // return the data frame.  If it's null, you got a bad packet.
    return thisdataArray;
  }
 public static void main(String[] passedArgs) {
   String[] appletArgs = new String[] {"crop_graphics_tri_large"};
   if (passedArgs != null) {
     PApplet.main(concat(appletArgs, passedArgs));
   } else {
     PApplet.main(appletArgs);
   }
 }
Example #14
0
 public void registerEvents() {
   //		p.registerMouseEvent(this);
   //		p.registerKeyEvent(this);
   p.registerMethod("mouseEvent", this);
   p.registerMethod("keyEvent", this);
   p.addMouseWheelListener(this);
   callOriginal();
 }
Example #15
0
 public static void main(String[] passedArgs) {
   String[] appletArgs = new String[] {"EvvGC_GUI_v0_4"};
   if (passedArgs != null) {
     PApplet.main(concat(appletArgs, passedArgs));
   } else {
     PApplet.main(appletArgs);
   }
 }
 public static void main(String[] passedArgs) {
   String[] appletArgs = new String[] {"shapes_shapes"};
   if (passedArgs != null) {
     PApplet.main(concat(appletArgs, passedArgs));
   } else {
     PApplet.main(appletArgs);
   }
 }
Example #17
0
 public static void main(String[] passedArgs) {
   String[] appletArgs = new String[] {"getDataFromXively"};
   if (passedArgs != null) {
     PApplet.main(concat(appletArgs, passedArgs));
   } else {
     PApplet.main(appletArgs);
   }
 }
 public static void main(String[] passedArgs) {
   String[] appletArgs = new String[] {"GoogleBillboard"};
   if (passedArgs != null) {
     PApplet.main(concat(appletArgs, passedArgs));
   } else {
     PApplet.main(appletArgs);
   }
 }
Example #19
0
 protected static String getBasePath(PApplet parent, String filename) {
   // Obtaining the path
   File file = new File(parent.dataPath(filename));
   if (!file.exists()) {
     file = parent.sketchFile(filename);
   }
   String absolutePath = file.getAbsolutePath();
   return absolutePath.substring(0, absolutePath.lastIndexOf(File.separator));
 }
Example #20
0
  /**
   * Returns the exponential of the Quaternion.
   *
   * @see #log()
   */
  public final Quaternion exp() {
    float theta = PApplet.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);

    if (theta < 1E-6f) return new Quaternion(this.x, this.y, this.z, PApplet.cos(theta));
    else {
      float coef = PApplet.sin(theta) / theta;
      return new Quaternion(this.x * coef, this.y * coef, this.z * coef, PApplet.cos(theta));
    }
  }
    public void avoid(ArrayList obstacles) {

      // Make a vector that will be the position of the object
      // relative to the Boid rotated in the direction of boid's velocity
      PVector closestRotated = new PVector(sight + 1, sight + 1);
      float closestDistance = 99999;
      Obstacle avoid = null;

      // Let's look at each obstacle
      for (int i = 0; i < obstacles.size(); i++) {
        Obstacle o = (Obstacle) obstacles.get(i);

        float d = PVector.dist(loc, o.loc);
        PVector dir = vel.get();
        dir.normalize();
        PVector diff = PVector.sub(o.loc, loc);

        // Now we use the dot product to rotate the vector that points from boid to obstacle
        // Velocity is the new x-axis
        PVector rotated = new PVector(diff.dot(dir), diff.dot(getNormal(dir)));

        // Is the obstacle in our path?
        if (PApplet.abs(rotated.y) < (o.radius + r)) {
          // Is it the closest obstacle?
          if ((rotated.x > 0) && (rotated.x < closestRotated.x)) {
            closestRotated = rotated;
            avoid = o;
          }
        }
      }

      // Can we actually see the closest one?
      if (PApplet.abs(closestRotated.x) < sight) {

        // The desired vector should point away from the obstacle
        // The closer to the obstacle, the more it should steer
        PVector desired =
            new PVector(closestRotated.x, -closestRotated.y * sight / closestRotated.x);
        desired.normalize();
        desired.mult(closestDistance);
        desired.limit(maxspeed);
        // Rotate back to the regular coordinate system
        rotateVector(desired, vel.heading2D());

        // Draw some debugging stuff
        if (debug) {
          stroke(0);
          line(loc.x, loc.y, loc.x + desired.x * 10, loc.y + desired.y * 10);
          avoid.highlight(true);
        }

        // Apply Reynolds steering rules
        desired.sub(vel);
        desired.limit(maxforce);
        acc.add(desired);
      }
    }
Example #22
0
 public static void main(String[] passedArgs) {
   String[] appletArgs =
       new String[] {"--full-screen", "--bgcolor=#666666", "--hide-stop", "build"};
   if (passedArgs != null) {
     PApplet.main(concat(appletArgs, passedArgs));
   } else {
     PApplet.main(appletArgs);
   }
 }
Example #23
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();
  }
Example #24
0
  public InteractModel setupDisplay() {
    parent.noStroke(); // NoStroke para que muestre el material

    // parent.stroke(255,0,0);
    // parent.strokeWeight(1);
    parent.rotateX(PApplet.radians(90));
    parent.rotateY(PApplet.radians(180));

    return this;
  }
Example #25
0
  /**
   * Returns the logarithm of the Quaternion.
   *
   * @see #exp()
   */
  public final Quaternion log() {
    // Warning: this method should not normalize the Quaternion
    float len = PApplet.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);

    if (len < 1E-6f) return new Quaternion(this.x, this.y, this.z, 0.0f, false);
    else {
      float coef = PApplet.acos(this.w) / len;
      return new Quaternion(this.x * coef, this.y * coef, this.z * coef, 0.0f, false);
    }
  }
Example #26
0
    public void addPlant(int type, int mouseX, int mouseY) {
      if (mouseX <= left || mouseX >= right || mouseY <= top || mouseY >= bottom) return;
      println(mouseX, mouseY);
      int colIndex = floor((mouseX - left) / wSpacing);
      int rowIndex = floor((mouseY - top) / hSpacing);

      int x = PApplet.parseInt(left + colIndex * wSpacing);
      int y = PApplet.parseInt(top + rowIndex * hSpacing);
      if (plants[colIndex][rowIndex] == null) plants[colIndex][rowIndex] = new Plant(type, x, y);
    }
Example #27
0
  public Display(PApplet p, int x, int y, int w, int h) {
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    this.p = p;

    piece1 = p.loadImage("images/red_ball.png");
    piece2 = p.loadImage("images/blue_ball.png");
  }
 public static void main(String[] passedArgs) {
   String[] appletArgs =
       new String[] {
         "--full-screen", "--bgcolor=#666666", "--stop-color=#cccccc", "fruitloop_processing"
       };
   if (passedArgs != null) {
     PApplet.main(concat(appletArgs, passedArgs));
   } else {
     PApplet.main(appletArgs);
   }
 }
 public DisplayFrame() {
   this.setSize(1000, 800); // The window Dimensions
   setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
   javax.swing.JPanel panel = new javax.swing.JPanel();
   panel.setBounds(20, 20, 1000, 800);
   PApplet sketch = new CTCOffice();
   panel.add(sketch);
   this.add(panel);
   sketch.init(); // this is the function used to start the execution of the sketch
   this.setVisible(true);
   this.setTitle("Breathless Bovine: CTC Office         by Jake Lyons");
 }
Example #30
0
 private Method findCallback(final String name) {
   try {
     return parent.getClass().getMethod(name, this.getClass());
   } catch (Exception e) {
   }
   // Permit callback(Object) as alternative to callback(Serial).
   try {
     return parent.getClass().getMethod(name, Object.class);
   } catch (Exception e) {
   }
   return null;
 }