Posted by Tony Jeffree on 11/02/2023 11:57:31:
…
My own rather amateurish messing around with a "free" pendulum that is electromagnetically impulsed under the control of a single board computer has led me to start thinking about a third possible approach which takes advantage of the processing power and electronic sensors that could be applied to the problem – measure the environmental factors that could affect the pendulum (temperature, pressure, humidity,…), feed those measurements into the SBC, and use its processing power to determine how much impulse to give to the pendulum in order to correct for the environmental effects. Even for the lowly BBC Micro Bit that I am using has add-on boards that will measure temperature, pressure, and humidity. Obviously the calculation is probably going to be non-trivial, and the details specific to a particular pendulum, but in principle…?
…or are you all way ahead of me…?
Similar to what I'm doing in the 'Experimental Pendulum' thread. My method:
- Build attempts a high Q pendulum without mechanical temperature or barometric compensation, that isn't designed to beat at a particular frequency. The bob is impulsed by an electromagnet, triggered by the bob breaking an infra-red beam, so there's nothing mechanical apart from my bad design and workmanship to spoil the pendulum. Not tried yet, but the pendulum is designed to run in a vacuum.
- Logs temperature, air pressure and humidity on every beat, also measuring period at high resolution for external statistical analysis.
- The statistical analysis quantifies the relationship between temperature, pressure, and humidity (if any). My clock isn't noticeably effected by humidity, so that's been dropped. The relationship between period, temperature and air pressure is quantified numerically by doing a 'Multivariable Regression', on the log.
- The regression results are loaded into the clock, where the microcontroller uses them to turn mechanical ticks into microsecond accurate 'should be values'. When time-keeping independently, the actual pendulum period isn't measured. Instead the tick event causes the microcontroller to calculate the 'correct' period from temperature and pressure, and it counts that rather than actual pendulum time. Very different from other clocks I believe!
The log looks like this, millibars, humidity, and temperature in bold, actual period and corrected period in italics:
13277507 0.4059 0.3600 36 1024.02 73.72 13.55 823472 1676117346 766006 1676118087 862746
13279885 0.4059 0.3600 36 1024.02 73.72 13.55 823472 1676117347 589478 1676118088 688123
Note that the microcontroller corrects both actual tick periods into the same value in microseconds based on temperature and pressure. The smoothing is aggressive, and may be cheating!
The maths is easy enough, when you know how, because someone else did all the hard work! I'm using python with numpy and sklearn, both modules built by experts! Numpy is designed to make working with numeric arrays easy, whilst sklearn is a machine learning module that includes multi-variable regression. The two are compatible.
Mult-vartiable regression may be complicated behind the scenes but the Python code needed to use it as a tool is simple:
X = np.column_stack((pressures, temps)) # Combine pressure and temperature arrays
regr = linear_model.LinearRegression() # Create an object that does regression sums
regr.fit(X, ticks) # Get relationship between ticks( aka period), temperature and pressure
intercept = regr.intercept_ # The answer is in three parts
pressureCoef = regr.coef_[0]
tempCoef = regr.coef_[1]
Regression results loaded into the clock, the microcontroller uses the intercept, pressure and temperature coefficients to do a simple sum:
void update( float temp, float pressure ) {
float compPerioduS;
if (compensate) {
compPerioduS = (intercept + pressureCoef*pressure + tempCoef*temp);
compPerioduS += cDrift;
perioduS = round((compPerioduS/xtal)*1e6);
}
timePair.adduS(perioduS);
}
</code>
Written in C because I'm using an Arduino, but nothing other languages couldn't do just as well.
Example values:
#define INTERCEPT 13112795.02168
#define TCOEF 52.67560
#define PCOEF 59.51222
What I hadn't thought of doing is computing the impulse power as necessary to adjust Amplitude - an idea I shall certainly steal!
Thanks,
Dave
Edited By SillyOldDuffer on 11/02/2023 15:16:06