Hi my new friend!

无人机降落

  • Home
  • 无人机降落
Scroll down

任务目标

无人机自主解锁,在完成飞行任务后进行自主降落

难点

难以判断是否落地然后停桨

解决方案

  1. 调用mavros的服务使其自动解锁
    注:千万不要自动offboard

    • 通过rosservice list可以查阅到可调用的服务:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      /mavros/cmd/arming
      /mavros/cmd/command
      /mavros/cmd/command_ack
      /mavros/cmd/command_int
      /mavros/cmd/land
      /mavros/cmd/set_home
      /mavros/cmd/takeoff
      /mavros/cmd/trigger_control
      /mavros/cmd/trigger_interval
      /mavros/cmd/vtol_transition
      /mavros/ftp/checksum
      /mavros/ftp/close
      /mavros/ftp/list
      /mavros/ftp/mkdir
      /mavros/ftp/open
      /mavros/ftp/read
      /mavros/ftp/remove
      /mavros/ftp/rename
      /mavros/ftp/reset
      /mavros/ftp/rmdir
      /mavros/ftp/truncate
      /mavros/ftp/write
      /mavros/geofence/clear
      /mavros/geofence/pull
      /mavros/geofence/push
      /mavros/get_loggers
      /mavros/home_position/req_update
      /mavros/mission/clear
      /mavros/mission/pull
      /mavros/mission/push
      /mavros/mission/set_current
      /mavros/param/get
      /mavros/param/pull
      /mavros/param/push
      /mavros/param/set
      /mavros/rallypoint/clear
      /mavros/rallypoint/pull
      /mavros/rallypoint/push
      /mavros/set_logger_level
      /mavros/set_message_interval
      /mavros/set_mode
      /mavros/set_stream_rate
      /mavros/setpoint_position/mav_frame
      /mavros/setpoint_trajectory/mav_frame
      /mavros/setpoint_trajectory/reset
      /mavros/setpoint_velocity/mav_frame
      /mavros/vehicle_info_get
      /rosout/get_loggers
      /rosout/set_logger_level
      • 在这里调用/mavros/cmd/arming服务进行解锁
        Python代码为:
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        import rospy
        from mavros_msgs.srv import SetMode, CommandBool, CommandBoolRequest

        def arm():
        rospy.init_node('takeoff_node', anonymous=True)

        # 等待连接
        rospy.wait_for_service('mavros/cmd/arming')

        arming_service = rospy.ServiceProxy('mavros/cmd/arming', CommandBool)

        # 解锁和解锁无人机
        arm_command = CommandBoolRequest(value=False)
        arming_service.call(arm_command)

        if __name__ == '__main__':
        try:
        arm()
        except rospy.ROSInterruptException:
        pass
  2. 调用mavros的服务使其自动降落

    • 在这里调用/mavros/set_mode服务进行模式切换,可切换的模式有:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      static const cmode_map px4_cmode_map{{
      { px4::define_mode(px4::custom_mode::MAIN_MODE_MANUAL), "MANUAL" },
      { px4::define_mode(px4::custom_mode::MAIN_MODE_ACRO), "ACRO" },
      { px4::define_mode(px4::custom_mode::MAIN_MODE_ALTCTL), "ALTCTL" },
      { px4::define_mode(px4::custom_mode::MAIN_MODE_POSCTL), "POSCTL" },
      { px4::define_mode(px4::custom_mode::MAIN_MODE_OFFBOARD), "OFFBOARD" },
      { px4::define_mode(px4::custom_mode::MAIN_MODE_STABILIZED), "STABILIZED" },
      { px4::define_mode(px4::custom_mode::MAIN_MODE_RATTITUDE), "RATTITUDE" },
      { px4::define_mode_auto(px4::custom_mode::SUB_MODE_AUTO_MISSION), "AUTO.MISSION" },
      { px4::define_mode_auto(px4::custom_mode::SUB_MODE_AUTO_LOITER), "AUTO.LOITER" },
      { px4::define_mode_auto(px4::custom_mode::SUB_MODE_AUTO_RTL), "AUTO.RTL" },
      { px4::define_mode_auto(px4::custom_mode::SUB_MODE_AUTO_LAND), "AUTO.LAND" },
      { px4::define_mode_auto(px4::custom_mode::SUB_MODE_AUTO_RTGS), "AUTO.RTGS" },
      { px4::define_mode_auto(px4::custom_mode::SUB_MODE_AUTO_READY), "AUTO.READY" },
      { px4::define_mode_auto(px4::custom_mode::SUB_MODE_AUTO_TAKEOFF), "AUTO.TAKEOFF" },
      { px4::define_mode_auto(px4::custom_mode::SUB_MODE_AUTO_FOLLOW_TARGET), "AUTO.FOLLOW_TARGET" },
      { px4::define_mode_auto(px4::custom_mode::SUB_MODE_AUTO_PRECLAND), "AUTO.PRECLAND" },}};
    • 调用示例
      1
      2
      3
      4
      import rospy
      from mavros_msgs.srv import CommandBool, CommandBoolRequest, SetMode, SetModeRequest
      set_mode_client = rospy.ServiceProxy("/mavros/set_mode", SetMode)
      set_mode_client(0,'AUTO.LAND')

