Originally Posted by
Rick19468
What is troubling me with your method is the length of your sampling window and the then needed correction to offset the IMU drift.
Ah, I see.
There is really no sampling "window" for the GPS coordinate filter, because the weights follow a simple power law -- mathematically, it extends to infinity --, but you control the same effect by adjusting the weight of the new GPS coordinates.
If the weight factor is w = 5% = 0.05, then the weight of the sample n time steps ago is w (1-w)n. No, it does not tell me much either, but if you have Gnuplot, then you can plot the sample window for the last n (say 100) steps, relative to the weight of the newest sample, using
Code:
gnuplot -p -e 'w = 0.05; n = 100 ; plot [0:n] (1-w)**x notitle w lines'
To calculate some window width, you must state where the cutoff is. For example, the step where the weight is less than half the original step, is -log(2)/log(1-w). The step where the weight drops to 1/10th of the original step, is -log(10)/log(1-w), and so on. I would not bother with that either, I'd just draw those into the graph, and decide it visually:
Code:
gnuplot -p -e 'w = 0.05; n = 100 ; plot [0:n] (1-w)**x notitle w lines, 0.5 notitle w lines, 0.1 notitle w lines'
(With weight 5% = 0.05, the sampling window is of the order of fourty to eighty time steps. With weight 15% = 0.15, maybe twenty to thirty steps. With weight 33% = 0.33, maybe a dozen steps. With weight 50% = 0.5, just a few steps.)
_ _ _ _
Resetting the fix point, the origin for the IMU coordinates, is a completely separate thing. It has no relation to the averaging above.
Because the IMU coordinates are by definition relative -- there is no absolute point or fix they refer to, just movement --, we need a reference point, the fix point. The gps0_x and gps0_y provide just that.
The fix point can be freely moved just after we have updated the GPS fix but not prepared for the next GPS sample. It really is nothing more than moving the GPS reference point to somewhere else. And its physical location does not matter, it is just a reference point for the IMU coordinates.
In fact, you can quite safely have your coordinate system work like this:
Code:
// Boot-up.
// Get first GPS coordinates into gps_x and gps_y
// Since we have no other samples, we start
// by relying on the initial GPS reading.
gps0_x = gps_x
gps0_y = gps_y
// Weight number N defines the weight factor,
// weight factor w = 1/N
N = 5
// Operation loop:
// ...
// Other work .. coordinates are gps0_x + imu_x, gps0_y + imu_y
// ...
// Receive signal, or estimate using a timer, that the GPS unit
// has sampled the location and has started calculations.
// We use the IMU coordinates at that moment for reference.
imu_ref_x = imu_x
imu_ref_y = imu_y
// ...
// Other work .. coordinates are gps0_x + imu_x, gps0_y + imu_y
// ...
// Receive new GPS coordinates gps_x, gps_y
// Update fix coordinates,
gps0_x = ((N-1)*gps0_x + gps_x - imu_ref_x) / N
gps0_y = ((N-1)*gps0_y + gps_y - imu_ref_y) / N
// and move fix location so IMU coordinates
// stay as near zero as possible.
gps0_x = gps0_x + imu_ref_x
gps0_y = gps0_y + imu_ref_y
imu_x = imu_x - imu_ref_x
imu_y = imu_y - imu_ref_y
// Note: the above does not affect the actual
// coordinates, gps0_x+imu_x, gps0_y+imu_y, at all.
// It really only moves the fix location.
// ...
// Other work .. coordinates are gps0_x + imu_x, gps0_y + imu_y
// ...
Originally Posted by
Rick19468
With my method , I use the IMU for the shortest possible time, (with the GPS capable of 5 reads per sec. for 2 dimensions) ....... I read and refresh the IMU at this rate as well. My greatest need for accuracy is in the short term (5-10 seconds) ...when the dog is standing there .... then bolts to the fence very fast.
Given an absolute top speed of about 20 m/s, it means the coordinates may change by as much as 4 m (thirteen feet) per one measurement interval (0.2 seconds). Less for normal pets, of course.
It sounds to me you could easily rely on just the GPS for these cases. Given a 0.2 second measurement interval, even an average pet may sprint several feet per interval.
I would personally use much more rapid IMU rate, in the hopes of shortening the reaction time. A large sampling weight (small N in the pseudocode above, maybe 2 to 5), would mean IMU drift would be limited to the drift that accumulates in about one second.
Don't you have hardware you can test this on? I don't mean your final hardware, but a development kit with the same sensors you can read to your computer? Robust enough to swing at the end of a cord? Maybe strap it (data via wifi?) on the back of an unsuspecting dog, camera in the ceiling, then play time. Compare the measured trajectory to the video. Adjust the factors and timings, and repeat. That's what I'd do, anyway.