% which observation to use as the test point
test_ind = 6;
% how much of the test data to keep
% mod=16,cap=4 means take 64 samples (16 sensors, 4 offsets) from each
% location. That way the samples we save are evenly spaced around the
% robot, rather than a lot of useless repeated samples.
thin_mod = 16;
thin_cap = 3;
blur_var = 1.0;	% how much the votes are blurred to smooth out noise

% compute the sonar calibration function (linear)
coeff=fittyline;

% load the map data and thin it down to reduce computation time
load map.ext;
thin;

% parse the map data into columns
mappy

% position to extract from map for testing
matchpos = zuniq(test_ind);

% extract a test set from the map data
extract

% compute the set of valid votes
votes

% tally the votes and plot it
tally

% plot the data in one display
clf;
ih = imagesc([ll_r, rr_r], [ll_i, rr_i], svt);
	% not sure why, but image likes to flip/flop x & y axes
set(gca,'YDir','normal')
hold on;
quiver(real(mzp),imag(mzp),-real(mzd),-imag(mzd),0.2,'y');
plot(real(max_spot), imag(max_spot), 'wx');
plot(real(matchpos), imag(matchpos), 'k+');

% print out the error result
the_error = abs(matchpos-max_spot);
disp(sprintf('thin_mod = %d   test_ind = %d  the_error = %f', thin_mod, test_ind, the_error));
