Skip to content

Commit

Permalink
Merged in state_plugin (pull request #1)
Browse files Browse the repository at this point in the history
State plugin

Approved-by: Davide Antonio Cucci
  • Loading branch information
jbmag authored and Davide Antonio Cucci committed Mar 11, 2021
2 parents 31cb650 + 231317c commit b32d668
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 35 deletions.
2 changes: 1 addition & 1 deletion _development/Matlab/PluginViewer/plugins/GenericEdge.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function GenericEdge( area, globalConfig, pluginConfig )

yl = max(std(err));

title([pluginConfig.sensorName ' res']);
title([pluginConfig.sensorName ' res'], 'interpreter', 'none');

xlim([0, edge(end,1)-edge(1,1)])
ylim([-3*yl-eps 3*yl+eps]);
Expand Down
120 changes: 90 additions & 30 deletions _development/Matlab/PluginViewer/plugins/StateObserver.m
Original file line number Diff line number Diff line change
@@ -1,37 +1,97 @@
function StateObserver(area, globalConfig, pluginConfig)

edgef = sprintf('%s%s.log',globalConfig.logPath, pluginConfig.sensorName);
edgef = sprintf('%s%s.log',globalConfig.logPath, pluginConfig.sensorName);

if exist(edgef, 'file')

[edge, outcome] = stubbornLoad(edgef);

if outcome == 1
if exist(edgef, 'file')

subplot('Position', squeezeArea(area,0.02))

if strcmp(pluginConfig.stateComponent, 'x')
range = 4:6;
elseif strcmp(pluginConfig.stateComponent, 'q')
range = 7:10;
elseif strcmp(pluginConfig.stateComponent, 'v')
range = 11:13;
elseif strcmp(pluginConfig.stateComponent, 'w')
range = 14:16;
elseif strcmp(pluginConfig.stateComponent, 'a')
range = 17:19;
elseif strcmp(pluginConfig.stateComponent, 'alpha')
range = 20:22;
end

plot(edge(:,1) - edge(1,1),[edge(:,range)])

axis tight

title(sprintf('%s %s',pluginConfig.sensorName, pluginConfig.stateComponent));
end
end

[edge, outcome] = stubbornLoad(edgef);

if outcome == 1
isQuaternion = false;

subplot('Position', squeezeArea(area,0.05))
grid on
hold on
x_axis = 'Time [s]';
plot_legend = {};
if strcmp(pluginConfig.stateComponent, 'x')
range = 4:6;
state_name = 'Position';
y_axis = 'Position [m]';
plot_legend = {'x', 'y', 'z'};
elseif strcmp(pluginConfig.stateComponent, 'q')
range = 7:10;
isQuaternion = true;
state_name = 'Orientation';
y_axis = 'Orientation [rad]';
plot_legend = {'roll', 'pitch', 'yaw'};
elseif strcmp(pluginConfig.stateComponent, 'v')
range = 11:13;
state_name = 'Velocity';
y_axis = 'Velocity [m.s^{-1}]';
plot_legend = {'v_x', 'v_y', 'v_z'};
elseif strcmp(pluginConfig.stateComponent, 'w')
range = 14:16;
state_name = 'Angular Velocity';
y_axis = 'Angular Velocity [rad.s^{-1}]';
plot_legend = {'{\omega}_x', '{\omega}_y', '{\omega}_z'};
elseif strcmp(pluginConfig.stateComponent, 'a')
range = 17:19;
state_name = 'Acceleration';
y_axis = 'Acceleration [m.s^{-2}]';
plot_legend = {'a_x', 'a_y', 'a_z'};
elseif strcmp(pluginConfig.stateComponent, 'alpha')
range = 20:22;
y_axis = '';
end

if (isfield(pluginConfig', 'referenceFile') && exist(pluginConfig.referenceFile, 'file'))
if strcmp(pluginConfig.stateComponent, 'x')
range_gt = 2:4;
elseif strcmp(pluginConfig.stateComponent, 'q')
range_gt = 5:8;
isQuaternion = true;
elseif strcmp(pluginConfig.stateComponent, 'v')
range_gt = 9:11;
elseif strcmp(pluginConfig.stateComponent, 'w')
range_gt = 12:14;
elseif strcmp(pluginConfig.stateComponent, 'a')
range_gt = 15:17;
elseif strcmp(pluginConfig.stateComponent, 'alpha')
range_gt = 18:20;
end

[ground_truth, ~] = stubbornLoad(pluginConfig.referenceFile);

% get values of groundtruth when at the same timesteps than the measurements
reference = interp1(ground_truth(:,1), ground_truth(:,range_gt), edge(:,1));

if isQuaternion
quat_rot_error = quatprod(quatinv(edge(:,range)), reference);
state_error = rad2deg(quat2euler(quat_rot_error));
else
state_error = edge(:,range) - reference;
end
plot(edge(:,1) - edge(1,1), state_error)
title(sprintf('%s: error on estimated %s',pluginConfig.sensorName, state_name), 'interpreter', 'none');
else
if isQuaternion
rpy_from_quat = rad2deg(quat2euler(edge(:,range)));
plot(edge(:,1) - edge(1,1),rpy_from_quat)
else
plot(edge(:,1) - edge(1,1),edge(:,range))
end
title(sprintf('%s: estimated %s',pluginConfig.sensorName, state_name), 'interpreter', 'none');
end

axis tight

xlabel(x_axis);
ylabel([y_axis]);
legend(plot_legend);
hold off
end
end

end

10 changes: 6 additions & 4 deletions _development/Matlab/quatlib/quatprod.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
function ret = quatprod(q1, q2)
ret = [
q1(1)*q2(1) - q1(2)*q2(2) - q1(3)*q2(3) - q1(4)*q2(4);
q1(1)*q2(2) + q1(2)*q2(1) + q1(3)*q2(4) - q1(4)*q2(3);
q1(1)*q2(3) - q1(2)*q2(4) + q1(3)*q2(1) + q1(4)*q2(2);
q1(1)*q2(4) + q1(2)*q2(3) - q1(3)*q2(2) + q1(4)*q2(1);
q1(:,1).*q2(:,1) - q1(:,2).*q2(:,2) - q1(:,3).*q2(:,3) - q1(:,4).*q2(:,4), ...
q1(:,1).*q2(:,2) + q1(:,2).*q2(:,1) + q1(:,3).*q2(:,4) - q1(:,4).*q2(:,3), ...
q1(:,1).*q2(:,3) - q1(:,2).*q2(:,4) + q1(:,3).*q2(:,1) + q1(:,4).*q2(:,2), ...
q1(:,1).*q2(:,4) + q1(:,2).*q2(:,3) - q1(:,3).*q2(:,2) + q1(:,4).*q2(:,1)
];
a=q1(:,1).*q2(:,1) - q1(:,2).*q2(:,2) - q1(:,3).*q2(:,3) - q1(:,4).*q2(:,4);
b=q1(:,1).*q2(:,2) + q1(:,2).*q2(:,1) + q1(:,3).*q2(:,4) - q1(:,4).*q2(:,3);

end

0 comments on commit b32d668

Please sign in to comment.