After careful analysis, I found the problem. The second input parameter of the addRelativePose function, "measurement", can easily be misinterpreted as a relative value in the global world coordinate system, but in fact it is a relative observed value relative to the current ego, as shown in the following diagram, with the pentagram being the observed target and theta being the observed angle (note that theta is in radians).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1219122/image.jpeg)
%% poseGraph 姿态轨迹图问题
load measurements.mat
pg = poseGraph();
preAbsPose = rigidtform2d();
absPoseCum = [];
numsNodes = numel(relPoses);
for i = 1:numsNodes
currRelPose = relPoses(i);% note:这里的相对姿态数值单位是指参考的基准是世界坐标系(一般不变)
currAbsPose = rigidtform2d(currRelPose.A*preAbsPose.A);% Calculated absolute pose
absPoseCum = [absPoseCum;preAbsPose];
% measurement = [currRelPose.A(1,3),currRelPose.A(2,3),deg2rad(currRelPose.RotationAngle)];
relR = preAbsPose.R'*currAbsPose.R; % https://ww2.mathworks.cn/matlabcentral/answers/1720045-how-to-get-the-relative-camera-pose-to-another-camera-pose
relT = preAbsPose.R'*(currAbsPose.Translation'-preAbsPose.Translation');
eul = rotm2eul(blkdiag(relR,1));
measurement = [relT(1),relT(2),eul(1)];% Relative measurement pose, [x,y,theta] format,theta is in radians.
addRelativePose(pg,measurement);
preAbsPose = currAbsPose;
end
%% plot trajectory result
figure;pg.show();title("poseGraph node trajectory")
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1219137/image.png)
traj = [];
for i = 1:numel(absPoseCum)
A = absPoseCum(i).A;
traj = [traj;A(1,3),A(2,3)];
end
figure;plot(traj(:,1),traj(:,2),'k-');axis equal;grid on;
title("calculate trajectory")
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1219142/image.png)
Now they are the same.
-------------------------Off-topic interlude, 2024-------------------------------
I am currently looking for a job in the field of CV algorithm development, based in Shenzhen, Guangdong, China,or a remote support position. I would be very grateful if anyone is willing to offer me a job or make a recommendation. My preliminary resume can be found at: https://cuixing158.github.io/about/ . Thank you!
Email: cuixingxing150@gmail.com