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,29 +593,34 @@ open class MainActivity : BaseActivity() {
} else {
initTimes++
LogUtil.log(TAG, "初始化$initTimes")
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()
//负载
PayloadWidgetManager.getInstance().initPayloadInfo()
//初始化上报
LTEManager.getInstance().initLTEInfo()
WirelessLinkManager.getInstance().initWirelessLink()
CameraManager.getInstance().initCameraInfo()
LEDsSettingsManager.getInstance().initLEDsInfo()
LogUtil.log(TAG,"自定义推流方式:"+PreferenceUtils.getInstance().customStreamType)
Handler().postDelayed(Runnable {
MissionV3Manager.getInstance().initMissionManager()
FlightManager.getInstance().initFlightInfo()
BatteryManager.getInstance().initBatteryInfo()
StickManager.getInstance().initStickInfo()
AlternateLandingManager.getInstance().initAlterLandingInfo()
OSDManager.getInstance().initOsd()
FlightTaskProgressManager.getInstance().initFlightTaskProgress()
MediaManager.getInstance().init()
StreamManager.getInstance().initStreamManager()
GimbalManager.getInstance().initGimbalInfo()
//负载
PayloadWidgetManager.getInstance().initPayloadInfo()
//初始化上报
LTEManager.getInstance().initLTEInfo()
WirelessLinkManager.getInstance().initWirelessLink()
CameraManager.getInstance().initCameraInfo()
LEDsSettingsManager.getInstance().initLEDsInfo()
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,19 +32,18 @@ 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";
@Override
public void connectionLost(Throwable cause) {
LogUtil.log(TAG, "MQtt connectionLost:" + cause.toString());
LogUtil.log(TAG, "MQtt connectionLost:"+cause.toString());
//短线也要清空这个
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());
//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);
@ -212,7 +217,7 @@ public class MqttCallBack implements MqttCallbackExtended {
LogUtil.log(TAG, "收到:进入指令飞行控制模式" + jsonString);
StickManager.getInstance().setVirtualStickModeEnabled(message);
break;
//退出控制权时要自动触发续飞航线
//退出控制权时要自动触发续飞航线
case Constant.DRC_MODE_EXIT:
LogUtil.log(TAG, "收到:退出指令飞行控制模式" + jsonString);
//清理这个时间戳循环
@ -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,23 +673,21 @@ public class MqttCallBack implements MqttCallbackExtended {
public void deliveryComplete(IMqttDeliveryToken token) {
}
String[] topics = new String[]{
String[] topics = new String[] {
AMSConfig.getInstance().DOWN_UAV_EVENT_REPLY,
AMSConfig.getInstance().DOWN_UAV_SERVICES,
};
int[] qos = new int[]{
int[] qos = new int[] {
1, 1
};
@Override
public void connectComplete(boolean reconnect, String serverURI) {
try {
// if (reconnect) {//重新订阅
LogUtil.log(TAG, "MQtt ConnectComplete:" + serverURI);
MqttManager.getInstance().mqttAndroidClient.subscribe(topics, qos);//订阅主题:注册
LogUtil.log(TAG, "MQtt ConnectComplete:" + serverURI);
MqttManager.getInstance().mqttAndroidClient.subscribe(topics, qos);//订阅主题:注册
// MqttManager.getInstance().mqttAndroidClient.subscribe(AMSConfig.DOWN_UAV_EVENT_REPLY, 1);//订阅主题:注册
// publish(topic,"注册",0);
// publish(topic,"注册",0);
// }
} catch (Exception e) {
LogUtil.log(TAG, "MQtt ConnectException:" + e.toString());

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;

File diff suppressed because it is too large Load Diff

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;
@ -93,7 +98,7 @@ public class FlightManager extends BaseManager {
if (newValue != null) {
if (!newValue) {
LogUtil.log(TAG,"遥控器断开连接");
LogUtil.log(TAG, "遥控器断开连接");
// 飞机未连接时设置未连接状态
Movement.getInstance().setMode_code(14);
OSDManager.getInstance().pushFlightAttitude();
@ -101,10 +106,9 @@ public class FlightManager extends BaseManager {
Movement.getInstance().setMissionFinish(true);
}else{
} else {
LogUtil.log(TAG,"setMode_code1(0)");
LogUtil.log(TAG, "setMode_code1(0)");
//连上就待机
Movement.getInstance().setMissionFinish(false);
Movement.getInstance().setMode_code(0);
@ -114,14 +118,13 @@ public class FlightManager extends BaseManager {
}
});
//重新复制一下如果一直断开这个回调会不执行
if(isConnect){
LogUtil.log(TAG,"setMode_code2(0)");
if (isConnect) {
LogUtil.log(TAG, "setMode_code2(0)");
Movement.getInstance().setMode_code(0);
}else{
} else {
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();
}
@ -147,11 +152,11 @@ public class FlightManager extends BaseManager {
@Override
public void onUpdate(@NonNull PerceptionInfo information) {
if (information != null) {
if (information.getDownwardObstacleAvoidanceWorking()!=null){
if (information.getDownwardObstacleAvoidanceWorking() != null) {
Movement.getInstance().setDownside(information.getDownwardObstacleAvoidanceWorking() ? 1 : 0);
}
Movement.getInstance().setHorizon(information.isHorizontalObstacleAvoidanceEnabled() ? 1 : 0);
if (information.getUpwardObstacleAvoidanceWorking()!=null){
if (information.getUpwardObstacleAvoidanceWorking() != null) {
Movement.getInstance().setUpside(information.getUpwardObstacleAvoidanceWorking() ? 1 : 0);
}
pushFlightAttitude();
@ -187,13 +192,13 @@ public class FlightManager extends BaseManager {
ApronExecutionStatus.getInstance().setAircraftWaitShutDown(false);
//起飞了这个状态就看这里
if(Movement.getInstance().getFlightmode()==1){
if (Movement.getInstance().getFlightmode() == 1) {
Movement.getInstance().setMode_code(5);
}else if(Movement.getInstance().getFlightmode()==2){
} else if (Movement.getInstance().getFlightmode() == 2) {
Movement.getInstance().setMode_code(17);
}
}else{
LogUtil.log(TAG,"setMode_code3(0)");
} else {
LogUtil.log(TAG, "setMode_code3(0)");
Movement.getInstance().setMode_code(0);
OSDManager.getInstance().pushFlightAttitude();
@ -204,7 +209,6 @@ public class FlightManager extends BaseManager {
pushFlightAttitude();
}
}
});
@ -214,7 +218,7 @@ public class FlightManager extends BaseManager {
public void onValueChange(@Nullable Boolean oldValue, @Nullable Boolean newValue) {
if (newValue != null) {
if(newValue==false){
if (newValue == false) {
//电机不转待机
Movement.getInstance().setMode_code(0);
OSDManager.getInstance().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) {
@ -385,7 +405,7 @@ public class FlightManager extends BaseManager {
KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyWindDirection), this, new CommonCallbacks.KeyListener<WindDirection>() {
@Override
public void onValueChange(@Nullable WindDirection windDirection, @Nullable WindDirection t1) {
if (t1!=null){
if (t1 != null) {
Movement.getInstance().setWind_direction(t1.value());
pushFlightAttitude();
}
@ -429,45 +449,45 @@ public class FlightManager extends BaseManager {
Movement.getInstance().setPlaneMode(newValue.name());
pushFlightAttitude();
switch (newValue){
case TAKE_OFF_READY:
//Movement.getInstance().setMode_code(2);
break;
case VIRTUAL_STICK:
//Movement.getInstance().setMode_code(3);
break;
case AUTO_TAKE_OFF:
//我觉得可能会重复设置
//Movement.getInstance().setMode_code(4);
break;
case WAYPOINT:
//Movement.getInstance().setMode_code(5);
break;
case PANO:
Movement.getInstance().setMode_code(6);
break;
case FOLLOW_ME:
Movement.getInstance().setMode_code(7);
break;
case AUTO_AVOIDANCE:
Movement.getInstance().setMode_code(8);
break;
case GO_HOME:
Movement.getInstance().setMode_code(9);
break;
case AUTO_LANDING:
Movement.getInstance().setMode_code(10);
//重置这个飞行状态
Movement.getInstance().setFlightmode(0);
break;
case FORCE_LANDING:
Movement.getInstance().setMode_code(11);
break;
case POI:
Movement.getInstance().setMode_code(20);
break;
switch (newValue) {
case TAKE_OFF_READY:
//Movement.getInstance().setMode_code(2);
break;
case VIRTUAL_STICK:
//Movement.getInstance().setMode_code(3);
break;
case AUTO_TAKE_OFF:
//我觉得可能会重复设置
//Movement.getInstance().setMode_code(4);
break;
case WAYPOINT:
//Movement.getInstance().setMode_code(5);
break;
case PANO:
Movement.getInstance().setMode_code(6);
break;
case FOLLOW_ME:
Movement.getInstance().setMode_code(7);
break;
case AUTO_AVOIDANCE:
Movement.getInstance().setMode_code(8);
break;
case GO_HOME:
Movement.getInstance().setMode_code(9);
break;
case AUTO_LANDING:
Movement.getInstance().setMode_code(10);
//重置这个飞行状态
Movement.getInstance().setFlightmode(0);
break;
case FORCE_LANDING:
Movement.getInstance().setMode_code(11);
break;
case POI:
Movement.getInstance().setMode_code(20);
break;
}
}
}
}
});
@ -732,7 +752,7 @@ public class FlightManager extends BaseManager {
//开舱门
openCabinDoor();
//降落时将云台朝下
//gimbalDownwards();
gimbalDownwards();
//返航时将云台归中,曝光ISO降低
//gimbalAndCameraReset();
//开始视觉识别降落
@ -744,8 +764,9 @@ public class FlightManager extends BaseManager {
//(决定飞机触发电量低的返航)
public boolean isTriggerRoomBattrryLanding;
private void batteryLowLanding() {
if (isTriggerRoomBattrryLanding){
if (isTriggerRoomBattrryLanding) {
return;
}
int forcedBattery = Integer.valueOf(PreferenceUtils.getInstance().getForcedBattery());
@ -754,23 +775,23 @@ public class FlightManager extends BaseManager {
String missionState = Movement.getInstance().getWaypointMissionExecuteState();
boolean isMissionExecuting = (!TextUtils.isEmpty(missionState) &&
(missionState.equals("EXECUTING") || missionState.equals("ENTER_WAYLINE"))
||(!TextUtils.isEmpty(Movement.getInstance().getPlaneMode())
&&Movement.getInstance().getPlaneMode().equals("WAYPOINT")));
|| (!TextUtils.isEmpty(Movement.getInstance().getPlaneMode())
&& Movement.getInstance().getPlaneMode().equals("WAYPOINT")));
// 获取飞行状态和航线状态
boolean isFlyingAndBatteryOk = isFlying &&value!=null&&value< forcedBattery&&isMissionExecuting;
boolean isAlterLandStatus=(PreferenceUtils.getInstance().getNeedTriggerAlterArucoLand()||PreferenceUtils.getInstance().getTriggerToAlternatePoint());
boolean isFlyingAndBatteryOk = isFlying && value != null && value < forcedBattery && isMissionExecuting;
boolean isAlterLandStatus = (PreferenceUtils.getInstance().getNeedTriggerAlterArucoLand() || PreferenceUtils.getInstance().getTriggerToAlternatePoint());
if (isFlyingAndBatteryOk&& !isTriggerRoomBattrryLanding&&!isAlterLandStatus) {
if (isFlyingAndBatteryOk && !isTriggerRoomBattrryLanding && !isAlterLandStatus) {
isTriggerRoomBattrryLanding = true;
KeyManager.getInstance().performAction(createKey(FlightControllerKey.KeyStartGoHome), new CommonCallbacks.CompletionCallbackWithParam<EmptyMsg>() {
@Override
public void onSuccess(EmptyMsg emptyMsg) {
sendEvent2Server("电量低于阈值,强制返航",2);
sendEvent2Server("电量低于阈值,强制返航", 2);
}
@Override
public void onFailure(@NonNull IDJIError error) {
sendEvent2Server("电量低于阈值,返航失败",2);
sendEvent2Server("电量低于阈值,返航失败", 2);
}
});
@ -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;
@ -907,17 +925,17 @@ public class FlightManager extends BaseManager {
PreferenceUtils.getInstance().setNeedTriggerAlterArucoLand(true);
PreferenceUtils.getInstance().setNeedTriggerApronArucoLand(false);
LogUtil.log(TAG, "开始识别备降点二维码,椭球高度:" + Movement.getInstance().getElevation() + "" + "--超声波高度:" + Movement.getInstance().getUltrasonicHeight() + "分米");
sendEvent2Server("开始备降点视觉降落",1);
sendEvent2Server("开始备降点视觉降落", 1);
} else {
LogUtil.log(TAG, "识别ApronTag:" + PreferenceUtils.getInstance().getNeedTriggerApronArucoLand());
EventBus.getDefault().post(FLAG_START_DETECT_ARUCO_APRON);
PreferenceUtils.getInstance().setNeedTriggerAlterArucoLand(false);
PreferenceUtils.getInstance().setNeedTriggerApronArucoLand(true);
LogUtil.log(TAG, "开始识别机库二维码,椭球高度:" + Movement.getInstance().getElevation() + "" + "--超声波高度:" + Movement.getInstance().getUltrasonicHeight() + "分米");
sendEvent2Server("开始视觉降落",1);
sendEvent2Server("开始视觉降落", 1);
}
isSendDetect = true;
PerceptionManager.getInstance().setPerceptionEnable(false);
//PerceptionManager.getInstance().setPerceptionEnable(false);
}
@ -966,8 +984,8 @@ public class FlightManager extends BaseManager {
return !isTriggerLanding && (isFlying || isMotorsOn) && AlternateArucoDetect.getInstance().isCanLanding();
} else {
return !isTriggerLanding && (isFlying || isMotorsOn) && (
ApronArucoDetect.getInstance().isCanLanding()|| (ApronArucoDetect.getInstance().isStartFastStick()
&& ApronArucoDetect.getInstance().getCheckThrowingErrorsTimes() > 100));
ApronArucoDetect.getInstance().isCanLanding() || (ApronArucoDetect.getInstance().isStartFastStick()
&& ApronArucoDetect.getInstance().getCheckThrowingErrorsTimes() > 100));
}
}
@ -996,7 +1014,7 @@ public class FlightManager extends BaseManager {
if (!PreferenceUtils.getInstance().getNeedTriggerAlterArucoLand()) {
// 发送无人机入库消息到服务器********************待修改************************
ApronExecutionStatus.getInstance().setAircraftWaitShutDown(false);
DockStorageManager.getInstance().sendDockStorageMsg2Server( );
DockStorageManager.getInstance().sendDockStorageMsg2Server();
}
// 上传媒体文件
SystemManager.getInstance().upLoadMedia(MqttManager.getInstance().mqttAndroidClient);
@ -1015,7 +1033,7 @@ public class FlightManager extends BaseManager {
Movement.getInstance().setMissionFinish1(true);
Movement.getInstance().setTask_current_step(25);
sendOpenCabinDoorMsg=false;
sendOpenCabinDoorMsg = false;
}
}
@ -1035,15 +1053,16 @@ public class FlightManager extends BaseManager {
KeyManager.getInstance().performAction(createKey(FlightControllerKey.KeyStartGoHome), new CommonCallbacks.CompletionCallbackWithParam<EmptyMsg>() {
@Override
public void onSuccess(EmptyMsg emptyMsg) {
sendMsg2Server( message);
sendMsg2Server(message);
}
@Override
public void onFailure(@NonNull IDJIError error) {
sendFailMsg2Server( message, "返航执行失败:" + getIDJIErrorMsg(error));
sendFailMsg2Server(message, "返航执行失败:" + getIDJIErrorMsg(error));
}
});
} else {
sendFailMsg2Server( message, "返航执行失败:飞控未连接");
sendFailMsg2Server(message, "返航执行失败:飞控未连接");
}
}
@ -1058,22 +1077,21 @@ public class FlightManager extends BaseManager {
public void onSuccess(EmptyMsg emptyMsg) {
//只有在取消返航时才能显示取消返航失败
Movement.getInstance().setMode_code(3);
sendMsg2Server( message);
sendMsg2Server(message);
}
@Override
public void onFailure(@NonNull IDJIError error) {
LogUtil.log(TAG,"取消返航执行失败"+error);
sendFailMsg2Server( message, "取消返航执行失败:" + getIDJIErrorMsg(error));
LogUtil.log(TAG, "取消返航执行失败" + error);
sendFailMsg2Server(message, "取消返航执行失败:" + getIDJIErrorMsg(error));
}
});
} else {
sendFailMsg2Server( message, "飞控未连接");
sendFailMsg2Server(message, "飞控未连接");
}
}
private void resetAircrftLandingStatus() {
// 避免在下次起飞时触发视觉识别
PreferenceUtils.getInstance().setNeedTriggerApronArucoLand(false);
@ -1133,21 +1151,21 @@ public class FlightManager extends BaseManager {
KeyManager.getInstance().performAction(createKey(FlightControllerKey.KeyStartAutoLanding), new CommonCallbacks.CompletionCallbackWithParam<EmptyMsg>() {
@Override
public void onSuccess(EmptyMsg emptyMsg) {
if (message!=null){
sendMsg2Server( message);
if (message != null) {
sendMsg2Server(message);
}
}
@Override
public void onFailure(@NonNull IDJIError error) {
LogUtil.log(TAG, "降落失败:" + new Gson().toJson(error));
if (message!=null){
sendFailMsg2Server( message, "降落失败:" + getIDJIErrorMsg(error));
if (message != null) {
sendFailMsg2Server(message, "降落失败:" + getIDJIErrorMsg(error));
}
}
});
} else {
sendFailMsg2Server( message, "飞控未连接");
sendFailMsg2Server(message, "飞控未连接");
}
}
@ -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) {
@ -1163,14 +1182,13 @@ public class FlightManager extends BaseManager {
@Override
public void onSuccess(EmptyMsg emptyMsg) {
LogUtil.log(TAG, "紧急悬停,取消返航成功");
sendMsg2Server( message);
sendMsg2Server(message);
resetAircrftLandingStatus();
}
@Override
public void onFailure(@NonNull IDJIError error) {
sendFailMsg2Server( message, "紧急悬停,取消返航失败:" + getIDJIErrorMsg(error));
sendFailMsg2Server(message, "紧急悬停,取消返航失败:" + getIDJIErrorMsg(error));
}
});
break;
@ -1181,14 +1199,14 @@ public class FlightManager extends BaseManager {
@Override
public void onSuccess() {
LogUtil.log(TAG, "紧急悬停,终止任务成功");
sendMsg2Server( message);
sendMsg2Server(message);
resetAircrftLandingStatus();
}
@Override
public void onFailure(@NonNull IDJIError error) {
sendFailMsg2Server( message, "紧急悬停,终止任务失败:" + getIDJIErrorMsg(error));
sendFailMsg2Server(message, "紧急悬停,终止任务失败:" + getIDJIErrorMsg(error));
}
});
break;
@ -1196,7 +1214,7 @@ public class FlightManager extends BaseManager {
KeyManager.getInstance().performAction(createKey(FlightControllerKey.KeyStopAutoLanding), new CommonCallbacks.CompletionCallbackWithParam<EmptyMsg>() {
@Override
public void onSuccess(EmptyMsg emptyMsg) {
sendMsg2Server( message);
sendMsg2Server(message);
resetAircrftLandingStatus();
}
@ -1204,7 +1222,7 @@ public class FlightManager extends BaseManager {
@Override
public void onFailure(@NonNull IDJIError error) {
LogUtil.log(TAG, "紧急悬停,取消降落失败:" + new Gson().toJson(error));
sendFailMsg2Server( message, "紧急悬停,取消降落失败:" + getIDJIErrorMsg(error));
sendFailMsg2Server(message, "紧急悬停,取消降落失败:" + getIDJIErrorMsg(error));
}
});
break;
@ -1213,19 +1231,52 @@ public class FlightManager extends BaseManager {
@Override
public void onSuccess() {
LogUtil.log(TAG, "紧急悬停,控制权释放成功");
sendMsg2Server( message);
sendMsg2Server(message);
resetAircrftLandingStatus();
}
@Override
public void onFailure(@NonNull IDJIError error) {
sendFailMsg2Server( message, "紧急悬停,控制权失败:" + getIDJIErrorMsg(error));
sendFailMsg2Server(message, "紧急悬停,控制权失败:" + getIDJIErrorMsg(error));
}
});
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,10 +68,14 @@ public class OSDManager extends BaseManager {
}
lastExecuteTime = now;
Boolean isConnect = KeyManager.getInstance().getValue(createKey(FlightControllerKey.KeyConnection));
if (isConnect != null && isConnect && !Movement.getInstance().isMissionFinish()) {
pushFlightAttitude();
}else{
LogUtil.log(TAG,"osd stop:flight controller is null");
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);
StickManager.getInstance().enableVirtualStick(message);
sendMsg2Server(message);
new Handler(Looper.getMainLooper()).postDelayed(() -> {
// 这里放你要延迟执行的代码
StickManager.getInstance().enableVirtualStick(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);
}
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);
}
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);
}
pushKMZFileToAircraft(message);
}
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) {
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方向不变
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