@@ -569,6 +569,13 @@ def uploadMission(self, mission_type: int, waypoints: List[dict]) -> Response:
569569 }
570570
571571 def importMissionFromFile (self , mission_type : int , file_path : str ) -> Response :
572+ """
573+ Imports a mission from a file into the drone's mission loader, return the waypoints loaded.
574+
575+ Args:
576+ mission_type (int): The type of mission to import. 0=Mission,1=Fence,2=Rally.
577+ file_path (str): The path to the waypoint file to import.
578+ """
572579 mission_type_check = self ._checkMissionType (mission_type )
573580 if not mission_type_check .get ("success" ):
574581 return mission_type_check
@@ -602,15 +609,23 @@ def importMissionFromFile(self, mission_type: int, file_path: str) -> Response:
602609
603610 # Remove the first point if it's a command 16 as this is usually a home point or placeholder.
604611 if mission_type in [TYPE_FENCE , TYPE_RALLY ]:
605- first_wp = loader .item (0 )
606- if first_wp .command == 16 :
607- loader .remove (first_wp )
612+ if loader .count () > 0 :
613+ first_wp = loader .item (0 )
614+ if first_wp .command == 16 :
615+ loader .remove (first_wp )
616+ else :
617+ self .drone .logger .error ("Loader is empty; no waypoints to process." )
618+ return {
619+ "success" : False ,
620+ "message" : "Loader is empty; no waypoints to process." ,
621+ }
608622
609623 for wp in loader .wpoints :
610- if isinstance (wp .x , float ):
611- wp .x = int (wp .x * 1e7 )
612- if isinstance (wp .y , float ):
613- wp .y = int (wp .y * 1e7 )
624+ if hasattr (wp , "x" ) and hasattr (wp , "y" ):
625+ if isinstance (wp .x , float ):
626+ wp .x = int (wp .x * 1e7 )
627+ if isinstance (wp .y , float ):
628+ wp .y = int (wp .y * 1e7 )
614629
615630 self .drone .logger .info (
616631 f"Loaded waypoint file with { loader .count ()} points successfully"
0 commit comments