Monday, April 20, 2015

Data Visualization Labs

Part 1
https://docs.google.com/a/stern.nyu.edu/file/d/0B2SeRUgxADHINk9GcDBIanE5Wjg/edit
We used a line graph to show how many times the word Amos showed up in books over time.

Part 2
https://docs.google.com/a/stern.nyu.edu/file/d/0B2SeRUgxADHISFR5ZVpsVTducEE/edit
Comparing spending per day between two months.

Part 3
https://docs.google.com/a/stern.nyu.edu/file/d/0B2SeRUgxADHINEVLQXBJakNzOW8/edit
Realtime updating chart of the length of articles on wikipedia.

Mechatronic Project

For this project Me, Zach, and Kevin built a ballista style catapult.

Here is a picture of the setup workspace
https://drive.google.com/file/d/0B8ZGdT5f3eJkRklSTHRwR240ZXc/view?usp=sharing

Here is a video of the catapult in action
https://drive.google.com/file/d/0B8ZGdT5f3eJkUkRJTFhqZm1ndms/view?usp=sharing

----------------------------------------------------------------

The two types of machines we used here were
A DC motor used to wind up a "chain" that pulled the loaded chamber back.
This machine uses a circular motion to build up potential energy in the rubber bands holding the loaded chamber

A Servo Motor that acted as switch to release the chain holding the chamber to fire the catapult.
This was a conversion of rotational energy into a much larger amount of energy built up in the rubber bands.
By using a small force to release a built up larger force, this machine acted similarly to how transistors work.

Miscalculations and Problems
-------------------------------------
This particular project had more problems than any previous project.
First, building a steady structure for the ballista was near impossible given the funds available.
The structure was built out of chopsticks and tape.

Second, the DC motor had no textured surface attached to the spinning pin. As such it was difficult to get a chain to rotate with the motor pin.
This was resolved with thread, needles, a cut rubberband, and super glue.

Third, the rubberbands really didn't hold enough power to launch our projectiles very far.
Rather, the structure wasn't built long enough to pull the chamber back far enough.
However, given the weak rotational power of the DC motor, it was impossible to make the structure any longer.

Given these problems, this catapult is more a proof of concept to show that the design works.
It isn't ready to be mass-produced and marketed as a weapon of damage.

Wednesday, April 15, 2015

Pong Assignment

Here's a video explaining what I did

https://drive.google.com/file/d/0B8ZGdT5f3eJkZG5CaGktZnVlRjg/view?usp=sharing

ARDUINO CODE
/////////////////////////////////////////
const int potPin1 = A0;
const int potPin2 = A5;

const int button1=3;
const int button2=5;

void setup() {
 Serial.begin(9600);
}
void loop() {
 int potVal1 = analogRead(potPin1);
 potVal1 = map(potVal1,0,1023,0,127);
 int potVal2 = analogRead(potPin2);
 potVal2 = map(potVal2,0,1023,0,127);

 int buttonVal1 = digitalRead(button1);
 int buttonVal2 = digitalRead(button2);


 Serial.write(buttonVal1);
 delay(10);
 Serial.write(buttonVal2);
 delay(10);
 Serial.write(potVal1);
 delay(10);
 Serial.write(potVal2);
 delay(50);
}
////////////////////////////////////////////

