Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / mapping / matlab / prob_map.m @ 1134

History | View | Annotate | Download (3.12 KB)

1
%Function which creates a heat map of wall location probabilities.
2

    
3
%Input comes from 'filename' where each line contains 8 space-separated values
4
%Each line contains: x, y, theta, IR1, IR2, IR3, IR4, IR5 in that order
5
%Example line of input file:
6
%17 23 .45 -1 42 -1 -1 -1
7
%x and y are centimeters, theta is in radians
8
%IR values are the values seen by the robot, where -1 means that nothing is seen
9

    
10
%Output: probability density map.
11
%All output measurements are in centimeters
12

    
13
%TODO
14
%find conversion factor between IR sensor values and centimeters (currently 1 is being used)
15
function map(filename)
16

    
17
%Vectors from center of bot to IR sensors
18
Bot_IR1 = [4.5,3.5];
19
Bot_IR2 = [7.5,0];
20
Bot_IR3 = [4.5,-3.5];
21
Bot_IR4 = [-4,-3.5];
22
Bot_IR5 = [-4,3.5];
23
Bot_IR = [Bot_IR1; Bot_IR2; Bot_IR3; Bot_IR4; Bot_IR5];
24

    
25
%Unit vectors with the same angle that the IR sensors are tilted at
26
Angle_IR1 = [.78,.63];
27
Angle_IR2 = [1,0];
28
Angle_IR3 = [.78,-.63];
29
Angle_IR4 = [0,-1];
30
Angle_IR5 = [0,1];
31
Angle_IR = [Angle_IR1; Angle_IR2; Angle_IR3; Angle_IR4; Angle_IR5];
32

    
33
%For now, read input in from a file
34
Data = dlmread(filename, ' ');
35

    
36
points = [];
37

    
38
%Map area, defined in centimeters:
39
[X,Y] = meshgrid(-100:2:100,-100:2:100);
40
%V = [X1(:),X2(:)];
41
prob_map = zeros(size(X,1),size(Y,2));
42

    
43

    
44
%Set position and range error constant for testing FIXME!
45
range_error = 250;
46
pos_error = 500;
47

    
48
%loop through each line of file
49
i = 1; ir = 1;
50
%for i=1:size(Data, 1)
51
    row = Data(i, :);
52
    x = row(1);
53
    y = row(2);
54
    theta = row(3);
55
	%look at each IR sensor reading
56
    %for ir=1:5
57
        %if row(ir+3) ~= -1
58
            %Find vector of object relative to center of bot
59
            distance = row(ir+3) * 1; %TODO!!!!!!!!! replace 1 with a conversion factor to cm
60
            ObjectVector = distance * Angle_IR(ir, :);
61
            ObjectVector = ObjectVector + Bot_IR(ir, :);
62
            
63
            %rotate by theta
64
            objR = sqrt(ObjectVector(1)^2 + ObjectVector(2)^2);
65
            objTheta = atan2(ObjectVector(2), ObjectVector(1));
66
            objTheta = objTheta + theta;
67
            
68
            %add absolute position and shift into image
69
            objX = (objR * cos(objTheta)) + x + 1500;
70
            objY = (objR * sin(objTheta)) + y + 1500;
71
            ObjectVector = [objX, objY];
72
        	
73
			%Calculate distribution for this point:
74
			
75
			%Range variance in y direction, rotated by the object angle.
76
			rotation = [cos(objTheta),sin(objTheta); -sin(objTheta),cos(objTheta)];
77
			range_error_cov = inv(rotation)*[0,0;0,range_error]*rotation; 
78

    
79
			%Position variance in the robot direction 
80
			%(TODO introduce error in position estimation perpendicular to the robot)
81
			rotation = [cos(theta),sin(theta); -sin(theta),cos(theta)];
82
			position_error_cov = inv(rotation)*[0,0;0,pos_error]*rotation;
83

    
84
			covar = position_error_cov + range_error_cov;
85
			
86
			dist = reshape(mvnpdf(X,[x,y],covar), size(X1,1),size(X2,2))
87
			surf(X1,X2,dist);
88
			colormap default;
89
			return;
90

    
91
			%Using the values of the pdf as an approximation for the prob. density map
92
			%(needs to change) update as:
93
			prob_map = prob_map.*(1-dist) + dist;	
94
        %end
95
    %end
96
%end
97

    
98
%graph the probability map.
99
surf(X1,X2,prob_map);
100

    
101