Initialize now initailizes first two cameras, makes so much more sense!
parent
7eb449c205
commit
c784a9c7df
|
|
@ -8,7 +8,7 @@ global SAVE_GRAPH PRINT_STATS DRAW_INTERVAL CAMERA_INTERVAL DRAW_TRUE_POSES
|
||||||
global SAVE_FIGURES SAVE_GRAPHS SHOW_TIMING
|
global SAVE_FIGURES SAVE_GRAPHS SHOW_TIMING
|
||||||
global data
|
global data
|
||||||
global poseNoise pointNoise odometryNoise measurementNoise
|
global poseNoise pointNoise odometryNoise measurementNoise
|
||||||
global frame_i isam newFactors initialEstimates result
|
global frame_i isam result
|
||||||
|
|
||||||
% Start GUI
|
% Start GUI
|
||||||
VisualISAM_gui
|
VisualISAM_gui
|
||||||
|
|
@ -11,7 +11,8 @@
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
%% Global variables used in VisualISAMExample
|
%% Global variables used in VisualISAMExample
|
||||||
global data
|
global data isam frame_i result
|
||||||
|
global poseNoise odometryNoise pointNoise measurementNoise
|
||||||
global HARD_CONSTRAINT POINT_PRIORS BATCH_INIT REORDER_INTERVAL ALWAYS_RELINEARIZE
|
global HARD_CONSTRAINT POINT_PRIORS BATCH_INIT REORDER_INTERVAL ALWAYS_RELINEARIZE
|
||||||
global SAVE_GRAPH PRINT_STATS DRAW_INTERVAL CAMERA_INTERVAL DRAW_TRUE_POSES
|
global SAVE_GRAPH PRINT_STATS DRAW_INTERVAL CAMERA_INTERVAL DRAW_TRUE_POSES
|
||||||
global SAVE_FIGURES SAVE_GRAPHS
|
global SAVE_FIGURES SAVE_GRAPHS
|
||||||
|
|
@ -44,7 +45,7 @@ figure;
|
||||||
VisualISAMPlot
|
VisualISAMPlot
|
||||||
|
|
||||||
%% Main loop for iSAM: stepping through all poses
|
%% Main loop for iSAM: stepping through all poses
|
||||||
for frame_i=2:options.nrCameras
|
for frame_i=3:options.nrCameras
|
||||||
VisualISAMStep
|
VisualISAMStep
|
||||||
if mod(frame_i,DRAW_INTERVAL)==0
|
if mod(frame_i,DRAW_INTERVAL)==0
|
||||||
VisualISAMPlot
|
VisualISAMPlot
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
%% Global variables used in VisualISAMExample
|
%% Global variables used in VisualISAMExample
|
||||||
global data
|
global data isam frame_i result
|
||||||
|
global poseNoise odometryNoise pointNoise measurementNoise
|
||||||
global HARD_CONSTRAINT POINT_PRIORS BATCH_INIT REORDER_INTERVAL ALWAYS_RELINEARIZE
|
global HARD_CONSTRAINT POINT_PRIORS BATCH_INIT REORDER_INTERVAL ALWAYS_RELINEARIZE
|
||||||
global SAVE_GRAPH PRINT_STATS DRAW_INTERVAL CAMERA_INTERVAL DRAW_TRUE_POSES
|
global SAVE_GRAPH PRINT_STATS DRAW_INTERVAL CAMERA_INTERVAL DRAW_TRUE_POSES
|
||||||
global SAVE_FIGURES SAVE_GRAPHS
|
global SAVE_FIGURES SAVE_GRAPHS
|
||||||
|
|
@ -44,7 +45,7 @@ figure;
|
||||||
VisualISAMPlot
|
VisualISAMPlot
|
||||||
|
|
||||||
%% Main loop for iSAM: stepping through all poses
|
%% Main loop for iSAM: stepping through all poses
|
||||||
for frame_i=2:options.nrCameras
|
for frame_i=3:options.nrCameras
|
||||||
VisualISAMStep
|
VisualISAMStep
|
||||||
if mod(frame_i,DRAW_INTERVAL)==0
|
if mod(frame_i,DRAW_INTERVAL)==0
|
||||||
VisualISAMPlot
|
VisualISAMPlot
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
function VisualISAMStep
|
function VisualInitialize
|
||||||
% VisualISAMStep: execute one update step of visualSLAM::iSAM object
|
% VisualInitialize: initialize visualSLAM::iSAM object and noise parameters
|
||||||
% Authors: Duy Nguyen Ta and Frank Dellaert
|
% Authors: Duy Nguyen Ta and Frank Dellaert
|
||||||
|
|
||||||
|
% options
|
||||||
|
global REORDER_INTERVAL HARD_CONSTRAINT POINT_PRIORS BATCH_INIT ALWAYS_RELINEARIZE
|
||||||
|
|
||||||
% global variables, input
|
% global variables, input
|
||||||
global data pointNoise poseNoise measurementNoise
|
global data
|
||||||
|
|
||||||
% global variables, output
|
% global variables, output
|
||||||
global isam newFactors initialEstimates frame_i result
|
global isam frame_i result
|
||||||
global poseNoise odometryNoise pointNoise measurementNoise
|
global poseNoise odometryNoise pointNoise measurementNoise
|
||||||
|
|
||||||
% options
|
|
||||||
global REORDER_INTERVAL HARD_CONSTRAINT POINT_PRIORS
|
|
||||||
|
|
||||||
%% Initialize iSAM
|
%% Initialize iSAM
|
||||||
isam = visualSLAMISAM(REORDER_INTERVAL);
|
isam = visualSLAMISAM(REORDER_INTERVAL);
|
||||||
|
|
||||||
|
|
@ -24,27 +24,50 @@ measurementNoise = gtsamSharedNoiseModel_Sigma(2, 1.0);
|
||||||
%% Add constraints/priors
|
%% Add constraints/priors
|
||||||
newFactors = visualSLAMGraph;
|
newFactors = visualSLAMGraph;
|
||||||
initialEstimates = visualSLAMValues;
|
initialEstimates = visualSLAMValues;
|
||||||
i1 = symbol('x',1);
|
for frame_i=1:2
|
||||||
camera1 = data.cameras{1};
|
ii = symbol('x',frame_i);
|
||||||
pose1 = camera1.pose;
|
if frame_i==1 & HARD_CONSTRAINT % add hard constraint
|
||||||
if HARD_CONSTRAINT % add hard constraint
|
newFactors.addPoseConstraint(ii,data.cameras{1}.pose);
|
||||||
newFactors.addPoseConstraint(i1,pose1);
|
else
|
||||||
else
|
newFactors.addPosePrior(ii,data.cameras{frame_i}.pose, poseNoise);
|
||||||
newFactors.addPosePrior(i1,pose1, poseNoise);
|
end
|
||||||
|
% TODO: init should not be from ground truth!
|
||||||
|
initialEstimates.insertPose(ii,data.cameras{frame_i}.pose);
|
||||||
end
|
end
|
||||||
initialEstimates.insertPose(i1,pose1); % TODO: should not be from ground truth!
|
|
||||||
|
|
||||||
%% Add visual measurement factors from first pose
|
%% Add visual measurement factors from two first poses
|
||||||
|
for frame_i=1:2
|
||||||
|
ii = symbol('x',frame_i);
|
||||||
|
for j=1:size(data.points,2)
|
||||||
|
jj = symbol('l',j);
|
||||||
|
zij = data.cameras{frame_i}.project(data.points{j});
|
||||||
|
newFactors.addMeasurement(zij, measurementNoise, ii, jj, data.K);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
%% Initialize points, possibly add priors on them
|
||||||
for j=1:size(data.points,2)
|
for j=1:size(data.points,2)
|
||||||
jj = symbol('l',j);
|
jj = symbol('l',j);
|
||||||
if POINT_PRIORS % add point priors
|
if POINT_PRIORS % add point priors
|
||||||
newFactors.addPointPrior(jj, data.points{j}, pointNoise);
|
newFactors.addPointPrior(jj, data.points{j}, pointNoise);
|
||||||
end
|
end
|
||||||
zij = camera1.project(data.points{j});
|
|
||||||
newFactors.addMeasurement(zij, measurementNoise, i1, jj, data.K);
|
|
||||||
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
|
||||||
|
|
||||||
frame_i = 1;
|
%% Update ISAM
|
||||||
result = initialEstimates;
|
if BATCH_INIT % Do a full optimize for first two poses
|
||||||
|
fullyOptimized = newFactors.optimize(initialEstimates);
|
||||||
|
isam.update(newFactors, fullyOptimized);
|
||||||
|
else
|
||||||
|
isam.update(newFactors, initialEstimates);
|
||||||
|
end
|
||||||
|
% figure(1);tic;
|
||||||
|
% t=toc; plot(frame_i,t,'r.'); tic
|
||||||
|
result = isam.estimate();
|
||||||
|
% t=toc; plot(frame_i,t,'g.');
|
||||||
|
|
||||||
|
if ALWAYS_RELINEARIZE % re-linearize
|
||||||
|
isam.reorder_relinearize();
|
||||||
|
end
|
||||||
|
|
||||||
cla;
|
cla;
|
||||||
|
|
@ -6,6 +6,7 @@ global data frame_i isam result
|
||||||
|
|
||||||
% options
|
% options
|
||||||
global CAMERA_INTERVAL DRAW_TRUE_POSES SAVE_FIGURES SAVE_GRAPHS
|
global CAMERA_INTERVAL DRAW_TRUE_POSES SAVE_FIGURES SAVE_GRAPHS
|
||||||
|
global SAVE_GRAPH PRINT_STATS
|
||||||
|
|
||||||
%% Plot results
|
%% Plot results
|
||||||
h=gca;
|
h=gca;
|
||||||
|
|
@ -46,4 +47,12 @@ if SAVE_GRAPHS && (frame_i>1)
|
||||||
isam.saveGraph(sprintf('VisualiSAM%03d.dot',frame_i));
|
isam.saveGraph(sprintf('VisualiSAM%03d.dot',frame_i));
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if SAVE_GRAPH
|
||||||
|
isam.saveGraph(sprintf('VisualiSAM.dot',frame_i));
|
||||||
|
end
|
||||||
|
|
||||||
|
if PRINT_STATS
|
||||||
|
isam.printStats();
|
||||||
|
end
|
||||||
|
|
||||||
drawnow
|
drawnow
|
||||||
|
|
@ -3,7 +3,7 @@ function VisualISAMStep
|
||||||
% Authors: Duy Nguyen Ta and Frank Dellaert
|
% Authors: Duy Nguyen Ta and Frank Dellaert
|
||||||
|
|
||||||
% global variables, input
|
% global variables, input
|
||||||
global frame_i odometryNoise measurementNoise newFactors initialEstimates
|
global frame_i odometryNoise measurementNoise
|
||||||
global data
|
global data
|
||||||
|
|
||||||
% global variables, input/output
|
% global variables, input/output
|
||||||
|
|
@ -13,16 +13,12 @@ global isam
|
||||||
global result
|
global result
|
||||||
|
|
||||||
% options
|
% options
|
||||||
global BATCH_INIT SHOW_TIMING ALWAYS_RELINEARIZE
|
global SHOW_TIMING ALWAYS_RELINEARIZE
|
||||||
global SAVE_GRAPH PRINT_STATS
|
|
||||||
|
|
||||||
% 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.
|
||||||
% We do not clear in frame 2 so we add to the factors added in Initialize
|
newFactors = visualSLAMGraph;
|
||||||
if frame_i > 2
|
initialEstimates = visualSLAMValues;
|
||||||
newFactors = visualSLAMGraph;
|
|
||||||
initialEstimates = visualSLAMValues;
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Add odometry
|
%% Add odometry
|
||||||
newFactors.addOdometry(symbol('x',frame_i-1), symbol('x',frame_i), data.odometry, odometryNoise);
|
newFactors.addOdometry(symbol('x',frame_i-1), symbol('x',frame_i), data.odometry, odometryNoise);
|
||||||
|
|
@ -33,29 +29,17 @@ for j=1:size(data.points,2)
|
||||||
newFactors.addMeasurement(zij, measurementNoise, symbol('x',frame_i), symbol('l',j), data.K);
|
newFactors.addMeasurement(zij, measurementNoise, symbol('x',frame_i), symbol('l',j), data.K);
|
||||||
end
|
end
|
||||||
|
|
||||||
%% Initial estimates for the new pose. Also initialize data.points while in the first frame.
|
%% Initial estimates for the new pose.
|
||||||
if (frame_i==2), prevPose = data.cameras{1}.pose;
|
prevPose = result.pose(symbol('x',frame_i-1));
|
||||||
else, prevPose = result.pose(symbol('x',frame_i-1)); end
|
|
||||||
initialEstimates.insertPose(symbol('x',frame_i), prevPose.compose(data.odometry));
|
initialEstimates.insertPose(symbol('x',frame_i), prevPose.compose(data.odometry));
|
||||||
|
|
||||||
%% Update ISAM
|
%% Update ISAM
|
||||||
if BATCH_INIT & (frame_i==2) % Do a full optimize for first two poses
|
|
||||||
fullyOptimized = newFactors.optimize(initialEstimates);
|
|
||||||
initialEstimates = fullyOptimized;
|
|
||||||
end
|
|
||||||
% figure(1);tic;
|
% figure(1);tic;
|
||||||
isam.update(newFactors, initialEstimates);
|
isam.update(newFactors, initialEstimates);
|
||||||
% t=toc; plot(frame_i,t,'r.'); tic
|
% t=toc; plot(frame_i,t,'r.'); tic
|
||||||
result = isam.estimate();
|
result = isam.estimate();
|
||||||
% t=toc; plot(frame_i,t,'g.');
|
% t=toc; plot(frame_i,t,'g.');
|
||||||
|
|
||||||
if ALWAYS_RELINEARIZE % re-linearize
|
if ALWAYS_RELINEARIZE % re-linearize
|
||||||
isam.reorder_relinearize();
|
isam.reorder_relinearize();
|
||||||
end
|
end
|
||||||
|
|
||||||
if SAVE_GRAPH
|
|
||||||
isam.saveGraph(sprintf('VisualiSAM.dot',frame_i));
|
|
||||||
end
|
|
||||||
|
|
||||||
if PRINT_STATS
|
|
||||||
isam.printStats();
|
|
||||||
end
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue