| 
									
										
										
										
											2012-06-13 22:58:15 +08:00
										 |  |  | function [isam,result] = VisualISAMStep(data,noiseModels,isam,result,truth, options)
 | 
					
						
							| 
									
										
										
										
											2012-06-10 11:31:09 +08:00
										 |  |  | % VisualISAMStep: execute one update step of visualSLAM::iSAM object | 
					
						
							|  |  |  | % Authors: Duy Nguyen Ta and Frank Dellaert | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | % iSAM expects us to give it a new set of factors  | 
					
						
							|  |  |  | % along with initial estimates for any new variables introduced. | 
					
						
							| 
									
										
										
										
											2012-06-10 13:00:42 +08:00
										 |  |  | newFactors = visualSLAMGraph; | 
					
						
							|  |  |  | initialEstimates = visualSLAMValues; | 
					
						
							| 
									
										
										
										
											2012-06-09 04:08:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | %% Add odometry | 
					
						
							| 
									
										
										
										
											2012-06-13 20:05:39 +08:00
										 |  |  | i = result.nrPoses+1; | 
					
						
							| 
									
										
										
										
											2012-06-11 06:32:24 +08:00
										 |  |  | odometry = data.odometry{i-1}; | 
					
						
							|  |  |  | newFactors.addOdometry(symbol('x',i-1), symbol('x',i), odometry, noiseModels.odometry); | 
					
						
							| 
									
										
										
										
											2012-06-09 04:08:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-13 22:58:15 +08:00
										 |  |  | %% Add visual measurement factors and initializations as necessary | 
					
						
							|  |  |  | for k=1:length(data.Z{i}) | 
					
						
							|  |  |  |     zij = data.Z{i}{k}; | 
					
						
							|  |  |  |     j = data.J{i}{k}; | 
					
						
							|  |  |  |     jj = symbol('l', j); | 
					
						
							|  |  |  |     newFactors.addMeasurement(zij, noiseModels.measurement, symbol('x',i), jj, data.K); | 
					
						
							|  |  |  |     % TODO: initialize with something other than truth | 
					
						
							|  |  |  |     if ~result.exists(jj) && ~initialEstimates.exists(jj) | 
					
						
							|  |  |  |         lmInit = truth.points{j}; | 
					
						
							|  |  |  |         initialEstimates.insertPoint(jj, lmInit); | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-06-09 04:08:53 +08:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-10 13:00:42 +08:00
										 |  |  | %% Initial estimates for the new pose. | 
					
						
							| 
									
										
										
										
											2012-06-11 02:46:56 +08:00
										 |  |  | prevPose = result.pose(symbol('x',i-1)); | 
					
						
							| 
									
										
										
										
											2012-06-11 06:32:24 +08:00
										 |  |  | initialEstimates.insertPose(symbol('x',i), prevPose.compose(odometry)); | 
					
						
							| 
									
										
										
										
											2012-06-09 04:08:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | %% Update ISAM | 
					
						
							|  |  |  | % figure(1);tic; | 
					
						
							|  |  |  | isam.update(newFactors, initialEstimates); | 
					
						
							|  |  |  | % t=toc; plot(frame_i,t,'r.'); tic | 
					
						
							|  |  |  | result = isam.estimate(); | 
					
						
							|  |  |  | % t=toc; plot(frame_i,t,'g.'); | 
					
						
							| 
									
										
										
										
											2012-06-10 13:00:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-10 23:26:59 +08:00
										 |  |  | if options.alwaysRelinearize % re-linearize | 
					
						
							| 
									
										
										
										
											2012-06-09 04:08:53 +08:00
										 |  |  |     isam.reorder_relinearize(); | 
					
						
							|  |  |  | end |