In my previous post, modeling-and-simulation-car-suspension- ... ode45-5787
I tried to show how a Car Suspension system can be modeled from Ordinary Differential Equation (ODE) in GNU Octave. Furthermore, software simulations from different values of mass, spring constant and damping force were performed.
Also, in this post i showed how Mechanical system can be analogous to Electrical systems.
analogies-between-elements-in-electrica ... stems-5072
So, i was thinking how can i do the reverse of this. I mean to collect real data from the damping system (displacement and velocity) and then manipulate/plot them so that to prove the theoretical software simulations as done in my previous post. But, i was not able to find the equipment unless in the Universities or Research centers. So, i thought of the analogous behavior between mechanical system and electrical system as it is cheap to deal with electronics. The below relationships between physical quantities have been shown in the posts above.
Mechanical Force Electromotive force
Velocity Current
Mass Inductor
Reciprocal spring constant Capacitor
Damper Resistor
So, i connected series RLC (Resistor, Inductor, Capacitor) and tap the voltage that is flowing through the capacitor into Arduino to GNU Octave.
Equipments and software used
L = unknown (I had difficulties finding an inductor, so i got unknown value from a speaker)
LED (2.8Vmax), Arduino Uno Board, CoolTerm COM Capture, Fritzing software, GNU Octave
Charging and discharging a Capacitor
Initially, the 5V wire from Arduino is not connected to the breadboard. During charging, run the code in Arduino Terminal then connect the 5V wire into the resistor in the breadboard. In the code, analog input pin A0 to A5 can be chosen to retrieve data into serial COM with an interval of 1microsec in a for loop. I collected 2048 voltage readings. Unused pin A0 to A5 have floating voltages which may affect the readings so ground them as well. To discharge, remove 5V pin wire and connect it in the ground of the breadboard.
- pinMode(A1,OUTPUT);
- digitalWrite(A1,LOW);
- //
- for(int j = 0; j<N; j++){
- Capvoltage = analogRead(A0)*5/1024.;
- Serial.println(Capvoltage );
- delay(time);
- }
In Octave
Observation of capacitor voltages were done in Octave environment, where by fitting of data and dealing with noise Algorithms were implemented. I noticed there are some floating voltages so i tried to smooth with Exponential Moving Algorithm (EMA). Also, these data can be used to predict future performance of the same system like in machine learning. I implemented Least Square Method (LSM) Algorithm to predict the future manipulations.
- % Exponential Moving Average Algorithm
- % alpha is the value between 0 and 1
- for i = 2:length(volt)
- y(i) = (alpha*volt(i)) + ((1-alpha)*y(i-1));
- endfor
- % Least Square Method Algorithm
- for i = 2:length(v)-1
- dv = max(v) - min(v);
- a(i-1) = dv * v(i-1);
- yy = log((a(i-1)- v)/k(i-1));
- b = inv(t'*t)*t'*yy;
- T (i-1)= -1/b;
- if ( T ~= 0 ) %Skip divide by Zero Error
- yFit=a(i-1)*(1-exp(-t/T(i-1)));
- endif
- endfor
- plot(t,yFit,t,v)
- }
Calculations of Inductance
The value of inductance can be calculated from the Time Constant (T) in the graph. Time constant is the time it takes 63% of input voltage source to charge a capacitor. Recalling series RLC ODE,
Laplace Transform;
Rearranging:
In time domain
Time constant
, ,
So, i could calculate the value of unknown inductor from the speaker using the data from Arduino. Insert these inductance, capacitance and resistance into wolframalpha you can see the equivalency
, ,
https://m.wolframalpha.com/input/?i=RLC ... 400uF&lk=3
Conclusion:
In this topic seems a lot can be learned, simulating real time damping system is hard however its electronics equivalent can be done easily. The system above is over-dumped it does not have oscillation. I have attached the voltages that i captured in .txt file with interval of 1microsec, play with them and improve Least Square Method and Exponential Moving Average Algorithms in other Languages like C, C++, Python etc.
- You can learn programming Arduino
- Integrating hardware and software
- Estimation Algorithms
- Pseudoinverse of matrix: Moore–Penrose inverse
- Electrical safety: Voltage to LED should not exceed 2.8V
- Machine Learning; Teach data on how to predict the future values through regression
- Drawing through Fritzing Tool
- Capturing data stream in CoolTerm