# px4_ros2 **Repository Path**: potato77/px4_ros2 ## Basic Information - **Project Name**: px4_ros2 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2026-01-26 - **Last Updated**: 2026-02-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # px4_ros2 ## 安装 // 下载代码 git clone https://gitee.com/potato77/px4_ros2 // 编译 cd px4_ros2 && ./build.sh // 记得source // gazebo仿真包ROS-gz sudo apt install ros-jazzy-ros-gz ## 启动 // 启动DDS端 MicroXRCEAgent udp4 -p 8888 // 启动订阅PX4话题 ros2 run uav_control sub_all_px4_msgs // 启动动捕 ? // 发送动捕数据到PX4 ros2 run uav_control mocap_to_px4 ## gazebo仿真 1.启动PX4 SITL仿真 ``` make px4_sitl gz_x500 ``` 2.启动MicroXRCEAgent ``` MicroXRCEAgent udp4 -p 8888 ``` 3.启动QGC地面站 ``` ./QGroundControl-x86_64.AppImage ``` ### 使用px4默认控制器 4.启动指点飞行节点 ``` ros2 run uav_control send_px4_pos_cmd ``` 运行该节点后,无人机会在固定高度按正方形轨迹飞行,最后回到原点降落并结束节点。 ### 使用SO3控制器 4.启动launch文件 ``` ros2 launch uav_control simulator_example.launch.py ``` 启动后无人机会飞往(0,5,5)点并悬停。控制器修改自https://github.com/ZJU-FAST-Lab/ego-planner-swarm.git,全链路修改为PX4要求的NED系和FRD系。 ## 备忘录 新建一个包 ros2 pkg create --build-type ament_cmake 新建一个python包 ros2 pkg create --build-type ament_python my_package 查看gazebo版本 gz sim --version gz环境变量:修改bashrc,增加如下: export GZ_SIM_RESOURCE_PATH=/path/to/your/resources:$GZ_SIM_RESOURCE_PATH 验证是否添加gz环境变量成功:能够看到对应的路径名字 echo $GZ_SIM_RESOURCE_PATH 添加参考: export GZ_SIM_RESOURCE_PATH=~/px4_ros2/px4_gz_simulation/worlds:$GZ_SIM_RESOURCE_PATH export GZ_SIM_RESOURCE_PATH=~/px4_ros2/px4_gz_simulation/models:$GZ_SIM_RESOURCE_PATH export GZ_SIM_RESOURCE_PATH=~/px4_ros2/px4_gz_simulation/models/scence_models:$GZ_SIM_RESOURCE_PATH export GZ_SIM_RESOURCE_PATH=~/px4_ros2/px4_gz_simulation/models/sensor_models:$GZ_SIM_RESOURCE_PATH export GZ_SIM_RESOURCE_PATH=~/px4_ros2/px4_gz_simulation/models/drone_models:$GZ_SIM_RESOURCE_PATH export GZ_SIM_RESOURCE_PATH=~/px4_ros2/px4_gz_simulation/models/ugv_models:$GZ_SIM_RESOURCE_PATH export GZ_SIM_RESOURCE_PATH=~/px4_ros2/px4_gz_simulation/models/world_models:$GZ_SIM_RESOURCE_PATH ## px4_msg_listener.cpp - 订阅 无人机当前状态 - /fmu/out/vehicle_status 无人机电池状态 - /fmu/out/battery_status 无人机当前位置,速度 - /fmu/out/vehicle_local_position 订阅无人机当前欧拉角(qTOeuler) - /fmu/out/vehicle_attitude - 打印 有一个1秒刷新一次的打印函数,输出到终端,打印的时候记得带单位 ## mocap_to_px4.cpp - 订阅: vrpn数据的话题(刚体的名字为ros参数,可以在laucnh中修改) 一个是位置话题 一个是速度话题 分别订阅得到 - 发布 px4_vision_pose_pub = this->create_publisher("/fmu/in/vehicle_visual_odometry", 10); - 打印: 打印一下vrpn的原始数据 - 这个程序写完后,能够和px4_msg_listener联动检查: vehicle_local_position的位置与vrpn数据一致; vehicle_attitude的yaw数据和vrpn数据一致 ## send_px4_pos_cmd.cpp:控制无人机去几个离散的点 - 发布 - /fmu/in/offboard_control_mode - /fmu/in/vehicle_command - /fmu/in/trajectory_setpoint ## fastlio_to_px4.cpp