Example #1
0
    def getBatteryState(self, callback=None, timeout=10):
        """
        Returns:
            [BatteryState]: the current state of battery.
        """

        checkParameters(callback=callback,
                        method_name="BatteryState",
                        timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.GET_BATTERY_STATE,
            message_class=MessageBuilder.BATTETY,
            message_data=None,
        )

        return_type = BatteryState

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
Example #2
0
    def goToAction(self, coordinate, altitude, callback=None, timeout=10):
        """
        Go to the specified coordinate and altitude (in meters) from the current aircraft position.
        """

        checkParameters(callback=callback,
                        method_name="goToAction",
                        timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.GO_TO_ACTION,
            message_class=MessageBuilder.MISSION_ACTION,
            message_data={
                "coordinate": coordinate.__dict__,
                "altitude": altitude
            },
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
Example #3
0
    def aircraftYawAction(self, angle, isAbsolute, callback=None, timeout=10):
        """
        Initialize with a yaw angle relative to current heading or absolute heading against true north.
        The range of angle is [-180, 180]. This initializer should be preferred when accuracy of the angle
        is more of a priority than smooth yaw movement.
        """

        checkParameters(callback=callback,
                        method_name="aircraftYawAction",
                        timeout=timeout)

        is_absolute_str = "true" if isAbsolute else "false"
        message = MessageBuilder.build_message(
            message_method=MessageBuilder.AIRCRAFT_YAW_ACTION,
            message_class=MessageBuilder.MISSION_ACTION,
            message_data={
                "angle": angle,
                "isAbsolute": is_absolute_str
            },
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
Example #4
0
    def setDisplayMode(self, display_mode, callback=None, timeout=10):
        """
            Sets the display mode to coordinate the video feeds from both the visual camera and the thermal camera.
            Only supported by XT2 camera and Mavic 2 Enterprise Dual Thermal Camera.
        """

        checkParameters(callback=callback, method_name="setDisplayMode", timeout=timeout)

        #assert isinstance(display_mode, DisplayMode)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.SET_DISPLAY_MODE,
            message_class=MessageBuilder.CAMERA,
            message_data={"display_mode": display_mode}
        )

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=DJIError,
            blocking=blocking
        )
