Automaton: Physical Physics Simulation

photo(2)

The Physical Physics Simulation is a miniature mechanical self contained universe that consists of one body and three universal constants (gravity, friction, and elasticity).

The machine was inspried by events that live inside boxes, cabinets of curiosity, and the orrery, which is essentially a solar system simulation.

Screen Shot 2014-11-10 at 4.34.17 PM

// simple physics for physical physics simulation
// by luca and zach

#include 

Servo servoX;
Servo servoY;

// position
float px = 180;
float py = 0;

// velocity
float vx = 8;
float vy = 0;

float g = 800 * 0.001f; // gravitational constant
float f = 0.9f;         // friction constant
float e = 0.98f;        // elasticity constant

float tickTime = 105; // how often to update? 

void setup()
{
  servoX.attach(10);
  servoY.attach(11);
}

void loop()
{
  // add gravity to y veloctity (ball falling)
  vy += g;
  
  // update position
  px += vx;
  py += vy;
  
  // save old positions
  float ppx = px;
  float ppy = py;
  
  // collision with walls
  if(px < 0 || px > 180) {
    px = ppx;
    vx = -vx*e;
  }
  if(py < 0 || py > 180) {
    py = ppy;
    vy = -vy*e;
  }
  
  // friction (ball on floor)
  if(py < 2) {
    vx = vx * f;
  }
  
  // bounds
  float agpx;
  float agpy;
  agpx = map(px, 0, 180, 35, 150);
  agpy = map(py, 0, 180, 25, 165);
  
  //move servos
  servoX.write(agpx);
  delay(tickTime);
  servoY.write(agpy);
  delay(tickTime);
  
}

Comments are closed.