任务目标
无人机自主解锁,在完成飞行任务后进行自主降落
难点
难以判断是否落地然后停桨
解决方案
调用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
20import 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
- 在这里调用
- 通过
调用mavros的服务使其自动降落
- 在这里调用
/mavros/set_mode
服务进行模式切换,可切换的模式有:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17static 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
4import 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 | /mavlink/from |
我是学生,给我钱