Android Tutorial DJI virtual stick-tutorial, waypoint- and hotpoint-mission for DJI Mini- and Air-series

schimanski

Well-Known Member
Licensed User
Longtime User
I think I can do it over the weekend
 

schimanski

Well-Known Member
Licensed User
Longtime User
The attached example is a modified version of Erel's DJI-example to show the functions of virtual sticks. But be careful, it's just a rudimentary version to show the waypoint-, hotpoint- and followme-mission. I did not have implemented all security features out of this thread.

To start a mission, choose one of the three radio-buttons and press START, after you have chosen a location in the google map. 'Waypoint' and 'hotpoint' always takes the location in the center of the map (=target). 'Followme' takes your own location with a distance of 20 meters. Don't use 'followme' with your location directly (see post #2).

To use the code, you first have to set your own DJI-app-key under
B4X:
AddReplacement($DJI_KEY$, ec3xxxxxxxxxxx)

and your googlemaps-api-key under
B4X:
AddApplicationText(
<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="AIxxxxxxxxxxxxxxxxxxxxxxx"/>
)
in the manifest-editor.

Under Process_Globals, you can change the flight parameters:
B4X:
   'flight parameters:
    Dim AutoFLightSpeed As Int = 15              'in m/s
    Dim GoHomeAltitude As Int= 40                'in meters
    Dim WaypointAltitude As Int = 40              'in meters
    Dim HotpointAltitude As Int = 40               'in meters
    Dim HotpointRadius As Int = 50                 'in meters (diameter=100 meters)
    Dim FollowMeAltitude As Float = 40          'in meters
    Dim FollowMeDistance As Int = 20             'in meters
    Dim FailSafeBehavior As String = "GO_HOME"    'choose HOVER, LANDING or GO_HOME

To stop the virtual sticks-mode immediately, press the STOP-Button or move one of the two controller-sticks.

It is tested with the DJI mini 2!
 

Attachments

  • VirtualSticks.zip
    8.3 KB · Views: 149
Last edited:

derez

Expert
Licensed User
Longtime User
I tested it in flight this morning, without modifications. The response in all missions is very good, the drone does what it should do.
Problem - I can't see the staus of the camera.
Is it possible to give gimbal commands and "take picture" or "start video"by the program ?
 
Last edited:

schimanski

Well-Known Member
Licensed User
Longtime User
All you need for that is posted in #10 and #16.

Copy the code of post #10 and #16 into the example and activate the lines with 'camerainstance and 'AddwaypointAction. That's it.
 

schimanski

Well-Known Member
Licensed User
Longtime User
Yes, that's right. At the moment, photo works, but video doesn't with my mini 2. It seems, that there exists dependencies, which need more testing. The code only works completly on the mavic...
 

derez

Expert
Licensed User
Longtime User
With startvideo sub I can start recording of the video but there is no stop video command. How to stop the vide recording ?
From the first part of startvideo I get
Failed to set camera mode: The command is not supported by the current firmware version.(255)
And from the second sometimes I get "Aircraft is recording!!!" and other time the same error.
 

derez

Expert
Licensed User
Longtime User
Yes, that's right. At the moment, photo works, but video doesn't with my mini 2. It seems, that there exists dependencies, which need more testing. The code only works completly on the mavic...
How do I take a picture by code ? (not by waypoint.addaction - it does not work on the mini 2)
 
Last edited:

derez

Expert
Licensed User
Longtime User
I found this tutorial , https://developer.dji.com/mobile-sdk/documentation/ios-tutorials/index.html , including this, maybe you know how to deal with it. I think that the video does record but never closed so it is corruptd :
 

schimanski

Well-Known Member
Licensed User
Longtime User

To stop record video, use this code:
B4X:
Dim callback2 As Object= CameraInstance.CreateEventFromUI("dji.common.util.CommonCallbacks$CompletionCallback", "recordcallback", Null)
CameraInstance.RunMethod("stopRecordVideo", Array(callback2))
Wait For (CameraInstance) recordcallback_Event (MethodName As String, Args() As Object)
If Args(0) = Null Then
  Log("Stop Recording")
Else
  Log("Failed to stop recording: " & Args(0))
End If
After that, a new start should not fail.

