Assignment: Sensing PART II: Force sensors and photocells
Collaborators:
Assignment: Sensing PART II: Force sensors and photocells
Collaborators: Tilman, David
Description
TouchMarine is an application that visualizes force sensor input data. The more pressure is being put on the sensor the bigger the submarine's uplift gets. We tried to model the physics in a way that the submarine is being pulled down by its own weight in case no pressure is on the sensor. On the other hand, the submarine can be accelerated in a way that makes it jump out of the water.
Components Used
Source Code
package touchmarine;
import processing.core.*;
import processing.serial.*;
import java.awt.*;
/**
* Arduino TouchMarine
* @author Tilman, David
* {@link} http://courses.ischool.berkeley.edu/i290-4/f08/?q=node/159
* ----------------------
*
* Using FSR in order to control the uplift of a submarine
*
* Receives an ASCII number over the serial port,
* terminated with a carriage return (ascii 13) then newline (10).
*
*
* Created 28 September 2008
*/
public class TouchMarine extends PApplet {
String portname = "/dev/tty.usbserial-A7006x0V";
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
PImage bgimage;
PImage subImage;
int uplift;
int posX;
int posY;
public void setup() {
bgimage = loadImage("/Users/Til/Documents/workspace/TUI/images/background.jpg");
subImage = loadImage("/Users/Til/Documents/workspace/TUI/images/sub.gif");
size(bgimage.width,bgimage.height);
background(bgimage);
frameRate(40);
smooth();
noStroke();
println("**Initializing.. (Screen: " + width + "x" + height + ")");
uplift = 0;
posX = (width/2) - (subImage.width/2);
posY = height-100;
port = new Serial(this, portname, 9600);
drawSub(posX,posY);
}
public void draw() {
}
public void keyPressed() {
}
// draw submarine
public void drawSub(int x, int y) {
println("+Drawing sub [" + x + "," + y + "]");
background(bgimage);
image(subImage, x, y);
}
// called whenever serial data arrives
public void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += PApplet.parseChar(c);
}
if (c == lf) {
int val = PApplet.parseInt(buf);
println("val = " + val + "(Math.log: " + Math.log(val) + ")");
if(val > 0) {
uplift += Math.log(val);
}
else
uplift -= 1;
println("Uplift: " + uplift);
if((posY - uplift) >= (height - subImage.height)) { //case: submarine reaches the bottom
//TODO: event in case ball drops out of frame
posY = height - subImage.height;
uplift = 0;
}
else if ((posY - uplift)<=0) { //case: submarine reaches the top
posY = 0;
uplift -= 15;
}
else if((posY - uplift) <= (150)) { //case: submarine jumps out of the water
uplift -= 14;
posY -= uplift;
}
else
posY -= uplift;
drawSub(posX,posY);
buf = "";
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "TouchMarine" });
}
}
We experimented with a couple of force diffuser implementations. So here are the top 3:
A ball diffuser, just sit and squeeze:
The shoe diffuser, just step and squeeze:
The bottle diffuser, just squeeze and squeeze: