Skip to content

Commit

Permalink
added method to insert a waypoint into commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ashum68 committed Aug 16, 2024
1 parent b55dfd3 commit ea9c7d8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions mavlink/modules/flight_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,32 @@ def get_next_waypoint(self) -> "tuple[bool, drone_odometry.DronePosition | None]
if command.command == self.__MAVLINK_WAYPOINT_COMMAND:
return drone_odometry.DronePosition.create(command.x, command.y, command.z)
return False, None

def insert_waypoint(self, index, latitude: float, longitude: float, altitude: float) -> bool:
"""
Insert a waypoint into the current list of commands at a certain index and reupload the list to the drone.
"""
result, commands = self.download_commands()
if not result:
return False

new_waypoint = dronekit.Command(
0,
0,
0,
self.__MAVLINK_LANDING_FRAME,
self.__MAVLINK_WAYPOINT_COMMAND,
0,
0,
0, # param1
0,
0,
0,
latitude,
longitude,
altitude,
)

commands.insert(index, new_waypoint)

return self.upload_commands(commands)

0 comments on commit ea9c7d8

Please sign in to comment.