在机器人的开发中,通常会使用rosbag工具来分析机器人的一些性能指标是否符合要求,在Windows平台,使用matlab分析rosbag是一个不错的选择,这里给出简单的使用示例:
示例:读取rosbag中机器人的位置信息,并绘图分析。
%% rosbag auto
auto_filepath = fullfile('F:\MatlabFiles\rosbag\robot_pose_test\pose_test_init.bag');
auto_bag = rosbag(auto_filepath);
robot_pose_auto_topic = select(auto_bag, 'Topic', '/robot_pose');
% pose_msgs = readMessages(select(bag, 'Topic', '/pose_topic', 'MessageType', 'geometry_msgs/Pose'));
robot_pose_auto_data = readMessages(robot_pose_auto_topic);
robot_pose_x = zeros(length(robot_pose_auto_data), 1);
robot_pose_y = zeros(length(robot_pose_auto_data), 1);
for i = 1:length(robot_pose_auto_data)
robot_pose_x(i) = robot_pose_auto_data{i}.Position.X;
robot_pose_y(i) = robot_pose_auto_data{i}.Position.Y;
end
plot(robot_pose_x, robot_pose_y, 'r-', 'LineWidth', 1);
hold on;
%% rosbag teach
teach_bag = rosbag('F:\MatlabFiles\rosbag\robot_pose_test\teach_pose_test.bag');
robot_pose_teach_topic = select(teach_bag, 'Topic', '/robot_pose');
robot_pose_teach_data = readMessages(robot_pose_teach_topic);
robot_pose_teach_x = zeros(length(robot_pose_teach_data), 1);
robot_pose_teach_y = zeros(length(robot_pose_teach_data), 1);
for i = 1:length(robot_pose_teach_data)
robot_pose_teach_x(i) = robot_pose_teach_data{i}.Position.X;
robot_pose_teach_y(i) = robot_pose_teach_data{i}.Position.Y;
end
plot(robot_pose_teach_x, robot_pose_teach_y, 'g-', 'LineWidth', 1);