Lab 4 :: Posture Alert

Submitted by ajeeta on Tue, 02/26/2013 - 08:29
ajeeta's picture

Description

For this assignment, I've used an FSR with Arduino and Processing to create a mechanism that displays a visualization of a user's posture, and prompts him to sit up straight when his posture slouches. 

The FSR is to be mounted on the back rest of the user's chair, between two sponges, for comfort and for even force distribution.

While the user sits up straight and exerts force against the FSR, the screen displays an illustration of a person sitting up straight. When the user hunches forward and loses touch with the FSR, no force is detected, and the illustration changes to that of a person hunching forward.

My code is adapted from the stock code provided in class, and the sample code here. I created the illustration in Adobe Illustrator, used 'PShape' and 'loadShape' to load the exported .svg file in Processing, and used the 'getChild' method of the 'PShape' class to access individual vector shapes for animation.

 

Components

1 Arduino-Uno

1 10k Resistor

1 Force Sensing Resistor (FSR)

Wires and USB cable

Software: Processing

 

Arduino Code

(To send serial communication from Arduino via the serial port, and to test the FSR circuit with LED output. LED blinking rate increases porportionately with the force read from the FSR).

int FSR = 0;  

int fsrVal = 0;   

int LEDPin = 13;  
 
void setup() {
  pinMode(LEDPin, OUTPUT);  
  Serial.begin(9600);
}
 
void loop() {
  fsrVal = analogRead(FSR)/4; 
  Serial.println(fsrVal);
  analogWrite(LEDPin, fsrVal); 
  delay(fsrVal);  
  digitalWrite(LEDPin, 0);  
  delay(fsrVal);  
}
 
 
Processing Code
 
import processing.serial.*;
String portname = "/dev/tty.usbmodemfd121"; // or "COM5"
Serial port;
 
PShape scene;
PShape object0;
PShape object45;
 
float oldInput = 0;
float inputCount = 10;
 
void setup(){
  size(900,600);
  frameRate(30);
  smooth();
  background(255);
  noStroke();
  scene = loadShape("fsrtest.svg");
  object0 = scene.getChild("object0");
  object45 = scene.getChild("object45");
  object0.getChild("pivot").setVisible( false );
  
 
  port = new Serial(this, portname, 9600);
}
 
void draw() {
}
 
 
void serialEvent (Serial port) {
  String inString = port.readStringUntil('\n');  //read serial until new line
     if (inString != null) {
       inString = trim(inString);
       println(inString);
       float input = float(inString);
     
       if (input > 125) {
         shape( object0, 0, 0 );
       }
    
       if (input > 0 && input < 125 && oldInput - input > inputCount) {
         shape( object45, 0, 0 );
       }
      
       oldInput = input;
    }
}
 
// tried using rotate initially within the serial loop, but didn't work quite right as rotation is cumulative.
//void rotateShape( PShape object, String pivot, float angle ) {
//  float[] p = object.getChild("pivot").getParams();
//  float px = p[0];
//  float py = p[1];
//  object.translate( px, py );
//  object.rotate( angle );
//  object.translate( -px, -py );
//}
 
Posture Visualization _ Hunching
Posture Visualization _ Straight
Sponge for Force Distribution
0
Your rating: None
Drupal theme by Kiwi Themes.