用matlab解析ulg文件,方便日志分析处理。matlab官网都有教程,不过贴在这儿节省朋友们一点时间。
path = '测试数据\20240814\';
ulog = ulogreader([path 'log100.ulg']);
topicName = ulog.AvailableTopics.TopicNames; % string array
instanceID = ulog.AvailableTopics.InstanceID; % array
dataCol = length(instanceID);
for i = 1:dataCol
name = topicName{i};
switch name
case "debug_vect"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
debug_vect = msg.TopicMessages{1,1};
case "estimator_aid_src_fake_pos"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
estimator_aid_src_fake_pos = msg.TopicMessages{1,1};
case "estimator_event_flags"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
estimator_event_flags = msg.TopicMessages{1,1};
case "estimator_innovation_test_ratios"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
estimator_innovation_test_ratios = msg.TopicMessages{1,1};
case "estimator_innovation_variances"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
estimator_innovation_variances = msg.TopicMessages{1,1};
case "estimator_innovations"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
estimator_innovations = msg.TopicMessages{1,1};
case "estimator_sensor_bias"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
estimator_sensor_bias = msg.TopicMessages{1,1};
case "estimator_states"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
estimator_states = msg.TopicMessages{1,1};
case "estimator_status"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
estimator_status = msg.TopicMessages{1,1};
case "estimator_status_flags"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
estimator_status_flags = msg.TopicMessages{1,1};
case "event"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
event = msg.TopicMessages{1,1};
case "sensor_combined"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
sensor_combined = msg.TopicMessages{1,1};
case "sensor_selection"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
sensor_selection = msg.TopicMessages{1,1};
case "vehicle_air_data"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
vehicle_air_data = msg.TopicMessages{1,1};
case "vehicle_attitude"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
vehicle_attitude = msg.TopicMessages{1,1};
case "vehicle_command"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
vehicle_command = msg.TopicMessages{1,1};
case "vehicle_land_detected"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
vehicle_land_detected = msg.TopicMessages{1,1};
case "vehicle_magnetometer"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
vehicle_magnetometer = msg.TopicMessages{1,1};
case "vehicle_odometry"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
vehicle_odometry = msg.TopicMessages{1,1};
case "vehicle_status"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
vehicle_status = msg.TopicMessages{1,1};
case "simulink_custom_message"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
simulink_custom_message = msg.TopicMessages{1,1};
case "ekf2_timestamps"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
ekf2_timestamps = msg.TopicMessages{1,1};
case "vehicle_imu"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
vehicle_imu = msg.TopicMessages{1,1};
case "vehicle_local_position"
msg = readTopicMsgs(ulog,'TopicNames',{name}, 'InstanceID',{instanceID(i)});
vehicle_local_position = msg.TopicMessages{1,1};
otherwise
continue
end
end