瀏覽代碼

1、起飞海拔、返航高度、相对航高、返航距离 功能开发测试完成
2、计算距离暂时采用Arcgis for runtime计算长度方式

不会爬树的猴 1 年之前
父節點
當前提交
0b4abbeba8

+ 12 - 0
.idea/deploymentTargetDropDown.xml

@@ -1,6 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="deploymentTargetDropDown">
+    <runningDeviceTargetSelectedWithDropDown>
+      <Target>
+        <type value="RUNNING_DEVICE_TARGET" />
+        <deviceKey>
+          <Key>
+            <type value="SERIAL_NUMBER" />
+            <value value="10.88.88.112:5555" />
+          </Key>
+        </deviceKey>
+      </Target>
+    </runningDeviceTargetSelectedWithDropDown>
+    <timeTargetWasSelectedWithDropDown value="2023-08-16T09:09:50.939110Z" />
     <runningDeviceTargetsSelectedWithDialog>
       <Target>
         <type value="RUNNING_DEVICE_TARGET" />

+ 20 - 0
.idea/jarRepositories.xml

@@ -36,5 +36,25 @@
       <option name="name" value="maven2" />
       <option name="url" value="https://jitpack.io" />
     </remote-repository>
+    <remote-repository>
+      <option name="id" value="maven3" />
+      <option name="name" value="maven3" />
+      <option name="url" value="https://repo.osgeo.org/repository/release/" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="maven4" />
+      <option name="name" value="maven4" />
+      <option name="url" value="http://download.osgeo.org/webdav/geotools/" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="maven3" />
+      <option name="name" value="maven3" />
+      <option name="url" value="http://repo.boundlessgeo.com/main" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="maven4" />
+      <option name="name" value="maven4" />
+      <option name="url" value="https://repo.osgeo.org/repository/snapshot/" />
+    </remote-repository>
   </component>
 </project>

+ 3 - 1
app/build.gradle

@@ -109,5 +109,7 @@ dependencies {
     implementation 'me.jessyan:autosize:1.2.1'
 
     //TODO 地理计算工具
-    implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:6.13.0'
+    api 'org.locationtech.jts:jts-core:1.18.2'
+    //api "org.geotools:gt-main:$geotools_version"
+    //api "org.geotools:gt-epsg-hsql:$geotools_version"
 }

+ 2 - 2
app/src/main/java/com/cr/common/CrFlightControlInfo.kt