To make a photo, you have to use this code:
B4X:
If CameraInstance.IsInitialized Then
  Dim callback As Object = CameraInstance.CreateEventFromUI("dji.common.util.CommonCallbacks$CompletionCallback", "setmodecallback", Null)
  CameraInstance.RunMethod("setMode", Array("SHOOT_PHOTO", callback))

  Wait For (CameraInstance) setmodecallback_Event (MethodName As String, Args() As Object)
  If Args(0) = Null Then
    Log("Camera mode set to SHOOT_PHOTO")
  Else
    Log("Failed to set camera mode:" & Args(0))
  End If
  Sleep(0)
 
  Dim callback2 As Object= CameraInstance.CreateEventFromUI("dji.common.util.CommonCallbacks$CompletionCallback", "photocallback", Null)
  CameraInstance.RunMethod("startShootPhoto", Array(callback2))
 
  Wait For (CameraInstance) photocallback_Event (MethodName As String, Args() As Object)
  If Args(0) = Null Then
    Log("Shot photo!")
  Else
    Log("Failed to shoot photo: " & Args(0))
  End If
 
End If

I don't know, why it doesn't work all the time. Try to use another mode and see here:

https://developer.dji.com/api-refer...html#djicamera_djicamerashootphotomode_inline

There are the following modes available. You have to try some other mode.
Perhaps there is one mode, which works better with the mini 2:
 
Last edited:

derez

Expert
Licensed User
Longtime User
All the following worked yesterday, today no photos are taken at all !
With this error: "Failed to set camera mode: The command is not supported by the current firmware version.(255)"
Problem solved, see #37

I attach here a modified version of schimanski's posted code in #22.
I added the following :
1. flying waypoints plan of several waypoint which are added on the map. Flight is performed by the waypoints order until the last, where the VS mode stops.
2. Selection of map types - normal, satelites and terrain.
3. showing important data bellow and under the camera's view , including heading, bearing and range to the user's point.
4. A button to shoot photo during flight.
5. Taking photos automatically during mission flight every 3 seconds.
6. selection of auto photo or auto video during mission, however video does not work
7. Go Home - the function on the controller works well, no need for a button on the screen.
8. Setting the mission parameters on a setup panel and saving them for next activation. The altitude for waypoints, hotspot and followme were united to one parameter but this is not a limitation since it can be changed easily before changing of the mission.
9. A violet marker shows the drone's position on the map during the mission.

Not working still is the video (probably on mini2 only) and automatic setting of the gimbal. the camera gimbal works manually from the controller. I left commented lines for where and how it should be set for the various missions.
I'll be glad to hear your comments.
The pictures show the screens and a series of photos taken in a followme mission. The designer variant is set for my Pixel4a so it may require adaptations to other devices (sorry...).
Don't forget to insert your codes for dji developer and google map.
 

Attachments

  • Virtual_stick.zip
    21 KB · Views: 138
  • cam.png
    451.9 KB · Views: 138
  • setup.png
    255.6 KB · Views: 132
  • DJI_0362.JPG
    77.7 KB · Views: 135
  • DJI_0363.JPG
    77.9 KB · Views: 119
  • DJI_0364.JPG
    79 KB · Views: 123
  • DJI_0365.JPG
    83.4 KB · Views: 129
  • DJI_0366.JPG
    81.6 KB · Views: 129
  • DJI_0367.JPG
    79.2 KB · Views: 126
  • DJI_0368.JPG
    72.2 KB · Views: 117
  • DJI_0369.JPG
    69.7 KB · Views: 122
  • DJI_0370.JPG
    72.4 KB · Views: 125
Last edited:

PABLO2013

Well-Known Member
Licensed User
Longtime User
Greetings Derez, I'm not an expert , 6. - it could be due to the version of the sdk

I'll test your app over the weekend, thanks.
 

derez

Expert
Licensed User
Longtime User
An improved version of post #35:
The time between succesive photos is calculated for each mission for the worst case of vertical gimbal.
For Waypoints - each photo is advanced by half frame. For Hotpoint - advance of ~30 degrees, for Followme - 3 seconds.
Photo mode settings and shooting is split to two subs.
A red circle shows for 1 sec in the top right corner of the video view when a picture is (successfully) taken.
The problem of not shootin photos is solved.

Video is still not working and gimbal is still just manual.

Edit:
Updated version 6 atttached.
Setup panel re-arranged,
FollowMe altitude can be defined separately from mission altitude.
Added Bearing display as small triangle around the compass, showing direction from the drone to the control box.
"Stop Mission" button is removed since touching any of the two stick does it.
 

Attachments

  • vs6.png
    250.4 KB · Views: 125
  • VirtualStick6.zip
    22.2 KB · Views: 128
Last edited:

derez

Expert
Licensed User
Longtime User
As video does not work on the mini 2 I think maybe to record the video which is displayed on the phone, to the phone.
Does anyone know how to get it from the videoview which shows the camera, or get it from the stream coming down from the drone?
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…