当我通过 Mission Planner 上传到 Pixhawk,然后再次下载时,似乎没有任何问题。但是当我使用 Dronekit 上传任务文件时,它回来看起来很奇怪。
这是我用来上传的(简化的)代码:
upload_mission_file("D:\TestMission.txt")
# Upload mission file
def upload_mission_file(file_name):
mission_list = load_mission(file_name)
# Clear existing mission from vehicle
print(' Clear mission')
cmds = communications_global.vehicle.commands
cmds.clear()
# Add new mission to vehicle
for command in mission_list:
cmds.add(command)
#for command in cmds:
# print(str(command))
print('Upload mission')
communications_global.vehicle.commands.upload()
print("Uploaded mission")
# Load mission from file
def load_mission(file_name):
# Load a mission from a file into a list. The mission definition is in the Waypoint file
# format (http://qgroundcontrol.org/mavlink/waypoint_protocol#waypoint_file_format).
# This function is used by upload_mission().
print("\nReading mission from file: %s" % file_name)
cmds = communications_global.vehicle.commands
missionlist = []
with open(file_name) as f:
for i, line in enumerate(f):
if i == 0:
if not line.startswith('QGC WPL 110'):
raise Exception('File is not supported WP version')
else:
linearray = line.split('\t')
ln_index = int(linearray[0])
ln_currentwp = int(linearray[1])
ln_frame = int(linearray[2])
ln_command = int(linearray[3])
ln_param1 = float(linearray[4])
ln_param2 = float(linearray[5])
ln_param3 = float(linearray[6])
ln_param4 = float(linearray[7])
ln_param5 = float(linearray[8])
ln_param6 = float(linearray[9])
ln_param7 = float(linearray[10])
ln_autocontinue = int(linearray[11].strip())
cmd = Command(0, 0, 0, ln_frame, ln_command, ln_currentwp, ln_autocontinue, ln_param1, ln_param2,
ln_param3, ln_param4, ln_param5, ln_param6, ln_param7)
missionlist.append(cmd)
return missionlist
--
这是我上传的内容:
QGC WPL 110
0 1 0 16 0 0 0 0 -41.5066668 173.7577779 100 1
1 0 0 178 0.00000000 0.50000000 50.00000000 0.00000000 0.00000000 0.00000000 0.000000 1
2 0 3 16 0 0 0 0 -41.5066668 173.7577779 100 0
3 0 3 16 0 0 0 0 -41.5066667 173.7577778 100 0
4 0 3 16 0 0 0 0 -41.5066666 173.7577777 100 0
5 0 3 16 0 0 0 0 -41.5066665 173.7577776 100 0
6 0 3 16 0 0 0 0 -41.5066664 173.7577775 100 0
7 0 3 16 0 0 0 0 -41.5066663 173.7577774 100 0
8 0 3 16 0 0 0 0 -41.5066662 173.7577773 100 0
9 0 3 16 0 0 0 0 -41.5066661 173.7577772 100 0
10 0 3 16 0 0 0 0 -41.5066660 173.7577771 100 0
这是我通过任务规划器下载它时返回的内容:
QGC WPL 110
0 1 0 16 0 0 0 0 -35.363262 149.165237 1168.000000 1
1 0 0 178 0.00000000 0.50000000 50.00000000 0.00000000 0.00000000 0.00000000 0.000000 1
2 0 3 16 0.00000000 0.00000000 0.00000000 0.00000000 -41.50666880 173.75778560 100.000000 1
3 0 3 16 0.00000000 0.00000000 0.00000000 0.00000000 -41.50666880 173.75778560 100.000000 1
4 0 3 16 0.00000000 0.00000000 0.00000000 0.00000000 -41.50666880 173.75778560 100.000000 1
5 0 3 16 0.00000000 0.00000000 0.00000000 0.00000000 -41.50666880 173.75778560 100.000000 1
6 0 3 16 0.00000000 0.00000000 0.00000000 0.00000000 -41.50666880 173.75778560 100.000000 1
7 0 3 16 0.00000000 0.00000000 0.00000000 0.00000000 -41.50666880 173.75778560 100.000000 1
8 0 3 16 0.00000000 0.00000000 0.00000000 0.00000000 -41.50666880 173.75778560 100.000000 1
9 0 3 16 0.00000000 0.00000000 0.00000000 0.00000000 -41.50666560 173.75778560 100.000000 1
10 0 3 16 0.00000000 0.00000000 0.00000000 0.00000000 -41.50666560 173.75778560 100.000000 1
我已经阅读了官方dronekit 文档中的舍入问题: https ://dronekit-python.readthedocs.io/en/latest/examples/mission_import_export.html
但是,我一直检查到最终上传,似乎没有任何舍入问题。因此,除非它在 pymavlink 库或 pixhawk 本身的深处(我怀疑这是因为通过任务规划器上传和下载不会导致此问题),否则我认为这不是问题。
有人有什么想法吗?