diff --git a/software/apps/Motion/PendulumBillsLatest/PendulumBillsLatest.ino b/software/apps/Motion/PendulumBillsLatest/PendulumBillsLatest.ino index 0dafa11..0fac5f7 100644 --- a/software/apps/Motion/PendulumBillsLatest/PendulumBillsLatest.ino +++ b/software/apps/Motion/PendulumBillsLatest/PendulumBillsLatest.ino @@ -1,11 +1,10 @@ // "Pendulum" - spring-mass oscillator -// +// Spring-Mass oscillator (no damping) //#include #include float dt = .005; //time per cycle float m = 4.0; //time constant was .002 - float k = 1.0; // spring constant was .15 float xf,vf,ff; // floating point versions of pendulum x and v and force int x; // input from analogRead(); @@ -18,7 +17,6 @@ byte incomingByte; void setup() { - //Timer1.initialize(64); //64 microsecond period MotorA.init(); //initializes Timer1, pinModes Serial.begin(9600); //initialize position (xf), velocity (vf), force (ff) @@ -35,8 +33,8 @@ void loop(){ vf = vf + (ff/m)*dt; // integrate F/m to get velocity xf = xf + vf*dt; // integrate velocity to get position - f = min(ff,512); //Motor has max torque of 512 - duty = abs(f); + duty = abs(ff); + duty = min(duty,512); //Motor has max torque of 512 MotorA.torque(duty); diff --git a/software/apps/Motion/PendulumDampedBV/PendulumDampedBV.ino b/software/apps/Motion/PendulumDampedBV/PendulumDampedBV.ino new file mode 100644 index 0000000..33abb70 --- /dev/null +++ b/software/apps/Motion/PendulumDampedBV/PendulumDampedBV.ino @@ -0,0 +1,85 @@ +// Damped Spring-Mass Oscillator +// BV 24Jan13 + +#include +int Fout, Xin, duty; + +// mass sring damper model +float m = 4.0; +float k = 1.0; +float b = 0.0; +float dT = .005; +float X, V, F; // model parameters (2nd-order oscil) + +byte c=0; //counts up until 0 then prints + +byte incomingByte; + +void setup(){ + Serial.begin(9600); + MotorA.init(); // initializes Timer1, pinModes + Xin = analogRead(A0) - 512; //middle of 0-1023 range + // initialize model variables + X = Xin; + V = 0.0; + F = 0.0; +} + +void loop(){ + Xin = analogRead(A0) - 512; + F = k*(Xin - X) - b*V; //spring and damper + V += (F/m) * dT; + X += V * dT; + + duty = abs(Fout); + duty = min(duty,512); + + MotorA.torque(duty); + if(Fout>0)MotorA.direction(FORWARD); + else MotorA.direction(BACKWARD); + +if (c++ == 0){ + Serial.println(X); +} +/* +if (Serial.available() > 0) { + incomingByte = Serial.read(); + if(incomingByte == '}''){ + dT = dT * 1.1; + Serial.println(dT); + } + if(incomingByte == '\'){ shift \ + dT = dT / 1.1; + Serial.println(dT); + } + if(incomingByte == '|'){ + k = k / 1.1; + Serial.println(k); + } + if(incomingByte == '}'){ //shift ] + k = k * 1.1; + Serial.println(k); + } + if(incomingByte == '['){ + b = b / 1.1; + Serial.println(b); + } + if(incomingByte == '{'){ //shift [ + b = b * 1.1; + Serial.println(b); + } + if(incomingByte == '['){ + m = m / 1.1; + Serial.println(m); + } + if(incomingBmyte == '{'){ //shift [ + m = m * 1.1; + Serial.println(m); + } + } + } + */ +} + + +