@@ -47,7 +47,7 @@ data class CrFlightControlInfo(var isConnection: Boolean = false) :CrDataCommon(
     var homeLongitude:Double = 0.0
     var homeLatitude:Double = 0.0
     var homeDistance:Double = 0.0
-    var homeAltitude:Double = 0.0
+    var homeAltitude:Int = 0
     var homeDistanceStr:String = DEFAULT_STR
     var homeAltitudeStr:String = DEFAULT_STR
 
@@ -76,7 +76,7 @@ data class CrFlightControlInfo(var isConnection: Boolean = false) :CrDataCommon(
         speedZ = 0.0
         homeLongitude = 0.0
         homeLatitude = 0.0
-        homeAltitude = 0.0
+        homeAltitude = 0
         homeDistance = 0.0
         homeDistanceStr = DEFAULT_STR
         homeAltitudeStr = DEFAULT_STR

+ 56 - 0
app/src/main/java/com/cr/common/CrJTMManager.kt

@@ -0,0 +1,56 @@
+package com.cr.common
+
+import com.esri.arcgisruntime.geometry.*
+import org.locationtech.jts.geom.Coordinate
+import org.locationtech.jts.geom.GeometryFactory
+
+/**
+ * 操作系统:MAC系统
+ * 创建者:王成
+ * 创建日期:2023/8/16 13:37
+ * 描述:JTS地理计算工具
+ */
+class CrJTMManager {
+    companion object {
+        /**
+         * 根据经纬度计算距离
+         * @param lon1 Double 经度1
+         * @param lat1 Double 纬度1
+         * @param lon2 Double 经度2
+         * @param lat2 Double 纬度2
+         * @return Double 计算距离
+         */
+        fun calculateDistance(lon1:Double,lat1:Double,lon2:Double,lat2:Double):Double{
+            var pt1 = Point(lon1,lat1, SpatialReference.create(4326))
+            var pt2 = Point(lon2,lat2, SpatialReference.create(4326))
+            var polylineBuilder = PolylineBuilder(SpatialReference.create(4326))
+            polylineBuilder.addPoint(pt1)
+            polylineBuilder.addPoint(pt2)
+            var linearUnit = LinearUnit(LinearUnitId.METERS)
+            return GeometryEngine.lengthGeodetic(polylineBuilder.toGeometry(),linearUnit,GeodeticCurveType.GREAT_ELLIPTIC)
+        }
+
+        /**
+         * 通过函数计算经纬度距离
+         * @param longitude1 Double 经度1
+         * @param latitude1 Double 纬度1
+         * @param longitude2 Double 经度2
+         * @param latitude2 Double 纬度2
+         * @return Double
+         */
+        fun getDistance(longitude1:Double, latitude1:Double, longitude2:Double, latitude2:Double):Double {
+            var lat1 = (Math.PI / 180) * latitude1;
+            var lat2 = (Math.PI / 180) * latitude2;
+
+            var lon1 = (Math.PI / 180) * longitude1;
+            var lon2 = (Math.PI / 180) * longitude2;
+
+            //两点间距离 km,如果想要米的话,结果*1000
+            var d = Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1)) * 6378.137
+            return if (d < 1)
+                (d * 1000)
+            else
+                String.format("%.2f", d * 1000).toDouble()
+        }
+    }
+}

+ 4 - 21
app/src/main/java/com/cr/cruav/AvLogin.kt

@@ -12,10 +12,7 @@ import android.widget.Switch
 import android.widget.TextView
 import androidx.core.app.ActivityCompat
 import androidx.core.content.ContextCompat
-import com.cr.common.DataManager
-import com.cr.common.CrFileManager
-import com.cr.common.CrUnitManager
-import com.cr.common.DatabaseBaseManager
+import com.cr.common.*
 import com.cr.data.CrConfig
 import com.cr.data.CrUtil
 import com.cr.data.CrUtil.Companion.onStart
@@ -147,28 +144,14 @@ class AvLogin : CrActivity(), OnClickListener {
 //                    showFragment(it)
 //                }
 //                showMessage(CrUnitManager.getDeviceDpi(this))
-                GlobalScope.launch {
-                    withContext(Dispatchers.IO){
-                        var one = one()
-                        var two = two(one)
-                    }
-                }
+                var dis = CrJTMManager.calculateDistance(118.3556,35.1234,118.2314,35.2341)
+                var dis1 = CrJTMManager.getDistance(118.3556,35.1234,118.2314,35.2341)
+                CrUtil.print("距离A${dis}距离B${dis1}")
             }
 
         }
     }
 
