From dca2a5acd43043baf68412351099f385057eb3a3 Mon Sep 17 00:00:00 2001 From: Bill Verplank Date: Sun, 4 Nov 2012 15:42:58 +0100 Subject: [PATCH] DampSpringMass code none works yet - having trouble with velocity estimation. --- software/apps/Motion/Damp/Damp/Damp.ino | 23 + software/apps/Motion/Damp2/Damp2.ino | 28 + .../Motion/DampMass/DampMass/DampMass.ino | 1 + software/apps/Motion/GraphArduinoA0.maxpat | 576 ++++++++++++++++++ 4 files changed, 628 insertions(+) create mode 100644 software/apps/Motion/Damp/Damp/Damp.ino create mode 100644 software/apps/Motion/Damp2/Damp2.ino create mode 100644 software/apps/Motion/DampMass/DampMass/DampMass.ino create mode 100644 software/apps/Motion/GraphArduinoA0.maxpat diff --git a/software/apps/Motion/Damp/Damp/Damp.ino b/software/apps/Motion/Damp/Damp/Damp.ino new file mode 100644 index 0000000..97f16d6 --- /dev/null +++ b/software/apps/Motion/Damp/Damp/Damp.ino @@ -0,0 +1,23 @@ +//Damp - measure velocity then f=Bv +#import +int x; //position measured +float v, f, t, xold; //velocity, force, time delta +byte c; //for debug print every 256th loop + +void setup(){ + Serial.begin(9600); + xold = analogRead(A0); +} + +void loop(){ + x = analogRead(A0); + v = x - xold; //lag v, too + xold += 0.1*(x-xold); //slide xold with lag + + if(c++==0){ + //Serial.print(xold); + //Serial.print(" "); + Serial.println(100*v); + } +} + diff --git a/software/apps/Motion/Damp2/Damp2.ino b/software/apps/Motion/Damp2/Damp2.ino new file mode 100644 index 0000000..af8764a --- /dev/null +++ b/software/apps/Motion/Damp2/Damp2.ino @@ -0,0 +1,28 @@ +//Damp 2 with running average position + +#define n 10 //number in buffer +int x; //position measured +float xf; // running average on n samples +int buff[n]; +int index = 0; +float v, oldavg; // estimate of velocity +byte c; + +void setup(){ + Serial.begin(9600); +} + +void loop(){ + buff[index] = analogRead(A0); + index++; + if(index > n-1) index = 0; + int acc = 0; + for(int i=0; i