How to convert .csv/.xlsl to .waypoints?

Dear all,

I would like to use python to create 360 versions of a mission plan, so that I can quickly load the right one up on my experiment day depending on the direction of the wind.

I am doing the following but get stuck at step 4:

  1. Create one .waypoints file in mission planner
  2. Convert it (save as) .xlsx or .csv
  3. Use python to adjust these xlsx/csv’s and create e.g. 360 of versions of them
  4. Convert these xlsx’s back to .waypoints files.

Can anyone suggest a good way help me on this last step, i.e. convert back to .waypoints? “Saving as” and then changing to .waypoints will not do the trick (I am guessing due to encodings).

Any alternatives approaches are welcome, too. All insights are appreciated!

Erik

There is an example in here:
https://dronekit-python.readthedocs.io/en/latest/examples/mission_import_export.html

1 Like

Thanks, Mustafa. It was not exactly what I was looking for, but I stripped out parts which I needed. It isn’t necessary to convert to xlsx after all, but rather easier to stay in txt format and adjust there.

An example of the code I am using is found below in case anyone is looking for something similar. Use and verify at your own caution of course.

#!/usr/bin/env python
# -- coding: utf-8 --

def adjust_waypoints_file(filename_, deg):
    with open(filename_) as f:

        # Add file-format information
        output = 'QGC WPL 110\n'

        # Adjust lines and add back to output
        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:
                lines = line.split('\t')

                real_lines = lines # use real_lines = lines[0].split() if you are using Python 2.7 (for dronekit)

                # EXTRACT FROM TXT FILE
                ln_index = int(real_lines[0])
                ln_currentwp = int(real_lines[1])
                ln_frame = int(real_lines[2])
                ln_command = int(real_lines[3])
                ln_param1 = float(real_lines[4])
                ln_param2 = float(real_lines[5])
                ln_param3 = float(real_lines[6])
                ln_param4 = float(real_lines[7])
                ln_param5 = float(real_lines[8])
                ln_param6 = float(real_lines[9])
                ln_param7 = float(real_lines[10])
                ln_autocontinue = int(real_lines[11].strip())

                # ALTER STUFF HERE, FOR EXAMPLE
                if ln_index == 2:
                    ln_param1 += deg

                # NOW AMEND BACK TO TXT / WAYPOINTS FILE
                commandline = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % (
                    ln_index, ln_currentwp, ln_frame, ln_command,
                    ln_param1, ln_param2, ln_param3, ln_param4,
                    ln_param5, ln_param6, ln_param7, ln_autocontinue)

                output += commandline
    return output


# Set how you want to automate the file writing
max_degree = 10
increment = 2

# Select the file you want to work from
filename = "waypoints_in/120m_wind0deg.waypoints"
add_new_home = False

# Loop through the increments and save
for deg in range(max_degree):
    if deg % increment == 0:

        # Scan through and adjust waypoint
        output = adjust_waypoints_file(filename, deg)

        # Save output file
        filename_out = f"waypoints_out/120m_wind{deg}deg.waypoints"
        with open(filename_out, 'w') as file_:
            file_.write(output)
            print("Mission written!")

1 Like