附录:mavros的话题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/mavlink/from
/mavlink/gcs_ip
/mavlink/to
/mavros/actuator_control
/mavros/altitude
/mavros/battery
/mavros/estimator_status
/mavros/extended_state
/mavros/geofence/waypoints
/mavros/global_position/compass_hdg
/mavros/global_position/global
/mavros/global_position/gp_lp_offset
/mavros/global_position/gp_origin
/mavros/global_position/local
/mavros/global_position/raw/fix
/mavros/global_position/raw/gps_vel
/mavros/global_position/raw/satellites
/mavros/global_position/rel_alt
/mavros/global_position/set_gp_origin
/mavros/hil/actuator_controls
/mavros/hil/controls
/mavros/hil/gps
/mavros/hil/imu_ned
/mavros/hil/optical_flow
/mavros/hil/rc_inputs
/mavros/hil/state
/mavros/home_position/home
/mavros/home_position/set
/mavros/imu/data
/mavros/imu/data_raw
/mavros/imu/diff_pressure
/mavros/imu/mag
/mavros/imu/static_pressure
/mavros/imu/temperature_baro
/mavros/imu/temperature_imu
/mavros/local_position/accel
/mavros/local_position/odom
/mavros/local_position/pose
/mavros/local_position/pose_cov
/mavros/local_position/velocity_body
/mavros/local_position/velocity_body_cov
/mavros/local_position/velocity_local
/mavros/manual_control/control
/mavros/manual_control/send
/mavros/mission/reached
/mavros/mission/waypoints
/mavros/nav_controller_output
/mavros/param/param_value
/mavros/radio_status
/mavros/rallypoint/waypoints
/mavros/rc/in
/mavros/rc/out
/mavros/rc/override
/mavros/setpoint_accel/accel
/mavros/setpoint_attitude/cmd_vel
/mavros/setpoint_attitude/thrust
/mavros/setpoint_position/global
/mavros/setpoint_position/global_to_local
/mavros/setpoint_position/local
/mavros/setpoint_raw/attitude
/mavros/setpoint_raw/global
/mavros/setpoint_raw/local
/mavros/setpoint_raw/target_attitude
/mavros/setpoint_raw/target_global
/mavros/setpoint_raw/target_local
/mavros/setpoint_trajectory/desired
/mavros/setpoint_trajectory/local
/mavros/setpoint_velocity/cmd_vel
/mavros/setpoint_velocity/cmd_vel_unstamped
/mavros/state
/mavros/statustext/recv
/mavros/statustext/send
/mavros/sys_status
/mavros/target_actuator_control
/mavros/time_reference
/mavros/timesync_status
/mavros/vfr_hud
/mavros/wind_estimation

我是学生,给我钱

其他文章
目录导航 置顶
  1. 1. 任务目标
  2. 2. 难点
  3. 3. 解决方案
请输入关键词进行搜索