IRDYn/getTorqueData.m

74 lines
2.2 KiB
Mathematica
Raw Permalink Normal View History

2025-10-23 07:47:58 +00:00
%
load('idntfcnTrjctryCell_full2.mat');
%
data = idntfcnTrjctryCell{7,1};
[num_samples, ~] = size(data);
%
joint_cols = 105:3:126; % J1J8 (105,108,111,...,126)
% 2000 Hz
t = (0:num_samples-1)' / 2000; %
%
for joint_idx = 1:8
%
fig = figure('Position', [100, 100, 800, 500], 'Color', 'white');
%
col = joint_cols(joint_idx);
if joint_idx == 8
torque = data(:, joint_cols(joint_idx-1)+2);
else
torque = data(:, joint_cols(joint_idx));
end
%
[max_abs, max_idx] = max(abs(torque));
max_time = t(max_idx);
max_value = torque(max_idx);
% 线
plot(t, torque, 'b-', 'LineWidth', 1.5);
%
hold on;
plot(max_time, max_value, 'ro', 'MarkerSize', 10, 'LineWidth', 2);
%
annotation_text = sprintf('Max Abs Torque: %.3f Nm\\nAt Time: %.3f s', max_abs, max_time);
text(0.98, 0.98, annotation_text, ...
'Units', 'normalized', ...
'VerticalAlignment', 'top', ...
'HorizontalAlignment', 'right', ...
'FontSize', 12, ...
'BackgroundColor', [1 1 1 0.7], ...
'Margin', 5, ...
'EdgeColor', 'k');
%
title(sprintf('J%d Torque vs Time', joint_idx), 'FontSize', 16, 'FontWeight', 'bold');
xlabel('Time (s)', 'FontSize', 14);
ylabel('Torque (Nm)', 'FontSize', 14);
grid on;
%
% xlim([min(t), max(t)]);
% y_range = max_abs * 1.3; % Y
% ylim([-y_range, y_range]);
%
text(0.98, 0.02, 'Sampling Rate: 2000 Hz', ...
'Units', 'normalized', ...
'FontSize', 10, ...
'HorizontalAlignment', 'right', ...
'BackgroundColor', [1 1 1 0.5]);
% PNG
filename = sprintf('Torque_joint_%d.png', joint_idx);
saveas(fig, filename);
fprintf('Saved: %s\n', filename);
%
close(fig);
end