-
• #2
More on adaptive control
The code has been reworked to show the results of an early step change in set point from 0.5 to 0.6 and to 0.5. This is repeated ten times and the results sent to the console.
The early and final values of the weight vector are also available for comparison
The code is attached Acontrol.js.
Acontrol1a.csv and Acontrol1a.xlsx show the results of R=100k and C=10uF. The sample interval is 500ms.
The response to the step change shows a slight overshoot of the set point with damped ringing. The weight vector shows some change with time.
Acontrol1b.csv and Acontrol1b.xlsx show the results of R=100k and C=50uF. The sample interval is 500ms.
The response to the step change shows a smooth transition to set point with no overshoot. The weight vector shows some change with time.
The 50uF/ 100k circuit has a time constant 5 times greater than the 10uF/100k circuit. So a second run was made with the 10uF/100k circuit but changing the sample rate from 500 to 100ms. These results follow.
Acontrol1c.csv and Acontrol1c.xlsx show the results of R=100k and C=10uF. The sample interval is 100ms.
The response to the step change shows a smooth transition to set point with no overshoot. The weight vector shows some change with time.
7 Attachments
-
• #3
Adaptive Control Continued
The file W-VectorComparisons.xlsx compares the W vectors from previous runs of the adaptive control algorithm. Note that curve for W10a is different from the curves of W10b and W10c. Recall that W10a was the R100k_C10uf sampled at 500ms intervals.
W10b was the R100k_C50uf sampled at 500ms intervals and W10c was the R100k_C10uf sampled at 100ms intervals.
The attached code Acontrol2.js makes use the W10c vector data to preload the control algorithm. The program is setup to run continuously until the variable “stop” is set to a non-zero value. The variable “setpoint” can be changed as well. The console displays the values. The variable sample_interval should be changed to match the RC circuit.@allObjects has mentioned in another thread that WebIDE has a graphing feature that can be turned on. If you are not familiar with it, access the WebIDE setups using the “gear” icon in the upper left and select testing. Try the tutorial.
For use with Acontrol2.js, the WebIDE testing settings are as follows:
Plots
,
out, A.outputY
SP, setpoint
inp, inpAt the bottom add
setpoint,setpoint,Number
Stop,stop,Number
In the properties
Interval 0.5Make setpoint changes as it is running and observe
Try it with the 100k_C50uF low pass filter.
It doesn’t work as well with the 100k_C10uF low pass filter with both the code and the WebIDE intervals changed to 100ms. It works at first but the control seems to stop after a bit. Something about the interface between the two stops working.
Remaining questions:
What is the optimum length of the adaptive vectors X, Y and W ?
In the initial program the process was stepped from 0 to 1 and the inverse transfer function was acquired. What happens is the step was from 0 to 0.5 instead? Would it be better to do a series of steps up and down?
What happens with a second order low pass filter? (Two resistors and two capacitors)
2 Attachments
Source for the algorithm
http://adsabs.harvard.edu/abs/1985ph...book.....W%E5%AF%86
The process:
Testing an R-C low pass filter response R=100k, C= 10uF sampled at 500ms. intervals
On an Espruino board the resistor connects to pin A4. The resistor-capacitor junction connects to pin A1. The remaining capacitor lead connects to ground.
The RC circuit has a time constant of R*C = 1 second. The cut off frequency is 1/(2pi*R*C) = 1/6.28 =0.159 Hz or 6.28 seconds per cycle.
The software constructs an adaptive linear combiner. This consists of a N element shift register (X array) (sample 0, sample 1, … sample N), and a weight vector (W array) of equal length. The W array is initially all zeros.
A sample is shifted into the X array. The dot product of W and X is computed (output).
The error between a desired value and the output is calculated and the values in the W vector are adjusted. Wi= 2 * mu * error * Xi, where mu is the adaptive gain. If mu is too large the error increases. Below a critical value the error tends toward zero as successive iterations of the modeling process occur.
Adapt1.js Adapt2.csv and Adapt2.xlsx connects the adaptive linear combiner in parallel with the RC filter process. The RC filter is discharged to zero and then charged. The W array in the adaptive linear combiner acquires the transfer function of the RC filter process. Finally the acquired model is used to repeat the discharge/charge cycle.
The spreadsheet compares the RC process and the modeled process.
The program Acontrol.js and the output files Acontrol.csv and Acontrol.xlxs show the results of connecting the adaptive linear combiner to model the inverse transfer function of the RC filter process. Then the program uses the model to control the process while continuing to adapt the W vector. The set point goes from 1.0 to 0.5 and then to 0.6.
6 Attachments