LoginSignup
0
0

More than 1 year has passed since last update.

Java Gsonライブラリで簡単に DJI Drone の WaypointV2Mission データをJSONに変換

Last updated at Posted at 2022-10-16

この記事ではJavaのGsonライブラリで簡単に DJI Drone の WaypointV2Mission データをJSONに変換できることを紹介します。

背景

DJI Droneの自動飛行には、DJI Droneに自動飛行ミッション情報をDJI WaypointV2Missionのウェイポイント情報(WaypointV2)と
アクション情報(WaypointV2Action)に設定してアップロード必要です。

DJIのウェイポイントアクション情報(WaypointV2Action)には、どのようなデータが入っているかを確認したいですが、
WaypointV2Actionの構造が複雑、中のメンバークラスの階層が一杯で簡単に設定情報を見えないです。

Javaで
DJIのウェイポイントアクション情報(WaypointV2Action)をwaypointV2Action.toString()関数で出力できますが、
メンバークラス等(WaypointReachPointTriggerParam)の中身が出力されていなかった。

WaypointV2Action{
  actionID=1, 
  trigger=WaypointTrigger{
    triggerType=REACH_POINT, 
    complexReachPointParam=null, 
    associateParam=null, 
    trajectoryParam=null, 
    reachPointParam=dji.common.mission.waypointv2.Action.WaypointReachPointTriggerParam@500513d, 
    simpleIntervalTriggerParam=null
  }, 
  actuator=WaypointActuator{
    actuatorType=AIRCRAFT_CONTROL,
    actuatorIndex=0, 
    subActuatorIndex=0,
    cameraActuatorParam=null,
    gimbalActuatorParam=null, 
    aircraftControlActuatorParam=dji.common.mission.waypointv2.Action.WaypointAircraftControlParam@c115d32,
    payloadActuatorParam=null,
    navigationActionParam=null,
    djiSYSActuatorParam=null
  }
}

解決方法

GoogleのJava Gsonは、JavaオブジェクトをJSON表現に変換するために使用できるJavaライブラリです。
これを使用して、DJIのウェイポイントアクション情報(WaypointV2Action)をJSON文字列に変換することができます。

Gsonの使い方

Android アプリのappのbuild.gradleに設定

dependencies {
    implementation 'com.google.code.gson:gson:2.9.1'
}

ソースファイルでimport

import com.google.gson.Gson;

GsonでJavaオブジェクト ⇒ JSONに変換

メンバークラス等の中身がちゃんとJSONとして出力されます。

Gson gson = new Gson();
gson.toJson(waypointV2Action);
{
	"actionID": 13,
	"actuator": {
		"actuatorIndex": 0,
		"actuatorType": "AIRCRAFT_CONTROL",
		"aircraftControlActuatorParam": {
			"aircraftControlType": "START_STOP_FLY",
			"flyControlParam": {
				"isStartFly": false
			}
		},
		"subActuatorIndex": 0
	},
	"trigger": {
		"reachPointParam": {
			"autoTerminateCount": 0,
			"startIndex": 2
		},
		"triggerType": "REACH_POINT"
	}
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0