-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfine_search.m
37 lines (36 loc) · 1.37 KB
/
fine_search.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
function target_angle = fine_search(spot_range, ros_node, pub, sub)
pub_angle = pub;
sub_angle = sub;
msg_rorate_angle = rosmessage(pub_angle);
TRUS_pos_init = spot_range(1);
sample_interval = 1;
sample_angle = spot_range(1): sample_interval : spot_range(2);
sample_intensity = [];
for i = 1 : length(sample_angle)
% command TURS rotate
msg_rorate_angle.data = TRUS_pos_init + sample_interval * (i - 1);
send(pub_angle, msg_rorate_angle);
disp('msg sent!');
pause(1)
while isempty(sub_angle.LatestMessage)
pause(1)
disp('waiting for sub_angle')
end
while abs(sub_angle.LatestMessage.data - msg_rorate_angle.data) >= 0.1
pause(1);
disp('not move to the correct position')
end
disp('rotated to goal angle');
% calculate intensity from beam forming image
disp('Please refresh data!')
pause; % wait until press any key
[~, ~, intensity_value] = calculate_PA_coordinates(ros_node, msg_rorate_angle.data);
sample_intensity = [sample_intensity, intensity_value];
end
% Fit using Gaussian
f = fit(sample_angle', sample_intensity', 'gauss2');
angle_ = spot_range(1) : 0.01 : spot_range(2);
intensity_fit = f(angle_);
[~, idx] = max(intensity_fit);
target_angle = angle_(idx);
end