PX4 ULG日志文档解析

用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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将PX4飞行数据提取到Matlab中,可以按照以下步骤进行操作: 1. 首先,确保你已经安装了Matlab软件,并且已经安装了pyulog库。你可以在https://github.com/PX4/pyulog找到pyulog的安装教程。 2. 将存储有PX4飞行数据的存储卡插入读卡器,并将读卡器连接到计算机上。在存储卡中找到以.ulg结尾的日志文件,例如log001.ulg,并将其复制到计算机上。 3. 打开Matlab软件,并在命令窗口中导航到存储日志文件的文件夹。 4. 使用pyulog库中的ulog2csv命令将.ulg文件转换为.csv文件。在Matlab命令窗口中输入以下命令: ``` ulog2csv log001.ulg ``` 5. 执行上述命令后,将在当前文件夹中生成一系列导出的.csv文件,包含了各种飞行数据。 6. 使用Matlab的csvread函数或readmatrix函数来读取感兴趣的.csv文件中的数据。例如,要读取原始加速度计数据,可以使用以下命令: ``` data = csvread('log001_sensor_combined_0.csv', 1, 0); ``` 7. 现在,你可以在Matlab中使用data变量来处理和分析飞行数据了。 请注意,上述步骤中的文件名和变量名可能需要根据你的实际情况进行调整。此外,你还可以根据你的需求选择其他感兴趣的飞行数据进行提取和分析。 #### 引用[.reference_title] - *1* *2* [PX4日志读取并转化为.scv文件、MATLAB显示](https://blog.csdn.net/weixin_41869763/article/details/112617357)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值