-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransformation.m
More file actions
executable file
·65 lines (55 loc) · 2.66 KB
/
Copy pathTransformation.m
File metadata and controls
executable file
·65 lines (55 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
classdef(Sealed) Transformation
%Transformation Implements methods to get coordinate tranformation
%between Turtlebot's layers and components.
methods(Access = private)
function obj = Transformation()
end
end
methods(Static)
% Useful information
% Turtlebot3 Model Burger returns just a transformation, from odom
% coordinate system to the base_footprint.
% The coordinate frame transformation should be characterized just
% by small X, Y axes translations and Z axis rotation.
% To read the official definitions for odom and base_footprint
% follow the two reported links.
% odom -> https://www.ros.org/reps/rep-0105.html
% base_footprint -> https://www.ros.org/reps/rep-0120.html
function [convertedTf, n] = convertTransformation(msg)
%convertTransformation Convert a ROS TransformStamped object in
%a easy-to-read form.
% Messages published in /tf topic contain arrays of ROS
% TransformStamped object (geometry_msgs/TransformStamped
% type). convertTransformation methods extracts usefull
% information as Initial and Target Frame Names,
% translational vector and rotational angles.
% Translational vector contains, in order, [X, Y, Z] values.
% Rotational vector contains Euler's angles, hence [Z, Y, X]
% rotation values.
% convertedTf is an array of structs; each struct contains
% aforementioned properties.
% Output 'n' is the array length.
convertedTf = []; n = 0;
if ~isstruct(msg) || strcmp(msg.MessageType, ...
'tf2_msgs/TFMessage') ~= 1
disp("Input argument tf must be a Ros Message of type" +...
" tf2_msgs/TFMessaged");
return
end
n = numel(msg.Transforms);
for i=1:n
currentTf = msg.Transforms(i);
newTf = {};
newTf.inizialFrame = currentTf.Header.FrameId;
newTf.targetFrame = currentTf.ChildFrameId;
newTf.translation = [...
currentTf.Transform.Translation.X;
currentTf.Transform.Translation.Y;
currentTf.Transform.Translation.Z ];
quat = currentTf.Transform.Rotation;
newTf.eulRotation = quat2eul([quat.W quat.X quat.Y quat.Z])';
convertedTf = [convertedTf, newTf];
end
end
end
end