Photo mode#
Photo capture can operate in different modes that can be configured with Camera APIs:
single: take a single photo
bracketing: take a burst of multiple photos, each using different EV compensation values
burst: take a burst of photos
timeLapse: take frames at a regular time interval
gpsLapse: take frames at a regular GPS position interval
Camera 1#
Photo mode is configured with field CameraPhotoSettings.mode
.
The list of supported modes is given by CameraPhotoSettings.supportedModes
.
Each photo mode (except single mode) is configured with another setting:
bracketing
configured with field
CameraPhotoSettings.bracketingValue
supported values given by
CameraPhotoSettings.supportedBracketingValues
burst
configured with field
CameraPhotoSettings.burstValue
supported values given by
CameraPhotoSettings.supportedBurstValues
timeLapse
configured with field
CameraPhotoSettings.timelapseCaptureInterval
supported values given by
CameraPhotoSettings.supportedTimelapseIntervals
gpsLapse
configured with field
CameraPhotoSettings.gpslapseCaptureInterval
supported values given by
CameraPhotoSettings.supportedGpslapseIntervals
Sample code to monitor photo mode:
/// Keep reference on MainCamera peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera>?
/// Monitors and prints photo mode.
func monitorPhotoMode(drone: Drone) {
cameraRef = drone.getPeripheral(Peripherals.mainCamera) { camera in
// called on main thread when the camera peripheral changes
if let camera = camera {
// get photo settings
let photoSettings = camera.photoSettings
if photoSettings.supportedModes.isEmpty {
// setting value is not relevant if there is no supported value
print("No supported value")
} else {
// get setting value
let mode = photoSettings.mode
switch mode {
case .single:
print("Photo mode: single")
case .bracketing:
// get bracketing configuration
let bracketing = photoSettings.bracketingValue
print("Photo mode: bracketing \(bracketing)")
case .burst:
// get burst configuration
let burst = photoSettings.burstValue
print("Photo mode: burst \(burst)")
case .gpsLapse:
// get location interval
let interval = photoSettings.gpslapseCaptureInterval
print("Photo mode: gpsLapse \(interval) meters")
case .timeLapse:
// get time interval
let interval = photoSettings.timelapseCaptureInterval
print("Photo mode: timeLapse \(interval) seconds")
}
}
}
}
}
Example of output:
Photo mode: burst 10 Over 4s
Sample code to modify photo mode:
/// Sets photo mode.
func setPhotoMode(drone: Drone, photoMode: CameraPhotoMode) {
if let camera = drone.getPeripheral(Peripherals.mainCamera) {
// set setting value
camera.photoSettings.mode = photoMode
}
}
Trying to change the setting value to an unsupported value has no effect.
Values supported by the camera are provided by CameraPhotoSettings.supportedModes
.
For bracketing mode, the bracketing value can be configured as follows:
/// Sets bracketing value.
func setBracketingValue(drone: Drone, bracketing: CameraBracketingValue) {
if let camera = drone.getPeripheral(Peripherals.mainCamera) {
// set setting value
camera.photoSettings.bracketingValue = bracketing
}
}
For burst mode, the burst value can be configured as follows:
/// Sets burst value.
func setBurstValue(drone: Drone, burst: CameraBurstValue) {
if let camera = drone.getPeripheral(Peripherals.mainCamera) {
// set setting value
camera.photoSettings.burstValue = burst
}
}
For gpsLapse mode, the interval can be configured as follows:
/// Sets location interval.
func setGpsLapseInterval(drone: Drone, interval: Double) {
if let camera = drone.getPeripheral(Peripherals.mainCamera) {
// set setting value
camera.photoSettings.gpslapseCaptureInterval = interval
}
}
For timeLapse mode, the interval can be configured as follows:
/// Sets time interval.
func setTimeLapseInterval(drone: Drone, interval: Double) {
if let camera = drone.getPeripheral(Peripherals.mainCamera) {
// set setting value
camera.photoSettings.timelapseCaptureInterval = interval
}
}
Camera 2#
Photo mode is configured with parameter Camera2Params.photoMode
.
Each photo mode (except single mode) is configured with another parameter:
bracketing: configured with parameter
Camera2Params.photoBracketing
burst: configured with parameter
Camera2Params.photoBurst
timeLapse: configured with parameter
Camera2Params.photoTimelapseInterval
gpsLapse: configured with parameter
Camera2Params.photoGpslapseInterval
Sample code to monitor photo mode:
/// Keep reference on MainCamera2 peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera2>?
// Monitors and prints photo mode.
func monitorPhotoMode(drone: Drone) {
cameraRef = drone.getPeripheral(Peripherals.mainCamera2) { camera in
// called on main thread when the camera peripheral changes
if let camera = camera {
// get current configuration
let config = camera.config
// get configuration parameter
if let configParam = config[Camera2Params.photoMode] {
if configParam.currentSupportedValues.isEmpty {
// parameter value is not relevant
// if there is not supported values in current configuration
print("No supported value in current configuration")
} else {
// get parameter value
let mode = configParam.value
switch mode {
case .single:
print("Photo mode: single")
case .bracketing:
// get bracketing configuration
let bracketing = config[Camera2Params.photoBracketing]?.value
print("Photo mode: bracketing \(bracketing)")
case .burst:
// get burst configuration
let burst = config[Camera2Params.photoBurst]?.value
print("Photo mode: burst \(burst)")
case .gpsLapse:
// get location interval
let interval = config[Camera2Params.photoGpslapseInterval]?.value
print("Photo mode: gpsLapse \(interval) meters")
case .timeLapse:
// get time interval
let interval = config[Camera2Params.photoTimelapseInterval]?.value
print("Photo mode: timeLapse \(interval) seconds")
}
}
}
}
}
}
Example of output:
Photo mode: burst Optional(burst10Over4s)
Sample code to modify photo mode:
/// Sets photo mode.
func setPhotoMode(drone: Drone, photoMode: Camera2PhotoMode) {
if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
// create configuration editor, starting from current configuration
let editor = camera.config.edit(fromScratch: false)
// retrieve configuration parameter
if let configParam = editor[Camera2Params.photoMode] {
// change parameter value,
// and unset other parameters conflicting with this new value
configParam.value = photoMode
// complete configuration, by setting missing parameters values
editor.autoComplete()
// send new configuration to drone
editor.commit()
}
}
}
Trying to change the parameter value to an unsupported value has no effect.
Values supported by the camera are provided by the parameter field configParam.overallSupportedValues
.
For bracketing mode, the bracketing value can be configured as follows:
/// Sets bracketing value.
func setBracketingValue(drone: Drone, bracketing: Camera2BracketingValue) {
if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
// create configuration editor, starting from current configuration
let editor = camera.config.edit(fromScratch: false)
// retrieve configuration parameter
if let configParam = editor[Camera2Params.photoBracketing] {
// change parameter value,
// and unset other parameters conflicting with this new value
configParam.value = bracketing
// complete configuration, by setting missing parameters values
editor.autoComplete()
// send new configuration to drone
editor.commit()
}
}
}
For burst mode, the burst value can be configured as follows:
/// Sets burst value.
func setBurstValue(drone: Drone, burst: Camera2BurstValue) {
if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
// create configuration editor, starting from current configuration
let editor = camera.config.edit(fromScratch: false)
// retrieve configuration parameter
if let configParam = editor[Camera2Params.photoBurst] {
// change parameter value,
// and unset other parameters conflicting with this new value
configParam.value = burst
// complete configuration, by setting missing parameters values
editor.autoComplete()
// send new configuration to drone
editor.commit()
}
}
}
For gpsLapse mode, the interval can be configured as follows:
/// Sets location interval.
func setGpsLapseInterval(drone: Drone, interval: Double) {
if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
// create configuration editor, starting from current configuration
let editor = camera.config.edit(fromScratch: false)
// retrieve configuration parameter
if let configParam = editor[Camera2Params.photoGpslapseInterval] {
// change parameter value,
// and unset other parameters conflicting with this new value
configParam.value = interval
// complete configuration, by setting missing parameters values
editor.autoComplete()
// send new configuration to drone
editor.commit()
}
}
}
For timeLapse mode, the interval can be configured as follows:
/// Sets time interval.
func setTimeLapseInterval(drone: Drone, interval: Double) {
if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
// create configuration editor, starting from current configuration
let editor = camera.config.edit(fromScratch: false)
// retrieve configuration parameter
if let configParam = editor[Camera2Params.photoTimelapseInterval] {
// change parameter value,
// and unset other parameters conflicting with this new value
configParam.value = interval
// complete configuration, by setting missing parameters values
editor.autoComplete()
// send new configuration to drone
editor.commit()
}
}
}