Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #275 from Ph0tonic/feature/droneMeasures
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0tonic authored Jun 5, 2020
2 parents 93dd3f6 + 761d6d4 commit 68e2726
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
8 changes: 0 additions & 8 deletions app/src/androidTest/java/ch/epfl/sdp/drone/DroneTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito


@RunWith(AndroidJUnit4::class)
class DroneTest {

private fun <T> any(): T {
Mockito.any<T>()
return uninitialized()
}

private fun <T> uninitialized(): T = null as T

companion object {
const val SIGNAL_STRENGTH = 1.0
private const val EPSILON = 1e-5
Expand Down
19 changes: 11 additions & 8 deletions app/src/main/java/ch/epfl/sdp/drone/Drone.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import kotlin.math.sqrt

object Drone {
// Maximum distance between passes in the strategy
const val GROUND_SENSOR_SCOPE: Double = 5.0
const val GROUND_SENSOR_SCOPE: Double = 7.5
const val DEFAULT_ALTITUDE: Float = 10.0F
const val MAX_DISTANCE_BETWEEN_POINTS_IN_AREA = 1000 //meters

Expand All @@ -49,7 +49,7 @@ object Drone {

/*Will be useful later on*/
val debugGetSignalStrength: () -> Double = {
1000 / positionLiveData.value!!.distanceTo(LatLng(47.303584, 7.159724)).pow(2)
1000 / positionLiveData.value!!.distanceTo(LatLng(47.301836, 7.156145)).pow(2)
}

private val instance: System = DroneInstanceProvider.provide()
Expand Down Expand Up @@ -114,6 +114,7 @@ object Drone {
{ error -> Timber.e("Error connectionState : $error") }
)
)
setupMeasureTracking()
}

/**
Expand All @@ -139,27 +140,29 @@ object Drone {
this.missionLiveData.postValue(missionPlan.missionItems)
this.isMissionPausedLiveData.postValue(false)
ToastHandler().showToast(R.string.drone_mission_success, Toast.LENGTH_SHORT)
takeMeasure(missionCallBack)
},
{ ToastHandler().showToast(R.string.drone_mission_error, Toast.LENGTH_SHORT) }
{
ToastHandler().showToast(R.string.drone_mission_error, Toast.LENGTH_SHORT)
onMeasureTakenCallbacks.clear()
}
)
)
// TODO("See what to do with added disposables")
}

private fun takeMeasure(missionCallBack: (LatLng, Double) -> Unit) {
private fun setupMeasureTracking() {
disposables.add(
getConnectedInstance()
.andThen(instance.mission.missionProgress)
.subscribe(
{ missionProgress ->
if (missionProgress.current == missionProgress.total) {
onMeasureTakenCallbacks.remove(missionCallBack)
}
val missionItem = missionLiveData.value?.getOrNull(missionProgress.current - 1)
val location = missionItem?.longitudeDeg?.let { it1 -> LatLng(missionItem.latitudeDeg, it1) }
val signal = getSignalStrength()
location?.let { it1 -> onMeasureTaken(it1, signal) }
if (missionProgress.current == missionProgress.total) {
onMeasureTakenCallbacks.clear()
}
},
{}
)
Expand Down

0 comments on commit 68e2726

Please sign in to comment.