-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowOdometry.m
80 lines (63 loc) · 2.37 KB
/
ShowOdometry.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
% ShowOdometry: Plot the odometry-estimated path corresponding to a data
% file. A drop down menu opens to choose a data file from the "data"
% folder of your current work folder.
% Author: G. Garcia
% 13 March 2013.
RobotAndSensorDefinition ;
Xodom = [ 0 0 0*pi/180 ].' ; % Set this according to robot initial position.
%Load the data file
dataFile = uigetfile('data/*.txt','Select data file') ;
if isunix
eval(['load data/' , dataFile]) ;
else
eval(['load data\' , dataFile]) ;
end
dataFile = strrep(dataFile, '.txt', '') ;
fprintf('Data file: %s\n',dataFile) ;
eval(['data = ',dataFile,'; clear ',dataFile]) ;
travDistance = 0 ;
% Skip motionless parts of the data at beginning and end of the experiment
% and return only meaningful data, with wheel rotations in radians.
% Also reduce encoder resolution and frequency according to factors
% set in RobotDefinition.m
[nbLoops,t,qL,qR,sensorReadings] = PreprocessData(data, dots2rad, ...
dumbFactor, subSamplingFactor ) ;
Xodo = zeros(3,nbLoops) ;
vOdo = zeros(1,nbLoops) ;
wOdo = zeros(1,nbLoops) ;
Xodo(:,1) = Xodom ;
wbHandle = waitbar(0,'Computing...') ;
for mainLoopIndex = 2 : nbLoops
waitbar(mainLoopIndex/nbLoops) ;
% Calculate input vector from proprioceptive sensors
deltaq = [ qR(mainLoopIndex) - qR(mainLoopIndex-1) ;
qL(mainLoopIndex) - qL(mainLoopIndex-1) ] ;
U = jointToCartesian * deltaq ; % joint speed to Cartesian speed.
% Predic state (here odometry)
Xodom = EvolutionModel( Xodom , U ) ;
Xodo(:,mainLoopIndex) = Xodom ;
vOdo(mainLoopIndex) = U(1)/( t(mainLoopIndex)-t(mainLoopIndex-1) ) ;
wOdo(mainLoopIndex) = U(2)/( t(mainLoopIndex)-t(mainLoopIndex-1) ) ;
end
close(wbHandle) ;
% Plot robot path, Kalman fiter estimation and odometry only estimation
figure;
plot( Xodo(1,:), Xodo(2,:) , 'r' , 'LineWidth',2 ) ;
zoom on ; grid on; axis('equal');
title('Path estimated by odometry');
xlabel('x (mm)');
ylabel('y (mm)');
% Plot odometry-estimated speed and rotation speed
figure;
subplot(2,1,1);
plot( t,vOdo , 'LineWidth',2 );
xlabel('t (s)')
ylabel('v (mm/s)');
title('Odometry-estimated speed');
zoom on ; grid on;
subplot(2,1,2);
plot( t,wOdo*180/pi , 'LineWidth',2 );
xlabel('t (s)')
ylabel('w (deg/s)');
title('Odometry-estimated rotation speed');
zoom on ; grid on;