-    private suspend fun one():String{
-        delay(5000)
-        CrUtil.print("函数一返回")
-        return "函数一测试"
-    }
-
-    private suspend fun two(demo:String){
-        delay(1000)
-        CrUtil.print(demo)
-    }
-
     /**
      * 登录验证
      * @param userName String 账号

+ 24 - 2
app/src/main/java/com/cr/pages/FragmentDynamicInfo.kt

@@ -16,6 +16,7 @@ import com.cr.event.CrCommonAction
 import com.cr.event.EventCommon
 import com.cr.viewmodel.CrCameraVM
 import com.cr.viewmodel.CrFlightControlVM
+import com.cr.widget.CrSpeedWidget
 import com.squareup.otto.Subscribe
 import dji.sdk.keyvalue.key.CameraKey
 import dji.sdk.keyvalue.key.KeyTools
@@ -53,9 +54,13 @@ class FragmentDynamicInfo : CrFragment(), View.OnClickListener {
 
     private var lblMessage: TextView? = null // define: 2023/8/7 消息
     private var lblAltitude: TextView? = null // define: 2023/8/15 相对航高
-    private var lblTakeoffAltitude:TextView? = null  // define: 2023/8/15 起飞海拔
+    private var lblTakeoffAltitude: TextView? = null  // define: 2023/8/15 起飞海拔
     private var lblDistanceByHome: TextView? = null // define: 2023/8/15 返航距离
-    private var lblAltitudeByHome:TextView?=null // define: 2023/8/15 返航高度
+    private var lblAltitudeByHome: TextView? = null // define: 2023/8/15 返航高度
+
+    private var speedX: CrSpeedWidget? = null  // define: 2023/8/16 x方向速度
+    private var speedY: CrSpeedWidget? = null  // define: 2023/8/16 y方向速度
+    private var speedZ: CrSpeedWidget? = null // define: 2023/8/16 z方向速度
 
     /**
      * 初始化
@@ -112,6 +117,15 @@ class FragmentDynamicInfo : CrFragment(), View.OnClickListener {
             lblDistanceByHome = it.findViewById(R.id.lbl_home_distance)
             lblAltitudeByHome = it.findViewById(R.id.lbl_home_altitude)
 
+            // todo: 2023/8/16 挂载速度
+            speedX = it.findViewById(R.id.speed_x)
+            speedY = it.findViewById(R.id.speed_y)
+            speedZ = it.findViewById(R.id.speed_z)
+
+            speedX?.setProgressMax(30)
+            speedY?.setProgressMax(30)
+            speedZ?.setProgressMax(10)
+
             // todo: 2023/8/2 挂载事件
             lblSDPhotoCount?.setOnClickListener(this)
         }
@@ -177,6 +191,14 @@ class FragmentDynamicInfo : CrFragment(), View.OnClickListener {
         flightControlVm.flightControlInfo.observe(requireActivity()) {
             it?.let {
                 lblAltitude?.text = it.altitudeStr
+                lblTakeoffAltitude?.text = it.takeoffAltitudeStr
+                lblAltitudeByHome?.text = it.homeAltitudeStr
+                lblDistanceByHome?.text = it.homeDistanceStr
+
+                // todo: 2023/8/16 更新速度
+                speedX?.setProgressValue(it.speedX.toInt())
+                speedY?.setProgressValue(it.speedY.toInt())
+                speedZ?.setProgressValue(it.speedZ.toInt())
             }
         }
     }

+ 25 - 5
app/src/main/java/com/cr/viewmodel/CrFlightControlVM.kt

@@ -2,14 +2,14 @@ package com.cr.viewmodel
 
 import androidx.lifecycle.MutableLiveData
 import com.cr.common.CrFlightControlInfo
+import com.cr.common.CrJTMManager
+import com.cr.common.CrUnitManager
 import com.cr.cruav.R
-import com.cr.data.DEFAULT_STR
 import dji.sdk.keyvalue.key.BatteryKey
 import dji.sdk.keyvalue.key.FlightControllerKey
 import dji.sdk.keyvalue.key.KeyTools
 import dji.sdk.keyvalue.key.ProductKey
 import dji.sdk.keyvalue.value.flightcontroller.CompassCalibrationState
-import dji.sdk.keyvalue.value.flightcontroller.FlyLimitLicenseVersion
 import dji.sdk.keyvalue.value.flightcontroller.IMUCalibrationState
 import dji.sdk.keyvalue.value.product.ProductType
 import dji.v5.et.create
@@ -17,6 +17,8 @@ import dji.v5.et.listen
 import dji.v5.manager.KeyManager
 import dji.v5.utils.common.ContextUtil
 import dji.v5.utils.common.StringUtils
+import org.locationtech.jts.geom.Coordinate
+import org.locationtech.jts.geom.GeometryFactory
 
 /**
  * 操作系统:MAC系统
@@ -40,7 +42,13 @@ class CrFlightControlVM : CrViewModel() {
      * 计算距离
      */
     private fun calculateDistance(){
-
+        flightControlInfo.value?.let {
+            if(it.homeLongitude > 0 && it.homeLatitude>0 && it.longitude>0 && it.latitude>0){
+                val distance = CrJTMManager.calculateDistance(it.homeLongitude,it.homeLatitude,it.longitude,it.latitude)
+                it.homeDistance = distance
+                it.homeDistanceStr = CrUnitManager.formatLength(distance)
+            }
+        }
     }
 
     /**
@@ -138,7 +146,9 @@ class CrFlightControlVM : CrViewModel() {
                 flightControlInfo.value?.altitude = it.altitude
                 flightControlInfo.value?.longitudeStr = String.format("%.5f",it.longitude)
                 flightControlInfo.value?.latitudeStr = String.format("%.5f",it.latitude)
-                flightControlInfo.value?.altitudeStr = String.format("%.1f",it.altitude)
+                flightControlInfo.value?.altitudeStr = String.format("%.1f米",it.altitude)
+                // todo: 2023/8/16 计算返航距离
+                calculateDistance()
                 refresh(flightControlInfo)
             }
         }
@@ -156,6 +166,8 @@ class CrFlightControlVM : CrViewModel() {
             it?.let {
                 flightControlInfo.value?.homeLongitude = it.longitude
                 flightControlInfo.value?.homeLatitude = it.latitude
+                // todo: 2023/8/16 计算返航距离
+                calculateDistance()
                 refresh(flightControlInfo)
             }
         }
@@ -163,7 +175,15 @@ class CrFlightControlVM : CrViewModel() {
         FlightControllerKey.KeyTakeoffLocationAltitude.create().listen(this){
             it?.let {
                 flightControlInfo.value?.takeoffAltitude = it
-                flightControlInfo.value?.takeoffAltitudeStr = String.format("%.1f",it)
+                flightControlInfo.value?.takeoffAltitudeStr = String.format("%.1f米",it)
+                refresh(flightControlInfo)
+            }
+        }
+        // todo: 2023/8/16 返航高度
+        FlightControllerKey.KeyGoHomeHeight.create().listen(this){
+            it?.let {
+                flightControlInfo.value?.homeAltitude = it
+                flightControlInfo.value?.homeAltitudeStr = String.format("%d米",it)
                 refresh(flightControlInfo)
             }
         }

+ 27 - 0
app/src/main/java/com/cr/widget/CrSpeedWidget.kt

@@ -216,4 +216,31 @@ class CrSpeedWidget @JvmOverloads constructor(
             it.typeface = CrFontManager.getTTGBTypeface(context)
         }
     }
+
+    /**
+     * 设置当前值
+     * @param value Int
+     */
+    fun setProgressValue(value:Int){
+        if(value < 0){
+            this.progressValue = -1 * value
+        }else{
+            this.progressValue = value
+        }
+        // todo: 2023/8/16 计算绘制角度
+        this.progressAngle = this.progressValue*270/this.progressMax
+        invalidate()
+    }
+
+    /**
+     * 设置最大速度
+     * @param value Int
+     */
+    fun setProgressMax(value:Int){
+        if(value <= 0){
+            this.progressMax = 20
+        }else{
+            this.progressMax = value
+        }
+    }
 }

+ 2 - 2
build.gradle

@@ -6,11 +6,11 @@ buildscript {
     repositories {
         google()
         jcenter()
+        mavenCentral()
     }
     dependencies {
         classpath 'com.android.tools.build:gradle:4.2.2'
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
-
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
     }
@@ -20,8 +20,8 @@ allprojects {
     repositories {
         google()
         jcenter()
-        /* 添加ArcGIS For Android 依赖 */
         mavenCentral()
+        /* 添加ArcGIS For Android 依赖 */
         maven {
             url 'https://esri.jfrog.io/artifactory/arcgis'
         }