-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfitness_autobalance.m
31 lines (20 loc) · 1.15 KB
/
fitness_autobalance.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
function fitness = fitness_autobalance(Efinal, Edot, lookahead, start_pos, current_pos, target_pos)
global m g GR_approx
% a is vector from start pos to target pos
% b is vector from current pos to target pos
a_vector = (target_pos-start_pos);
a_len = norm(a_vector);
p_size = size(current_pos);
% b = squeeze(current_pos - repmat(start_pos, [1, p_size(2:3)])); % [3,ntf,ntf] vectors from start to current
% track_distance = squeeze(dot(b, repmat(a_vector/a_len, [1, p_size(2:3)]),1)); % [ntf,ntf] matrix
b = squeeze(repmat(target_pos, [1, p_size(2:3)]) - current_pos); % [3,ntf,ntf] vectors from target to current
b_len = squeeze(sqrt(sum(b.^2, 1)));
track_distance = (a_len - b_len);
% E_required = m*g*(squeeze(current_pos(3,:,:) - target_pos(3)) + ...
% norm(a_vector(1:2))/GR_approx);
min_E_weight = 0.2;
E_weight_100 = 0.6;
weight_auto = (1-min_E_weight)*exp(log((E_weight_100-min_E_weight)/(1-min_E_weight))/100*b_len) + min_E_weight;
% E_weight = (E_required >= 0).*weight_auto + (E_required < 0)*.4;
E_weight = weight_auto;
fitness = E_weight.*(0.5*Efinal + 0.5*Edot*lookahead) + (1-E_weight).*m*g*track_distance/GR_approx;