Example #5
0
    def getISO(self, callback=None, timeout=10):
        """
        Gets the camera's ISO value.
        """
        checkParameters(callback=callback, method_name="getISO", timeout=timeout)

        checkParameters(callback=callback, method_name="getExposureMode", timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.GET_ISO,
            message_class=MessageBuilder.CAMERA,
            message_data=None,
        )

        return_type = ISO

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
Example #6
0
    def setShutterSpeed(self, shutter_speed, callback=None, timeout=10):
        """
            Sets the camera's ISO value.

            See ISO to view all possible ISO settings for the camera.

            Args:
                - callback (function): The execution callback with the returned execution result.
                - shutter_speed (ShutterSpeed): The ISO value to set the camera to use.
        """
        checkParameters(
            callback=callback, method_name="setShutterSpeed", timeout=timeout,
        )

        assert isinstance(shutter_speed, ShutterSpeed)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.SET_SHUTTER_SPEED,
            message_class=MessageBuilder.CAMERA,
            message_data={"shutter_speed": shutter_speed.value},
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
Example #7
0
    def getShutterSpeed(self, callback=None, timeout=10):
        """
            Gets the camera's shutter speed.
        """

        checkParameters(callback=callback, method_name="getShutterSpeed", timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.GET_SHUTTER_SPEED,
            message_class=MessageBuilder.CAMERA,
            message_data=None,
        )

        return_type = ShutterSpeed

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
Example #8
0
    def setISO(self, iso, callback=None, timeout=10):
        """
            Sets the camera's ISO value.

            See ISO to view all possible ISO settings for the camera.

            Args:
                - callback (function): The execution callback with the returned execution result.
                - iso (ISO): 	The ISO value to set the camera to use.
        """
        checkParameters(
            callback=callback, method_name="setExposureMode", timeout=timeout,
        )

        assert isinstance(iso, ISO)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.SET_ISO,
            message_class=MessageBuilder.CAMERA,
            message_data={"iso": iso.value},
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
    def confirmLanding(self, callback=None, timeout=10):
        """
        Confirms continuation of landing action.
        When the clearance between the aircraft and the ground is less than 0.3m, the aircraft will pause landing and wait for user's confirmation.
        Can use isLandingConfirmationNeeded in FlightControllerState to check if confirmation is needed. It is supported by flight controller firmware 3.2.0.0 and above.

        Args:
            - callback (function): An callback function with a simgle parameter of type CustomError
            - timeout (int): A timeout seconds time
        """
        checkParameters(callback=callback,
                        method_name="confirmLanding",
                        timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.CONFIRM_LANDING,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data=None,
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
Example #10
0
    def stopMission(self, callback=None, timeout=10):
        "Stops the executing or paused mission."
        "It can only be called when the getCurrentState"
        "is one of the following: - EXECUTING - "
        "EXECUTION_PAUSED After a mission is stopped"
        "successfully, getCurrentState will become READY_TO_UPLOAD."

        checkParameters(callback=callback,
                        method_name="stopMission",
                        timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.STOP_MISSION,
            message_class=MessageBuilder.WAYPOINT_MISSION_OPERATOR,
            message_data=None,
        )

        blocking = callback is None

        return_type = DJIError

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
    def isConnected(self, timeout=1):
        """
        Gets boolean value from flight controller connection

        Args:
            - timeout (int): A timeout seconds time
        Returns:
            [boolean]: boolean value from flight controller connection.
        """

        checkParameters(callback=None, method_name="isConnected", timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.IS_CONNECTED,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data=None,
        )

        return_type = bool

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=None,
            timeout=timeout,
            return_type=return_type,
            blocking=True,
        )
