Hi, I'm newbie for Arduino micro controller. I need to do the mapping use 3D to show the mapping display. I use the ultrasonic as a sensor. The sensor is working in Arduino serial monitor.
I try to use the Arduino website provide the source code to implement the graph method, it is working.
I try again to use the processing to get the 3D output display. I try many times also cannot get the result.
Below is my 3D Scan Data Visualization source code.
Thanks a lot.
I try to use the Arduino website provide the source code to implement the graph method, it is working.
I try again to use the processing to get the 3D output display. I try many times also cannot get the result.
Below is my 3D Scan Data Visualization source code.
- import processing.serial.*;
Serial myPort; // The serial port
//int xPos = 1; // horizontal position of the graph
int x, y, z; // variable to store x and y co-ordinates for vertices
int value = 0; // value from sensor
int[][][] data = new int[181][61][1]; // create an array to store each new sensor value for each servo position
int count;
int average = 1;
int numberOfSegments = 179;
PFont myFont; // setup fonts in Processing
createArc Arc; // create an instance of the Arc class
float radius = 150;
float angle = 0;
void setup () // set the window size:
{
size(640, 360, P3D );
Arc = new createArc(); // assign the Arc classes to an object
myFont = createFont("verdana", 12);
textFont(myFont);
println(Serial.list());// List all the available serial ports
myPort = new Serial(this, "COM3", 9600); // don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
background(0); // set inital background:
}
/*void draw () {
// everything happens in the serialEvent()
}
*/
void draw()
{
background(255);
float tempX = 0, tempY = 1, tempZ = 0;
fill(200);
lights();
translate(width/2, 200, 110);
angle = 180.0 / numberOfSegments;
rotateY(count * PI/10800);
for (int j = 0; j < numberOfSegments; j++)
{
tempZ = cos(radians(angle))*radius;
tempX = sin(radians(angle))*radius;
pushMatrix();
translate(tempX, tempY, tempZ); // move each instance we create of the arc object to a slightly new position and rotation
rotateY(radians(angle));
Arc.create(j);
popMatrix();
angle += 180.0/numberOfSegments;
}
}
// creates an arc object using QUAD_STRIP
class createArc {
// pass values to create method to know which array to load 1 to 180...
void create(int degree){
pushMatrix();
rotateY(radians(135));
beginShape(QUAD_STRIP);
for(int a=60; a < 120;a++) {
float x1 = cos(radians(((90+a))))*(data[degree][a-60][0]/average);
float y1 = sin(radians(((90+a))))*(data[degree][a-60][0]/average);
float x2 = cos(radians(((90+a))))*(data[degree+1][a-60][0]/average);
float y2 = sin(radians(((90+a))))*(data[degree+1][a-60][0]/average);
vertex(x1,y1,100);
vertex(x2,y2,105);
}
endShape();
popMatrix();
}
void serialEvent (Serial myPort) // get the ASCII string:
{
String xString = myPort.readStringUntil('\n');
if (xString != null)
{
xString = trim(xString); // trim off any whitespace:
String getY = xString.substring(1, xString.indexOf("X")); // get the value of the servo position
String getX = xString.substring(xString.indexOf("X")+1, xString.indexOf("Z")); // get the value of the sensor reading
String getZ = xString.substring(xString.indexOf("Z")+1, xString.length()); // get the value of the sensor reading
x = Integer.parseInt(getX); // set the values to variables
y = Integer.parseInt(getY);
z = Integer.parseInt(getZ);
data[x][y][0] += z;
//println(z); // for debugging
count++;
if (count < 10800)
{
count = 0;
average++;
}
}
}
}
Thanks a lot.
1