pythondronekitpx4

Dronekit upload to Pixhawk 4 - rounding issue


When I upload to the Pixhawk via Mission Planner, and then download it again, there doesn't seem to be any issue. But when I use Dronekit to upload a mission file, it comes back looking very strange.

Here's the (simplified) code I use to upload:

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

--

Here's what I upload:

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

And here's what comes back when I download it via mission planner:

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

I've read about rounding issues in the official dronekit documentation: https://dronekit-python.readthedocs.io/en/latest/examples/mission_import_export.html

However, I've checked right up to the final upload, and there don't seem to be any rounding issues. So unless its something deep in the pymavlink library or on the pixhawk itself (which I doubt because uploading and downloading via mission planner does not cause this issue), I don't think this is the issue.

Anyone has any ideas?


Solution

  • I have made a post on the dronekit github explaining how to fix this issue. The issue linked below is one I created myself with the same question as above and I have answered it with the solution to this problem.

    https://github.com/dronekit/dronekit-python/issues/1005