dji-sdk / Mobile-SDK-iOS

DJI Mobile SDK for iOS: http://developer.dji.com/mobile-sdk/
Other
577 stars 256 forks source link

Custom MissionTriggerAction for DJIWaypointReachedMissionTrigger #435

Closed RushivArora closed 3 years ago

RushivArora commented 3 years ago

Hello,

I am working with a DJI Mavic 2 Zoom and programming it the with mission controller Timeline to run a waypoint mission as well as execute a certain trigger based on some waypoints. I hope to run custom actions (for example a print/log function at a specific waypoint, or something more complicated) and implement calls to some custom functions when the waypoint is reached and triggered.

I am really struggling to implement my own custom action on reaching the given waypoint, and I was hoping to get some help on this. I have spent a lot of time on it already!

My idea so far is below. This could would print only when I reach the 2nd waypoint.

`

Thank you!

RushivArora commented 3 years ago

As an update, I thought of another way to get my program to do the same thing.

I can create my own DJIMIssionAction function and have the drone do nothing but print/log, and then schedule that action as part of my timeline. So the timeline could be something like: Waypoint Mission -> Action -> Waypoint Mission. Or else I could use that DJIMissionAction as my DJIMissionTriggerAction?

How would I go about creating y own DJIMissionAction? That is, how do I make sure the print action method is called when the action is running? I am subclassing AircraftAction to DJIMissionAction.

` @implementation AircraftAction

@end `

Could I please get some help on this, I would really appreciate the help.

Thank you!

Matheus193dn commented 3 years ago

@RushivArora Hey, Did you check DJI sample? https://github.com/dji-sdk/Mobile-SDK-iOS/blob/master/Sample%20Code/ObjcSampleCode/DJISdkDemo/Demo/MissionManager/WaypointMissionViewController.m

Also, there is a listener for Timeline here: image You can track the kind of current element that your Timeline is executing.

RushivArora commented 3 years ago

@Matheus193dn Thank you so much for your reply!

I did check the DJI sample. Eventually I referred the Android SDK to find out how to define my own custom actions/events (it is the same as the IOS SDK, I just found the documentation style made it easier since they refer parent classes in there). https://developer.dji.com/api-reference/android-api/Components/Missions/DJIMissionAction.html#djimissioncontroltimelineelement_willrun_inline

And your timeline listener is a lifesaver! Thank you so much for that. I am using the Timeline listener and the "TimeLine Pause/TImeLine Resume" as a workaround. I also found a trigger listener, and turns out my trigger is getting started and stopped, but my WayPointReachedTrigger is not being triggered (I wonder why? I have no idea).

Either way, I am moving forward with the Timeline listener and custom Actions/Events for the drone. If anyone has some documentation/sample on using triggers that would be great! @dji-dev would it be possible to get some sample code/clarity on using triggers, that would be wonderful! Maybe this is a potential bug with triggers? If not maybe I am doing something wrong.

Also @Matheus193dn, would you know why my triggers are not working? It is the same code as above, but the actionTriggeredEvent never gets called

Matheus193dn commented 3 years ago

@RushivArora Oh, really sorry because I didn't try trigger in Timeline yet, I only added element, which is single action, to timelineStack. I will test with these triggers in my spare time, will let you know ASAP when I get the result.

Matheus193dn commented 3 years ago

@RushivArora Hey, I tested with my sample and it work normally in Timeline. You can take a look at my sample code here: at line // MARK: - Add trigger for WaypointMission in Timeline https://github.com/Matheus193dn/Mobile-SDK-iOS/blob/master/Sample%20Code/SwiftSampleCode/DJISDKSwiftDemo/Camera/fpv/CameraFPVViewController.swift

P/S: If you run my sample, plz set home position near my list coords. When you are at FPV screen, just tap on "Start mission" button then watch it happens. IMG_0189

RushivArora commented 3 years ago

@Matheus193dn Thank you so much for your sample code! I have gone through it and found that it was very helpful. I haven't run it yet, but I can see that it works. It is indeed very helpful.

Couple questions. What aircraft are you using? I have the Mavic 2 Zoom, and I'm not sure if it supports WaypointV2 missions as opposed to Waypoint V1.

I am currently using WayPoint V1 missions, and for triggers I am using the DJIMissionTrigger class (as opposed to DJIWayPointV2Trigger class). Have you ever had any luck trying the DJIMissionTrigger class? Also, if you use a Mavic 2, I will work on switching my waypoint code to a WaypointV2 format since the WaypointV1 triggers didn't work for me.

Matheus193dn commented 3 years ago

@RushivArora waypointMissionV2 only supports Matrice 300 RTK. My team have M2Zoom, M2DualEnterprise and M300RTK. P/S: My sample code also includes waypointMissionV2 for M300RTK. Plz notice at the condition to check if current drone is M300 or not.

RushivArora commented 3 years ago

@Matheus193dn that part missed my eye.

For now I will stick with WaypointV1 and use the timeline listeners you mentioned earlier along with defining my own custom actions. Once again, thank you so so much for helping me out, especially with the timeline listener since that is a big lifesaver!

I will leave this thread open on the chance either one of us gets the triggers working. Either way, I found a great workaround in the timeline listener (combined with the pause and resume timeline calls).

Thank you!

Matheus193dn commented 3 years ago

@RushivArora Happy to help. But our projects for DJI's drones won't last long, may be in the next 2-3 months. I will try my best to help in that time.

RushivArora commented 3 years ago

@Matheus193dn thank you!

My project ends in the next few months as well, so I presume I will be active on this forum till then as well. I would also be happy to help if you ever need any!

Michael-DJI commented 3 years ago

@RushivArora thanks for it!