This commit is contained in:
cxf 2026-02-10 20:46:40 +08:00
parent cf1cc1105f
commit 5dba8fa2c5
30 changed files with 2074 additions and 1456 deletions

View File

@ -90,7 +90,8 @@ open class ConnectionActivity : BaseActivity() {
}
if (TextUtils.isEmpty(PreferenceUtils.getInstance().mqttServerUri)){
PreferenceUtils.getInstance().mqttServerUri =
"tcp://192.168.20.90:2883"
// "tcp://192.168.20.90:2883"
"tcp://broker.emqx.io"
}
if (TextUtils.isEmpty(PreferenceUtils.getInstance().mqttUserName)){

View File

@ -47,8 +47,10 @@ import com.aros.apron.tools.MqttManager
import com.aros.apron.tools.PreferenceUtils
import com.dji.wpmzsdk.manager.WPMZManager
import com.google.gson.Gson
import dji.sdk.keyvalue.key.CameraKey
import dji.sdk.keyvalue.key.DJIKey
import dji.sdk.keyvalue.key.FlightControllerKey
import dji.sdk.keyvalue.key.GimbalKey
import dji.sdk.keyvalue.key.KeyTools
import dji.sdk.keyvalue.value.common.CameraLensType
import dji.sdk.keyvalue.value.common.ComponentIndexType
@ -578,9 +580,12 @@ open class MainActivity : BaseActivity() {
val isFlightControllerConnect =
KeyManager.getInstance().getValue(DJIKey.create(FlightControllerKey.KeyConnection))
// val isCameraConnect =
// KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey.KeyConnection, ComponentIndexType.PORT_1))
// LogUtil.log(TAG,isCameraConnect.toString())
val isCameraConnect =
KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey.KeyConnection, ComponentIndexType.PORT_1))
val isGimbal =KeyManager.getInstance().getValue(KeyTools.createKey(GimbalKey.KeyConnection, ComponentIndexType.PORT_1))
LogUtil.log(TAG,isCameraConnect.toString())
//全装在初始化
if ((isFlightControllerConnect == null || !isFlightControllerConnect)) {
handler.postDelayed({
initDJIManager()
@ -588,17 +593,22 @@ open class MainActivity : BaseActivity() {
} else {
initTimes++
LogUtil.log(TAG, "初始化$initTimes")
LogUtil.log(TAG,"自定义推流方式:"+PreferenceUtils.getInstance().customStreamType)
Handler().postDelayed(Runnable {
MissionV3Manager.getInstance().initMissionManager()
FlightManager.getInstance().initFlightInfo()
BatteryManager.getInstance().initBatteryInfo()
StickManager.getInstance().initStickInfo()
GimbalManager.getInstance().initGimbalInfo()
AlternateLandingManager.getInstance().initAlterLandingInfo()
OSDManager.getInstance().initOsd()
FlightTaskProgressManager.getInstance().initFlightTaskProgress()
MediaManager.getInstance().init()
StreamManager.getInstance().initStreamManager()
GimbalManager.getInstance().initGimbalInfo()
//负载
PayloadWidgetManager.getInstance().initPayloadInfo()
//初始化上报
@ -609,8 +619,8 @@ open class MainActivity : BaseActivity() {
LEDsSettingsManager.getInstance().initLEDsInfo()
LogUtil.log(TAG,"自定义推流方式:"+PreferenceUtils.getInstance().customStreamType)
Handler().postDelayed(Runnable {
if (PreferenceUtils.getInstance().customStreamType==1){
StreamManager.getInstance()
.startLiveWithRTSP()

View File

@ -8,9 +8,12 @@ import com.aros.apron.tools.LogUtil
import com.aros.apron.xclog.CrashHandler
import com.aros.apron.xclog.XcFileLog
import com.aros.apron.xclog.XcLogConfig
import com.dji.wpmzsdk.manager.WPMZManager
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.Logger
import com.orhanobut.logger.PrettyFormatStrategy
import dji.v5.common.utils.GeoidManager
import dji.v5.utils.common.ContextUtil
import org.opencv.android.OpenCVLoader
@ -57,13 +60,9 @@ open class ApronApp : Application() {
return true
}
})
XcFileLog.init(XcLogConfig())
//打印崩溃日志
CrashHandler.getInstance().init()
// 初始化 OpenCV
if (OpenCVLoader.initLocal()) {
LogUtil.log("qwq","opencv" +

View File

@ -5,11 +5,13 @@ import static com.aros.apron.tools.Utils.getIDJIErrorMsg;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import com.aros.apron.constant.AMSConfig;
import com.aros.apron.constant.Constant;
import com.aros.apron.entity.CameraPhotoTakeProgress;
import com.aros.apron.entity.CurrentWayline;
import com.aros.apron.entity.FlightTaskProgress;
import com.aros.apron.entity.MediaUpLoad;
@ -17,6 +19,7 @@ import com.aros.apron.entity.MessageDown;
import com.aros.apron.entity.MessageEvent;
import com.aros.apron.entity.MessageReply;
import com.aros.apron.entity.Movement;
import com.aros.apron.entity.TakeoffToPointProgress;
import com.aros.apron.entity.TaskFailEvent;
import com.aros.apron.entity.WirelessLink;
import com.aros.apron.tools.LogUtil;
@ -27,6 +30,7 @@ import com.google.gson.Gson;
import org.eclipse.paho.android.service.MqttAndroidClient;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import java.util.Locale;
import java.util.UUID;
import dji.v5.common.callback.CommonCallbacks;
@ -131,7 +135,7 @@ public abstract class BaseManager {
* 发送常规event事件
*/
public void sendEvent2Server(String msg,int level) {
LogUtil.log(TAG,"发送常规事件:"+"run_log -"+msg);
//LogUtil.log(TAG,"发送常规事件:"+"run_log -"+msg);
try {
if (MqttManager.getInstance().mqttAndroidClient.isConnected()) {
MessageEvent messageEvent = new MessageEvent();
@ -164,7 +168,7 @@ public abstract class BaseManager {
* 发送媒体文件上传事件
*/
public void sendMediaUpload2Server(String fileName,int uploaded_file_count,int expected_file_count) {
LogUtil.log(TAG,"发送媒体上传完成事件:"+fileName);
//LogUtil.log(TAG,"发送媒体上传完成事件:"+fileName);
try {
if (MqttManager.getInstance().mqttAndroidClient.isConnected()) {
MediaUpLoad mediaUpLoad = new MediaUpLoad();
@ -204,17 +208,23 @@ public abstract class BaseManager {
final FlightTaskProgress.Data.Output.Ext ext = new FlightTaskProgress.Data.Output.Ext();
ext.setCurrent_waypoint_index(Movement.getInstance().getTask_current_waypoint_index());
ext.setFlight_id(PreferenceUtils.getInstance().getFlightId());
//媒体文件数量
ext.setMedia_count(Movement.getInstance().getTask_media_count());
ext.setTrack_id(Movement.getInstance().getTrack_id());
ext.setWayline_id(Movement.getInstance().getTask_wayline_id());
ext.setWayline_mission_state(Movement.getInstance().getTask_wayline_mission_state());
final FlightTaskProgress.Data.Output.Progress progress = new FlightTaskProgress.Data.Output.Progress();
// LogUtil.log(TAG,"CurrentWayline"+CurrentWayline.getInstance().getWaypoints()+"size"+CurrentWayline.getInstance().getWaypoints().size()
// +"getTask_wayline_mission_state"+Movement.getInstance().getTask_wayline_mission_state());
if (CurrentWayline.getInstance().getWaypoints() != null
&& CurrentWayline.getInstance().getWaypoints().size() > 0
&& Movement.getInstance().getTask_wayline_mission_state() == 6) {
//这个没执行到
progress.setPercent((100 * (Movement.getInstance().getCurrentWaypointIndex() + 1)
/ CurrentWayline.getInstance().getWaypoints().size()));
}
progress.setCurrent_step(Movement.getInstance().getTask_current_step());
@ -264,6 +274,7 @@ public abstract class BaseManager {
breakPoint.setLatitude(breakPointInfo.getLocation().getLatitude());
breakPoint.setLongitude(breakPointInfo.getLocation().getLongitude());
breakPoint.setProgress(Movement.getInstance().getTask_progress());
breakPoint.setState(Movement.getInstance().getState());
breakPoint.setWayline_id(Movement.getInstance().getTask_wayline_id());
@ -353,9 +364,8 @@ public abstract class BaseManager {
MqttMessage mqttMessage = new MqttMessage(new Gson().toJson(flightTaskProgress).getBytes("UTF-8"));
mqttMessage.setQos(0);
MqttManager.getInstance().mqttAndroidClient.publish(AMSConfig.UP_UAV_EVENT, mqttMessage);
LogUtil.log(TAG, "发送任务进度事件(正常状态):" + new Gson().toJson(flightTaskProgress));
//LogUtil.log(TAG, "发送任务进度事件(正常状态):" + new Gson().toJson(flightTaskProgress));
}
} else {
LogUtil.log(TAG, "发送任务进度event失败mqtt 未连接");
}
@ -380,6 +390,7 @@ public abstract class BaseManager {
Movement.getInstance().setHeight(breakPointInfo.getLocation().getAltitude());
Movement.getInstance().setTask_latitude(breakPointInfo.getLocation().getLatitude());
Movement.getInstance().setTask_longitude(breakPointInfo.getLocation().getLongitude());
Movement.getInstance().setTask_progress(breakPointInfo.getSegmentProgress());
Movement.getInstance().setTask_state(0);
Movement.getInstance().setTask_wayline_id(breakPointInfo.getWaylineID());
@ -434,6 +445,109 @@ public abstract class BaseManager {
LogUtil.log(TAG, "发送sdr异常" + e.toString());
}
}
/**
* 上报一键起飞任务进度
*/
public void sendTakeoffToPointProgress2Server() {
try {
if (MqttManager.getInstance().mqttAndroidClient.isConnected()) {
// 构建 data 数据
TakeoffToPointProgress.Data data = new TakeoffToPointProgress.Data();
data.setFlightId(PreferenceUtils.getInstance().getFlightId());
data.setTrackId(PreferenceUtils.getInstance().getFlightId());
data.setStatus(Movement.getInstance().getTakeoff_status());
data.setResult(Movement.getInstance().getTakeoff_result());
data.setWayPointIndex(Movement.getInstance().getCurrentWaypointIndex());
data.setRemainingDistance(Movement.getInstance().getTakeoff_remaining_distance());
data.setRemainingTime(Movement.getInstance().getTakeoff_remaining_time());
data.setPlannedPathPoints(Movement.getInstance().getTakeoff_planned_path_points());
// 构建事件对象
TakeoffToPointProgress progress = new TakeoffToPointProgress();
progress.setBid(UUID.randomUUID().toString());
progress.setTid(UUID.randomUUID().toString());
progress.setTimestamp(System.currentTimeMillis());
progress.setMethod("takeoff_to_point_progress");
progress.setNeedReply(1);
progress.setData(data);
// 发送
MqttMessage mqttMessage = new MqttMessage(new Gson().toJson(progress).getBytes("UTF-8"));
mqttMessage.setQos(0);
MqttManager.getInstance().mqttAndroidClient.publish(AMSConfig.UP_UAV_EVENT, mqttMessage);
LogUtil.log(TAG, "发送一键起飞进度事件:" + new Gson().toJson(progress));
} else {
LogUtil.log(TAG, "发送一键起飞进度event失败mqtt 未连接");
}
} catch (Exception e) {
e.printStackTrace();
LogUtil.log(TAG, "发送一键起飞进度event异常" + e.toString());
}
}
/**
* 上报拍照进度camera_photo_take_progress
* 目前仅支持全景拍照模式
* 数据先存 Movement再组装发送
*/
public void sendCameraPhotoTakeProgress2Server() {
try {
if (MqttManager.getInstance().mqttAndroidClient.isConnected()) {
// 构建 output.progress
CameraPhotoTakeProgress.Data.Output.Progress progress =
new CameraPhotoTakeProgress.Data.Output.Progress();
progress.setCurrent_step(Movement.getInstance().getPhoto_current_step());
progress.setPercent(Movement.getInstance().getPhoto_percent());
// 构建 output.ext
CameraPhotoTakeProgress.Data.Output.Ext ext =
new CameraPhotoTakeProgress.Data.Output.Ext();
ext.setCamera_mode(3);
// 构建 output
CameraPhotoTakeProgress.Data.Output output =
new CameraPhotoTakeProgress.Data.Output();
output.setStatus(Movement.getInstance().getPhoto_status());
output.setProgress(progress);
output.setExt(ext);
// 构建 data
CameraPhotoTakeProgress.Data data = new CameraPhotoTakeProgress.Data();
data.setResult(Movement.getInstance().getPhoto_result());
data.setOutput(output);
// 构建完整消息
CameraPhotoTakeProgress photoProgress = new CameraPhotoTakeProgress();
photoProgress.setBid(UUID.randomUUID().toString());
photoProgress.setTid(UUID.randomUUID().toString());
photoProgress.setTimestamp(System.currentTimeMillis());
photoProgress.setMethod("camera_photo_take_progress");
photoProgress.setData(data);
// 发送
MqttMessage mqttMessage = new MqttMessage(
new Gson().toJson(photoProgress).getBytes("UTF-8")
);
mqttMessage.setQos(0);
MqttManager.getInstance().mqttAndroidClient.publish(
AMSConfig.UP_UAV_EVENT,
mqttMessage
);
LogUtil.log(TAG, "发送拍照进度事件:" + new Gson().toJson(photoProgress));
} else {
LogUtil.log(TAG, "发送拍照进度失败mqtt 未连接");
}
} catch (Exception e) {
e.printStackTrace();
LogUtil.log(TAG, "发送拍照进度异常:" + e.toString());
}
}
public boolean getGimbalAndCameraEnabled() {

View File

@ -6,6 +6,7 @@ import android.os.Looper;
import android.util.Log;
import com.aros.apron.app.ApronApp;
import com.aros.apron.base.BaseManager;
import com.aros.apron.constant.AMSConfig;
import com.aros.apron.constant.Constant;
import com.aros.apron.entity.ApronExecutionStatus;
@ -31,7 +32,7 @@ import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
import org.eclipse.paho.client.mqttv3.MqttMessage;
public class MqttCallBack implements MqttCallbackExtended {
public class MqttCallBack extends BaseManager implements MqttCallbackExtended {
private String TAG = "MqttCallBack";
@ -43,7 +44,6 @@ public class MqttCallBack implements MqttCallbackExtended {
clearVirtualStickHeartbeat();
}
//断线重连
public void reConnect() throws Exception {
if (null != MqttManager.getInstance().mqttAndroidClient) {
@ -52,6 +52,7 @@ public class MqttCallBack implements MqttCallbackExtended {
}
// 心跳检测
private volatile long lastDrControlTime = 0;
private final Handler vsHandler = new Handler(Looper.getMainLooper());
@ -59,9 +60,7 @@ public class MqttCallBack implements MqttCallbackExtended {
private static final long TIMEOUT_MS = 500; // 500ms 无数据触发
/**
* 每次收到控制指令都调
*/
/** 每次收到控制指令都调 */
private void resetVirtualStickHeartbeat() {
lastDrControlTime = System.currentTimeMillis();
@ -80,9 +79,7 @@ public class MqttCallBack implements MqttCallbackExtended {
vsHandler.postDelayed(vsTimeoutCheck, TIMEOUT_MS);
}
/**
* 清理虚拟摇杆心跳断网/退出/销毁时调
*/
/** 清理虚拟摇杆心跳(断网/退出/销毁时调) */
private void clearVirtualStickHeartbeat() {
if (vsTimeoutCheck != null) {
vsHandler.removeCallbacks(vsTimeoutCheck);
@ -92,17 +89,24 @@ public class MqttCallBack implements MqttCallbackExtended {
}
@Override
public void messageArrived(String topic, MqttMessage mqttMessage) {
String jsonString = null;
//Log.e(TAG, "入口打印:" +mqttMessage.toString());
try {
jsonString = new String(mqttMessage.getPayload(), "UTF-8");
} catch (Exception e) {
LogUtil.log(TAG, "解析异常");
throw new RuntimeException(e);
}
MessageDown message = new Gson().fromJson(jsonString, MessageDown.class);
//LogUtil.log(TAG,message.getMethod());
switch (message.getMethod()) {
case Constant.PILOT_ON:
// LogUtil.log(TAG, "收到:遥控器是否开机" + jsonString);
@ -140,7 +144,7 @@ public class MqttCallBack implements MqttCallbackExtended {
LogUtil.log(TAG, "收到:航线" + jsonString);
//设置modecode
Movement.getInstance().setMode_code(1);
OSDManager.getInstance().pushFlightAttitude();
sendFlightTaskProgress2Server();
//设置标志为
Movement.getInstance().setFlightmode(1);
MissionV3Manager.getInstance().taskExecute(message);
@ -158,6 +162,7 @@ public class MqttCallBack implements MqttCallbackExtended {
LogUtil.log(TAG, "收到:返航" + jsonString);
//自动返航 (如果调用方法失败了 这个设置就有一个问题但是为了方便看懂我就放这里了没放成功的回调里面)
Movement.getInstance().setMode_code(9);
sendFlightTaskProgress2Server();
FlightManager.getInstance().startGoHome(message);
break;
case Constant.RETURN_HOME_CANCEL:
@ -184,7 +189,7 @@ public class MqttCallBack implements MqttCallbackExtended {
LogUtil.log(TAG, "收到:一键起飞" + jsonString);
//设置modecode
Movement.getInstance().setMode_code(1);
OSDManager.getInstance().pushFlightAttitude();
sendFlightTaskProgress2Server();
//设置标志为
Movement.getInstance().setFlightmode(2);
TakeOffToPointManager.getInstance().taskExecute(message);
@ -260,10 +265,6 @@ public class MqttCallBack implements MqttCallbackExtended {
LogUtil.log(TAG, "收到:负载控制—变焦" + jsonString);
CameraManager.getInstance().setCameraZoomRatios(message);
break;
case Constant.CAMERA_FRAME_ZOOM:
LogUtil.log(TAG, "收到:框选变焦" + jsonString);
CameraManager.getInstance().camera_frame_zoom(message);
break;
case Constant.GIMBAL_RESET:
LogUtil.log(TAG, "收到:负载控制—重置云台" + jsonString);
GimbalManager.getInstance().gimbalReset(message);
@ -316,6 +317,11 @@ public class MqttCallBack implements MqttCallbackExtended {
case Constant.POI_CIRCLE_SPEED_SET:
LogUtil.log(TAG, "收到飞行控制—POI 环绕速度设置" + jsonString);
break;
case Constant.CAMERA_FRAME_ZOOM:
LogUtil.log(TAG, "收到:框选变焦" + jsonString);
CameraManager.getInstance().camera_frame_zoom(message);
break;
// //获取控制权
// case 60007:
// LogUtil.log(TAG, "收到:获取控制权" + jsonString);
@ -667,7 +673,6 @@ public class MqttCallBack implements MqttCallbackExtended {
public void deliveryComplete(IMqttDeliveryToken token) {
}
String[] topics = new String[] {
AMSConfig.getInstance().DOWN_UAV_EVENT_REPLY,
AMSConfig.getInstance().DOWN_UAV_SERVICES,
@ -675,7 +680,6 @@ public class MqttCallBack implements MqttCallbackExtended {
int[] qos = new int[] {
1, 1
};
@Override
public void connectComplete(boolean reconnect, String serverURI) {
try {

View File

@ -277,13 +277,14 @@ public class Constant {
* 遥控器上报sdr和4g状态
*/
public static final String WIRELESS_LINK="wireless_link";
/**
* 框选变焦
*/
public static final String CAMERA_FRAME_ZOOM="camera_frame_zoom";
/**
* 急停
*/

View File

@ -88,6 +88,10 @@ public class FlightMission {
this.speed = speed;
}
public Float getTakeOffSecurityHeight() {
return takeOffSecurityHeight;
}

View File

@ -68,7 +68,7 @@ public class MessageDown {
private int out_of_control_action;
private boolean takeoffToPointTask;
private BreakPoint break_point;
private int camera_mode;
private int camera_mode=0;//初始化为拍照
private String h;
private String seq;
private String w;
@ -90,13 +90,13 @@ public class MessageDown {
private int focus_mode;
private int focus_value;
private int commander_flight_height;
private double commander_flight_height;
private int commander_mode_lost_action;
private String max_speed;
private int rc_lost_action;
private int rth_altitude;
private String security_takeoff_height;
private int target_height;
private double target_height;
private double target_latitude;
private double target_longitude;
private String fly_to_id;
@ -110,6 +110,7 @@ public class MessageDown {
private float width;
public float getWidth() {
return width;
}
@ -187,7 +188,7 @@ public class MessageDown {
this.longitude = longitude;
}
}
public int getCommander_flight_height() {
public double getCommander_flight_height() {
return commander_flight_height;
}
@ -227,7 +228,7 @@ public class MessageDown {
this.security_takeoff_height = security_takeoff_height;
}
public int getTarget_height() {
public double getTarget_height() {
return target_height;
}

View File

@ -0,0 +1,135 @@
package com.aros.apron.entity;
/**
* 服务端下发的整条 JSON 对应实体
*/
public class MissionDataBean {
/** 备降点 */
private LatLngAlt alternate_land_point;
/** 指挥官飞行高度 */
private int commander_flight_height;
/** 指挥官模式丢失动作 */
private int commander_mode_lost_action;
/** 航线唯一编号 */
private String flight_id;
/** 最大飞行速度 (m/s) */
private int max_speed;
/** 遥控丢失动作 */
private int rc_lost_action;
/** 返航高度 (m) */
private int rth_altitude;
/** 安全起飞高度 (m) */
private double security_takeoff_height;
/** 目标高度 (m) */
private double target_height;
/** 目标纬度 (°) */
private double target_latitude;
/** 目标经度 (°) */
private double target_longitude;
/* ---------------- getter / setter ---------------- */
public LatLngAlt getAlternateLandPoint() {
return alternate_land_point;
}
public void setAlternateLandPoint(LatLngAlt alternate_land_point) {
this.alternate_land_point = alternate_land_point;
}
public int getCommanderFlightHeight() {
return commander_flight_height;
}
public void setCommanderFlightHeight(int commander_flight_height) {
this.commander_flight_height = commander_flight_height;
}
public int getCommanderModeLostAction() {
return commander_mode_lost_action;
}
public void setCommanderModeLostAction(int commander_mode_lost_action) {
this.commander_mode_lost_action = commander_mode_lost_action;
}
public String getFlightId() {
return flight_id;
}
public void setFlightId(String flight_id) {
this.flight_id = flight_id;
}
public int getMaxSpeed() {
return max_speed;
}
public void setMaxSpeed(int max_speed) {
this.max_speed = max_speed;
}
public int getRcLostAction() {
return rc_lost_action;
}
public void setRcLostAction(int rc_lost_action) {
this.rc_lost_action = rc_lost_action;
}
public int getRthAltitude() {
return rth_altitude;
}
public void setRthAltitude(int rth_altitude) {
this.rth_altitude = rth_altitude;
}
public double getSecurityTakeoffHeight() {
return security_takeoff_height;
}
public void setSecurityTakeoffHeight(int security_takeoff_height) {
this.security_takeoff_height = security_takeoff_height;
}
public double getTargetHeight() {
return target_height;
}
public void setTargetHeight(double target_height) {
this.target_height = target_height;
}
public double getTargetLatitude() {
return target_latitude;
}
public void setTargetLatitude(double target_latitude) {
this.target_latitude = target_latitude;
}
public double getTargetLongitude() {
return target_longitude;
}
public void setTargetLongitude(double target_longitude) {
this.target_longitude = target_longitude;
}
/* ---------------- 内部嵌套类:备降点 ---------------- */
public static class LatLngAlt {
private double latitude;
private double longitude;
private double safe_land_height;
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public double getSafeLandHeight() {
return safe_land_height;
}
public void setSafeLandHeight(int safe_land_height) {
this.safe_land_height = safe_land_height;
}
}
}

View File

@ -113,6 +113,8 @@ public class Movement {
private boolean virtualcontrollget=false;//是否已经获得过控制权
private int GPSSatelliteCount; //卫星个数
//适配上云格式参数拿到后再进行组装
private double measure_target_altitude;
@ -274,6 +276,124 @@ public class Movement {
private String sdr_freq_band;
private String freq_band_4g;
// ========== 一键起飞相关字段 ==========
private boolean takeofftopointmission;
private String takeoff_status; // task_ready/wayline_progress/wayline_ok/wayline_failed/wayline_cancel/task_finish
private int takeoff_result; // 0成功非0错误
private float takeoff_remaining_distance; // 剩余距离
private float takeoff_remaining_time; // 剩余时间
private double speed; //全局速度
private List<TakeoffToPointProgress.PlannedPathPoint> takeoff_planned_path_points; // 规划轨迹点
// ========== 上报拍照进度 ==========(全景)
private String photo_status; // in_progress/ok/fail
private int photo_current_step; // 3000/3002/3005
private int photo_percent; // 0-100
private int photo_result; // 0成功非0错误
public int getGPSSatelliteCount() {
return GPSSatelliteCount;
}
public void setGPSSatelliteCount(int GPSSatelliteCount) {
this.GPSSatelliteCount = GPSSatelliteCount;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
public boolean isTakeofftopointmission() {
return takeofftopointmission;
}
public void setTakeofftopointmission(boolean takeofftopointmission) {
this.takeofftopointmission = takeofftopointmission;
}
public int getPhoto_current_step() {
return photo_current_step;
}
public void setPhoto_current_step(int photo_current_step) {
this.photo_current_step = photo_current_step;
}
public int getPhoto_result() {
return photo_result;
}
public void setPhoto_result(int photo_result) {
this.photo_result = photo_result;
}
public String getPhoto_status() {
return photo_status;
}
public void setPhoto_status(String photo_status) {
this.photo_status = photo_status;
}
public int getPhoto_percent() {
return photo_percent;
}
public void setPhoto_percent(int photo_percent) {
this.photo_percent = photo_percent;
}
public String getTakeoff_status() {
return takeoff_status;
}
public void setTakeoff_status(String takeoff_status) {
this.takeoff_status = takeoff_status;
}
public int getTakeoff_result() {
return takeoff_result;
}
public void setTakeoff_result(int takeoff_result) {
this.takeoff_result = takeoff_result;
}
public float getTakeoff_remaining_distance() {
return takeoff_remaining_distance;
}
public void setTakeoff_remaining_distance(float takeoff_remaining_distance) {
this.takeoff_remaining_distance = takeoff_remaining_distance;
}
public float getTakeoff_remaining_time() {
return takeoff_remaining_time;
}
public void setTakeoff_remaining_time(float takeoff_remaining_time) {
this.takeoff_remaining_time = takeoff_remaining_time;
}
public List<TakeoffToPointProgress.PlannedPathPoint> getTakeoff_planned_path_points() {
return takeoff_planned_path_points;
}
public void setTakeoff_planned_path_points(List<TakeoffToPointProgress.PlannedPathPoint> takeoff_planned_path_points) {
this.takeoff_planned_path_points = takeoff_planned_path_points;
}
public boolean isVirtualcontrollget() {
return virtualcontrollget;
}

View File

@ -77,7 +77,7 @@ public class Osd {
public static class Data {
@SerializedName("53-0-0")
private Data._$5300 _$5300;
private _$5300 _$5300;
private int activation_time;
private double attitude_head;
private double attitude_pitch;

View File

@ -4,6 +4,8 @@ import static com.aros.apron.tools.Utils.getIDJIErrorMsg;
import static dji.sdk.keyvalue.key.KeyTools.createKey;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -28,14 +30,20 @@ import dji.sdk.keyvalue.value.camera.CameraStorageInfo;
import dji.sdk.keyvalue.value.camera.CameraStorageInfos;
import dji.sdk.keyvalue.value.camera.CameraStorageLocation;
import dji.sdk.keyvalue.value.camera.CameraThermalPalette;
import dji.sdk.keyvalue.value.camera.CameraType;
import dji.sdk.keyvalue.value.camera.CameraVideoStreamSourceType;
import dji.sdk.keyvalue.value.camera.LaserMeasureInformation;
import dji.sdk.keyvalue.value.camera.PanoramaExitStatus;
import dji.sdk.keyvalue.value.camera.PhotoPanoStichingState;
import dji.sdk.keyvalue.value.camera.PhotoState;
import dji.sdk.keyvalue.value.camera.RecordingState;
import dji.sdk.keyvalue.value.camera.TapZoomMode;
import dji.sdk.keyvalue.value.camera.ThermalDigitalZoomFactor;
import dji.sdk.keyvalue.value.camera.ThermalDisplayMode;
import dji.sdk.keyvalue.value.camera.ThermalGainMode;
import dji.sdk.keyvalue.value.camera.ThermalTemperatureMeasureMode;
import dji.sdk.keyvalue.value.camera.VideoRecordingStatus;
import dji.sdk.keyvalue.value.camera.VisionPhotoPanoramaMissionState;
import dji.sdk.keyvalue.value.camera.ZoomTargetPointInfo;
import dji.sdk.keyvalue.value.common.CameraLensType;
import dji.sdk.keyvalue.value.common.ComponentIndexType;
@ -47,6 +55,39 @@ import dji.v5.common.error.IDJIError;
import dji.v5.manager.KeyManager;
public class CameraManager extends BaseManager {
private Handler panoHandler = new Handler(Looper.getMainLooper());
private Runnable panoRunnable;
private boolean isPanoRunning = false;
private static final long INTERVAL = 1000; // 1秒
private void startReport() {
if (isPanoRunning) return; // 已开启则忽略
isPanoRunning = true;
panoRunnable = new Runnable() {
@Override
public void run() {
if (!isPanoRunning) return;
sendCameraPhotoTakeProgress2Server(); // 你的方法
panoHandler.postDelayed(this, INTERVAL); // 1秒后循环
}
};
panoHandler.post(panoRunnable); // 立即执行
}
private void stopReport() {
if (!isPanoRunning) return;
isPanoRunning = false;
panoHandler.removeCallbacks(panoRunnable);
sendCameraPhotoTakeProgress2Server(); // 最后报一次
}
private CameraManager() {
@ -73,6 +114,84 @@ public class CameraManager extends BaseManager {
}
}
});
//全景任务状态
KeyManager.getInstance().listen(createKey(CameraKey.KeyVisionPhotoPanoramaMissionState, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener<VisionPhotoPanoramaMissionState>() {
@Override
public void onValueChange(@Nullable VisionPhotoPanoramaMissionState visionPhotoPanoramaMissionState, @Nullable VisionPhotoPanoramaMissionState t1) {
if (t1 != null) {
if (t1 == VisionPhotoPanoramaMissionState.IDLE) {
Movement.getInstance().setPhoto_current_step(3000);
} else if (t1 == VisionPhotoPanoramaMissionState.RELEASE) {
// Movement.getInstance().setPhoto_result(0);
// Movement.getInstance().setPhoto_status("ok");
// Movement.getInstance().setCameraMode(3);
// stopReport();
} else if (t1 == VisionPhotoPanoramaMissionState.RUNNING) {
Movement.getInstance().setPhoto_status("in_progress");
Movement.getInstance().setPhoto_current_step(3002);
} else if (t1 == VisionPhotoPanoramaMissionState.UNKNOWN) {
// Movement.getInstance().setPhoto_result(1);
// Movement.getInstance().setPhoto_current_step(3000);
// Movement.getInstance().setPhoto_status("fail");
} else if (t1 == VisionPhotoPanoramaMissionState.PROCESSING) {
Movement.getInstance().setPhoto_current_step(3005);
} else if (t1 == VisionPhotoPanoramaMissionState.FORBIDDEN) {
Movement.getInstance().setPhoto_result(1);
Movement.getInstance().setPhoto_current_step(3000);
Movement.getInstance().setPhoto_status("fail");
}
}
}
});
//全景退出
KeyManager.getInstance().listen(createKey(CameraKey.KeyPanoramaExitStatus, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener<PanoramaExitStatus>() {
@Override
public void onValueChange(@Nullable PanoramaExitStatus panoramaExitStatus, @Nullable PanoramaExitStatus t1) {
if(t1!=null){
LogUtil.log(TAG,t1.toString());
if(t1==PanoramaExitStatus.SUCCESSFUL){
Movement.getInstance().setPhoto_current_step(3000);
Movement.getInstance().setPhoto_result(0);
Movement.getInstance().setPhoto_status("ok");
Movement.getInstance().setCameraMode(3);
Movement.getInstance().setMode_code(3);
stopReport();
}
}
}
});
KeyManager.getInstance().listen(createKey(CameraKey.KeyPanoramaProgressInPercent, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener<Integer>() {
@Override
public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) {
if (t1 != null) {
Movement.getInstance().setPhoto_percent(t1);
if(t1==100){
Movement.getInstance().setPhoto_current_step(3000);
Movement.getInstance().setPhoto_result(0);
Movement.getInstance().setPhoto_status("ok");
Movement.getInstance().setCameraMode(3);
Movement.getInstance().setMode_code(3);
stopReport();
}
}
}
});
//是否正在拍全景
KeyManager.getInstance().listen(createKey(CameraKey.KeyIsShootingPhotoPanorama, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener<Boolean>() {
@Override
public void onValueChange(@Nullable Boolean aBoolean, @Nullable Boolean t1) {
if (t1 != null) {
if (t1 == true) {
startReport();
} else {
stopReport();
}
}
}
});
//激光测距信息
KeyManager.getInstance().listen(createKey(CameraKey.KeyLaserMeasureInformation, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener<LaserMeasureInformation>() {
@Override
@ -160,8 +279,8 @@ public class CameraManager extends BaseManager {
@Override
public void onValueChange(@Nullable CameraMode oldValue, @Nullable CameraMode newValue) {
if (newValue != null) {
Movement.getInstance().setCamera_mode(newValue.value());
LogUtil.log(TAG, "相机模式:" + newValue + "old" + oldValue);
//Movement.getInstance().setCamera_mode(newValue.value());
// LogUtil.log(TAG, "相机模式:" + newValue + "old" + oldValue);
}
}
});
@ -222,7 +341,6 @@ public class CameraManager extends BaseManager {
}
});
//视频录制时长
KeyManager.getInstance().listen(KeyTools.createKey(CameraKey.
KeyRecordingTime, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener<Integer>() {
@ -233,8 +351,6 @@ public class CameraManager extends BaseManager {
}
}
});
//视频录制状态
KeyManager.getInstance().listen(KeyTools.createKey(CameraKey.
KeyRecordingState, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener<RecordingState>() {
@ -252,39 +368,53 @@ public class CameraManager extends BaseManager {
@Override
public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) {
if (t1 != null) {
LogUtil.log(TAG, "剩余拍照数setRemain_photo_num" + t1 + "old" + integer);
//LogUtil.log(TAG, "剩余拍照数setRemain_photo_num" + t1 + "old" + integer);
if (t1 != 0) {
Movement.getInstance().setRemain_photo_num(t1);
}
}
}
});
//剩余录像时间
KeyManager.getInstance().listen(KeyTools.createKey(CameraKey.
KeySSDAvailableRecordingTimeInSeconds, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener<Integer>() {
KeyIsRecording, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener<Boolean>() {
@Override
public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) {
public void onValueChange(@Nullable Boolean aBoolean, @Nullable Boolean t1) {
if(t1!=null){
//
LogUtil.log(TAG, "剩余录像时间KeySSDAvailableRecordingTimeInSeconds" + t1 + "old" + integer);
Movement.getInstance().setRemain_record_duration(t1);
if(t1==true){
Integer recordingTime = KeyManager.getInstance().getValue(
KeyTools.createKey(CameraKey.KeySSDAvailableRecordingTimeInSeconds, ComponentIndexType.PORT_1)
);
LogUtil.log(TAG,"录像时间"+recordingTime);
}
}
}
});
//视频录制时长
KeyManager.getInstance().listen(KeyTools.createKey(CameraKey.
KeySSDAvailableRecordingTimeInSeconds, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener<Integer>() {
KeyManager.getInstance().listen(KeyTools.createKey(CameraKey.KeyRecordingTime, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener<Integer>() {
@Override
public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) {
if (t1 != null) {
Movement.getInstance().setRemain_record_duration(t1);
Movement.getInstance().setRecord_time(t1);
}
}
});
//是否在录像
KeyManager.getInstance().listen(KeyTools.createKey(CameraKey.KeyVideoRecordingStatus, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener<VideoRecordingStatus>() {
@Override
public void onValueChange(@Nullable VideoRecordingStatus videoRecordingStatus, @Nullable VideoRecordingStatus t1) {
if (t1 != null) {
Boolean recording = t1.getIsRecording();
if (recording != null && recording) {
Movement.getInstance().setRecording_state(1); // 正在录
} else {
Movement.getInstance().setRecording_state(0); // 未录或未知
}
}
}
});
//分屏是否使能
KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalDisplayMode,
ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener<ThermalDisplayMode>() {
@ -302,7 +432,7 @@ public class CameraManager extends BaseManager {
@Override
public void onValueChange(@Nullable CameraExposureMode cameraExposureMode, @Nullable CameraExposureMode t1) {
if (t1 != null) {
LogUtil.log(TAG, "监听曝光模式:" + t1.name());
//LogUtil.log(TAG, "监听曝光模式:" + t1.name());
Movement.getInstance().setWide_exposure_mode(t1.value());
}
}
@ -395,7 +525,15 @@ public class CameraManager extends BaseManager {
}
}
});
KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalZoomRatios,
ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener<Double>() {
@Override
public void onValueChange(@Nullable Double aDouble, @Nullable Double t1) {
if (t1 != null) {
Movement.getInstance().setZoom_factor(t1);
}
}
});
//变焦倍数
KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraZoomRatios,
ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener<Double>() {
@ -515,7 +653,15 @@ public class CameraManager extends BaseManager {
KeyConnection, ComponentIndexType.PORT_1));
if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) {
if (message != null) {
int cameraMode = message.getData().getCamera_mode();
// 新增如果当前已经是该模式直接返回成功
if (cameraMode == Movement.getInstance().getCamera_mode()) {
LogUtil.log(TAG, "相机模式已是" + cameraMode + ",无需切换");
sendMsg2Server(message);
return;
}
ProductType productType = KeyManager.getInstance().getValue(KeyTools.createKey(ProductKey.KeyProductType));
if (productType != null) {
int cameraModevalue = 0;
@ -526,14 +672,16 @@ public class CameraManager extends BaseManager {
} else if (cameraMode == 3) {
cameraModevalue = 12;
}
//设置相机模式
Movement.getInstance().setCamera_mode(cameraMode);
KeyManager.getInstance().setValue(KeyTools.createKey(CameraKey.KeyCameraMode, ComponentIndexType.PORT_1),
KeyManager.getInstance().setValue(KeyTools.createKey(CameraKey.KeyCameraMode, ComponentIndexType.PORT_1),
CameraMode.find(cameraModevalue),
new CommonCallbacks.CompletionCallback() {
@Override
public void onSuccess() {
//设置相机模式
Movement.getInstance().setCamera_mode(cameraMode);
LogUtil.log(TAG, "切换成功" + Movement.getInstance().getCamera_mode());
OSDManager.getInstance().pushFlightAttitude();
sendMsg2Server(message);
}
@ -633,6 +781,7 @@ public class CameraManager extends BaseManager {
Double.valueOf(zoomRatio), new CommonCallbacks.CompletionCallback() {
@Override
public void onSuccess() {
LogUtil.log(TAG, "变焦成功");
sendMsg2Server(message);
}
@ -642,12 +791,14 @@ public class CameraManager extends BaseManager {
}
});
}
@Override
public void onFailure(@NonNull IDJIError error) {
sendFailMsg2Server(message, "aim操作失败:" + getIDJIErrorMsg(error));
}
});
}
//设置变焦倍率
public static double calculateZoomRatio(double width, double height) {
// 防呆如果传入 0 或负数返回 1 zoom
@ -668,6 +819,7 @@ public class CameraManager extends BaseManager {
return Math.max(1.0, Math.min(200.0, zoom));
}
//开始拍照
public void startShootPhoto(MessageDown message) {
Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey.
@ -678,6 +830,7 @@ public class CameraManager extends BaseManager {
new CommonCallbacks.CompletionCallbackWithParam<EmptyMsg>() {
@Override
public void onSuccess(EmptyMsg emptyMsg) {
LogUtil.log(TAG,"拍照成功");
sendMsg2Server(message);
}
@ -716,6 +869,7 @@ public class CameraManager extends BaseManager {
}
}
//开始录像
public void startRecordVideo(MessageDown message) {
Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey.
@ -765,39 +919,119 @@ public class CameraManager extends BaseManager {
public void setCameraZoomRatios(MessageDown message) {
Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey.
KeyConnection, ComponentIndexType.PORT_1));
if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) {
if (message != null) {
int type = 1;
switch (message.getData().getCamera_type()) {
if (isConnect == null || !isConnect || !getGimbalAndCameraEnabled()) {
sendFailMsg2Server(message, "当前状态相机禁止操作");
return;
}
if (message == null) return;
String cameraType = message.getData().getCamera_type();
double zoomFactor = message.getData().getZoom_factor();
// 检查是否有红外H30T
CameraType cameraTypeEnum = KeyManager.getInstance().getValue(
KeyTools.createKey(CameraKey.KeyCameraType, ComponentIndexType.PORT_1));
boolean hasThermal = (cameraTypeEnum == CameraType.ZENMUSE_H30T);
// 1. 映射视频流类型和镜头类型
CameraVideoStreamSourceType streamSource;
CameraLensType lensType;
double minZoom, maxZoom;
final boolean isWide;
final boolean isIr;
switch (cameraType) {
case "ir":
type = 3;
break;
case "normal":
type = 0;
if (!hasThermal) {
sendFailMsg2Server(message, "当前负载无红外功能仅H30T支持");
return;
}
streamSource = CameraVideoStreamSourceType.INFRARED_CAMERA;
lensType = CameraLensType.CAMERA_LENS_THERMAL;
minZoom = 2;
maxZoom = 20; // 红外 2-20倍
isWide = false;
isIr = true;
break;
case "wide":
type = 1;
streamSource = CameraVideoStreamSourceType.WIDE_CAMERA;
lensType = CameraLensType.CAMERA_LENS_WIDE;
minZoom = 1;
maxZoom = 1;
isWide = true;
isIr = false;
break;
case "zoom":
type = 2;
streamSource = CameraVideoStreamSourceType.ZOOM_CAMERA;
lensType = CameraLensType.CAMERA_LENS_ZOOM;
minZoom = 2;
maxZoom = 200;
isWide = false;
isIr = false;
break;
default:
streamSource = CameraVideoStreamSourceType.DEFAULT_CAMERA;
lensType = CameraLensType.CAMERA_LENS_ZOOM;
minZoom = 2;
maxZoom = 200;
isWide = false;
isIr = false;
break;
}
KeyManager.getInstance().setValue(KeyTools.createKey(CameraKey.KeyCameraVideoStreamSource,
ComponentIndexType.PORT_1)
, CameraVideoStreamSourceType.find(type),
// 2. 切换视频流
final double finalMinZoom = minZoom;
final double finalMaxZoom = maxZoom;
KeyManager.getInstance().setValue(
KeyTools.createKey(CameraKey.KeyCameraVideoStreamSource, ComponentIndexType.PORT_1),
streamSource,
new CommonCallbacks.CompletionCallback() {
@Override
public void onSuccess() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
int cameraZoomRatios = message.getData().getZoom_factor();
KeyManager.getInstance().setValue(KeyTools.createCameraKey(CameraKey.KeyCameraZoomRatios,
ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM),
Double.valueOf(cameraZoomRatios), new CommonCallbacks.CompletionCallback() {
// 广角不设置变焦
if (isWide) {
LogUtil.log(TAG, "广角切换成功,无需设置变焦");
Movement.getInstance().setZoom_factor(1);
sendMsg2Server(message);
return;
}
// 强制截断变焦范围
final double validZoom = Math.max(finalMinZoom, Math.min(finalMaxZoom, zoomFactor));
new Handler(Looper.getMainLooper()).postDelayed(() -> {
if (isIr) {
KeyManager.getInstance().setValue(
KeyTools.createCameraKey(CameraKey.KeyThermalZoomRatios,
ComponentIndexType.PORT_1, lensType),
validZoom,
new CommonCallbacks.CompletionCallback() {
@Override
public void onSuccess() {
Movement.getInstance().setZoom_factor(cameraZoomRatios);
LogUtil.log(TAG, "红外变焦成功: " + validZoom);
Movement.getInstance().setZoom_factor((int) validZoom);
sendMsg2Server(message);
}
@Override
public void onFailure(@NonNull IDJIError error) {
sendFailMsg2Server(message, "红外变焦失败:" + getIDJIErrorMsg(error));
}
}
);
} else {
// 可见光变焦
KeyManager.getInstance().setValue(
KeyTools.createCameraKey(CameraKey.KeyCameraZoomRatios,
ComponentIndexType.PORT_1, lensType),
validZoom,
new CommonCallbacks.CompletionCallback() {
@Override
public void onSuccess() {
LogUtil.log(TAG, "变焦成功: " + cameraType + "=" + validZoom);
Movement.getInstance().setZoom_factor((int) validZoom);
sendMsg2Server(message);
}
@ -805,7 +1039,8 @@ public class CameraManager extends BaseManager {
public void onFailure(@NonNull IDJIError error) {
sendFailMsg2Server(message, "设置变焦倍率失败:" + getIDJIErrorMsg(error));
}
});
}
);
}
}, 200);
}
@ -814,13 +1049,30 @@ public class CameraManager extends BaseManager {
public void onFailure(@NonNull IDJIError error) {
sendFailMsg2Server(message, "切换相机视频流失败:" + getIDJIErrorMsg(error));
}
});
} else {
sendFailMsg2Server(message, "当前状态相机禁止操作");
}
}
);
}
// private void setstepThermalZoomRatios(){
// KeyManager.getInstance().setValue(
// KeyTools.createKey(CameraKey.KeyThermalDigitalZoomFactor, ComponentIndexType.PORT_1),
// ThermalDigitalZoomFactor.FACTOR_X2,
// new CommonCallbacks.CompletionCallback() {
// @Override
// public void onSuccess() {
// //
// LogUtil.log(TAG,"设置红外步长为2x");
// }
//
// @Override
// public void onFailure(@NonNull IDJIError idjiError) {
// LogUtil.log(TAG,"设置红外步长为1x失败"+idjiError);
//
// }
// }
// );
// }
// //设置红外变焦倍率(支持1x2x4x8x变焦倍率)
// public void setThermalZoomRatios(MQMessage message) {
// Boolean isConnect =KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey.

View File

@ -7,8 +7,10 @@ import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.aros.apron.base.BaseManager;
import com.aros.apron.constant.AMSConfig;
import com.aros.apron.entity.ApronExecutionStatus;
@ -22,8 +24,11 @@ import com.aros.apron.tools.LogUtil;
import com.aros.apron.tools.MqttManager;
import com.aros.apron.tools.PreferenceUtils;
import com.google.gson.Gson;
import org.greenrobot.eventbus.EventBus;
import java.util.List;
import dji.sdk.keyvalue.key.AirLinkKey;
import dji.sdk.keyvalue.key.FlightControllerKey;
import dji.sdk.keyvalue.key.KeyTools;
@ -103,7 +108,6 @@ public class FlightManager extends BaseManager {
} else {
LogUtil.log(TAG, "setMode_code1(0)");
//连上就待机
Movement.getInstance().setMissionFinish(false);
@ -121,7 +125,6 @@ public class FlightManager extends BaseManager {
Movement.getInstance().setMode_code(14);
}
if (isConnect != null && isConnect) {
if (!TextUtils.isEmpty(PreferenceUtils.getInstance().getAlternatePointLon())
@ -131,10 +134,12 @@ public class FlightManager extends BaseManager {
}
iDeviceStatusManager = dji.v5.manager.diagnostic.DeviceStatusManager.getInstance();
LogUtil.log(TAG,"iDeviceStatusManager"+"设置成功");
iDeviceStatusManager.addDJIDeviceStatusChangeListener(new DJIDeviceStatusChangeListener() {
@Override
public void onDeviceStatusUpdate(DJIDeviceStatus from, DJIDeviceStatus to) {
if (to != null && !TextUtils.isEmpty(to.description())) {
LogUtil.log(TAG,"setPlaneMessage"+to.description());
Movement.getInstance().setPlaneMessage(to.description());
pushFlightAttitude();
}
@ -204,7 +209,6 @@ public class FlightManager extends BaseManager {
pushFlightAttitude();
}
}
});
@ -227,7 +231,6 @@ public class FlightManager extends BaseManager {
}
});
//挡位
KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyRemoteControllerFlightMode), this, new CommonCallbacks.KeyListener<RemoteControllerFlightMode>() {
@Override
@ -238,7 +241,6 @@ public class FlightManager extends BaseManager {
}
}
});
KeyManager.getInstance().listen(KeyTools.createKey(ProductKey.KeyProductType), this, new CommonCallbacks.KeyListener<ProductType>() {
@Override
public void onValueChange(@Nullable ProductType productType, @Nullable ProductType t1) {
@ -248,7 +250,6 @@ public class FlightManager extends BaseManager {
}
}
});
//飞机SN号
KeyManager.getInstance().listen(createKey(FlightControllerKey.KeySerialNumber), this, new CommonCallbacks.KeyListener<String>() {
@Override
@ -259,7 +260,6 @@ public class FlightManager extends BaseManager {
}
}
});
//RID状态
KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyRidWorkingStatusPush), this, new CommonCallbacks.KeyListener<RidWorkingStatusPushMsg>() {
@Override
@ -271,7 +271,6 @@ public class FlightManager extends BaseManager {
}
}
});
//rtk起飞高度(计算海拔高度使用)
KeyManager.getInstance().listen(createKey(RtkMobileStationKey.KeyRTKTakeoffAltitudeInfo), this, new CommonCallbacks.KeyListener<RTKTakeoffAltitudeInfo>() {
@Override
@ -305,10 +304,20 @@ public class FlightManager extends BaseManager {
Movement.getInstance().setLatitude(newValue.getLatitude());
Movement.getInstance().setLongitude(newValue.getLongitude());
pushFlightAttitude();
}
}
});
KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyAircraftVelocity), this, new CommonCallbacks.KeyListener<Velocity3D>() {
@Override
public void onValueChange(@Nullable Velocity3D velocity3D, @Nullable Velocity3D t1) {
}
});
//水平&垂直速度
KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyAircraftVelocity), this, new CommonCallbacks.KeyListener<Velocity3D>() {
@Override
@ -338,6 +347,17 @@ public class FlightManager extends BaseManager {
}
});
KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyGPSSatelliteCount), this, new CommonCallbacks.KeyListener<Integer>() {
@Override
public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) {
if(t1!=null){
Movement.getInstance().setGPSSatelliteCount(t1);
}
}
});
KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyGPSSignalLevel), this, new CommonCallbacks.KeyListener<GPSSignalLevel>() {
@Override
public void onValueChange(@Nullable GPSSignalLevel gpsSignalLevel, @Nullable GPSSignalLevel t1) {
@ -732,7 +752,7 @@ public class FlightManager extends BaseManager {
//开舱门
openCabinDoor();
//降落时将云台朝下
//gimbalDownwards();
gimbalDownwards();
//返航时将云台归中,曝光ISO降低
//gimbalAndCameraReset();
//开始视觉识别降落
@ -744,6 +764,7 @@ public class FlightManager extends BaseManager {
//(决定飞机触发电量低的返航)
public boolean isTriggerRoomBattrryLanding;
private void batteryLowLanding() {
if (isTriggerRoomBattrryLanding) {
return;
@ -820,16 +841,15 @@ public class FlightManager extends BaseManager {
//降落时将云台朝下
private void gimbalDownwards() {
if (goHomeExecutionState == GoHomeState.LANDING.value()
&& Movement.getInstance().getElevation() > 11
&& !isGimbalDownwards) {
DroneHelper.getInstance().setGimbalPitchDegree();
//将镜头设置为自动对焦
DroneHelper.getInstance().setCameraFocusMode();
isGimbalDownwards = true;
&& Movement.getInstance().getElevation() > 11) {
// DroneHelper.getInstance().setGimbalPitchDegree();
// //将镜头设置为自动对焦
// DroneHelper.getInstance().setCameraFocusMode();
// isGimbalDownwards = true;
PerceptionManager.getInstance().setPerceptionEnable(false);
if (Movement.getInstance().getIsRecording()==1){
CameraManager.getInstance().stopRecordVideo(null);
}
// if (Movement.getInstance().getIsRecording() == 1) {
// CameraManager.getInstance().stopRecordVideo(null);
// }
}
}
@ -860,9 +880,7 @@ public class FlightManager extends BaseManager {
}
private static final double FLYING_HEIGHT_THRESHOLD_MAX = 5;
private static final double FLYING_HEIGHT_THRESHOLD_MAX = 5.5;
private static final double FLYING_HEIGHT_THRESHOLD_MAX_ALTERNATE = 10;
private static final double FLYING_HEIGHT_THRESHOLD_MIN = -2;
private static final double FLYING_HEIGHT_THRESHOLD_MIN_ALTERNATE = 2.0;
@ -917,7 +935,7 @@ public class FlightManager extends BaseManager {
sendEvent2Server("开始视觉降落", 1);
}
isSendDetect = true;
PerceptionManager.getInstance().setPerceptionEnable(false);
//PerceptionManager.getInstance().setPerceptionEnable(false);
}
@ -1037,6 +1055,7 @@ public class FlightManager extends BaseManager {
public void onSuccess(EmptyMsg emptyMsg) {
sendMsg2Server(message);
}
@Override
public void onFailure(@NonNull IDJIError error) {
sendFailMsg2Server(message, "返航执行失败:" + getIDJIErrorMsg(error));
@ -1073,7 +1092,6 @@ public class FlightManager extends BaseManager {
}
private void resetAircrftLandingStatus() {
// 避免在下次起飞时触发视觉识别
PreferenceUtils.getInstance().setNeedTriggerApronArucoLand(false);
@ -1155,6 +1173,7 @@ public class FlightManager extends BaseManager {
* 紧急悬停
*/
public void emergencyHover(MessageDown message) {
FlightMode flightMode = KeyManager.getInstance().getValue(createKey(FlightControllerKey.KeyFlightMode));
if (flightMode != null) {
switch (flightMode) {
@ -1165,7 +1184,6 @@ public class FlightManager extends BaseManager {
LogUtil.log(TAG, "紧急悬停,取消返航成功");
sendMsg2Server(message);
resetAircrftLandingStatus();
}
@Override
@ -1225,7 +1243,40 @@ public class FlightManager extends BaseManager {
break;
}
}
if (Movement.getInstance().isOpendrc() == true) {
//直接关闭虚拟摇杆
VirtualStickManager.getInstance().disableVirtualStick(new CommonCallbacks.CompletionCallback() {
@Override
public void onSuccess() {
LogUtil.log(TAG, "紧急悬停,控制权释放成功");
sendMsg2Server(message);
resetAircrftLandingStatus();
Movement.getInstance().setOpendrc(false);
}
@Override
public void onFailure(@NonNull IDJIError error) {
sendFailMsg2Server(message, "紧急悬停,控制权失败:" + getIDJIErrorMsg(error));
}
});
}
VirtualStickManager.getInstance().setVirtualStickAdvancedModeEnabled(true);
VirtualStickManager.getInstance().enableVirtualStick(new CommonCallbacks.CompletionCallback() {
@Override
public void onSuccess() {
LogUtil.log(TAG, "紧急悬停获得控制权成功");
sendMsg2Server(message);
resetAircrftLandingStatus();
Movement.getInstance().setOpendrc(true);
Movement.getInstance().setMode_code(3);
OSDManager.getInstance().pushFlightAttitude();
}
@Override
public void onFailure(@NonNull IDJIError error) {
sendFailMsg2Server(message, "紧急悬停获得控制权失败" + getIDJIErrorMsg(error));
}
});
}
}

View File

@ -38,20 +38,15 @@ public class FlightTaskProgressManager extends BaseManager {
// sendFlightTaskProgress2Server();
//
// }
//只要一个满足就上报
if (Movement.getInstance().isPlaneWing() || Movement.getInstance().isMotorsOn()) {
sendFlightTaskProgress2Server();
}
if (Movement.getInstance().isMissionFinish1()) {
sendFlightTaskProgress2Server();
handler.removeCallbacks(this);
return;
}
// 始终基于实际执行时间来调度
handler.postDelayed(this, INTERVAL);
}

View File

@ -149,7 +149,7 @@ public class FlyToPointManager extends BaseManager {
KeyConnection));
if (isConnect != null && isConnect) {
WaypointMissionManager.getInstance().pushKMZFileToAircraft(Environment.getExternalStorageDirectory().getPath() + "/" + "FlyTo.kmz", new CommonCallbacks.CompletionCallbackWithProgress<Double>() {
WaypointMissionManager.getInstance().pushKMZFileToAircraft(getExternalStoragePublicDirectory("KMZ").getAbsolutePath() + "/" + "FlyTo.kmz", new CommonCallbacks.CompletionCallbackWithProgress<Double>() {
@Override
public void onProgressUpdate(Double progress) {
sendEvent2Server("指点航线上传进度:" + progress, 1);
@ -176,7 +176,7 @@ public class FlyToPointManager extends BaseManager {
sendFailMsg2Server(message,"指点航线上传失败:"+ Utils.getIDJIErrorMsg(error));
//待机
Movement.getInstance().setMode_code(0);
OSDManager.getInstance().pushFlightAttitude();
sendFlightTaskProgress2Server();
}
});
}
@ -204,6 +204,7 @@ public class FlyToPointManager extends BaseManager {
//指令飞行( 指点前置不需要起飞准备这些因为没有指点起飞的航线)
Movement.getInstance().setMode_code(17);
sendFlightTaskProgress2Server();
}
@Override
@ -211,10 +212,11 @@ public class FlyToPointManager extends BaseManager {
sendFailMsg2Server(message,"指点航线执行失败:" + new Gson().toJson(error));
//待机
Movement.getInstance().setMode_code(0);
OSDManager.getInstance().pushFlightAttitude();
sendFlightTaskProgress2Server();
}
};
WaypointMissionManager.getInstance().startMission("ToPoint", callback);
WaypointMissionManager.getInstance().startMission("FlyTo", callback);
} else {
sendEvent2Server("指点任务开始失败,设备未连接", 2);
}
@ -225,7 +227,7 @@ public class FlyToPointManager extends BaseManager {
KeyConnection));
if (isConnect != null && isConnect) {
IWaypointMissionManager missionManager = WaypointMissionManager.getInstance();
missionManager.stopMission("ToPoint", new CommonCallbacks.CompletionCallback() {
missionManager.stopMission("FlyTo", new CommonCallbacks.CompletionCallback() {
@Override
public void onSuccess() {
sendMsg2Server(message);

View File

@ -260,6 +260,7 @@ public class GimbalManager extends BaseManager {
public void gimbalLookAt(MessageDown message) {
Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(GimbalKey.
KeyConnection, ComponentIndexType.PORT_1));
// LogUtil.log(TAG,"isConnect"+isConnect);
if (isConnect != null && isConnect) {
LookAtInfo lookAtInfo = new LookAtInfo();
lookAtInfo.setMode(message.getData().isLocked() ?
@ -272,11 +273,13 @@ public class GimbalManager extends BaseManager {
KeyManager.getInstance().performAction(KeyTools.createKey(FlightControllerKey.KeyLookAt), lookAtInfo, new CommonCallbacks.CompletionCallbackWithParam<EmptyMsg>() {
@Override
public void onSuccess(EmptyMsg emptyMsg) {
LogUtil.log(TAG,"看向目标点成功");
sendMsg2Server(message);
}
@Override
public void onFailure(@NonNull IDJIError error) {
LogUtil.log(TAG,"看向目标点失败");
sendFailMsg2Server(message, "看向目标点失败:" + getIDJIErrorMsg(error));
}
}

View File

@ -19,6 +19,7 @@ import com.amazonaws.services.s3.model.ProgressListener;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.aros.apron.base.BaseManager;
import com.aros.apron.entity.ApronExecutionStatus;
import com.aros.apron.entity.Movement;
import com.aros.apron.tools.LogUtil;
import com.aros.apron.tools.PreferenceUtils;
import com.autonavi.base.amap.mapcore.FileUtil;
@ -140,6 +141,9 @@ public class MediaManager extends BaseManager {
if (mState == MediaFileListState.UP_TO_DATE) {
mediaFiles =
MediaDataCenter.getInstance().getMediaManager().getMediaFileListData().getData();
//倒是看会不会上传
Movement.getInstance().setTask_media_count(mediaFiles.size());
if (mediaFiles != null&&mediaFiles.size()>0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
pullOriginalMediaFileFromCamera();

View File

@ -324,42 +324,6 @@ public class MissionV3Manager extends BaseManager {
//4.信号收敛(等待GPS搜星)
if (statusOk) {
verifyGpsAndMissionState(message);
// String planeMessage = Movement.getInstance().getPlaneMessage();
// int quality = Movement.getInstance().getQuality();
//
// boolean isPlaneMessageValid = !TextUtils.isEmpty(planeMessage) && !planeMessage.equals("无法起飞");
// boolean isGpsQualityValid = (quality == 4 || quality == 5 || quality == 10);
//
//
//
// int tryCount = 99;
// while(--tryCount > 0){
// //下方航线
// if(isPlaneMessageValid && isGpsQualityValid){
// //下发航线
// downLoadKMZFile(message);
// //等待航线状态为
// int awaitTime =30;
// while(--awaitTime>0){
// int modeCode= Movement.getInstance().getMode_code();
// if( modeCode == 4){
// break;
// }else {
// sleep(1s)
// }
// }
// if(awaitTime>0){
// breeak;
// }
// }
//
//
//
// }
}
});
}
@ -432,14 +396,18 @@ public class MissionV3Manager extends BaseManager {
int missionStateCode = Movement.getInstance().getMissionStateCode();
String planeMessage = Movement.getInstance().getPlaneMessage();
int quality = Movement.getInstance().getQuality();
int GPSSatelliteCount=Movement.getInstance().getGPSSatelliteCount();
boolean isMissionStateValid = (missionStateCode == 2 || missionStateCode == 0 || missionStateCode == 7);
boolean isPlaneMessageValid = !TextUtils.isEmpty(planeMessage) && !planeMessage.equals("无法起飞");
boolean isGpsQualityValid = (quality == 4 || quality == 5 || quality == 10);
boolean GPSSatelliteCountValid=GPSSatelliteCount>15;
LogUtil.log(TAG,"isMissionStateValid"+isMissionStateValid+"isPlaneMessageValid"+isPlaneMessageValid+"isGpsQualityValid"+isGpsQualityValid);
// if (isMissionStateValid && isPlaneMessageValid && isGpsQualityValid) {
if (isPlaneMessageValid && isGpsQualityValid) {
//sendEvent2Server("卫星数量"+GPSSatelliteCount,1);
if (isGpsQualityValid||GPSSatelliteCountValid) {
//5.下载航线
downLoadKMZFile(message);
verifyGpsAndMissionStateSuccess = true;
@ -601,7 +569,7 @@ public class MissionV3Manager extends BaseManager {
//自主起飞
Movement.getInstance().setMode_code(4);
OSDManager.getInstance().pushFlightAttitude();
sendFlightTaskProgress2Server();
Movement.getInstance().setTask_current_step(22);
startMission(message);
@ -630,7 +598,7 @@ public class MissionV3Manager extends BaseManager {
} else {
//待机
Movement.getInstance().setMode_code(0);
OSDManager.getInstance().pushFlightAttitude();
sendFlightTaskProgress2Server();
sendEvent2Server("航线第" + pushKMZFileTimes + "次上传失败,直接关机", 2);
TaskFailManager.getInstance().sendTaskFailMsg2Server(-1);
@ -702,7 +670,7 @@ public class MissionV3Manager extends BaseManager {
//待机
Movement.getInstance().setMode_code(0);
OSDManager.getInstance().pushFlightAttitude();
sendFlightTaskProgress2Server();
sendEvent2Server("航线第" + startMissionFailTimes + "次开始失败,直接关机:" + "---" + new Gson().toJson(error) + "--" + Movement.getInstance().getQuality(), 2);
TaskFailManager.getInstance().sendTaskFailMsg2Server(-1);

View File

@ -68,11 +68,15 @@ public class OSDManager extends BaseManager {
}
lastExecuteTime = now;
Boolean isConnect = KeyManager.getInstance().getValue(createKey(FlightControllerKey.KeyConnection));
if (isConnect != null && isConnect && !Movement.getInstance().isMissionFinish()) {
if (!Movement.getInstance().isMissionFinish()) {
if (isConnect != null && isConnect) {
pushFlightAttitude();
} else {
LogUtil.log(TAG, "osd stop:flight controller is null");
}
} else {
LogUtil.log(TAG, "osd stop:flight controller is null");
}
// 始终基于实际执行时间来调度
handler.postDelayed(this, INTERVAL);
}
@ -96,8 +100,6 @@ public class OSDManager extends BaseManager {
public void pushFlightAttitude() {
try {
if (batteries != null && batteries.size() > 0) {
batteries.clear();
}

View File

@ -39,6 +39,7 @@ public class PerceptionManager extends BaseManager {
private boolean closePerceptionSuccess;
public void setPerceptionEnable(boolean perceptionEnable) {
if (PreferenceUtils.getInstance().getCloseObsEnable() && perceptionEnable) {
LogUtil.log(TAG, "全局避障关闭,不开启避障");
return;
@ -53,7 +54,7 @@ public class PerceptionManager extends BaseManager {
LogUtil.log(TAG, "避障开启");
} else {
closePerceptionSuccess = true;
LogUtil.log(TAG, "避障关闭");
//LogUtil.log(TAG, "避障关闭");
}
}

View File

@ -0,0 +1,78 @@
package com.aros.apron.manager;
import androidx.annotation.NonNull;
import com.aros.apron.entity.PayloadInfo;
import com.aros.apron.tools.LogUtil;
import java.util.Map;
import dji.sdk.keyvalue.key.FlightControllerKey;
import dji.sdk.keyvalue.key.KeyTools;
import dji.v5.common.callback.CommonCallbacks;
import dji.v5.common.error.IDJIError;
import dji.v5.manager.KeyManager;
import dji.v5.manager.aircraft.payload.PayloadCenter;
import dji.v5.manager.aircraft.payload.PayloadIndexType;
import dji.v5.manager.aircraft.payload.data.PayloadWidgetInfo;
import dji.v5.manager.aircraft.payload.listener.PayloadBasicInfoListener;
import dji.v5.manager.aircraft.payload.listener.PayloadDataListener;
import dji.v5.manager.aircraft.payload.listener.PayloadWidgetInfoListener;
import dji.v5.manager.interfaces.IPayloadManager;
public class PlayLoadManager {
private String TAG = this.getClass().getSimpleName();
private PlayLoadManager() {
}
public static PlayLoadManager getInstance() {
return PlayLoadManagerHolder.INSTANCE;
}
private static class PlayLoadManagerHolder {
private static final PlayLoadManager INSTANCE = new PlayLoadManager();
}
public void init() {
Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(FlightControllerKey.KeyConnection));
if (isConnect != null && isConnect) {
Map<PayloadIndexType, IPayloadManager> payloadManager = PayloadCenter.getInstance().getPayloadManager();
if (payloadManager != null) {
IPayloadManager iPayloadManager = payloadManager.get(PayloadIndexType.PORT_1);
if (iPayloadManager != null) {
iPayloadManager.addPayloadWidgetInfoListener(new PayloadWidgetInfoListener() {
@Override
public void onPayloadWidgetInfoUpdate(PayloadWidgetInfo info) {
LogUtil.log(TAG,"负载信息"+info.toString());
}
});
iPayloadManager.pullWidgetInfoFromPayload(new CommonCallbacks.CompletionCallback() {
@Override
public void onSuccess() {
LogUtil.log(TAG,"拉取成功");
}
@Override
public void onFailure(@NonNull IDJIError idjiError) {
LogUtil.log(TAG,"拉取成功");
}
});
} else {
LogUtil.log(TAG, "监听EXTERNAL PSDK数据失败:设备未连接");
}
}
}
}
}

View File

@ -4,6 +4,7 @@ import static com.aros.apron.tools.Utils.getIDJIErrorMsg;
import static dji.sdk.keyvalue.key.KeyTools.createKey;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import androidx.annotation.NonNull;
@ -58,6 +59,8 @@ public class StickManager extends BaseManager {
public void onSuccess() {
LogUtil.log(TAG, "控制权获取成功");
VirtualStickManager.getInstance().setVirtualStickAdvancedModeEnabled(true);
}
@Override
public void onFailure(@NonNull IDJIError error) {
@ -83,15 +86,19 @@ public class StickManager extends BaseManager {
}
//获得拟摇杆控制权
//取消虚拟摇杆控制权
public void enableVirtualStick(MessageDown message) {
//吐过开启了drc或者使用过摇杆
if(Movement.getInstance().isOpendrc()==false){
VirtualStickManager.getInstance().setVirtualStickAdvancedModeEnabled(true);
VirtualStickManager.getInstance().enableVirtualStick(new CommonCallbacks.CompletionCallback() {
@Override
public void onSuccess() {
Movement.getInstance().setOpendrc(true);
if (message != null) {
sendMsg2Server(message);
}
LogUtil.log(TAG, "控制权获取成功");
VirtualStickManager.getInstance().setVirtualStickAdvancedModeEnabled(true);
//获得过控制权
@ -106,6 +113,8 @@ public class StickManager extends BaseManager {
}
}
});
}
}
//取消虚拟摇杆控制权
@ -115,7 +124,6 @@ public class StickManager extends BaseManager {
public void onSuccess() {
if (message != null) {
sendMsg2Server(message);
if(Movement.getInstance().getFlightmode()==1){
Movement.getInstance().setMode_code(5);
}else if(Movement.getInstance().getFlightmode()==2){
@ -138,15 +146,17 @@ public class StickManager extends BaseManager {
});
}
//飞行控制权抢夺
public void setVirtualStickModeEnabled(MessageDown message) {
//Movement.getInstance().setMode_code(3);
//设置标志为
Movement.getInstance().setOpendrc(true);
new Handler(Looper.getMainLooper()).postDelayed(() -> {
// 这里放你要延迟执行的代码
StickManager.getInstance().enableVirtualStick(message);
sendMsg2Server(message);
}, 2000);
//sendMsg2Server(message);
////// Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(FlightControllerKey.KeyConnection));
////// if (isConnect != null && isConnect) {
@ -238,7 +248,6 @@ public class StickManager extends BaseManager {
LogUtil.log(TAG,"飞机未起飞:禁止手控");
return;
}
VirtualStickFlightControlParam param = new VirtualStickFlightControlParam();
param.setRollPitchControlMode(RollPitchControlMode.VELOCITY);//
param.setYawControlMode(YawControlMode.ANGULAR_VELOCITY);
@ -260,7 +269,6 @@ public class StickManager extends BaseManager {
param.setVerticalThrottle(Double.valueOf(message.getData().getH()));//上下(速度模式-4m/s-4m/s)
}
//手动飞行
Movement.getInstance().setMode_code(16);
VirtualStickManager.getInstance().sendVirtualStickAdvancedParam(param);

View File

@ -7,6 +7,7 @@ import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
@ -17,10 +18,12 @@ import com.aros.apron.entity.ApronExecutionStatus;
import com.aros.apron.entity.CurrentWayline;
import com.aros.apron.entity.FlightMission;
import com.aros.apron.entity.MessageDown;
import com.aros.apron.entity.MissionDataBean;
import com.aros.apron.entity.MissionPoint;
import com.aros.apron.entity.Movement;
import com.aros.apron.tools.DomParserKML;
import com.aros.apron.tools.DomParserWPML;
import com.aros.apron.tools.Generakmztools;
import com.aros.apron.tools.LogUtil;
import com.aros.apron.tools.PreferenceUtils;
import com.aros.apron.tools.RestartAPPTool;
@ -39,6 +42,8 @@ import dji.sdk.keyvalue.key.KeyTools;
import dji.sdk.keyvalue.value.flightcontroller.RemoteControllerFlightMode;
import dji.sdk.wpmz.value.mission.Wayline;
import dji.sdk.wpmz.value.mission.WaylineExecuteWaypoint;
import dji.sdk.wpmz.value.mission.WaylineMissionConfig;
import dji.sdk.wpmz.value.mission.WaylineMissionConfigParseInfo;
import dji.sdk.wpmz.value.mission.WaylineWaylinesParseInfo;
import dji.v5.common.callback.CommonCallbacks;
import dji.v5.common.error.IDJIError;
@ -67,6 +72,7 @@ public class TakeOffToPointManager extends BaseManager {
//收到一键起飞航线
public void taskExecute(MessageDown message) {
PreferenceUtils.getInstance().setMissionType(1);
PreferenceUtils.getInstance().setFlightId(message.getData().getFlight_id());
PreferenceUtils.getInstance().setAlternatePointLon(message.getData().getAlternate_land_point().getLongitude() + "");
@ -75,7 +81,7 @@ public class TakeOffToPointManager extends BaseManager {
message.getData().getAlternate_land_point().getSafe_land_height() + "");
Movement.getInstance().setTask_current_step(5);
LogUtil.log(TAG,"生成");
//1.检查图传是否连接
checkVtxWithDelay(() -> {
//避免重复执行
@ -88,8 +94,10 @@ public class TakeOffToPointManager extends BaseManager {
boolean statusOk = verifyAircraftStatus(message);
//4.信号收敛(等待GPS搜星)
if (statusOk) {
LogUtil.log(TAG,"verifyGpsAndMissionState(message)执行了");
verifyGpsAndMissionState(message);
}
});
}
@ -120,12 +128,12 @@ public class TakeOffToPointManager extends BaseManager {
TaskFailManager.getInstance().sendTaskFailMsg2Server(-1);
return false;
}
//6.检查航线参数
if (message.getData().getFile() == null) {
sendEvent2Server("航线参数异常",2);
TaskFailManager.getInstance().sendTaskFailMsg2Server(-1);
return false;
}
// //6.检查航线参数
// if (message.getData().getFile() == null) {
// sendEvent2Server("航线参数异常",2);
// TaskFailManager.getInstance().sendTaskFailMsg2Server(-1);
// return false;
// }
//7.检查电池电量
Integer value = KeyManager.getInstance().getValue(createKey(FlightControllerKey.
KeyBatteryPowerPercent, 0));
@ -171,6 +179,7 @@ public class TakeOffToPointManager extends BaseManager {
// if (isMissionStateValid && isPlaneMessageValid && isGpsQualityValid) {
if (isPlaneMessageValid && isGpsQualityValid) {
//5.生成航线
LogUtil.log(TAG,"执行toGenerateKMZFile");
toGenerateKMZFile(message);
verifyGpsAndMissionStateSuccess = true;
} else {
@ -217,68 +226,14 @@ public class TakeOffToPointManager extends BaseManager {
*/
public void toGenerateKMZFile(MessageDown message) {
Movement.getInstance().setTask_current_step(16);
// 创建第一个 MissionPoint 对象
MissionPoint missionPoint = new MissionPoint();
missionPoint.setLat(String.valueOf(Movement.getInstance().getLatitude()));
missionPoint.setLng(String.valueOf(Movement.getInstance().getLongitude()));
missionPoint.setSpeed(Double.parseDouble(message.getData().getMax_speed()));
missionPoint.setExecuteHeight(message.getData().getTarget_height() - 1);
// 创建第二个 MissionPoint 对象
MissionPoint missionPoint1 = new MissionPoint();
missionPoint1.setLat(message.getData().getTarget_latitude() + "");
missionPoint1.setLng(message.getData().getTarget_longitude() + "");
missionPoint1.setSpeed(Double.parseDouble(message.getData().getMax_speed()));
missionPoint1.setExecuteHeight(message.getData().getTarget_height());
// 创建一个 MissionPoint 列表
List<MissionPoint> missionPoints = new ArrayList<>();
missionPoints.add(missionPoint);
missionPoints.add(missionPoint1);
// 创建 FlightMission 对象并设置其属性
FlightMission flightMission = new FlightMission();
flightMission.setPoints(missionPoints);
flightMission.setMissionId(2);
flightMission.setFinishAction("noAction");
flightMission.setTakeOffSecurityHeight(
Float.parseFloat(message.getData().getSecurity_takeoff_height()));
flightMission.setSpeed(Double.parseDouble(message.getData().getMax_speed()));
LogUtil.log(TAG, "当前高度:" + Movement.getInstance().getElevation()
+ "-一键起飞安全起飞高度:" + message.getData().getSecurity_takeoff_height());
sendEvent2Server("开始生成一键起飞航线", 1);
// 生成xml文件
File file1 = new File(
getExternalStoragePublicDirectory("KMZ").getAbsolutePath() + File.separator + "wpmz");
if (!file1.exists()) {
if (file1.mkdirs()) {
sendEvent2Server("一键起飞航线文件生成成功", 1);
} else {
sendEvent2Server("一键起飞航线文件生成失败", 2);
}
}
DomParserKML domParserKML = new DomParserKML(getExternalStoragePublicDirectory("KMZ").getAbsolutePath() + File.separator + "wpmz",
"/template.kml");
domParserKML.createKml(flightMission);
DomParserWPML domParserWPML = new DomParserWPML(getExternalStoragePublicDirectory("KMZ").getAbsolutePath() + File.separator + "wpmz",
"/waylines.wpml");
domParserWPML.createWpml(flightMission);
File kmzFile = new File(getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + File.separator + "ToPoint.kmz");
kmzFile.getParentFile().mkdirs();
try {
ZipUtil.zip(getExternalStoragePublicDirectory("KMZ").getAbsolutePath() + "/wpmz",
getExternalStoragePublicDirectory("KMZ").getAbsolutePath() + File.separator + "ToPoint.kmz");
} catch (IOException e) {
sendEvent2Server("一键起飞任务生成异常", 2);
throw new RuntimeException(e);
}
MissionDataBean data = new Gson().fromJson(new Gson().toJson(message.getData()), MissionDataBean.class);
Boolean generateKmz=Generakmztools.getInstance().generateKmz(data);
LogUtil.log(TAG,"生成的boole"+generateKmz);
if(generateKmz==true){
pushKMZFileToAircraft(message);
}else{
sendEvent2Server("航线生成失败", 1);
}
}
private int pushKMZFileTimes = 0;
@ -298,22 +253,23 @@ public class TakeOffToPointManager extends BaseManager {
* 6.上传指点航线
* @param message
*/
private void pushKMZFileToAircraft(MessageDown message) {
public void pushKMZFileToAircraft(MessageDown message) {
Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(FlightControllerKey.
KeyConnection));
if (isConnect != null && isConnect) {
KMZInfo kmzInfo = WPMZManager.getInstance().getKMZInfo(
Environment.getExternalStorageDirectory().getPath() + "/" + "ToPoint.kmz");
String kmzAbsPath = "/storage/self/primary/DJIDemo/cache/kmz/takeofftopoint.kmz";
KMZInfo kmzInfo = WPMZManager.getInstance().getKMZInfo(kmzAbsPath);
if (kmzInfo != null) {
// Utils.printJson(TAG,"航点详情:"+new Gson().toJson(kmzInfo));
WaylineWaylinesParseInfo waylineWaylinesParseInfo = kmzInfo.getWaylineWaylinesParseInfo();
WaylineMissionConfig configParseInfo= kmzInfo.getWaylineMissionConfigParseInfo().getConfig();
if (waylineWaylinesParseInfo != null) {
List<Wayline> waylines = waylineWaylinesParseInfo.getWaylines();
if (waylines != null && waylines.size() >0) {
List<WaylineExecuteWaypoint> waypoints = waylines.get(0).getWaypoints();
if (waypoints != null && waypoints.size() > 0) {
//将航点列表保存在本地
Movement.getInstance().setSpeed(configParseInfo.getGlobalTransitionalSpeed());
CurrentWayline.getInstance().setWaypoints(waypoints);
LogUtil.log(TAG, "该航线有" + waypoints.size() + "个航点");
} else {
@ -332,18 +288,20 @@ public class TakeOffToPointManager extends BaseManager {
}
WaypointMissionManager.getInstance().pushKMZFileToAircraft(Environment.getExternalStorageDirectory().getPath() + "/" + "aros.kmz", new CommonCallbacks.CompletionCallbackWithProgress<Double>() {
WaypointMissionManager.getInstance().pushKMZFileToAircraft(kmzAbsPath, new CommonCallbacks.CompletionCallbackWithProgress<Double>() {
@Override
public void onProgressUpdate(Double progress) {
sendEvent2Server("航线上传进度:" + progress, 1);
Movement.getInstance().setTask_current_step(17);
}
@Override
public void onSuccess() {
//起飞准备完毕
Movement.getInstance().setMode_code(2);
sendFlightTaskProgress2Server();
sendEvent2Server("航线上传成功,准备执行任务", 1);
isPushKMZSuccess = true;
mainHandler.postDelayed(new Runnable() {
@ -352,9 +310,10 @@ public class TakeOffToPointManager extends BaseManager {
/**
* 7.开始任务
*/
//自主起飞
Movement.getInstance().setMode_code(4);
OSDManager.getInstance().pushFlightAttitude();
sendFlightTaskProgress2Server();
Movement.getInstance().setTask_current_step(22);
startMission(message);
pushKMZFileTimes = 0;
@ -382,7 +341,7 @@ public class TakeOffToPointManager extends BaseManager {
sendEvent2Server("航线第" + pushKMZFileTimes + "次上传失败,直接关机",2);
//待机
Movement.getInstance().setMode_code(0);
OSDManager.getInstance().pushFlightAttitude();
sendFlightTaskProgress2Server();
TaskFailManager.getInstance().sendTaskFailMsg2Server(-1);
}
@ -422,17 +381,7 @@ public class TakeOffToPointManager extends BaseManager {
sendEvent2Server("任务开始执行", 1);
Movement.getInstance().setTask_current_step(23);
sendFlightTaskProgress2Server();
// Movement.getInstance().setMode_code(5);
//
// //自动起飞
// Movement.getInstance().setMode_code(4);
// //延迟2s
// new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(() -> {
// Movement.getInstance().setMode_code(17);
// }, 2000);
}
@Override
public void onFailure(@NonNull IDJIError error) {
LogUtil.log(TAG, "航线执行失败:" + new Gson().toJson(error));
@ -452,7 +401,7 @@ public class TakeOffToPointManager extends BaseManager {
if (!Movement.getInstance().isPlaneWing()) {
//待机
Movement.getInstance().setMode_code(0);
OSDManager.getInstance().pushFlightAttitude();
sendFlightTaskProgress2Server();
sendEvent2Server("航线第" + startMissionFailTimes + "次开始失败,直接关机:" + "---" + new Gson().toJson(error) + "--" + Movement.getInstance().getQuality(),2);
TaskFailManager.getInstance().sendTaskFailMsg2Server(-1);
@ -464,8 +413,7 @@ public class TakeOffToPointManager extends BaseManager {
}
}
};
WaypointMissionManager.getInstance().startMission("ToPoint", callback);
WaypointMissionManager.getInstance().startMission("takeofftopoint", callback);
} else {
sendEvent2Server("任务开始失败,设备未连接", 2);
}

View File

@ -68,10 +68,10 @@ public class ApronArucoDetect {
// 关键修改1M400下视镜头右后方补偿量像素正值向右补偿
// 如果还往左偏就调大往右偏就调小建议范围 30-80
private static final double LENS_OFFSET_X = 35.0;
private static final double LENS_OFFSET_X = 15.0;
private static final double LENS_OFFSET_Y = 20.0;
// 关键修改2放宽居中判定阈值原40补偿后改为60更合理
private static final int CENTER_ERR_MAX = 35; // 居中误差px
private static final int CENTER_ERR_MAX = 40; // 居中误差px
public PIDControl pidControlX = null;
public PIDControl pidControlY = null;
@ -121,11 +121,13 @@ public class ApronArucoDetect {
}
private static final float SLOW_LAND_SPEED = -0.3f; // 远场慢降
private static final int PIXEL_TRIGGER = 350; // 近场像素阈值
private static final float SLOW_SUPER_SPEED = -0.1f; // 超近慢降
private static final int PIXEL_TRIGGER = 400; // 近场像素阈值
public void init() {
pidControlX = new PIDControl(0.8f, 0.002f, 0.09f, 0.05f, 2.0f, 0.05f);
pidControlY = new PIDControl(0.8f, 0.002f, 0.09f, 0.05f, 2.0f, 0.05f);
pidControlX = new PIDControl(0.6f, 0.015f, 0.12f, 0.05f, 2.0f, 0.05f);
pidControlY = new PIDControl(0.6f, 0.015f, 0.12f, 0.05f, 2.0f, 0.05f);
pidControlX.reset();
pidControlY.reset();
@ -198,7 +200,7 @@ public class ApronArucoDetect {
arucoNotFoundTag = false;
int[] idArray = ids.toArray();
int ultrasonicHeight = Movement.getInstance().getUltrasonicHeight();
//double flyingHeight = Movement.getInstance().getFlyingHeight();
// double flyingHeight = Movement.getInstance().getElevation();
// 如果只有一个而且是6
if (idArray.length == 1 && idArray[0] == 6) {
@ -226,7 +228,7 @@ public class ApronArucoDetect {
/* 近场 + 对准 + 像素够 → 立即速降 */
if (!startFastStick &&
pixelWidth >= PIXEL_TRIGGER &&
// flyingHeight <= 0.4 &&
// flyingHeight <= 1 &&
ultrasonicHeight <= 4 &&
errX < CENTER_ERR_MAX &&
errY < CENTER_ERR_MAX) {
@ -251,10 +253,8 @@ public class ApronArucoDetect {
endTime = System.currentTimeMillis();
long lostDuration = endTime - startTime;
//1s到8s内
if (lostDuration > 1000 && lostDuration <= 8000) {
if (lostDuration > 700 && lostDuration <= 8000) {
if (Movement.getInstance().getUltrasonicHeight()<=30) {
DroneHelper.getInstance().moveVxVyYawrateHeight(0f, 0f, 0f, 0.3f);
if (dropTimes > Integer.parseInt(AMSConfig.getInstance().getAlternateLandingTimes())) {
LogUtil.log(TAG, "超过复降限制,去备降点");
@ -398,24 +398,34 @@ public class ApronArucoDetect {
double cy = (pts[0].y + pts[1].y + pts[2].y + pts[3].y) / 4.0;
Point screenCenter = new Point(imageWidth / 2.0, imageHeight / 2.0);
// 关键修改4PID控制也加上相同的偏移补偿注意这里不加abs保留符号给PID判断方向
double errX = (cx - screenCenter.x) + LENS_OFFSET_X; // 向右补偿
double errY = (cy - screenCenter.y) - LENS_OFFSET_Y; // Y方向不变
/* 3. PID 微调水平 */
pidControlX.setInputFilterAll((float) (errX / 800.0));
pidControlY.setInputFilterAll((float) (-errY / 800));
pidControlX.setInputFilterAll((float) (errX / 700.0));
pidControlY.setInputFilterAll((float) (-errY/ 700.0));
float vx = (float) Math.max(-0.25, Math.min(0.25, pidControlX.get_pid()));
float vy = (float) Math.max(-0.25, Math.min(0.25, pidControlY.get_pid()));
/* 4. 远场慢降:像素 < 1500 且 > 2 m */
double pixelWidth = Math.sqrt(Math.pow(pts[1].x - pts[0].x, 2) +
Math.pow(pts[1].y - pts[0].y, 2));
// double flyingHeight = Movement.getInstance().getElevation();
float vz = (pixelWidth < PIXEL_TRIGGER &&
// Movement.getInstance().getFlyingHeight() > 0.4f &&
Movement.getInstance().getUltrasonicHeight() > 4) ?
SLOW_LAND_SPEED : 0.0f;
int currentHeight = Movement.getInstance().getUltrasonicHeight();
float vz;
if (currentHeight <= 4) {
vz = 0.0f; // 近场悬停等速降
} else if (currentHeight <= 6) {
vz = SLOW_SUPER_SPEED; // -0.1f过渡层
} else {
vz = SLOW_LAND_SPEED; // -0.3f远场慢降
}
// if (flyingHeight <= 0.2) {
// vz = 0.0f;
// LogUtil.log(TAG, "相对高度" + flyingHeight + "强制悬停");
// }
/* 5. 输出 */
DroneHelper.getInstance().moveVxVyYawrateHeight(vx, vy, 0f, vz);

View File

@ -1,4 +1,4 @@
//package com.shd.nest.viewmodel
package com.aros.apron.tools//package com.shd.nest.viewmodel
//
//import android.annotation.SuppressLint
//import android.graphics.Bitmap

View File

@ -1,4 +1,4 @@
package com.aros.apron.tools
import android.accessibilityservice.AccessibilityService
import android.annotation.SuppressLint
import android.app.Notification

View File

@ -0,0 +1,199 @@
package com.aros.apron.tools;
import android.util.Log;
import com.aros.apron.base.BaseManager;
import com.aros.apron.entity.MissionDataBean;
import com.aros.apron.entity.Movement;
import com.aros.apron.manager.TakeOffToPointManager;
import com.dji.wpmzsdk.common.data.Template;
import com.dji.wpmzsdk.manager.WPMZManager;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import dji.sdk.keyvalue.key.FlightControllerKey;
import dji.sdk.keyvalue.key.KeyTools;
import dji.sdk.keyvalue.value.common.LocationCoordinate3D;
import dji.sdk.wpmz.value.mission.*;
import dji.v5.manager.KeyManager;
/**
* 单航点起飞目标点返航
* Java Builder WaypointHeadingParam
*/
public class Generakmztools extends BaseManager {
private Generakmztools() {}
private static class Holder { private static final Generakmztools INSTANCE = new Generakmztools(); }
public static Generakmztools getInstance() { return Holder.INSTANCE; }
public Boolean generateKmz(MissionDataBean data) {
sendEvent2Server("开始生成一键起飞航线", 1);
LocationCoordinate3D lat = KeyManager.getInstance().getValue(KeyTools.createKey(FlightControllerKey.
KeyAircraftLocation3D));
if (lat == null) {
LogUtil.log("qwq", "当前位置为空,无法生成航线");
sendEvent2Server("生成失败:未获取到飞机当前位置", 1);
return false;
}
if (lat.getLatitude() == null || lat.getLongitude() == null|| lat.getAltitude() == null) {
LogUtil.log("qwq", "当前位置坐标无效");
sendEvent2Server("生成失败:位置坐标无效", 1);
return false;
}
File root = new File("/storage/self/primary/DJIDemo/cache/kmz");
if (!root.exists()) root.mkdirs();
File kmz = new File(root, "takeofftopoint.kmz");
/* 1. <wpml:mission> 基本信息 */
WaylineMission mission = new WaylineMission();
mission.setAuthor("aros");
double now = System.currentTimeMillis();
mission.setCreateTime(now);
mission.setUpdateTime(now);
/* 2. <wpml:missionConfig> 全局策略 */
WaylineMissionConfig config = new WaylineMissionConfig();
//飞向目标点的模式
config.setFlyToWaylineMode(WaylineFlyToWaylineMode.SAFELY);
//航线结束后的动作
config.setFinishAction(WaylineFinishedAction.NO_ACTION);
if(data.getCommanderModeLostAction()==0){
//继续
config.setExitOnRCLostBehavior(WaylineExitOnRCLostBehavior.GO_ON);
}else if(data.getCommanderModeLostAction()==1){
//失控退出航线
config.setExitOnRCLostBehavior(WaylineExitOnRCLostBehavior.EXCUTE_RC_LOST_ACTION);
}
//失控退出航线的动作
if(data.getRcLostAction()==0){
//悬停
config.setExitOnRCLostType(WaylineExitOnRCLostAction.HOVER);
} else if (data.getRcLostAction()==1) {
//精确着陆
config.setExitOnRCLostType(WaylineExitOnRCLostAction.LANDING);
} else if (data.getRcLostAction()==2) {
//返航
config.setExitOnRCLostType(WaylineExitOnRCLostAction.GO_BACK);
}
//全局过度速度
config.setGlobalTransitionalSpeed((double)data.getMaxSpeed());
//全局返航高度
config.setGlobalRTHHeight((double)data.getRthAltitude());
config.setIsGlobalRTHHeightSet(true);
//安全起飞高度
config.setSecurityTakeOffHeight((double)data.getSecurityTakeoffHeight());
config.setIsSecurityTakeOffHeightSet(true);
//为400准备的
WaylineDroneInfo droneInfo = new WaylineDroneInfo();
droneInfo.setDroneType(WaylineDroneType.PM440);
config.setDroneInfo(droneInfo);
//这个航点列表
WaylineWaypoint wp1 = new WaylineWaypoint();
WaylineWaypoint wp = new WaylineWaypoint();
//初始点
wp1.setWaypointIndex(0);
wp1.setLocation(new WaylineLocationCoordinate2D(lat.getLatitude(), lat.getLongitude()));
//wp1.setHeight((double)data.getCommanderFlightHeight());
wp1.setHeight(data.getTargetHeight()- Movement.getInstance().getHeight());
// wp1.setUseGlobalFlightHeight(true);
//椭球高
wp1.setEllipsoidHeight(data.getTargetHeight()- Movement.getInstance().getHeight());
wp1.setUseStraightLine(true);
wp1.setUseGlobalTurnParam(true);
wp1.setUseGlobalYawParam(true);
wp1.setUseGlobalGimbalHeadingParam(true);
wp1.setUseGlobalAutoFlightSpeed(true);
wp1.setIsRisky(false);
//基础设置
wp.setWaypointIndex(1);
wp.setLocation(new WaylineLocationCoordinate2D(data.getTargetLatitude(), data.getTargetLongitude()));
//wp.setHeight((double)data.getCommanderFlightHeight());
wp.setHeight(data.getTargetHeight()- Movement.getInstance().getHeight());
// wp.setUseGlobalFlightHeight(true);
//椭球高
wp.setEllipsoidHeight(data.getTargetHeight()- Movement.getInstance().getHeight());
wp.setUseStraightLine(true);
wp.setUseGlobalTurnParam(true);
wp.setUseGlobalYawParam(true);
wp.setUseGlobalGimbalHeadingParam(true);
wp.setUseGlobalAutoFlightSpeed(true);
wp.setIsRisky(false);
List<WaylineWaypoint> wpList = new ArrayList<>();
wpList.add(wp1);
wpList.add(wp);
/* 4. <wpml:waypointInfo> */
WaylineTemplateWaypointInfo waypointInfo = new WaylineTemplateWaypointInfo();
waypointInfo.setGlobalFlightHeight(data.getTargetHeight());
waypointInfo.setIsGlobalFlightHeightSet(true);
WaylineWaypointYawParam waypointYawParam=new WaylineWaypointYawParam();
waypointYawParam.setYawMode(WaylineWaypointYawMode.FOLLOW_WAYLINE);
waypointInfo.setGlobalYawParam(waypointYawParam);
waypointInfo.setIsTemplateGlobalYawParamSet(true);
WaylineWaypointGimbalHeadingParam waypointGimbalHeadingParam=new WaylineWaypointGimbalHeadingParam();
waypointGimbalHeadingParam.setHeadingMode(WaylineWaypointGimbalHeadingMode.FOLLOW_WAYLINE);
waypointGimbalHeadingParam.setYawAngle(0.0);
waypointGimbalHeadingParam.setPitchAngle(0.0);
waypointInfo.setGlobalGimbalHeadingParam(waypointGimbalHeadingParam);
waypointInfo.setGlobalTurnMode(WaylineWaypointTurnMode.COORDINATE_TURN);
waypointInfo.setIsTemplateGlobalTurnModeSet(true);
waypointInfo.setWaypoints(wpList);
waypointInfo.setUseStraightLine(true);
/* 5. <wpml:coordinateParam> */
WaylineCoordinateParam coordParam = new WaylineCoordinateParam();
coordParam.setCoordinateMode(WaylineCoordinateMode.WGS84);
coordParam.setAltitudeMode(WaylineAltitudeMode.RELATIVE_TO_START_POINT);
coordParam.setPositioningType(WaylinePositioningType.GPS);
/* 6. <wpml:template> */
Template template = new Template();
template.setTemplateId(0);
template.setCoordinateParam(coordParam);
template.setTransitionalSpeed((double)data.getMaxSpeed());
template.setWaypointInfo(waypointInfo);
template.setUseGlobalTransitionalSpeed(true);
template.setAutoFlightSpeed((double)data.getMaxSpeed());
//不写就报错
template.setPayloadParam(new ArrayList<>());
/* 7. 生成文件 */
WPMZManager.getInstance().generateKMZFile(kmz.getAbsolutePath(), mission, config, template);
//验证这个kmz
WaylineCheckErrorMsg result= WPMZManager.getInstance().checkValidation(kmz.getAbsolutePath());
LogUtil.log("qwq",result.toString());
if (result.getValue().isEmpty()) {
LogUtil.log("qwq", "KMZ 校验通过");
sendEvent2Server("一键起飞航线文件生成成功", 1);
return true;
} else {
// 其他错误码照旧报错
LogUtil.log("qwq", "校验失败,错误码:" + result.getValue());
sendEvent2Server("一键起飞航线文件生成失败错误码:"+result.getValue(), 1);
return false;
}
}
}

View File

@ -1,292 +0,0 @@
//package com.aros.apron.tools;
//
//import static org.opencv.core.Core.BORDER_DEFAULT;
//import static org.opencv.core.Core.extractChannel;
//
//import android.content.Context;
//import android.util.Log;
//
//import org.opencv.aruco.Aruco;
//import org.opencv.aruco.Dictionary;
//import org.opencv.core.Core;
//import org.opencv.core.CvType;
//import org.opencv.core.Mat;
//import org.opencv.core.MatOfDouble;
//import org.opencv.core.MatOfPoint3f;
//import org.opencv.core.MatOfRect;
//import org.opencv.core.Point;
//import org.opencv.core.Rect;
//import org.opencv.core.Scalar;
//import org.opencv.core.Size;
//import org.opencv.imgproc.Imgproc;
//import org.opencv.objdetect.CascadeClassifier;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import dji.v5.manager.aircraft.virtualstick.VirtualStickManager;
//
//public class OpenCVHelper {
// private static final Scalar FACE_RECT_COLOR = new Scalar(0, 255, 0, 255);
// private Context context;
// private MatOfPoint3f objPoints;
// private Mat intrinsic;
// private MatOfDouble distortion;
// private Mat logoImg;
// private MatOfPoint3f objectPoints;
//
// public OpenCVHelper(Context context) {
// this.context = context;
// }
//
// public Mat defaultImageProcessing(Mat input) {
// Imgproc.putText(input, "Default", new Point(150, 40), 1, 4, new Scalar(255, 255, 255), 2, 8, false);
// return input;
// }
//
// public Mat convertToGray(Mat input) {
// Mat output = new Mat();
// Imgproc.cvtColor(input, output, Imgproc.COLOR_RGBA2GRAY);
// return output;
// }
//
// public Mat detectEdgesUsingCanny(Mat input) {
// Mat output = new Mat();
// Imgproc.Canny(input, output, 80, 100);
// return output;
// }
//
// public Mat detectEdgesUsingLaplacian(Mat input) {
// Mat grayImg = new Mat();
// Mat intermediateMat = new Mat();
// Mat output = new Mat();
// Imgproc.cvtColor(input, grayImg, Imgproc.COLOR_RGBA2GRAY);
// Imgproc.GaussianBlur(grayImg, grayImg, new Size(3, 3), 0, 0);
// Imgproc.Laplacian(grayImg, intermediateMat, CvType.CV_8U, 3, 1, 0, BORDER_DEFAULT);
// Core.convertScaleAbs(intermediateMat, intermediateMat, 10, 0);
// Imgproc.cvtColor(intermediateMat, output, Imgproc.COLOR_GRAY2RGBA, 4);
// grayImg.release();
// intermediateMat.release();
// return output;
// }
//
// public Mat blurImage(Mat input) {
// Mat grayMat = new Mat();
// Mat output = new Mat();
// Imgproc.cvtColor(input, grayMat, Imgproc.COLOR_RGBA2GRAY);
// Imgproc.GaussianBlur(grayMat, output, new Size(35, 35), 0, 0);
// grayMat.release();
// return output;
// }
//
// public Mat detectFaces(Mat input, CascadeClassifier faceDetector) {
// Mat grayImgMat = new Mat();
// MatOfRect faces = new MatOfRect();
// Mat output;
// Imgproc.cvtColor(input, grayImgMat, Imgproc.COLOR_RGBA2GRAY);
// if (faceDetector != null) {
// faceDetector.detectMultiScale(grayImgMat, faces, 1.1, 2, 2, new Size(60, 60), new Size());
// }
// output = input;
// Rect[] facesArray = faces.toArray();
// for (Rect rect : facesArray) {
// Imgproc.rectangle(output, rect.tl(), rect.br(), FACE_RECT_COLOR, 3);
// }
// return output;
// }
//
// public Mat detectArucoTags(Mat input, Dictionary dictionary) {
//
// Mat grayImgMat = new Mat();
// Mat intermediateImgMat = new Mat();
// Mat output = new Mat();
// Imgproc.cvtColor(input, grayImgMat, Imgproc.COLOR_RGBA2GRAY);
// Imgproc.cvtColor(input, intermediateImgMat, Imgproc.COLOR_RGBA2RGB);
// Mat ids = new Mat();
// List<Mat> corners = new ArrayList<>();
// Aruco.detectMarkers(grayImgMat, dictionary, corners, ids);
// if (ids.depth() > 0) {
//// Log.e("检测到TAG", "----1111------");
// Aruco.drawDetectedMarkers(intermediateImgMat, corners, ids, new Scalar(255, 0, 255));
// moveOnArucoDetected(ids, corners, intermediateImgMat.width(), intermediateImgMat.height());
// }
// Imgproc.cvtColor(intermediateImgMat, output, Imgproc.COLOR_RGB2BGR);
// Imgproc.cvtColor(output, output, Imgproc.COLOR_BGR2RGBA, 4);
// grayImgMat.release();
// intermediateImgMat.release();
// return output;
// }
//
// private void moveOnArucoDetected(Mat ids,
// List<Mat> corners,
// int imageWidth,
// int imageHeight) {
// ////执行逻辑来决定将无人机移动到哪里
// ////计算标记中心
// Scalar markerCenter = new Scalar(0, 0);
// for (Mat corner : corners) {
// markerCenter = Core.mean(corner);
// }
//// Log.e("markerCenter:", markerCenter.toString());
//// Log.e("imageWidth" + imageWidth, "imageHeight" + imageHeight);
// //使所需的标签位于图像框的中心
// //计算相对于图像中心的图像矢量
// Scalar imageVector = new Scalar(markerCenter.val[0] - imageWidth / 2f, markerCenter.val[1] - imageHeight / 2f);
// //将矢量从图像坐标转换为无人机导航坐标
// Scalar motionVector = convertImageVectorToMotionVector(imageVector);
// //如果没有检测到标签则无需移动
// if (ids.size().empty()) {
// motionVector = new Scalar(0, 0);
//// Log.e("未检测到TAG","----1111------");
// }
// if (imageVector.val[0] < 100 && imageVector.val[0] > -100 && imageVector.val[1] < 100 && imageVector.val[1] > -100) {
// VirtualStickManager.getInstance().getLeftStick().setVerticalPosition(-30);
// } else {
// if (imageVector.val[0] < 0) {
// VirtualStickManager.getInstance().getRightStick().setHorizontalPosition(-10);
// }
// if (imageVector.val[0] > 0) {
// VirtualStickManager.getInstance().getRightStick().setHorizontalPosition(10);
// }
// if (imageVector.val[1] < 0) {
// VirtualStickManager.getInstance().getRightStick().setVerticalPosition(-10);
// }
// if (imageVector.val[1] > 0) {
// VirtualStickManager.getInstance().getRightStick().setVerticalPosition(10);
// }
// }
// }
//
//// public void doDroneMoveUsingImage(Mat input, DroneHelper droneHelper) {
//// /*
//// * Remember this function is called every time
//// * a frame is available. So don't do long loop here.
//// */
//// Imgproc.cvtColor(input, input, Imgproc.COLOR_BGR2YUV);
//// extractChannel(input, input, 0);
//// FlightControlData controlData =
//// new FlightControlData(0.1f, 0.0f, 0.0f, 0.0f); //pitch, roll, yaw, verticalThrottle
//// droneHelper.sendMovementCommand(controlData);
//// }
//
// public Mat doAROnImage(Mat input, Dictionary dictionary, DroneHelper droneHelper) {
// //TODO:
// // Since this is the bonus part, only high-level instructions will be provided
// // One way you can do this is to:
// // 1. Identify the Aruco tags with corner pixel location
// // Hint:Aruco.detectMarkers(...)
// // 2. For each corner in 3D space, define their 3D locations
// // The 3D locations you defined here will determine the origin of your coordinate frame
// // 3. Given the 3D locations you defined, their 2D pixel location in the image, and camera parameters
// // You can calculate the 6 DOF of the camera relative to the tag coordinate frame
// // Hint: Calib3d.solvePnP(...)
// // 4. To put artificial object in the image, you need to create 3D points first and project them into 2D image
// // With the projected image points, you can draw lines or polygon
// // Hint: Calib3d.projectPoints(...);
// // 5. To put dji image on a certain location,
// // you need find the homography between the projected 4 corners and the 4 corners of the logo image
// // Hint: Calib3d.findHomography(...);
// // 6. Once the homography is found, warp the image with perspective
// // Hint: Imgproc.warpPerspective(...);
// // 7. Now you have the warped logo image in the right location, just overlay them on top of the camera image
// Mat output = new Mat();
// Mat grayMat = convertToGray(input);
//
// //TODO: Do your magic!!!
// // Hint how to overlay warped logo onto the original camera image
// /*
// Imgproc.cvtColor(logoWarped, grayMat, Imgproc.COLOR_BGR2GRAY);
// Imgproc.threshold(grayMat, grayMat, 0, 255, Imgproc.THRESH_BINARY);
// bitwise_not(grayMat, grayInv);
// input.copyTo(src1Final, grayInv);
// logoWarped.copyTo(src2Final, grayMat);
// Core.add(src1Final, src2Final, output);
// */
// //end magic
//
// if (output.empty()) {
// output = grayMat;
// }
//
// return output;
// }
//
// public void startDetectAruco(DroneHelper droneHelper) {
//// droneHelper.enterVirtualStickMode();
//
// droneHelper.setVerticalModeToVelocity();
//
//// droneHelper.setGimbalPitchDegree(-90.0f);
// }
//
// public void startDroneMove(DroneHelper droneHelper) {
//// droneHelper.enterVirtualStickMode();
// droneHelper.setVerticalModeToVelocity();
// }
//
//// public void startDoAR(DroneHelper droneHelper) {
//// droneHelper.enterVirtualStickMode();
//// droneHelper.setVerticalModeToAbsoluteHeight();
//// Bitmap bMap = BitmapFactory.decodeResource(context.getResources(), R.drawable.dji_logo);
//// logoImg = new Mat();
//// Utils.bitmapToMat(bMap, logoImg);
////
//// //Camera calibration code
//// intrinsic = new Mat(3, 3, CvType.CV_32F);
//// intrinsic.put(0,
//// 0,
//// 1.2702029303551683e+03,
//// 0.,
//// 7.0369652952332717e+02,
//// 0.,
//// 1.2682183239938338e+03,
//// 3.1342369745005681e+02,
//// 0.,
//// 0.,
//// 1.);
////
//// distortion = new MatOfDouble(3.2177759275048554e-02,
//// 1.1688831035623757e+00,
//// -1.6742357543049650e-02,
//// 1.4173384809091350e-02,
//// -6.1914718831876847e+00);
////
//// // Please measure the marker size in Meter and enter it here
//// double markerSizeMeters = 0.13;
//// double halfMarkerSize = markerSizeMeters * 0.5;
////
//// // Self-defined tag location in 3D, this is used in step 2 in doAR
//// objPoints = new MatOfPoint3f();
//// List<Point3> point3List = new ArrayList<>();
//// point3List.add(new Point3(-halfMarkerSize, -halfMarkerSize, 0));
//// point3List.add(new Point3(-halfMarkerSize, halfMarkerSize, 0));
//// point3List.add(new Point3(halfMarkerSize, halfMarkerSize, 0));
//// point3List.add(new Point3(halfMarkerSize, -halfMarkerSize, 0));
//// objPoints.fromList(point3List);
////
//// // AR object points in 3D, this is used in step 4 in doAR
//// objectPoints = new MatOfPoint3f();
////
//// List<Point3> point3DList = new ArrayList<>();
//// point3DList.add(new Point3(-halfMarkerSize, -halfMarkerSize, 0));
//// point3DList.add(new Point3(-halfMarkerSize, halfMarkerSize, 0));
//// point3DList.add(new Point3(halfMarkerSize, halfMarkerSize, 0));
//// point3DList.add(new Point3(halfMarkerSize, -halfMarkerSize, 0));
//// point3DList.add(new Point3(-halfMarkerSize, -halfMarkerSize, markerSizeMeters));
//// point3DList.add(new Point3(-halfMarkerSize, halfMarkerSize, markerSizeMeters));
//// point3DList.add(new Point3(halfMarkerSize, halfMarkerSize, markerSizeMeters));
//// point3DList.add(new Point3(halfMarkerSize, -halfMarkerSize, markerSizeMeters));
////
//// objectPoints.fromList(point3DList);
//// }
//
// private Scalar convertImageVectorToMotionVector(Scalar imageVector) {
// double pX = -imageVector.val[1];
// double pY = imageVector.val[0];
// double divisor = Math.sqrt((pX * pX) + (pY * pY));
// pX = pX / divisor;
// pY = pY / divisor;
//
// return new Scalar(pX * 0.2, pY * 0.2);
// }
//}

View File

@ -1,4 +1,4 @@
//
package com.aros.apron.tools//
//
//import android.media.MediaCodec
//import android.util.Pair

View File

@ -1,4 +1,4 @@
//package com.shd.nest.gateway
package com.aros.apron.tools//package com.shd.nest.gateway
//
//import android.provider.MediaStore
//import com.amazonaws.ClientConfiguration