PX4 / PX4-Autopilot

PX4 Autopilot Software
https://px4.io
BSD 3-Clause "New" or "Revised" License
8.21k stars 13.38k forks source link

[Bug] offboard example can not work in real drone #22592

Open Mendeler opened 8 months ago

Mendeler commented 8 months ago

Describe the bug

Horizon Sunrise X3 PI is used; The system is Ubuntu20.04 + ros2; The flight controller is PixHawk 5x, firmware PX4 v1.14; Use uXRCE-DDS middleware for communication; A problem occurred when I ran the ROS 2 Offboard Control Example. In the simulation, execute

source install/setup.bash
ros2 run px4_ros_com sensor_combined_listener

I can see the drone taking off in the simulation, but on the actual aircraft, the drone does not respond, but the mode is successfully switched to offboard, and uXRCE-DDS can communicate;

To Reproduce

  1. run make px4_sitl gazebo in a shell
  2. In another shell source a ROS2 workspace with the micro_ros_agent, px4_msgs and px4_ros_com packages installed.
  3. In that shell run ros2 run MicroXRCEAgent serial -D /dev/ttyUSB0 -b 57600
  4. Start QGroundControl to be able to observe the drones behaviour better
  5. In another shell source that workspace again and run ros2 run px4_ros_com offboard_control

Expected behavior

run MicroXRCEAgent serial -D /dev/ttyUSB0 -b 57600 image

run ros2 run px4_ros_com offboard_control image

run ros2 topic echo /fmu/in/offboard_control_mode image

run ros2 topic echo /fmu/in/trajectory_setpoint image

run ros2 topic list image

But I cannot subscribe to the information of /fmu/out/vehicle_attitude and /fmu/out/vehicle_local_position; I follow, the result of executing the command listener offboard_control_mode is never published;

In Mavlink console,i check some topic as follow: `nsh: sysinit: fopen failed: No such file or directory

NuttShell (NSH) NuttX-11.0.0 nsh> listener offboard_control_mode never published nsh> listener trajectory_setpoint never published nsh> listener vehicle_command

TOPIC: vehicle_command vehicle_command timestamp: 25522531 (45.739536 seconds ago) param5: 0.000000 param6: 0.000000 param1: 1.00000 param2: 0.00000 param3: 0.00000 param4: 0.00000 param7: 0.00000 command: 400 target_system: 1 target_component: 1 source_system: 1 source_component: 0 confirmation: 1 from_external: False

nsh> nsh> listener vehicle_attitude

TOPIC: vehicle_attitude vehicle_attitude timestamp: 548617839 (0.002848 seconds ago) timestamp_sample: 548617197 (642 us before timestamp) q: [0.56360, -0.01876, -0.01652, 0.82566] (Roll: -2.8 deg, Pitch: 0.7 deg, Yaw: 111.3 deg) delta_q_reset: [0.56851, -0.00000, -0.00000, 0.82267] quat_reset_counter: 1

nsh> listener vehicle_local_position

TOPIC: vehicle_local_position vehicle_local_position timestamp: 893554907 (0.011224 seconds ago) timestamp_sample: 893553765 (1142 us before timestamp) ref_timestamp: 0 ref_lat: nan ref_lon: nan x: -0.00003 y: 0.00004 z: 1.55658 delta_xy: [0.00000, -0.00000] delta_z: 0.00000 vx: 0.00003 vy: 0.00010 vz: 0.00044 z_deriv: 0.00053 delta_vxy: [0.00000, -0.00000] delta_vz: 0.00077 ax: -0.01433 ay: 0.00354 az: -0.00041 heading: 1.93719 delta_heading: 1.93219 ref_alt: nan dist_bottom: 0.10044 eph: 0.01528 epv: 0.28516 evh: 0.04270 evv: 0.06929 vxy_max: inf vz_max: inf hagl_min: inf hagl_max: inf xy_valid: False z_valid: True v_xy_valid: False v_z_valid: True xy_reset_counter: 1 z_reset_counter: 1 vxy_reset_counter: 1 vz_reset_counter: 1 heading_reset_counter: 1 heading_good_for_control: False`

        offboard_control_mode_publisher_ = this->create_publisher<OffboardControlMode>("/fmu/in/offboard_control_mode", 10);
        trajectory_setpoint_publisher_ = this->create_publisher<TrajectorySetpoint>("/fmu/in/trajectory_setpoint", 10);
        vehicle_command_publisher_ = this->create_publisher<VehicleCommand>("/fmu/in/vehicle_command", 10);

Of the three topics sent, only vehicle_command seems to have been published.

Screenshot / Media

No response

Flight Log

https://logs.px4.io/plot_app?log=08d8bcd4-5666-4c82-b39e-1f3d3976d670

Software Version

PX4 v1.14

Flight controller

PixHawk 5x

Vehicle type

Multicopter

How are the different components wired up (including port information)

No response

Additional context

No response

Mendeler commented 8 months ago

Referring to https://github.com/PX4/PX4-Autopilot/issues/22558, I increased the baud rate and was able to run the listener offboard_control_mode and listener trajectory_setpoint in the Mavlink console of QGC. Both data appeared, and the flight mode was switched to Offboard;

root@ubuntu:/userdata/ws_ros# ros2 run px4_ros_com offboard_control
Starting offboard control node...
[INFO] [1704201282.802507466] [offboard_control]: Arm command send

But there seems to be a problem here. The offboard control node is switched successfully, but the flight status is still Ready To Fly instead of changing to Flying;

By the way, I want to fly indoors without linking to GPS. EKF2_AID_MASK has been deprecated in v1.14;Under the offboard control node, if I manually arm, a MAV_CMD(400) warning will appear; And I set the value of the parameter COM_ARM_WO_GPS to Allow arming without GPS, the value of the parameter EKF2_HGT_REF to Barometer pressure

Is the inability to arm because the GPS is not connected? If GPS is not used, what parameters should I set in the new version?