Movement traces

edited October 2015 in Arduino

Hello everybody,

any suggestions how I could merge my code below (movement tracing through for now a simple box) with e.g. this (http://studio.processingtogether.com/sp/pad/export/ro.9ldYvJUyiXGzi/latest) sketchpad code in which the trace fades slowly. I getting actual sensor data and am not using the mouse. I am trying to make the movement interpretation 'feel' more natural.

All suggestions or hints are super welcome Thank you already!!

import processing.serial.*;

Serial myPort;
int linefeed = 10; // Linefeed in ASCII int numSensors = 3; // we will be expecting for reading data from 3 sensors float sensors[]; // array to read the 3 values float pSensors[];

void setup() { size(1350, 800, P3D);
// List all the available serial ports in the output pane. // You will need to choose the port that the Wiring board is // connected to from this list. The first port in the list is // port #0 and the third port in the list is port #2. println(Serial.list());

myPort = new Serial(this, Serial.list()[2], 115200); // read bytes into a buffer until you get a linefeed (ASCII 10): myPort.bufferUntil(linefeed);

}

void draw() { if((pSensors != null)&&(sensors != null)) {

// now do something with the values read sensors[0] .. sensors[2]
 //First I find all my rotation angles in radians so that center screen is (0,0)

float rotx = (sensors[0]*PI)/180;
float roty = (sensors[1]*PI)/180;
float rotz = (sensors[2]*PI)/180;
//float roty = 0;

background(0);
stroke(0, 0, 200);
//line (0,20,420,20); // monitor bar
fill(255);
textSize(1);
text (" rotateX(" + rotx +" pi)"+" , rotateY("+roty+" pi)"+" , rotateZ("+rotz+" pi)", 0,10);
fill(0, 0, 200);

translate(610, 380, 0); // center drawing start point in screen  180 TO 380

strokeWeight(1);
stroke(50);

line(-60, 0, 60, 0);       //
line(0, 60, 0, -60);       // draw stationary axis lines
line(0, 0, -60, 0, 0, 60); //
strokeWeight(0); // PPP: STROKEWEIGHT VON 1 NACH 0
stroke(0, 150, 0);
noFill();
box(40);                  // draw stationary box


rotateX(rotx);  //
rotateY(roty);  // rotate drawing coordinates according to user input variables
rotateZ(rotz);  //
strokeWeight(0);
stroke(255);
line(10, 0, 10, 0);       //PPPP ALL PLACES WITH 50 USED TO BE 150
line(0, 10, 0, -10);       // draw the rotating axis lines
line(0, 0, -10, 0, 0, 10); //
strokeWeight(4);
stroke(57, 255, 20);
noFill();
box(100,60,350); // draw rotating red box PPPPP: CHANGED FROM 140!!!

} }

void serialEvent(Serial myPort) {

// read the serial buffer:2 String myString = myPort.readStringUntil(linefeed);

// if you got any bytes other than the linefeed: if (myString != null) {

myString = trim(myString);

// split the string at the commas
// and convert the sections into integers:

pSensors = sensors;
sensors = float(split(myString, ','));

// print out the values you got:

for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
  print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
}

// add a linefeed after all the sensor values are printed:
println();

} }

Answers

  • Second trial (Thank you GoToLoop)

    Hello everybody,

    I am trying to make the sensor movement interpretation/visualization 'feel' more natural. One idea I had was to show traces of the movement of the moving object - traces. Maybe something like this : http://studio.processingtogether.com/sp/pad/export/ro.9ldYvJUyiXGzi/latest .

    But I have no idea how to merge my code (below) with this sketchpad code. Any other ideas on visualisations (colors, shaders, etc) are also much much appreciated.

    Thank you and excuse my prior imprecision!

    // 
    import processing.serial.*;
    Serial myPort;
    int linefeed = 10; // Linefeed in ASCII int numSensors = 3; // we will be expecting for reading data from 3 sensors float sensors[]; // array to read the 3 values float pSensors[];
    
    void setup() { size(1350, 800, P3D);
    // List all the available serial ports in the output pane. // You will need to choose the port that the Wiring board is // connected to from this list. The first port in the list is // port #0 and the third port in the list is port #2. println(Serial.list());
    
    myPort = new Serial(this, Serial.list()[2], 115200); // read bytes into a buffer until you get a linefeed (ASCII 10): myPort.bufferUntil(linefeed);
    
    }
    
    void draw() { if((pSensors != null)&&(sensors != null)) {   
    // now do something with the values read sensors[0] .. sensors[2]
     //First I find all my rotation angles in radians so that center screen is (0,0)
     
    float rotx = (sensors[0]*PI)/180;
    float roty = (sensors[1]*PI)/180;
    float rotz = (sensors[2]*PI)/180;
    //float roty = 0;
     
    background(0);
    stroke(0, 0, 200);
    //line (0,20,420,20); // monitor bar
    fill(255);
    textSize(1);
    text (" rotateX(" + rotx +" pi)"+" , rotateY("+roty+" pi)"+" , rotateZ("+rotz+" pi)", 0,10);
    fill(0, 0, 200);
     
    translate(610, 380, 0); // center drawing start point in screen  180 TO 380
     
    strokeWeight(1);
    stroke(50);
     
    line(-60, 0, 60, 0);       //
    line(0, 60, 0, -60);       // draw stationary axis lines
    line(0, 0, -60, 0, 0, 60); //
    strokeWeight(0); // PPP: STROKEWEIGHT VON 1 NACH 0
    stroke(0, 150, 0);
    noFill();
    box(40);                  // draw stationary box
     
     
    rotateX(rotx);  //
    rotateY(roty);  // rotate drawing coordinates according to user input variables
    rotateZ(rotz);  //
    strokeWeight(0);
    stroke(255);
    line(10, 0, 10, 0);       //PPPP ALL PLACES WITH 50 USED TO BE 150
    line(0, 10, 0, -10);       // draw the rotating axis lines
    line(0, 0, -10, 0, 0, 10); //
    strokeWeight(4);
    stroke(57, 255, 20);
    noFill();
    box(100,60,350); // draw rotating red box PPPPP: CHANGED FROM 140!!!
    
    } }
    
    void serialEvent(Serial myPort) {
    
    // read the serial buffer:2 String myString = myPort.readStringUntil(linefeed);
    
    // if you got any bytes other than the linefeed: if (myString != null) {
    
    myString = trim(myString);
     
    // split the string at the commas
    // and convert the sections into integers:
     
    pSensors = sensors;
    sensors = float(split(myString, ','));
     
    // print out the values you got:
     
    for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
      print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
    }
     
    // add a linefeed after all the sensor values are printed:
    println();
    
    } }
    
  • Anybody? Please! Really looking for pointers. Any hins towards any other way would also be great Thank you p

Sign In or Register to comment.