PONG GAME CODE(I didn't take any code from any online sources, everything was written by me)
/////////////////////////////////////////////
import processing.serial.*;
Serial arduinoPort;

//Input Variables
int buttonVal1; // 0 or 1
int buttonVal2;
int potVal1; // 0 to 127(max byte)
int potVal2;

//Screen vars
int scrnW = 800;
int scrnH = 550;

//ball variables
static float bRad = 30;
float bPosX=0;
float bPosY=0;
float bVelX=0;
float bVelY=0;

//paddle variables
float pWidth = bRad;
float pHeight = 6*bRad;
float pPosX=0;
float pPosY=0;
float pVel=8;

void setup(){
  size(scrnW,scrnH);
  bPosX=width/2;
  bPosY=height/2;
 
  println(Serial.list());
  String portName = Serial.list()[0];
  arduinoPort = new Serial(this,portName,9600);
}

void draw(){
  byte [] inputBuffer = new byte[7];
  while(arduinoPort.available()>3){
    inputBuffer = arduinoPort.readBytes();
    arduinoPort.readBytes(inputBuffer);
    if(inputBuffer!=null){
      String myString = new String(inputBuffer);
      buttonVal1 = inputBuffer[0];
      buttonVal2 = inputBuffer[1];
      potVal1 = inputBuffer[2];
      potVal2 = inputBuffer[3];
     
      //println(buttonVal1 + " "+buttonVal2 + " " + potVal1+" "+potVal2);
    }
  }
 
 
 
  //UPDATE PHYSICS
  Update();
 
  //DRAW
  background(255,255,0);
 
  //draw paddle
  fill(0,0,255);
  rect(pPosX,pPosY,pWidth,pHeight,7);
 
  //draw ball
  fill(255,0,0);
  ellipse(bPosX,bPosY, bRad*2, bRad*2);
 
}


//bound of paddle
//0 to height-pHeight/2;
void Update(){
  //move paddle
  if(buttonVal1==1){
    pPosY+=pVel;
    if(pPosY>height-pHeight){pPosY=height-pHeight;}
  }
  if(buttonVal2==1){
    pPosY-=pVel;
    if(pPosY<0){pPosY=0;}
  }
 
  //update Ball Velocity
  float acellX = map(potVal1,6,127,1,-1);
  float acellY = map(potVal2,6,127,-1,1);
  bVelX+=acellX;
  bVelY+=acellY;
  if(bVelX>pVel){bVelX=pVel;}
  if(bVelX<-pVel){bVelX=-pVel;}
  if(bVelY>pVel){bVelY=pVel;}
  if(bVelY<-pVel){bVelY=-pVel;}
 
  //update Ball position
  bPosX+=bVelX;
  bPosY+=bVelY;
 
  //Process ball borders
  ballBorders();
 
  //Process ball-Paddle Collision
  paddleCollision();
}

void ballBorders(){
  float top = bPosY+bRad;
  float bot = bPosY-bRad;
  float left = bPosX-bRad;
  float right = bPosX+bRad;
 
  if(top>height){
    bPosY=height-bRad;
    bVelY*=-1;
  }
  if(bot<0){
    bPosY=0+bRad;
    bVelY*=-1;
  }
  if(right>width){
    bPosX=width-bRad;
    bVelX*=-1;
  }
  if(left<0){
    bPosX=bRad;
    bVelX*=-1;
    println("LOSE");
  }
 
}

void paddleCollision(){
  //find out if there is collision.
  boolean tf = isPaddleCollision();
  //if there is,
  if(tf){
    bVelX*=-1;
    bPosX=bRad+pWidth;
  }
}

boolean isPaddleCollision(){
  float topB = bPosY+bRad;
  float botB = bPosY-bRad;
  float leftB = bPosX-bRad;
  float rightB = bPosX+bRad;
 
  float topP = pPosY+pHeight;
  float botP = pPosY;
  float leftP = pPosX;
  float rightP = pPosX+pWidth;
 
  if(topB<botP) {
    println(1);
    return false;
  }
 
  if(botB>topP){
    println(2);
   return false;
  }
  if(rightB<leftP){
    println(3);
    return false;
  }
  if(leftB>rightP){
    println(4);
    return false;
  }
  println("COLLISION");
  return true;
 
 
}

/////////////////////////////////////////////

Monday, April 13, 2015

Motor Labs!

Part 1:
Moving servo motor using Processing
https://drive.google.com/file/d/0B2gmbe_Oq0vNeVRUNmcydTZ0aE0/view?usp=sharing

Part 2
Changing motor speed using potentiometer
Mapped the potentiometer input from 0-1023 to 0-255
Then I sent that mapped value to the transistor.

https://drive.google.com/file/d/0B2gmbe_Oq0vNdFJnTHhodDhqNVE/view?usp=sharing

Part 3
Moving motor speed with processing.
Using identical code in processing from part 1.
I modified the code in arduino from part 2 to read input from processing.
Since the processing input was already from 0 to 255, i directly used analogWrite() to pass in that value to the motor.

https://drive.google.com/file/d/0B2gmbe_Oq0vNZFB1bEZwamNTV28/view?usp=sharing

Thursday, April 2, 2015

Midterm Project (Delayed to Monday)

As stated in the last blog post, this project will use a 3-Space Sensor, accelerometer, gyroscope, and magnetometer to sense the movement, position, and orientation of a toy bunny.

The bunny acts as a remote control to play a game developed via Unity.

The game can be seen here:
https://drive.google.com/file/d/0B8ZGdT5f3eJkc0Joa25RQnpIQ1U/view?usp=sharing


Unfortunately due to the explosion on 2nd Avenue and 7th, we lost access to the sensor and our equipment for a duration of time. 

Furthermore, the sensor had not been working properly due to poor connection and failed to work using multiple code samples, blue tooth connection, and serial communication.

We decided to order another sensor, with various other parts.

They will arrive on Friday and given the weekend, this project should be completed and ready for demonstration by Monday.