Variable not showing up in workspace.

1 次查看(过去 30 天)
How come [x(i) y(i) theta(i)] does not show up in the workspace when I run this code.
clear all; clc; close all;
global Cc Co Ct tau fmax fmin i_ww
global rthr gthr bthr
% ---------Adjustable Parameters---------
tau = 10; %run time in seconds
rthr = 60; % red threshold
bthr = 60; % blue threshold
gthr = 60; % green threshold
frr = 2; % red: 1=rear, 2=front
frb = 1; % blue: 1=rear, 2=front
Cc = [1 1 .1 .1 .01 .01];
fmax = 0.144;
fmin = -0.045;
TLB = .4*0; %Total Length of the Boat
% ---------------------------------------
if (frr+frb~=3), error('Wrong front/rear combination'); end
i_ww = input('Enter 0 for no wave and wind or 1 for both: ');
% if i_ww == 1
% Cc = [1 1 .1 .1 .1 .1];
% end
% --Camera setup--
delete(imaqfind);
vid = videoinput('dcam');
vid.ReturnedColorSpace = 'bayer';
vid.BayerSensorAlignment = 'rggb';
vid.ROIPosition = [60 40 960 720];
vid.FramesPerTrigger = 1;
triggerconfig(vid,'manual')
vid.TriggerRepeat = Inf;
src = getselectedsource(vid); % Device Specific properties
src.Gain = 500;
start(vid)
pause(0.5)
gflag = 0;
i = 0;
ij = 0;
time = 0;
while time <= tau;
% 2- finds the 2 diode locations
trigger(vid)
[img time] = getdata(vid); % waits for frame to be available
[rrpts crpts rgpts_t cgpts_t rbpts cbpts] = gsearch_rgb(img);
if (length(rrpts) ~= 2) && (length(rbpts) ~= 2) || (length(rrpts) ~= 1) && (length(rbpts) ~= 1)
display([num2str(time) 's red:' num2str(length(rrpts)) ' blue:' num2str(length(rbpts))])
ij = ij + 1
missed_leds(:,:,:,ij) = img;
else
i = i + 1;
if i == 1
time0 = time;
end
t(i,1) = time - time0;
if length(rrpts) == 2
r_tr = rrpts(1) + crpts(1);
r_tr2 = rrpts(2) + crpts(2);
b_tr = rbpts(1) + cbpts(1);
b_tr2 = rbpts(2) + cbpts(2);
if i == 1
frr1 = 1; frr2 = 2;
frb1 = 1; frb2 = 2;
else
if abs(r_tr-r_tr_old) < abs(r_tr2-r_tr_old)
frr1 = 1; frr2 = 2;
else
frr1 = 2; frr2 = 1;
end
if abs(b_tr-b_tr_old) < abs(b_tr2-b_tr_old)
frb1 = 1; frb2 = 2;
else
frb1 = 2; frb2 = 1;
end
end
% --USV--
ip(frr) = crpts(frr1);
jp(frr) = rrpts(frr1);
ip(frb) = cbpts(frb1);
jp(frb) = rbpts(frb1);
ijp = [ip jp];
[x(i) y(i) theta(i)] = cam_calib(ijp);
% --Target--
ip(frr) = crpts(frr2);
jp(frr) = rrpts(frr2);
ip(frb) = cbpts(frb2);
jp(frb) = rbpts(frb2);
ijp = [ip jp];
[xt(i) yt(i) thetat(i)] = cam_calib(ijp);
xt(i) = xt(i) - TLB*cos(thetat(i));
yt(i) = yt(i) - TLB*sin(thetat(i));
else
% --USV--
ip(2) = crpts(1);
jp(2) = rrpts(1);
ip(1) = cbpts(1);
jp(1) = rbpts(1);
ijp = [ip jp];
[x(i) y(i) theta(i)] = cam_calib(ijp);
xt(i) = 1.5 + 0.5*cos(2*pi*t(i)/20);
yt(i) = 2 + 0.5*sin(2*pi*t(i)/20);
thetat(i) = 2*pi*t(i)/20 + pi/2;
end
Cos(i,1) = length(cgpts)/4;
n_o = Cos(i,1);
%Ct = [xi yi theta0 xf yf w0 k10 k20 eps_lc v1 v2 tc dt1 dist k10t k20t]
if i == 1
if n_o == 0
Ct = [0 0 0 0 0 .2 .05 .05 0 0 0 .1 .1 1 .25 .25];
else
Ct = [0 0 0 0 0 .2 .1 .1 0 0 0 .1 .1 1 .1 .1];
%Ct = [0 0 0 0 0 .2 .07 .07 0 0 0 .1 .1 1 .07 .07];%better for cw
%Cc = [1 1 .1 .1 .1 .1];
end
Ct(1) = x(1); Ct(2) = y(1); Ct(3)=theta(1);
Ct(4) = xt(1); Ct(5) = yt(1);
end
% --Obstacles--
Co(1) = n_o;
if n_o > 0
[pxobs pyobs] = cam_calib_obs(cgpts,rgpts);
d_obs_old = 1e10;
obs_grp(1:n_o,1:4) = 0;
obs_grp(1,1) = 1;
if i==1
cgpr = 1:4*n_o; %remaining grean LED's to be sorted
for i1 = 1:n_o-1
for ii1 = 1:length(cgpr)
for ii2 = 1:length(cgpr)
d_obs(ii2) = sqrt((pxobs(cgpr(ii2)) - pxobs(cgpr(ii1)))^2 + ...
(pyobs(cgpr(ii2)) - pyobs(cgpr(ii1)))^2);
end
end
[d_o_s id_o_s] = sort(d_obs(1:length(cgpr)));
obsn(i1,:) = id_o_s(1:4);
clear cgpr;
cgpr = id_o_s(5:end);
end
if n_o > 0
obsn(n_o,:) = cgpr;
end
end
%Co = [n_o x_oi y_oi v_o1 v_o2 a b phi phidot]
for ii1 = 1:Cos(i,1)
ii3 = 8*(ii1-1);
Cos(i,ii3+2) = sum(pxobs(obsn(ii1,:)))/4; %x
Cos(i,ii3+3) = sum(pyobs(obsn(ii1,:)))/4; %y
Cos(i,ii3+4) = 0;
Cos(i,ii3+5) = 0;
disd(1) = sqrt((pyobs(obsn(ii1,1))-pyobs(obsn(ii1,4)))^2+(pxobs(obsn(ii1,1))-pxobs(obsn(ii1,4)))^2);
disd(2) = sqrt((pyobs(obsn(ii1,2))-pyobs(obsn(ii1,4)))^2+(pxobs(obsn(ii1,2))-pxobs(obsn(ii1,4)))^2);
disd(3) = sqrt((pyobs(obsn(ii1,3))-pyobs(obsn(ii1,4)))^2+(pxobs(obsn(ii1,3))-pxobs(obsn(ii1,4)))^2);
[disd idisd] = sort(disd);
Cos(i,ii3+6) = disd(2)*1.2; %a
Cos(i,ii3+7) = disd(1)*1.2; %b
Cos(i,ii3+8) = atan((pyobs(obsn(ii1,idisd(2)))-pyobs(obsn(ii1,idisd(1))))/...
(pxobs(obsn(ii1,idisd(2)))-pxobs(obsn(ii1,idisd(1))))); %phi
Cos(i,ii3+9) = 0;
end
Co = Cos(i,:);
end
r_tr_old = r_tr;
b_tr_old = b_tr;
end % if all leds found
end % while loop
stop(vid);

回答(1 个)

Walter Roberson
Walter Roberson 2014-3-19
if length(rrpts) was not 2 and one of the other conditions in
(length(rrpts) ~= 2) && (length(rbpts) ~= 2) || (length(rrpts) ~= 1) && (length(rbpts) ~= 1)
did not hold, then you would not execute the code that assigns to x(i) y(i) theta(i)

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by