-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluateQ2.m
More file actions
executable file
·70 lines (52 loc) · 1.32 KB
/
Copy pathevaluateQ2.m
File metadata and controls
executable file
·70 lines (52 loc) · 1.32 KB
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
function [Qh,U,Xtn_out, TTR] = evaluateQ2(V,Grid,X,Uw,Ua,dt,G,gamma,horizon)
Length_U=length(Uw)*length(Ua);
ua = meshgrid(Ua,Uw);
ua=reshape(ua',[Length_U,1]);
uw = meshgrid(Uw,Ua);
uw=reshape(uw,[Length_U,1]);
U=[uw,ua];
Xt1 = dynamic(X,ua,uw,dt);
% Xt1 = dynamic(Xt1,u1,u2,dt);
Xtn_out = Xt1;
% n-step
for i=2:horizon
% HARD
% call evaluateP to greedy choose the current best action
% for time t+horizen-1
end
if horizon ==1
Xtn = Xt1;
end
%% apply the translation and rotation due to goal change
Xtn(:,3) = Xtn(:,3)-G(3);
% check rotation
Xtn_rot = [cos(G(3)) sin(G(3));
-sin(G(3)) cos(G(3))]*([Xtn(:,1)-G(1) Xtn(:,2)-G(2)])';
Xtn(:,1) = (Xtn_rot(1,:))';
Xtn(:,2) = (Xtn_rot(2,:))';
thet = Xtn(:,3) ;
thet(thet<-pi)=thet(thet<-pi)+2*pi;
thet(thet>pi)=thet(thet>pi)-2*pi;
Xtn(:,3) = thet;
%% discount V before (geometric series)
x1 = Grid(:,:,:,:,1);
x2 = Grid(:,:,:,:,2);
x3 = Grid(:,:,:,:,3);
x4 = Grid(:,:,:,:,4);
TTR = interpn(x1, x2, x3, x4, V, Xtn(:,1), Xtn(:,2), Xtn(:,3), Xtn(:,4), 'nearest', 100);
% TTR(TTR==0)=100;
r = -dt;
V = r*ones(Length_U,1) - gamma*TTR;
if gamma < 1
Qh = (((1-gamma^horizon)/(1-gamma)).*V)';
else
Qh = V';
end
% G = [0,0,0,0];
% Qh = - gamma*sqrt((Xt2(:,1)-G(1)).^2+(Xt2(:,2)-G(2)).^2)';
%plot
% [X,Y] = meshgrid(Uw,Ua)
% Z = reshape(Q',[5,7 ])
% surf(X,Y,Z)
%
end