Example #12
0
    def loadMission(self, mission, callback=None, timeout=10):
        """Loads the WaypointMission into device memory.
            This also verifies all the information of mission"""

        checkParameters(callback=callback,
                        method_name="loadMission",
                        timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.LOAD_MISSION,
            message_class=MessageBuilder.WAYPOINT_MISSION_OPERATOR,
            message_data={"data": mission.__dict__},
        )

        blocking = True

        return_type = DJIError

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
Example #13
0
    def rotate(self, pitch, roll, yaw, callback=None, timeout=10):
        """
        Rotate gimbal's pitch, roll, and yaw with ABSOLUTE_ANGLE.

        Args:
            - callback (function): An callback function with a simgle parameter of type DJIError
            - timeout (int): A timeout seconds time
        """
        checkParameters(callback=callback,
                        method_name="startLanding",
                        timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.ROTATE,
            message_class=MessageBuilder.GIMBAL,
            message_data={
                "pitch": pitch,
                "roll": roll,
                "yaw": yaw
            },
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
Example #14
0
    def startMission(self, callback=None, timeout=10):
        """Starts the uploaded mission"""

        checkParameters(callback=callback,
                        method_name="startMission",
                        timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.START_MISSION,
            message_class=MessageBuilder.WAYPOINT_MISSION_OPERATOR,
            message_data=None,
        )

        blocking = callback is None

        return_type = DJIError

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
    def startTakeoff(self, callback=None, timeout=10):
        """
        Allow your aircraft to start take off

        Starts aircraft takeoff. Takeoff is considered complete when the aircraft is hovering 1.2 meters (4 feet) above the ground. Callback is called when aircraft crosses 0.5 meters (1.6 feet). If the motors are already on, this command cannot be executed.

        Args:
            - callback (function): An callback function with a simgle parameter of type CustomError
            - timeout (int): A timeout seconds time
        """
        checkParameters(callback=callback, method_name="startTakeoff", timeout=timeout)
        message = MessageBuilder.build_message(
            message_method=MessageBuilder.START_TAKEOFF,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data=None,
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
Example #16
0
    def setExposureMode(self, mode, callback=None, timeout=10):
        """
        Sets the camera's exposure mode.

        Check ExposureMode to view all possible camera exposure modes.
        Please note that in different exposure mode, it will have different
        values for the same setting.

        Args:
            - callback (function): The execution callback with the returned execution result.
            - mode (ExposureMode): 	Camera exposure mode to set.
        """
        checkParameters(
            callback=callback, method_name="setExposureMode", timeout=timeout,
        )

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.SET_HOME_LOCATION,
            message_class=MessageBuilder.CAMERA,
            message_data={"mode": mode},
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
    def cancelGoHome(self, callback=None, timeout=10):
        """
        The aircraft will stop going home and will hover in place.

        Args:
            - callback (function): An callback function with a simgle parameter of type CustomError
            - timeout (int): A timeout seconds time
        """
        checkParameters(
            callback=callback, method_name="cancelGoHome", timeout=timeout,
        )

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.CANCEL_GO_HOME,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data=None,
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
    def setVerticalControlMode(self, vertical_control_mode, callback=None, timeout=10):
        """
        Sets whether virtual stick vertical controller changes aircraft's altitude or vertical velocity.

        Args:
            - vertical_control_mode (VerticalControlMode): Defines how vertical control values are interpreted by the aircraft.
            - callback (function): An callback function with a simgle parameter of type CustomError
            - timeout (int): A timeout seconds time
        """
        checkParameters(
            callback=callback, method_name="setVerticalControlMode", timeout=timeout,
        )

        assert isinstance(vertical_control_mode, VerticalControlMode)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.SET_VERTICAL_CONTROL_MODE,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data={"vertical_control_mode": vertical_control_mode.value},
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
    def startGoHome(self, callback=None, timeout=10):
        """
        The aircraft will start to go home.

        The completion callback will return execution result once this method is invoked.

        Args:
            - callback (function): An callback function with a simgle parameter of type CustomError
            - timeout (int): A timeout seconds time
        """
        checkParameters(
            callback=callback, method_name="startGoHome", timeout=timeout,
        )

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.START_GO_HOME,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data=None,
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
    def getState(self, callback=None, timeout=10):
        """
        Returns:
            [FlightControllerState]: the current state of flight controller.
        """

        checkParameters(callback=callback, method_name="getState", timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.GET_STATE,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data=None,
        )

        return_type = FlightControllerState

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
    def getVerticalControlMode(self, callback=None, timeout=10):
        """
        Gets the vertical control mode for virtual stick)

        CAUTION: It will be reset to VELOCITY when the flight controller is reconnected

        Args:
            - callback (function): An callback function with a simgle parameter of type VerticalControlMode
            - timeout (int): A timeout seconds time
        """

        checkParameters(
            callback=callback, method_name="getVerticalControlMode", timeout=timeout,
        )

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.GET_VERTICAL_CONTROL_MODE,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data=None,
        )

        return_type = VerticalControlMode

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
    def startLanding(self, callback=None, timeout=10):
        """
        Allow your aircraft to start landing

        Starts auto-landing of the aircraft. Callback is called once aircraft begins to descend for auto-land.

        Args:
            - callback (function): An callback function with a simgle parameter of type CustomError
            - timeout (int): A timeout seconds time
        """
        checkParameters(callback=callback, method_name="startLanding", timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.START_LANDING,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data=None,
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
    def getVirtualStickModeEnabled(self, callback=None, timeout=10):
        """
        Gets virtual stick mode status (enabled/disabled)

        Not supported by Mavic Pro when using the WiFi connection.

        Args:
            - callback (function): An callback function with a simgle parameter of type VirtualStickModeEnabled
            - timeout (int): A timeout seconds time
        """

        checkParameters(
            callback=callback, method_name="getVirtualStickModeEnabled", timeout=timeout
        )

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.GET_VIRTUAL_STICK_MODE_ENABLED,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data=None,
        )

        return_type = bool

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
    def setCollisionAvoidanceEnabled(self, enable, callback=None, timeout=10):
        """
        Enable collision avoidance. When enabled, the aircraft will stop and try to go around detected obstacles.
        """
        checkParameters(
            callback=callback,
            method_name="setCollisionAvoidanceEnabled",
            timeout=timeout,
        )
        enable_str = "true" if enable else "false"

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.SET_COLLISION_AVOIDANCE_ENABLED,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data={"enable": enable_str},
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
Example #25
0
    def getCurrentState(self, timeout=10):
        """
        Returns:
            [WaypointMissionState]: The current state of the operator.
        """

        checkParameters(callback=None,
                        method_name="getCurrentState",
                        timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.GET_CURRENT_STATE,
            message_class=MessageBuilder.WAYPOINT_MISSION_OPERATOR,
            message_data=None,
        )

        from dji_asdk_to_python.mission_control.waypoint import WaypointMissionState
        return_type = WaypointMissionState

        blocking = True

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=None,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
    def sendVirtualStickFlightControlData(self,
                                          flight_control_data,
                                          callback=None,
                                          timeout=1):
        """
        Sends flight control data using virtual stick commands.

        The isVirtualStickControlModeAvailable method must return true to use virtual stick commands. Virtual stick commands should be sent to the aircraft between 5 Hz and 25 Hz.

        Args:
            - flight_control_data (FlightControlData): A control data that contains all the virtual stick control data needed to move the aircraft in all directions.
            - callback (function): An callback function with a simgle parameter of type CustomError
            - timeout (int): A timeout seconds time
        """

        assert isinstance(flight_control_data, FlightControlData)
        flight_control_data = flight_control_data.__dict__
        checkParameters(
            callback=callback,
            method_name="sendVirtualStickFlightControlData",
            timeout=timeout,
        )
        message = MessageBuilder.build_message(
            message_method=MessageBuilder.
            SEND_VIRTUAL_STICK_FLIGHT_CONTROL_DATA,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data=flight_control_data,
        )

        return_type = DJIError

        blocking = callback is None

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=blocking,
        )
    def getHomeLocation(self, callback=None, timeout=10):
        """Gets the home point of the aircraft."""
        checkParameters(
            callback=callback, method_name="getHomeLocation", timeout=timeout,
        )

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.GET_HOME_LOCATION,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data=None,
        )

        return_type = str

        SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
        )
