Hi all,
I wanted to test virtual joysticks with my spark (waypoints not available...)
I saw this video which gives the evidence that it could work (and well !)
It's impressive how the "ground coordinate" frame could help to have nice motion of the drone.
code is available here : https://github.com/dbaldwin/Mobile-SDK-iOS/blob/master/Sample Code/SwiftSampleCode/DJISDKSwiftDemo/VirtualSticks/VirtualSticksViewController.swift
But limited to IOS swift... BTW it is almost readable even for me !
So I tried to mofiy the DJI example to introduce virtual Joysticks.
So far I have understood that you need to switch the controller to "virtualJoystick mode"
This seems to work with this code :
Happy with this success I tried to sendVirtualStickFlightControlData using the DJI API
Here is what I tried :
It does not work and crashes with this error :
Obviously I don't know how to call the method
I understand that I should first call the constructor for FlightControlData... but I don't know how !
I am not a master chief when using JavaObject... So please if a guru reads these lines, please help me
Thanks
I wanted to test virtual joysticks with my spark (waypoints not available...)
I saw this video which gives the evidence that it could work (and well !)
It's impressive how the "ground coordinate" frame could help to have nice motion of the drone.
code is available here : https://github.com/dbaldwin/Mobile-SDK-iOS/blob/master/Sample Code/SwiftSampleCode/DJISDKSwiftDemo/VirtualSticks/VirtualSticksViewController.swift
But limited to IOS swift... BTW it is almost readable even for me !
So I tried to mofiy the DJI example to introduce virtual Joysticks.
So far I have understood that you need to switch the controller to "virtualJoystick mode"
This seems to work with this code :
B4X:
Sub HardwareState_Event (MethodName As String, Args() As Object) As Object
Dim HardwareState As JavaObject = Args(0)
Dim c1button As JavaObject = HardwareState.RunMethod("getC1Button", Null)
Dim IsClicked As Boolean = c1button.RunMethod("isClicked", Null)
Log($"C1 button: ${IsClicked}"$)
Dim pauseButton As JavaObject = HardwareState.RunMethod("getPauseButton", Null)
Dim pauseClicked As Boolean = pauseButton.RunMethod("isClicked", Null)
Log($"pause button: ${pauseClicked}"$)
' Dim Lstick As JavaObject = HardwareState.RunMethod("getLeftStick", Null)
' Dim Lhoriz As Int = Lstick.RunMethod("getHorizontalPosition", Null)
' Log($"left stick H value: ${Lhoriz}"$)
'virtual joystick
FlightController = aircraft
FlightController = FlightController.RunMethod("getFlightController", Null) 'get the flight controller
Dim flag As Boolean = True
If IsClicked = True Then
flag = True
timerVirtualSticks.enabled = True
Else
flag = False
timerVirtualSticks.enabled = False
End If
FlightController.RunMethod("setVirtualStickModeEnabled",Array(flag, Null)) 'switch on/off the virtual joysticks
virtualStickAvailable = FlightController.RunMethod("isVirtualStickControlModeAvailable", Null)
Log($"virtual stick available: ${virtualStickAvailable}"$)
Return Null
End Sub
Happy with this success I tried to sendVirtualStickFlightControlData using the DJI API
Here is what I tried :
B4X:
Sub sendVirtualStickThrottle(tt As Float)
Dim controlData As JavaObject
Dim y, p, r As Float
y = 0
p = 0
r = 0
Try
controlData = FlightController.RunMethod("sendVirtualStickFlightControlData",Array(Array(p,r,y,tt),Null)) 'XXXXX ----> DOES NOT WORK
Catch
Log(LastException)
End Try
End Sub
Sub timerVirtualSticks_Tick
If (virtualStickAvailable) Then sendVirtualStickThrottle(50)
End Sub
It does not work and crashes with this error :
B4X:
pause button: false
virtual stick available: true
b4xmainpage_sendvirtualstickthrottle (java line: 1019)
java.lang.RuntimeException: Method: sendVirtualStickFlightControlData not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:129)
at fr.free.JulienGley.DjiSpark1.b4xmainpage._sendvirtualstickthrottle(b4xmainpage.java:1019)
at fr.free.JulienGley.DjiSpark1.b4xmainpage._timervirtualsticks_tick(b4xmainpage.java:1166)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
(RuntimeException) java.lang.RuntimeException: Method: sendVirtualStickFlightControlData not matched.
C1 button: false
Obviously I don't know how to call the method
I understand that I should first call the constructor for FlightControlData... but I don't know how !
I am not a master chief when using JavaObject... So please if a guru reads these lines, please help me
Thanks
Last edited: