dronekit / dronekit-python

DroneKit-Python library for communicating with Drones via MAVLink.
https://readthedocs.org/projects/dronekit-python/
Apache License 2.0
1.5k stars 1.42k forks source link

Unable to Update a Specific Mission Item in DroneKit: Seeking Guidance on a Workaround #1217

Open furkan-hub opened 5 months ago

furkan-hub commented 5 months ago

Hello friends, the other day while working with DroneKit, I noticed that I couldn't update a specific mission item. For example:

drone = connect("tcp:127.0.0.1:5772", wait_ready=True, rate=100)

command_drone = drone.commands

command_drone.download()
command_drone.wait_ready()

print(command_drone[2])
print(command_drone[2].x)
command_drone[2].x = -35.3611350
command_drone[2].y = 149.1648817

print(command_drone[2])
command_drone.upload()

I found that when I did this, the specific mission item wasn't being updated. It wasn't even sending the mission item at all. In any case, I had to call a function like .add(command_drone[2]) and then upload to update the mission item properly. However, this approach was adding an extra mission item to the end of the mission.

To address this issue, I started looking into the library's code and realized that there isn't a direct function to update a mission item. As a temporary solution, I added the following function:

    '''
    When you want to change the mission command only, use this function before upload.
    '''
    self.wait_ready()
    self._vehicle._wpts_dirty = True

This function sets the self._vehicle._wpts_dirty variable to True, even if you don't add any commands, allowing you to execute the .upload() function without using the .add() function. I'm not sure if this is a correct solution. Can you confirm if this is a valid approach, or suggest an alternative solution?