Skip to content

Commit

Permalink
update comments for all classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Qu committed May 11, 2014
1 parent edd9f4d commit 7b92272
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 90 deletions.
19 changes: 9 additions & 10 deletions code/PoseEdge.m
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
%%%
%> @file PoseNode.m
%> @brief A class for edge in a pose graph
%%%
classdef PoseEdge < handle
%POSEEDGE A class for edge in a pose graph

properties (SetAccess = private)
id_from %> This is the viewing frame of this edge
id_to %> This is the pose being observed from the viewing frame
mean %> Predicted virtual measurement
infm %> Information matrix of this edge
end % properties
id_from % This is the viewing frame of this edge
id_to % This is the pose being observed from the viewing frame
mean % Predicted virtual measurement
infm % Information matrix of this edge
end % properties set private

methods

function obj = PoseEdge(id_from, id_to, mean, infm)
% Consturctor of PoseEdge
obj.id_from = id_from;
obj.id_to = id_to;
obj.mean = mean(:);
obj.infm = infm;
end
end % methods

end % methods public

end % classdef
61 changes: 21 additions & 40 deletions code/PoseGraph.m
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
%%%
%> @file PoseGraph.m
%> @brief A class for doing pose graph optimization
%%%
classdef PoseGraph < handle
%POSEGRAPH A class for doing pose graph optimization

properties (SetAccess = private)
node %> Pose nodes in graph
edge %> Edge in graph
H %> Information matrix
b %> Information vector
end
node % Pose nodes in graph
edge % Edge in graph
H % Information matrix
b % Information vector
end % properties set private

properties (Dependent = true)
n_node %> Number of nodes in graph
n_edge %> Number of edges in graph
pose %> Poses of all nodes
end
n_node % Number of nodes in graph
n_edge % Number of edges in graph
pose % Poses of all nodes
end % properties dependent

methods
%%%
%> @brief Class constructor
%> Instantiates an object of GraphSlam
%>
%> @return instance of the GraphSlam class
%%%

function obj = PoseGraph()
% Constructor of PoseGraph
obj.node = PoseNode.empty;
obj.edge = PoseEdge.empty;
end

function readGraph(obj, vfile, efile)
% Reads graph from vertex and edge file

% Try opening vertex file
vfid = fopen(vfile);
if (vfid < 0)
Expand Down Expand Up @@ -75,19 +69,13 @@ function readGraph(obj, vfile, efile)
fprintf('Edges loaded from: %s\n', vfile);
end

%%%
%> @brief Plot all nodes and edges
%%%
function plot(obj)
% Plots pose graph
obj.node.plot();
end

%%%
%> @brief pose graph optimization
%> @param n_iter Number of iteration to optimizae
%> @param vis True to turn visualization on
%%%
function optimize(obj, n_iter, vis)
% Pose graph optimization
if nargin < 3, vis = false; end
if nargin < 2, n_iter = 1; end

Expand All @@ -104,10 +92,8 @@ function optimize(obj, n_iter, vis)
end
end

%%%
%> @brief one iteration of linearization and solving
%%%
function iterate(obj)
% One iteration of pose graph optimization
fprintf('Allocating Workspace.\n');
% Create new H and b matrices each time
obj.H = zeros(obj.n_node*3); % 3n x 3n square matrix
Expand All @@ -119,11 +105,9 @@ function iterate(obj)
fprintf('Solving.\n');
obj.solve();
end

%%%
%> @brief Linearize error functions and formulate a linear system
%%%

function linearize(obj)
% Linearize error functions and formulate a linear system
for i_edge = 1:obj.n_edge
ei = obj.edge(i_edge);
% Get edge information
Expand Down Expand Up @@ -171,11 +155,9 @@ function linearize(obj)
obj.b(j_ind) = obj.b(j_ind) + b_j;
end
end

%%%
%> @brief solve the linear system and update all pose node
%%%

function solve(obj)
% Solves the linear system and update all pose node
fprintf('Pose: %d, Edge: %d\n', obj.n_node, obj.n_edge);
% The system (H b) is obtained only from relative constraints.
% H is not full rank.
Expand All @@ -195,7 +177,6 @@ function solve(obj)
end
end

% Get methods
function n_node = get.n_node(obj)
n_node = numel(obj.node);
end
Expand All @@ -208,7 +189,7 @@ function solve(obj)
pose = [obj.node.pose];
end

end % methods
end % methods public

end % classdef

Expand Down
43 changes: 15 additions & 28 deletions code/PoseNode.m
Original file line number Diff line number Diff line change
@@ -1,46 +1,33 @@
%%%
%> @file PoseNode.m
%> @brief A class for node in a pose graph
%%%
classdef PoseNode < handle
%POSENODE Summary of this class goes here
% Detailed explanation goes here
%POSENODE A class for pose node

properties
id %> Id of this pose node
pose %> Pose of this pose node
end
properties (Access = public)
id % Id of this pose node
pose % Pose of this pose node
end % properties public

properties (Dependent = true)
x %> X coordinate
y %> Y coordinate
yaw %> Yaw angle
rt %> Transformation local to global
end
properties (Dependent = true)
x % X coordinate
y % Y coordinate
yaw % Yaw angle
rt % Transformation local to global
end % properties dependent

methods
%%%
%> @brief Class constructor
%> Instantiates an object of PoseNode
%>
%> @param pose a robot pose in 2d [x; y; yaw]
%> @return instance of the PoseNode class
%%%

function obj = PoseNode(id, pose)
% Constructor of PoseNode
obj.id = id;
obj.pose = pose(:);
end

%%%
%> @brief Plot one or more pose node
%%%
function plot(obj)
% Plot all pose nodes position
x = [obj.x];
y = [obj.y];
plot(x, y, 'b');
end

% Get methods
function x = get.x(obj)
x = obj.pose(1);
end
Expand All @@ -59,6 +46,6 @@ function plot(obj)
rt = [R [obj.x; obj.y]; 0 0 1];
end

end % methods
end % methods public

end % classdef
7 changes: 1 addition & 6 deletions code/t2v.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
%%%
%> @brief computes the pose vector v from an homogeneous transformation A
%> param A homogeneous transformation
%> return v pose vector
%> @author Giorgio Grisetti
%%%
function v = t2v(A)
% T2V homogeneous transformation to vector
v(1:2,1) = A(1:2,3);
v(3,1) = atan2(A(2,1), A(1,1));

end
7 changes: 1 addition & 6 deletions code/v2t.m
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
%%%
%> @brief computes the homogeneous transformation A of the pose vector v
%> @param v pose vector
%> @return A homogeneous transformation
%> @author Giorgio Grisetti
%%%
function A = v2t(v)
% V2T vector to homogeneous transformation
c = cos(v(3));
s = sin(v(3));
A = [c, -s, v(1);
s, c, v(2);
0 0 1];

end

0 comments on commit 7b92272

Please sign in to comment.