Mechanical Damper: Data Manipulation of RLC Step Response in Arduino via GNU Octave

Post Reply
Joseph Bundala
Expert Member
Reactions: 23
Posts: 55
Joined: 7 years ago
Has thanked: 14 times
Been thanked: 28 times
Contact:

#1

Hello guys,

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.

Image

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.

  1. pinMode(A1,OUTPUT);
  2. digitalWrite(A1,LOW);
  3. //
  4. for(int j = 0; j<N; j++){
  5.     Capvoltage  = analogRead(A0)*5/1024.;    
  6.     Serial.println(Capvoltage );
  7.     delay(time);    
  8.   }


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.

  1. % Exponential Moving Average Algorithm
  2. % alpha is the value between 0 and 1
  3. for i = 2:length(volt)
  4.          y(i)  = (alpha*volt(i)) + ((1-alpha)*y(i-1));
  5.  endfor
  6. % Least Square Method Algorithm
  7. for i = 2:length(v)-1
  8.           dv = max(v) - min(v);
  9.           a(i-1) = dv * v(i-1);
  10.           yy = log((a(i-1)- v)/k(i-1));  
  11.           b = inv(t'*t)*t'*yy;
  12.           T (i-1)= -1/b;
  13.           if ( T ~= 0 )             %Skip divide by Zero Error
  14.              yFit=a(i-1)*(1-exp(-t/T(i-1)));    
  15.           endif
  16.   endfor
  17. plot(t,yFit,t,v)
  18.   }

Capacitor.JPG
Capacitor.JPG (44.12 KiB) Viewed 6034 times
Capacitor.JPG
Capacitor.JPG (44.12 KiB) Viewed 6034 times
Capture1.JPG
Capture1.JPG (23.41 KiB) Viewed 6034 times
Capture1.JPG
Capture1.JPG (23.41 KiB) Viewed 6034 times

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
>Useful information can be found in Arduino Forum, Mathworks and other sources in the internet. I am open to suggestions and mistakes done in the coding part.

RLCArduino.jpg
Attachments
disturbances.txt
(4.69 KiB) Downloaded 173 times
disturbances.txt
(4.69 KiB) Downloaded 173 times
ChargeDischarge.txt
(12 KiB) Downloaded 111 times
ChargeDischarge.txt
(12 KiB) Downloaded 111 times
My-Movie.gif
(19.72 MiB) Not downloaded yet
My-Movie.gif
(19.72 MiB) Not downloaded yet
1
1 Image
Last edited by Joseph Bundala on Wed Jun 20, 2018 3:06 pm, edited 1 time in total.
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#2

Nice and interesting post. I just want to get an idea, how are the two codes, one in C and the other in Octave related?

Also, when you call, the function as below, which values of t,yFit,t,v did you specify?
Simulink wrote: 5 years ago plot(t,yFit,t,v)
It seems I have to ask a couple of questions to get what is going on here!
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Joseph Bundala
Expert Member
Reactions: 23
Posts: 55
Joined: 7 years ago
Has thanked: 14 times
Been thanked: 28 times
Contact:

#3

@@Eli ,The codes i have posted are only part but are the engines of the algorithms, what misses are the declarations and initiations of variables

The code in C is run in Arduino Atmega microcontroller whose purpose is to read analog data from the circuit and the code sends them to the serial Monitor of a computer(eg COM1). Octave or CoolTerm captures these data and the implemented algorithms manipulate them. As you know, Octave is a powerful tool in graphics and statistics.

If Capacitor voltages from Arduino are captured and say stored in a "data.m" or "data.txt" file, then the declarations will be like this in Octave

  1. m = load ("fileName");    % load data into the Octave workspace
  2. v = m(:,1);                     % Voltages: arranging them in a column
  3. t  = 1:length(v);            % Time intervals
  4. y  = zeros(1,length(v)); %Initiating a zero Matrix for Voltage
  5. .
  6. .blah blah for loops
  7. .
  8. plot(t,v,...)

0
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#4

Hi @Simulink

Thank you for your reply. So, your data come from real experimentation? It seems to realize this implementation, one needs arduino apart from getting the code right?

How did you differentiate



to have



I assume is constant and expected it to disappear upon differentiation of the first equation above, is that right?
1
1 Image
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Joseph Bundala
Expert Member
Reactions: 23
Posts: 55
Joined: 7 years ago
Has thanked: 14 times
Been thanked: 28 times
Contact:

#5

Hello @Eli

Sure the voltage data attached in this post in .txt files came from the real experiment and Arduino Uno is needed. Those voltages were real voltages tapped when charging or discharging a capacitor.

And, thanks for highlighting about differentiation, there was no need for differentiating but only Laplace Transform, so i am editing to remove the differentiation term.

However, if i differentiate that equation then will disappear. Furthermore, the denominator of the final equation is very important equation in Advanced Control Theory. With that denominator we can know at which value of a resistor, inductor or capacitor the system will oscillate and stability in Time and Frequency domains. When I get time I will write another post going deeper into Control Systems for Routh–Hurwitz stability criterion.



0
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#6

Thank you @Simulink , well explained. I will still have more questions in future, I'm learning...... :writing_hand:
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#7

I found this YouTube video about Arduino enlightening:

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#8

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Forbidden_Technology
Senior Expert Member
Reactions: 16
Posts: 115
Joined: 9 years ago
Has thanked: 25 times
Been thanked: 14 times

#9

Very good post, mathematics and engineering in action!
0
Post Reply

Return to “Electrical Engineering”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 8 guests