No more globals (except in gui and demo)
parent
cc829d36ae
commit
653d4ef131
|
@ -3,9 +3,7 @@
|
||||||
|
|
||||||
% Make sure global variables are visible on command prompt
|
% Make sure global variables are visible on command prompt
|
||||||
% so you can examine how they change as you step through
|
% so you can examine how they change as you step through
|
||||||
global data
|
global frame_i data noiseModels isam result options
|
||||||
global poseNoise pointNoise odometryNoise measurementNoise
|
|
||||||
global frame_i isam result
|
|
||||||
|
|
||||||
% Start GUI
|
% Start GUI
|
||||||
VisualISAM_gui
|
VisualISAM_gui
|
|
@ -10,10 +10,6 @@
|
||||||
% @author Duy-Nguyen Ta
|
% @author Duy-Nguyen Ta
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
%% Global variables used in VisualISAMExample
|
|
||||||
global options data isam result frame_i
|
|
||||||
global poseNoise odometryNoise pointNoise measurementNoise
|
|
||||||
|
|
||||||
% Data Options
|
% Data Options
|
||||||
options.triangle = false;
|
options.triangle = false;
|
||||||
options.nrCameras = 20;
|
options.nrCameras = 20;
|
||||||
|
@ -39,13 +35,13 @@ options.saveDotFiles = false;
|
||||||
data = VisualISAMGenerateData(options);
|
data = VisualISAMGenerateData(options);
|
||||||
|
|
||||||
%% Initialize iSAM with the first pose and points
|
%% Initialize iSAM with the first pose and points
|
||||||
VisualISAMInitialize(options)
|
[noiseModels,isam,result] = VisualISAMInitialize(data,options);
|
||||||
figure(1);
|
figure(1);
|
||||||
VisualISAMPlot(data, isam, result, options)
|
VisualISAMPlot(data, isam, result, options)
|
||||||
|
|
||||||
%% Main loop for iSAM: stepping through all poses
|
%% Main loop for iSAM: stepping through all poses
|
||||||
for frame_i=3:options.nrCameras
|
for frame_i=3:options.nrCameras
|
||||||
VisualISAMStep
|
[isam,result] = VisualISAMStep(data,noiseModels,isam,result,options);
|
||||||
if mod(frame_i,options.drawInterval)==0
|
if mod(frame_i,options.drawInterval)==0
|
||||||
VisualISAMPlot(data, isam, result, options)
|
VisualISAMPlot(data, isam, result, options)
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,10 +10,6 @@
|
||||||
% @author Duy-Nguyen Ta
|
% @author Duy-Nguyen Ta
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
%% Global variables used in VisualISAMExample
|
|
||||||
global options data isam result frame_i
|
|
||||||
global poseNoise odometryNoise pointNoise measurementNoise
|
|
||||||
|
|
||||||
% Data Options
|
% Data Options
|
||||||
options.triangle = true;
|
options.triangle = true;
|
||||||
options.nrCameras = 10;
|
options.nrCameras = 10;
|
||||||
|
@ -39,13 +35,13 @@ options.saveDotFiles = false;
|
||||||
data = VisualISAMGenerateData(options);
|
data = VisualISAMGenerateData(options);
|
||||||
|
|
||||||
%% Initialize iSAM with the first pose and points
|
%% Initialize iSAM with the first pose and points
|
||||||
VisualISAMInitialize(options)
|
[noiseModels,isam,result] = VisualISAMInitialize(data,options);
|
||||||
figure(1);
|
figure(1);
|
||||||
VisualISAMPlot(data, isam, result, options)
|
VisualISAMPlot(data, isam, result, options)
|
||||||
|
|
||||||
%% Main loop for iSAM: stepping through all poses
|
%% Main loop for iSAM: stepping through all poses
|
||||||
for frame_i=3:options.nrCameras
|
for frame_i=3:options.nrCameras
|
||||||
VisualISAMStep
|
[isam,result] = VisualISAMStep(data,noiseModels,isam,result,options);
|
||||||
if mod(frame_i,options.drawInterval)==0
|
if mod(frame_i,options.drawInterval)==0
|
||||||
VisualISAMPlot(data, isam, result, options)
|
VisualISAMPlot(data, isam, result, options)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,22 +1,15 @@
|
||||||
function VisualInitialize(options)
|
function [noiseModels,isam,result] = VisualInitialize(data,options)
|
||||||
% VisualInitialize: initialize visualSLAM::iSAM object and noise parameters
|
% VisualInitialize: initialize visualSLAM::iSAM object and noise parameters
|
||||||
% Authors: Duy Nguyen Ta and Frank Dellaert
|
% Authors: Duy Nguyen Ta and Frank Dellaert
|
||||||
|
|
||||||
% global variables, input
|
|
||||||
global data
|
|
||||||
|
|
||||||
% global variables, output
|
|
||||||
global isam frame_i result
|
|
||||||
global poseNoise odometryNoise pointNoise measurementNoise
|
|
||||||
|
|
||||||
%% Initialize iSAM
|
%% Initialize iSAM
|
||||||
isam = visualSLAMISAM(options.reorderInterval);
|
isam = visualSLAMISAM(options.reorderInterval);
|
||||||
|
|
||||||
%% Set Noise parameters
|
%% Set Noise parameters
|
||||||
poseNoise = gtsamSharedNoiseModel_Sigmas([0.001 0.001 0.001 0.1 0.1 0.1]');
|
noiseModels.pose = gtsamSharedNoiseModel_Sigmas([0.001 0.001 0.001 0.1 0.1 0.1]');
|
||||||
odometryNoise = gtsamSharedNoiseModel_Sigmas([0.001 0.001 0.001 0.1 0.1 0.1]');
|
noiseModels.odometry = gtsamSharedNoiseModel_Sigmas([0.001 0.001 0.001 0.1 0.1 0.1]');
|
||||||
pointNoise = gtsamSharedNoiseModel_Sigma(3, 0.1);
|
noiseModels.point = gtsamSharedNoiseModel_Sigma(3, 0.1);
|
||||||
measurementNoise = gtsamSharedNoiseModel_Sigma(2, 1.0);
|
noiseModels.measurement = gtsamSharedNoiseModel_Sigma(2, 1.0);
|
||||||
|
|
||||||
%% Add constraints/priors
|
%% Add constraints/priors
|
||||||
newFactors = visualSLAMGraph;
|
newFactors = visualSLAMGraph;
|
||||||
|
@ -26,7 +19,7 @@ for frame_i=1:2
|
||||||
if frame_i==1 & options.hardConstraint % add hard constraint
|
if frame_i==1 & options.hardConstraint % add hard constraint
|
||||||
newFactors.addPoseConstraint(ii,data.cameras{1}.pose);
|
newFactors.addPoseConstraint(ii,data.cameras{1}.pose);
|
||||||
else
|
else
|
||||||
newFactors.addPosePrior(ii,data.cameras{frame_i}.pose, poseNoise);
|
newFactors.addPosePrior(ii,data.cameras{frame_i}.pose, noiseModels.pose);
|
||||||
end
|
end
|
||||||
% TODO: init should not be from ground truth!
|
% TODO: init should not be from ground truth!
|
||||||
initialEstimates.insertPose(ii,data.cameras{frame_i}.pose);
|
initialEstimates.insertPose(ii,data.cameras{frame_i}.pose);
|
||||||
|
@ -38,7 +31,7 @@ for frame_i=1:2
|
||||||
for j=1:size(data.points,2)
|
for j=1:size(data.points,2)
|
||||||
jj = symbol('l',j);
|
jj = symbol('l',j);
|
||||||
zij = data.cameras{frame_i}.project(data.points{j});
|
zij = data.cameras{frame_i}.project(data.points{j});
|
||||||
newFactors.addMeasurement(zij, measurementNoise, ii, jj, data.K);
|
newFactors.addMeasurement(zij, noiseModels.measurement, ii, jj, data.K);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,7 +39,7 @@ end
|
||||||
for j=1:size(data.points,2)
|
for j=1:size(data.points,2)
|
||||||
jj = symbol('l',j);
|
jj = symbol('l',j);
|
||||||
if options.pointPriors % add point priors
|
if options.pointPriors % add point priors
|
||||||
newFactors.addPointPrior(jj, data.points{j}, pointNoise);
|
newFactors.addPointPrior(jj, data.points{j}, noiseModels.point);
|
||||||
end
|
end
|
||||||
initialEstimates.insertPoint(jj, data.points{j}); % TODO: should not be from ground truth!
|
initialEstimates.insertPoint(jj, data.points{j}); % TODO: should not be from ground truth!
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,33 +1,25 @@
|
||||||
function VisualISAMStep
|
function [isam,result] = VisualISAMStep(data,noiseModels,isam,result,options);
|
||||||
% VisualISAMStep: execute one update step of visualSLAM::iSAM object
|
% VisualISAMStep: execute one update step of visualSLAM::iSAM object
|
||||||
% Authors: Duy Nguyen Ta and Frank Dellaert
|
% Authors: Duy Nguyen Ta and Frank Dellaert
|
||||||
|
|
||||||
% global variables, input
|
|
||||||
global options data odometryNoise measurementNoise frame_i
|
|
||||||
|
|
||||||
% global variables, input/output
|
|
||||||
global isam
|
|
||||||
|
|
||||||
% global variables, output
|
|
||||||
global result
|
|
||||||
|
|
||||||
% iSAM expects us to give it a new set of factors
|
% iSAM expects us to give it a new set of factors
|
||||||
% along with initial estimates for any new variables introduced.
|
% along with initial estimates for any new variables introduced.
|
||||||
newFactors = visualSLAMGraph;
|
newFactors = visualSLAMGraph;
|
||||||
initialEstimates = visualSLAMValues;
|
initialEstimates = visualSLAMValues;
|
||||||
|
|
||||||
%% Add odometry
|
%% Add odometry
|
||||||
newFactors.addOdometry(symbol('x',frame_i-1), symbol('x',frame_i), data.odometry, odometryNoise);
|
i = double(result.nrPoses)+1;
|
||||||
|
newFactors.addOdometry(symbol('x',i-1), symbol('x',i), data.odometry, noiseModels.odometry);
|
||||||
|
|
||||||
%% Add visual measurement factors
|
%% Add visual measurement factors
|
||||||
for j=1:size(data.points,2)
|
for j=1:size(data.points,2)
|
||||||
zij = data.cameras{frame_i}.project(data.points{j});
|
zij = data.cameras{i}.project(data.points{j});
|
||||||
newFactors.addMeasurement(zij, measurementNoise, symbol('x',frame_i), symbol('l',j), data.K);
|
newFactors.addMeasurement(zij, noiseModels.measurement, symbol('x',i), symbol('l',j), data.K);
|
||||||
end
|
end
|
||||||
|
|
||||||
%% Initial estimates for the new pose.
|
%% Initial estimates for the new pose.
|
||||||
prevPose = result.pose(symbol('x',frame_i-1));
|
prevPose = result.pose(symbol('x',i-1));
|
||||||
initialEstimates.insertPose(symbol('x',frame_i), prevPose.compose(data.odometry));
|
initialEstimates.insertPose(symbol('x',i), prevPose.compose(data.odometry));
|
||||||
|
|
||||||
%% Update ISAM
|
%% Update ISAM
|
||||||
% figure(1);tic;
|
% figure(1);tic;
|
||||||
|
|
|
@ -224,28 +224,28 @@ function saveGraphsCB_Callback(hObject, ~, handles)
|
||||||
% --- Executes on button press in intializeButton.
|
% --- Executes on button press in intializeButton.
|
||||||
function intializeButton_Callback(hObject, ~, handles)
|
function intializeButton_Callback(hObject, ~, handles)
|
||||||
|
|
||||||
global options data isam result
|
global frame_i data noiseModels isam result options
|
||||||
|
|
||||||
% initialize global options
|
% initialize global options
|
||||||
global options
|
|
||||||
initOptions(handles)
|
initOptions(handles)
|
||||||
|
|
||||||
% Generate Data
|
% Generate Data
|
||||||
data = VisualISAMGenerateData(options);
|
data = VisualISAMGenerateData(options);
|
||||||
|
|
||||||
% Initialize and plot
|
% Initialize and plot
|
||||||
VisualISAMInitialize(options)
|
[noiseModels,isam,result] = VisualISAMInitialize(data,options);
|
||||||
VisualISAMPlot(data, isam, result, options)
|
VisualISAMPlot(data, isam, result, options)
|
||||||
|
frame_i = 2;
|
||||||
showFramei(hObject, handles)
|
showFramei(hObject, handles)
|
||||||
|
|
||||||
|
|
||||||
% --- Executes on button press in runButton.
|
% --- Executes on button press in runButton.
|
||||||
function runButton_Callback(hObject, ~, handles)
|
function runButton_Callback(hObject, ~, handles)
|
||||||
global options data frame_i isam result
|
global frame_i data noiseModels isam result options
|
||||||
while (frame_i<size(data.cameras,2))
|
while (frame_i<size(data.cameras,2))
|
||||||
frame_i = frame_i+1;
|
frame_i = frame_i+1;
|
||||||
showFramei(hObject, handles)
|
showFramei(hObject, handles)
|
||||||
VisualISAMStep
|
[isam,result] = VisualISAMStep(data,noiseModels,isam,result,options);
|
||||||
if mod(frame_i,options.drawInterval)==0
|
if mod(frame_i,options.drawInterval)==0
|
||||||
showWaiting(handles, 'Computing marginals...');
|
showWaiting(handles, 'Computing marginals...');
|
||||||
VisualISAMPlot(data, isam, result, options)
|
VisualISAMPlot(data, isam, result, options)
|
||||||
|
@ -256,11 +256,11 @@ end
|
||||||
|
|
||||||
% --- Executes on button press in stepButton.
|
% --- Executes on button press in stepButton.
|
||||||
function stepButton_Callback(hObject, ~, handles)
|
function stepButton_Callback(hObject, ~, handles)
|
||||||
global options data frame_i isam result
|
global frame_i data noiseModels isam result options
|
||||||
if (frame_i<size(data.cameras,2))
|
if (frame_i<size(data.cameras,2))
|
||||||
frame_i = frame_i+1;
|
frame_i = frame_i+1;
|
||||||
showFramei(hObject, handles)
|
showFramei(hObject, handles)
|
||||||
VisualISAMStep
|
[isam,result] = VisualISAMStep(data,noiseModels,isam,result,options);
|
||||||
showWaiting(handles, 'Computing marginals...');
|
showWaiting(handles, 'Computing marginals...');
|
||||||
VisualISAMPlot(data, isam, result, options)
|
VisualISAMPlot(data, isam, result, options)
|
||||||
showWaiting(handles, '');
|
showWaiting(handles, '');
|
||||||
|
@ -269,7 +269,8 @@ end
|
||||||
% --- Executes on button press in plotButton.
|
% --- Executes on button press in plotButton.
|
||||||
function plotButton_Callback(hObject, ~, handles)
|
function plotButton_Callback(hObject, ~, handles)
|
||||||
showWaiting(handles, 'Computing marginals...');
|
showWaiting(handles, 'Computing marginals...');
|
||||||
VisualISAMPlot;
|
global options data isam result
|
||||||
|
VisualISAMPlot(data, isam, result, options);
|
||||||
showWaiting(handles, '');
|
showWaiting(handles, '');
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue