How can i add current location as a waypoint via python while proceeding a mission?

Hello, I am trying to create a system like;
While my plane/drone is going to a waypoint, the minute it detects something with image processing I need to get the target’s location and i need to add this location as a waypoint with python automatically for the next tour. I have ben researching it for days but i couldn’t find the adding this location as a waypoint yet. Can you walk me through a way to do this?
Thanks in adance.

Start from here, you can manipulate mission with lua. In the script there is an example on how to add current position to the end of wp list.

There are also different way of doing it, you could read current position, store it and than add it to the file mission using python or whatever language you are familiar with. Just make sure to follow file format while editing it.

Lua i think is the easiest and more elegant at the moment.

A walk trough is a bit difficult, just start researching the link and ask whenever you find a problem you can’t solve.