Esempio n. 1
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,
        )
Esempio n. 2
0
    def _remote_start(self):
        ip = SocketUtils.getIp()
        message = MessageBuilder.build_message(
            message_method=MessageBuilder.START_RTP_STREAMING,
            message_class=MessageBuilder.RTP_STREAMING,
            message_data={
                "port": self.streaming_listener.port,
                "ip": ip
            },
        )

        self.streaming_listener.start()  # TODO check for pipe state

        def callback(result):
            if isinstance(result, bool) and result:
                return True
            else:
                return result

        return_type = bool
        timeout = 10
        result = SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=True,
        )
        return result
Esempio n. 3
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 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,
        )
    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 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 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 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,
        )
Esempio n. 9
0
    def addListener(self, listener):
        """
        Add listener to listen for events

        Args:
            listener (WaypointMissionOperatorListener): An WaypointMissionOperatorListener instance
        """

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.ADD_LISTENER,
            message_class=MessageBuilder.WAYPOINT_MISSION_OPERATOR,
            message_data={},
        )

        return_type = DJIError

        result = SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=None,
            timeout=10,
            return_type=return_type,
            listener=listener,
        )

        return result
Esempio n. 10
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,
        )
Esempio n. 11
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,
        )
Esempio n. 12
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
        )
Esempio n. 13
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,
        )
Esempio n. 14
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,
        )
Esempio n. 15
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,
        )
Esempio n. 16
0
    def setLiveUrl(self, live_url, timeout=10):
        """
        Determines if the live streaming starts or not. After starting this flag will not be affected by the RTMP server status.

        Args:
            - live_url (str): The URL address string of the RTMP Server.

        Returns:
            [bool]: True if live url was setted
        """

        assert isinstance(live_url, str)

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.SET_LIVE_URL,
            message_class=MessageBuilder.LIVE_STREAM_MANAGER,
            message_data={"live_url": live_url},
        )

        return_type = bool

        return SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            timeout=timeout,
            return_type=return_type,
            callback=None,
            blocking=True,
        )
Esempio n. 17
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,
        )
Esempio n. 18
0
    def _remote_stop(self):
        message = MessageBuilder.build_message(
            message_method=MessageBuilder.STOP_RTP_STREAMING,
            message_class=MessageBuilder.RTP_STREAMING,
            message_data={},
        )

        def callback(result):
            if isinstance(result, bool) and result:
                self.streaming_listener.stop()
                return True
            else:
                return result

        return_type = bool
        timeout = 10

        result = SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=callback,
            timeout=timeout,
            return_type=return_type,
            blocking=True,
        )
        return result
Esempio n. 19
0
    def removeListener(self, listener):
        """
        Remove waypoint mission operator listener

        Args:
            listener (WaypointMissionOperatorListener): An WaypointMissionOperatorListener instance
        """

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.REMOVE_LISTENER,
            message_class=MessageBuilder.WAYPOINT_MISSION_OPERATOR,
            message_data={},
        )

        return_type = bool

        result = SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=None,
            timeout=10,
            return_type=return_type,
            blocking=True,
        )

        listener._close()

        return result
Esempio n. 20
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,
        )
    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 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,
        )
    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 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,
        )
    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,
        )
Esempio n. 26
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 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,
        )
Esempio n. 28
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,
        )
    def addStateCallback(self, callback):
        """
        Add callback function that updates the flight controller's current state data. This method is called 10 times per second.


        Args:
            callback (FlightControllerState.Callback): The execution callback with the execution result returned.
        """

        message = MessageBuilder.build_message(
            message_method=MessageBuilder.ADD_STATE_CALLBACK,
            message_class=MessageBuilder.FLIGHT_CONTROLLER,
            message_data={},
        )

        return_type = DJIError

        result = SocketUtils.send(
            message=message,
            app_ip=self.app_ip,
            callback=None,
            timeout=10,
            return_type=return_type,
            listener=callback,
        )

        if result is None:
            # no news, good news
            self._state_callbacks[callback.uid] = callback

        return result
Esempio n. 30
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,
        )