Virtual Stick for Mini and Air 2 (Swift 5, Xcode 12, SDK 4.14)
4216 10 2020-11-27
Uploading and Loding Picture ...(0/1)
o(^-^)o
hdrpano
lvl.4
Flight distance : 598458 ft
  • >>>
Switzerland
Offline

I build a new kernel for virtual stick photogrammetry missions with AEB and SAEB. DJI SDK missions have only simple photo capabilities.

Sometimes we need to have AEB or SAEB or even multiple pitch photogrammetry missions. We can realize code with the virtual stick mode for any aircraft. This works for the Mavic Mini and the Mavic Air 2 or any other aircraft.

You can follow the project on GitHub

Virtual Stick offers the developers a lot of possibilities to do intelligent code.



The main issue with Virtual Stick is that you loose control over the remote sticks. The aircraft will not move if you move your sticks. We can add a security to stop the Virtual Stick Mode immediately when we touch the sticks.

First we delegate the remote controller

// Stop Virtual Stick if somebody touches the sticks
let rc = aircraft.remoteController
if rc != nil {
     rc?.delegate = self
}

We add an extension

//MARK: Remote Controller Delegate
extension VirtualSticksViewController: DJIRemoteControllerDelegate {
    func remoteController(_ remoteController: DJIRemoteController, didUpdate  state: DJIRCHardwareState) {
        if self.GCDProcess && (state.leftStick.verticalPosition != 0 || (state.leftStick.horizontalPosition != 0 || state.rightStick.verticalPosition != 0 || state.rightStick.horizontalPosition != 0) || state.goHomeButton.isClicked.boolValue) {
            NSLog("Stop VS \(state.leftStick) \(state.rightStick)")
           self.missionButton.setTitle("VS Remote Interrupt", for: .normal)
           self.stopVS()
      }
    }
}

During flight we check the distance to the target and the bearing to the target GPS.
If the distance become the same as speed we decrease the speed.
If the aircraft heading is not towards the target we correct the heading by the calculated bearing.
We change the altitude if necessary to the target.
If the distance to the target is near to 0.5m we stop sending Virtual Stick commands.

//MARK: Show Virtual Stick Move Action
func showVS() {
    let bearing = self.GPSController.getBearingBetweenTwoPoints(point1: self.aircraftLocation, point2: self.vsTargetLocation)
    let distance = self.GPSController.getDistanceBetweenTwoPoints(point1: self.aircraftLocation, point2: self.vsTargetLocation)

    // Slow down the aircraft
   if distance <= Double(self.vsSpeed) {
        self.vsSpeed = Float(distance / 2)
        if distance < 2 {
            print("Close, slow speed \((self.vsSpeed*10).rounded()/10)m/s distance to target \((distance*10).rounded()/10)m")
       }
    } else {
        print("Move, distance to target \((distance*10).rounded()/10)m speed \((self.vsSpeed*10).rounded()/10)m/s")
    }

    // Turn heading
   if self.aircraftHeading != bearing {
        self.vsTargetBearing = bearing
        if abs(self.aircraftHeading - bearing) > 1 {
            print("Move correct heading \((self.aircraftHeading*10).rounded()/10) \(Int(self.vsTargetBearing))")
        }
    }

    // Move to the target altitude
    if self.aircraftAltitude - self.vsTargetAltitude > self.nearTargetDistance {
        print("Move vertical \(Int(self.aircraftAltitude)) target [\(Int(self.vsTargetAltitude))")
    }

    // Virtual Stick send command
    self.vsController.vsMove(pitch: 0, roll: self.vsSpeed, yaw: Float(self.vsTargetBearing), vertical: Float(self.vsTargetAltitude))

    // We reach the waypoint
    if distance < self.nearTargetDistance && self.aircraftAltitude - self.vsTargetAltitude < self.nearTargetDistance {
        self.GCDvs = true
        print("VS Mission step complete")
       DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
            self.aircraftDispatchGroup.leave()
        }
   }
}


2020-11-27
Use props
twissmueller
lvl.4
Flight distance : 55797 ft
Germany
Offline

What does AEB and SAEB stand for?
2020-12-17
Use props
hdrpano
lvl.4
Flight distance : 598458 ft
  • >>>
Switzerland
Offline

The iOS sample code is not optimized for Xcode 12 and iOS 14... dark mode.
I corrected the iOS sample and added Virtual Stick native drone code.



It is on github, please let me know if you are interested for the sample code.
2020-12-19
Use props
hdrpano
lvl.4
Flight distance : 598458 ft
  • >>>
Switzerland
Offline

twissmueller Posted at 12-17 02:11
What does AEB and SAEB stand for?

Automatic Exposure Braketing
It is used for HDR images
2020-12-19
Use props
twissmueller
lvl.4
Flight distance : 55797 ft
Germany
Offline

hdrpano Posted at 12-19 09:51
Automatic Exposure Braketing
It is used for HDR images

Got it, thank you!
2020-12-20
Use props
twissmueller
lvl.4
Flight distance : 55797 ft
Germany
Offline

hdrpano Posted at 12-19 09:50
The iOS sample code is not optimized for Xcode 12 and iOS 14... dark mode.
I corrected the iOS sample and added Virtual Stick native drone code.

The sample code would be interesting for me. I would be grateful in case you can share it.
2020-12-20
Use props
hdrpano
lvl.4
Flight distance : 598458 ft
  • >>>
Switzerland
Offline

twissmueller Posted at 12-20 20:24
The sample code would be interesting for me. I would be grateful in case you can share it.

I am working on new DJI SDK iOS Swift 5 sample. I build it from scratch with Xcode 12. Stay tunded.
2020-12-30
Use props
fansf5a0ef5f
lvl.2
Flight distance : 427592 ft
France
Offline

It would actually be nice to have DJI support real waypoint features for the MIni & Mini 2 just like the Mavic Pro. Tell the bird to fly from x to y at z speed etc. Why this hassle with virtual sticks ? I use the waypoint features a lot in combination with Litchi. I would even get rid of the MP if my new Mini 2 had the same features. DJI, if you read this...
2021-1-29
Use props
richab
New

Canada
Offline

Thank you for making this available hdrpano!

Can you please clarify, when you say "This works for the Mavic Mini and the Mavic Air 2 or any other aircraft.", does this include the Mini 2?
2021-5-8
Use props
hdrpano
lvl.4
Flight distance : 598458 ft
  • >>>
Switzerland
Offline

richab Posted at 5-8 16:03
Thank you for making this available hdrpano!

Can you please clarify, when you say "This works for the Mavic Mini and the Mavic Air 2 or any other aircraft.", does this include the Mini 2?

It works for any aircraft who is supported from the SDK.
The Air 2S and the Mini 2 are not supported yet.
2021-5-8
Use props
eddwinpaz
lvl.1

Chile
Offline

is posible a dji drone to move vertically?

I want to track inventory vertically. I want to use the virtual sticks to make sure I can go up then right then down then right then up and repeat x amount of times. is this possible? thanks in advance for the information.

2022-7-5
Use props
Advanced
You need to log in before you can reply Login | Register now

Credit Rules