mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added satellite orbital velocity calculation function
This commit is contained in:
1 parent
7402b73ffe
commit
e37ac8e2ba
2 files changed
+28
-15
No files matched your search
@@ -5,11 +5,10 @@ import android.graphics.ColorMatrix
|
|||||||
import android.graphics.ColorMatrixColorFilter
|
import android.graphics.ColorMatrixColorFilter
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.Observer
|
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
@@ -37,6 +36,8 @@ import org.osmdroid.views.CustomZoomButtonsController
|
|||||||
import org.osmdroid.views.overlay.*
|
import org.osmdroid.views.overlay.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import kotlin.math.pow
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
class MapOsmFragment : Fragment(R.layout.fragment_map_osm) {
|
class MapOsmFragment : Fragment(R.layout.fragment_map_osm) {
|
||||||
|
|
||||||
@@ -120,7 +121,7 @@ class MapOsmFragment : Fragment(R.layout.fragment_map_osm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupObservers() {
|
private fun setupObservers() {
|
||||||
viewModel.getGSP().observe(viewLifecycleOwner, Observer { stationPosition ->
|
viewModel.getGSP().observe(viewLifecycleOwner, { stationPosition ->
|
||||||
when (stationPosition) {
|
when (stationPosition) {
|
||||||
is Result.Success -> {
|
is Result.Success -> {
|
||||||
setupPosOverlay(stationPosition.data)
|
setupPosOverlay(stationPosition.data)
|
||||||
@@ -128,7 +129,7 @@ class MapOsmFragment : Fragment(R.layout.fragment_map_osm) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
viewModel.getPassList().observe(viewLifecycleOwner, Observer { satPasses ->
|
viewModel.getPassList().observe(viewLifecycleOwner, { satPasses ->
|
||||||
when (satPasses) {
|
when (satPasses) {
|
||||||
is Result.Success -> {
|
is Result.Success -> {
|
||||||
if (satPasses.data.isNotEmpty()) {
|
if (satPasses.data.isNotEmpty()) {
|
||||||
@@ -145,7 +146,7 @@ class MapOsmFragment : Fragment(R.layout.fragment_map_osm) {
|
|||||||
Marker(binding.mapView).apply {
|
Marker(binding.mapView).apply {
|
||||||
setInfoWindow(null)
|
setInfoWindow(null)
|
||||||
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM)
|
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM)
|
||||||
icon = resources.getDrawable(R.drawable.ic_map_pos, mainActivity.theme)
|
icon = ResourcesCompat.getDrawable(resources, R.drawable.ic_map_pos, mainActivity.theme)
|
||||||
position = GeoPoint(gsp.latitude, gsp.longitude)
|
position = GeoPoint(gsp.latitude, gsp.longitude)
|
||||||
binding.mapView.overlays[0] = this
|
binding.mapView.overlays[0] = this
|
||||||
binding.mapView.invalidate()
|
binding.mapView.invalidate()
|
||||||
@@ -166,7 +167,8 @@ class MapOsmFragment : Fragment(R.layout.fragment_map_osm) {
|
|||||||
|
|
||||||
private suspend fun getSatIcons(passList: List<SatPass>): Overlay =
|
private suspend fun getSatIcons(passList: List<SatPass>): Overlay =
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
val icon = resources.getDrawable(R.drawable.ic_map_sat, mainActivity.theme)
|
val icon =
|
||||||
|
ResourcesCompat.getDrawable(resources, R.drawable.ic_map_sat, mainActivity.theme)
|
||||||
val items = mutableListOf<SatItem>()
|
val items = mutableListOf<SatItem>()
|
||||||
|
|
||||||
passList.forEach {
|
passList.forEach {
|
||||||
@@ -196,7 +198,7 @@ class MapOsmFragment : Fragment(R.layout.fragment_map_osm) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return@withContext ItemizedIconOverlay<SatItem>(items, icon, listener, mainActivity)
|
return@withContext ItemizedIconOverlay(items, icon, listener, mainActivity)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setSatDetails(satPass: SatPass) {
|
private fun setSatDetails(satPass: SatPass) {
|
||||||
@@ -208,7 +210,19 @@ class MapOsmFragment : Fragment(R.layout.fragment_map_osm) {
|
|||||||
|
|
||||||
private fun setSatInfo(satPass: SatPass) {
|
private fun setSatInfo(satPass: SatPass) {
|
||||||
val satPos = satPass.predictor.getSatPos(dateNow)
|
val satPos = satPass.predictor.getSatPos(dateNow)
|
||||||
Log.d("myTag", satPos.toString())
|
val satRng = satPos.range
|
||||||
|
val satAlt = satPos.altitude
|
||||||
|
val satVel = getSatVelocity(satAlt)
|
||||||
|
val satLat = Math.toDegrees(satPos.latitude).toFloat()
|
||||||
|
var satLon = Math.toDegrees(satPos.longitude).toFloat()
|
||||||
|
if (satLon > 180f) satLon -= 360f
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSatVelocity(satAlt: Double): Double {
|
||||||
|
val earthG = 6.674 * 10.0.pow(-11)
|
||||||
|
val earthM = 5.98 * 10.0.pow(24)
|
||||||
|
val orbitRadius = 6.37 * 10.0.pow(6) + satAlt * 10.0.pow(3)
|
||||||
|
return sqrt(earthG * earthM / orbitRadius) / 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSatTrack(pass: SatPass): Overlay {
|
private fun getSatTrack(pass: SatPass): Overlay {
|
||||||
|
|||||||
@@ -67,13 +67,13 @@ class MapViewFragment : Fragment(R.layout.fragment_map_view) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupObservers(binding: FragmentMapViewBinding) {
|
private fun setupObservers(binding: FragmentMapViewBinding) {
|
||||||
viewModel.getGSP().observe(viewLifecycleOwner, androidx.lifecycle.Observer { result ->
|
viewModel.getGSP().observe(viewLifecycleOwner, { result ->
|
||||||
when (result) {
|
when (result) {
|
||||||
is Result.Success -> gsp = result.data
|
is Result.Success -> gsp = result.data
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
viewModel.getPassList().observe(viewLifecycleOwner, androidx.lifecycle.Observer { result ->
|
viewModel.getPassList().observe(viewLifecycleOwner, { result ->
|
||||||
when (result) {
|
when (result) {
|
||||||
is Result.Success -> {
|
is Result.Success -> {
|
||||||
satPassList = result.data
|
satPassList = result.data
|
||||||
@@ -135,11 +135,10 @@ class MapViewFragment : Fragment(R.layout.fragment_map_view) {
|
|||||||
|
|
||||||
private fun setDataToTextViews() {
|
private fun setDataToTextViews() {
|
||||||
val currentTime = Date(System.currentTimeMillis())
|
val currentTime = Date(System.currentTimeMillis())
|
||||||
val orbitalPeriod = (24 * 60 / selectedSat.meanmo).toInt()
|
val position = predictor.getSatPos(currentTime)
|
||||||
val positions = predictor.getPositions(currentTime, 60, 0, orbitalPeriod * 3)
|
var lon = Math.toDegrees(position.longitude).toFloat()
|
||||||
var lon = Math.toDegrees(positions[0].longitude).toFloat()
|
val lat = Math.toDegrees(position.latitude).toFloat()
|
||||||
val lat = Math.toDegrees(positions[0].latitude).toFloat()
|
val rng = position.range
|
||||||
val rng = positions[0].range
|
|
||||||
|
|
||||||
if (lon > 180f) lon -= 360f
|
if (lon > 180f) lon -= 360f
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user