Example #28
0
    def retryUploadMission(self, callback=None, timeout=10):
        """Retry upload waypoint mission"""

        checkParameters(callback=callback,
                        method_name="retryUploadMission",
                        timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.RETRY_UPLOAD_MISSION,
            message_class=MessageBuilder.WAYPOINT_MISSION_OPERATOR,
            message_data=None,
        )

        return_type = DJIError

        SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
        )
Example #29
0
    def getLoadedMission(self, callback=None, timeout=10):
        """Gets the currently loaded mission of the operator"""

        checkParameters(callback=callback,
                        method_name="getLoadedMission",
                        timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.GET_LOADED_MISSION,
            message_class=MessageBuilder.WAYPOINT_MISSION_OPERATOR,
            message_data=None,
        )

        return_type = str

        SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
        )
Example #30
0
    def setAutoFlightSpeed(self, speed, callback=None, timeout=10):
        """Set the flight speed while the mission is executing automatically (without manual joystick speed input)"""

        checkParameters(callback=callback,
                        method_name="setAutoFlightSpeed",
                        timeout=timeout)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.SET_AUTO_FLIGHT_SPEED,
            message_class=MessageBuilder.WAYPOINT_MISSION_OPERATOR,
            message_data={"speed": speed},
        )

        return_type = DJIError

        SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
        )