Zoom#

Camera 1#

Zoom level is controlled with setting CameraZoom.

Sample code to monitor camera zoom:

/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null

/** Monitors and prints zoom information. */
fun monitorZoom(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        camera?.run {
            zoom()?.apply {
                println("Zoom level: $currentLevel")
                println("Zoom isAvailable: $isAvailable")
                val maxSpeed = maxSpeed().value
                println("Zoom maxSpeed: $maxSpeed tan(degree)/second")
                val velocityQualityDegradationAllowance = velocityQualityDegradationAllowance().isEnabled
                println("Zoom velocityQualityDegradationAllowance: $velocityQualityDegradationAllowance")
                println("Zoom maxLossLessLevel: $maxLossLessLevel")
                println("Zoom maxLossyLevel: $maxLossyLevel")
            } ?: run {
                println("Zoom not supported by camera")
            }
        }
    }
}

Example of output:

Zoom level 1.0
Zoom isAvailable true
Zoom maxSpeed 0.3400000035762787 tan(degree)/second
Zoom velocityQualityDegradationAllowance true
Zoom maxLossLessLevel 1.0
Zoom maxLossyLevel 2.999976396560669

Details:

  • CameraZoom.currentLevel is the current zoom level.

  • CameraZoom.isAvailable indicates whether zoom control is available at present. For instance, zoom control may be unavailable temporarily during an animation.

  • CameraZoom.maxLossyLevel is the maximum zoom level supported by the camera.

  • CameraZoom.maxLossLessLevel is the zoom level above which image quality will be degraded.

  • CameraZoom.maxSpeed() is used to configure the maximum zoom speed.

  • CameraZoom.velocityQualityDegradationAllowance() tells whether zoom level changes using zoom velocity will stop at CameraZoom.maxLossyLevel or at CameraZoom.maxLossLessLevel.

Zoom level can be controlled either by defining a zoom level or by giving a zoom change velocity.

Sample code to control zoom level by defining a zoom level:

/** Sets zoom level. */
fun setZoomLevel(drone: Drone, level: Double) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        if (zoom()?.isAvailable == true) {
            zoom()?.control(CameraZoom.ControlMode.LEVEL, level)
        } else {
            print("Zoom not available")
        }
    }
}

The zoom level target shall be contained between 1 (means no zoom) and maxLossyLevel.

Sample code to control zoom level by giving a zoom change velocity:

/** Sets zoom velocity. */
fun setZoomVelocity(drone: Drone, velocity: Double) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        if (zoom()?.isAvailable == true) {
            zoom()?.control(CameraZoom.ControlMode.VELOCITY, velocity)
        } else {
            print("Zoom not available")
        }
    }
}

The velocity value shall be in range [-1, 1]:

  • -1: the camera zooms out at the speed defined in CameraZoom.maxSpeed().

  • 0: the zoom level does not change.

  • 1: the camera zooms in at the speed defined in CameraZoom.maxSpeed().

Camera 2#

Zoom level is controlled with sub-component Camera.Zoom.

Zoom behavior is configured with parameters Camera.Config.ZOOM_MAX_SPEED and Camera.Config.ZOOM_VELOCITY_CONTROL_QUALITY_MODE.

Sample code to monitor video mode:

/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null
/** `MainCamera` peripheral. This is used to know when peripheral appears. */
private var mainCamera: Camera? = null

/** Monitors and prints zoom information. */
fun monitorZoom(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        camera?.run {
            // register sub-component listener, only when camera peripheral appears
            if (mainCamera == null) {
                // get notified every time zoom sub-component changes
                camera.component<Camera.Zoom> { zoom ->
                    zoom?.apply {
                        println("Zoom level: $level")
                        println("Zoom maxLosslessLevel: $maxLosslessLevel")
                        println("Zoom maxLevel: $maxLevel")
                    } ?: run {
                        println("Zoom not available")
                    }
                }
            }

            // get ZOOM_MAX_SPEED configuration parameter
            config[Camera.Config.ZOOM_MAX_SPEED].run {
                if (supportedValues(onlyCurrent = true) == DoubleRange.EMPTY) {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    println("ZoomMaxSpeed: no supported value in current configuration")
                } else {
                    println("ZoomMaxSpeed: $value tan(degree)/second")
                }
            }

            // get ZOOM_VELOCITY_CONTROL_QUALITY_MODE configuration parameter
            config[Camera.Config.ZOOM_VELOCITY_CONTROL_QUALITY_MODE].run {
                if (supportedValues(onlyCurrent = true).isEmpty()) {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    println("ZoomVelocityControlQualityMode: no supported value in current configuration")
                } else {
                    println("ZoomVelocityControlQualityMode: $value")
                }
            }
        }
        mainCamera = camera
    }
}

Example of output:

Zoom level 1.0
Zoom maxLossLessLevel 2.2625937783582715
Zoom maxLevel 6.014731352298322
zoomMaxSpeed: 0.0 tan(degree)/second
zoomVelocityControlQualityMode: ALLOW_DEGRADING

Details:

  • Camera.Zoom.level is the current zoom level.

  • Camera.Zoom.maxLevel is the maximum zoom level supported by the camera.

  • Camera.Zoom.maxLosslessLevel is the zoom level above which image quality will be degraded.

  • Camera.Config.ZOOM_MAX_SPEED is used to configure the maximum zoom speed.

  • Camera.Config.ZOOM_VELOCITY_CONTROL_QUALITY_MODE tells whether zoom level changes using zoom velocity will stop at Camera2Zoom.maxLevel or at Camera2Zoom.maxLossLessLevel.

Zoom level can be controlled either by defining a zoom level or by giving a zoom change velocity.

Sample code to control zoom level by defining a zoom level:

/** Sets zoom position. */
fun setZoomLevel(drone: Drone, level: Double) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        component<Camera.Zoom>()?.apply {
            control(Camera.Zoom.ControlMode.POSITION, level)
        } ?: run {
            // zoom component not available at present
            println("Zoom not available")
        }
    }
}

The zoom level target shall be contained between 1 (means no zoom) and Camera2Zoom.maxLevel.

Sample code to control zoom level by giving a zoom change velocity:

/** Sets zoom velocity. */
fun setZoomVelocity(drone: Drone, velocity: Double) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        component<Camera.Zoom>()?.apply {
            control(Camera.Zoom.ControlMode.VELOCITY, velocity)
        } ?: run {
            // zoom component not available at present
            println("Zoom not available")
        }
    }
}

The velocity value shall be in range [-1, 1]:

  • -1: the camera zooms out at the speed defined in Camera.Config.ZOOM_MAX_SPEED.

  • 0: the zoom level does not change.

  • 1: the camera zooms in at the speed defined in Camera.Config.ZOOM_MAX_SPEED.