简体   繁体   中英

How to to setup unit tests to test custom DJI missions?

Here , it states we can use the DJISimulator object to help facilitate continuous integration (ie unit/integration tests). But I can't seem to figure out how thats possible. DJISimulator and DJIFlightController do not conform to the same basic protocol, nor do they have the similar delegates.

What I'd love to be able to do is in my unit tests, is to simulate (without attaching drone hardware or running DJIAssistant 2) the drone taking off and flying the waypoint missions we build and upload, and upon completion, coming home and landing; following the same code flow that would execute if we were flying with a real drone and our custom iOS app that has the DJISDK integrated into it.

Is this possible?

At the moment, running the simulator without the hardware (drone + RC) physically in the loop is not possible . That is because the actual simulation takes place on the drone, and each different flight controller model for the different drones have their own little quirks which makes it very difficult to accurately simulate the entire thing completely in software.

However, you can simulate waypoint missions without actually flying the drone by having it connected and powered on in your testing loop.

To start the simulation, fetch the DJISimulator object from the aircraft's flightController , and then call the start simulation method with your desired location, frequency, etc. Once you have started the simulator, you can listen to the simulator's delegate method to get the state of the drone in the simulated world.


Edit :

To add more as to how to go about writing unit tests, here's what a rough series of steps would look like to test for example a mission like this [Take off, yaw to north, waypoint mission, go home and land]:

  1. Make sure to turn on the simulator, or restart it to clear out the state of the drone if simulator was already on.
  2. In your unit test method, create all the timeline actions and add them to the timeline.
  3. Add a timeline progress listener. This listener will fire whenever any timeline element updates. Most of your unit testing logic will go in this block. For example, if the timeline listener element is a Aircraft Yaw element at index 1, you know that it is your "yaw to north" step. So whenever the state of that element comes up as finished, you can then probe the drone to ask for it's attitude and assert that it's yaw is pointing to the north like you expect it to be. Similarly, during a waypoint, after each waypoint is reached you can check that the gps coordinate of the drone is where you expect it to be (+error threshold of a few meters). If at anytime the timeline spits out an error, you consider the test failed.
  4. Start your timeline.
  5. Since everything is asynchronous, you will need to add a wait until timeout with a reasonable amount of time and consider the test failed if your timeline does not successfully finish until then.

PS If you want even more granular updates on a mission (waypoint, hotpoint, etc.), you can also subscribe to listen to the MissionOperator listeners (WaypointMissionOperator, HotpointMissionOperator, etc.). Those have upload/download listeners which might be of interest.

Also, during any point in the test, you don't need to listen to the simulator's state listener at all because you can just probe the drone for its state (location, whether motors are on, etc.) and it will give the simulated values that you can check with your expected values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM