Skip to content

Commit

Permalink
Merge pull request #1098 from PhenoApps/geonav_distance_thresh
Browse files Browse the repository at this point in the history
geonav_distance_thresh
  • Loading branch information
trife authored Dec 6, 2024
2 parents 04c8eae + 2704557 commit ea1d232
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/src/main/assets/field_import/rtk_sample.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plot_id,row,column,plot,tray_row,tray_id,seed_id,seed_name,pedigree,geo_coordinates
13RPN00001,1,1,1,1,13RPN_TRAY001,12GHT00001B,Kharkof,Kharkof,36.6677618;-96.3431604
13RPN00001,1,1,1,1,13RPN_TRAY001,12GHT00001B,Kharkof,Kharkof,-96.3431604;36.6677618
13RPN00002,1,2,2,3,13RPN_TRAY001,12GHT00002B,Roughrider,Roughrider,
13RPN00003,1,3,3,4,13RPN_TRAY001,12GHT00003B,Nuplains,Nuplains,
13RPN00004,1,4,4,6,13RPN_TRAY001,12GHT00004B,Nekota,Nekota,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public class GeneralKeys {
public static final String GEONAV_PARAMETER_D1 = GEONAV_PREFIX + "parameters.trapezoid.D1";
public static final String GEONAV_PARAMETER_D2 = GEONAV_PREFIX + "parameters.trapezoid.D2";
public static final String GEONAV_SEARCH_METHOD = GEONAV_PREFIX + "SEARCH_METHOD";
public static final String GEONAV_DISTANCE_THRESHOLD = GEONAV_PREFIX + "DISTANCE_THRESHOLD";

public static final String GEONAV_LOGGING_MODE = GEONAV_PREFIX + "GEONAV_LOGGING_MODE";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ class LocationPreferencesFragment : PreferenceFragmentCompat(),
}
}

findPreference<EditTextPreference>(GeneralKeys.GEONAV_DISTANCE_THRESHOLD)?.let { distPref ->
distPref.setOnBindEditTextListener { editText ->
editText.inputType = android.text.InputType.TYPE_CLASS_NUMBER or android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL
}
}

setPreferenceChangeListeners(
listOf(
GeneralKeys.GEONAV_PARAMETER_D1,
Expand Down
27 changes: 21 additions & 6 deletions app/src/main/java/com/fieldbook/tracker/utilities/GeoNavHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,27 @@ class GeoNavHelper @Inject constructor(private val controller: CollectController
//run the algorithm and time how long it takes
if (start != null && currentFixQuality) {

val distanceThreshKm = try {
(preferences.getString(GeneralKeys.GEONAV_DISTANCE_THRESHOLD, "10.0") ?: "10.0").toDouble()
} catch (e: NumberFormatException) {
10.0
}

//long toc = System.currentTimeMillis();
val (first) = impactZoneSearch(
val (first, closestDistance) = impactZoneSearch(
mLimitedGeoNavLogWriter, mFullGeoNavLogWriter, preferences, currentLoggingMode(),
start, coordinates.toTypedArray(),
mAzimuth, theta, mTeslas, geoNavMethod, d1, d2
mAzimuth, theta, mTeslas, geoNavMethod, d1, d2, distanceThreshKm
)
//long tic = System.currentTimeMillis();

//if we received a result then show it to the user, create a button to navigate to the plot
if (first != null) {

if (closestDistance/1000 > distanceThreshKm) {
return
}

val id = first.observation_unit_db_id
with((controller.getContext() as CollectActivity)) {
if (id != getRangeBox().cRange.plot_id && id != lastPlotIdNav) {
Expand Down Expand Up @@ -837,10 +848,14 @@ class GeoNavHelper @Inject constructor(private val controller: CollectController
mTeslas = calculateNoise(mGeomagneticField)
if ((mTeslas < 25 || mTeslas > 65) && mNotWarnedInterference) {
mNotWarnedInterference = false
Toast.makeText(
controller.getContext(), R.string.activity_collect_geomagnetic_noise_detected,
Toast.LENGTH_SHORT
).show()
val geoNavMethod: String =
preferences.getString(GeneralKeys.GEONAV_SEARCH_METHOD, "0") ?: "0"
if (geoNavMethod != "0") {
Toast.makeText(
controller.getContext(), R.string.activity_collect_geomagnetic_noise_detected,
Toast.LENGTH_SHORT
).show()
}
}
val R = FloatArray(9)
val I = FloatArray(9)
Expand Down
34 changes: 19 additions & 15 deletions app/src/main/java/com/fieldbook/tracker/utilities/GeodeticUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ class GeodeticUtils {
teslas: Double,
geoNavMethod: String,
d1: Double,
d2: Double
d2: Double,
distanceThreshold: Double
): Pair<ObservationUnitModel?, Double> {

//greedy algorithm to find closest point, first point is set to inf
Expand Down Expand Up @@ -225,22 +226,25 @@ class GeodeticUtils {
//after a full run of IZ, update the last CLOSEST_UPDATE to CLOSEST_FINAL
izLogArray.findLast { it.closest == CLOSEST_UPDATE.toString() }?.closest = CLOSEST_FINAL.toString()

// limited mode
if (currentLoggingMode == GeoNavHelper.GeoNavLoggingMode.LIMITED.value || currentLoggingMode == GeoNavHelper.GeoNavLoggingMode.BOTH.value) {
//print only the closest plant to the log
izLogArray.forEach {
if (it.closest == CLOSEST_FINAL.toString()) writeGeoNavLog(
preferences,
limitedLog,
it
)
if (closestDistance/1000 < distanceThreshold) {

// limited mode
if (currentLoggingMode == GeoNavHelper.GeoNavLoggingMode.LIMITED.value || currentLoggingMode == GeoNavHelper.GeoNavLoggingMode.BOTH.value) {
//print only the closest plant to the log
izLogArray.forEach {
if (it.closest == CLOSEST_FINAL.toString()) writeGeoNavLog(
preferences,
limitedLog,
it
)
}
}
}

// full mode
if (currentLoggingMode == GeoNavHelper.GeoNavLoggingMode.FULL.value || currentLoggingMode == GeoNavHelper.GeoNavLoggingMode.BOTH.value) {
//print the entire array to log
izLogArray.forEach { writeGeoNavLog(preferences, fullLog, it) }
// full mode
if (currentLoggingMode == GeoNavHelper.GeoNavLoggingMode.FULL.value || currentLoggingMode == GeoNavHelper.GeoNavLoggingMode.BOTH.value) {
//print the entire array to log
izLogArray.forEach { writeGeoNavLog(preferences, fullLog, it) }
}
}

return closestPoint to closestDistance
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/signal_distance_variant.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M4,6V4A12,12 0,0 1,16 16H14A10,10 0,0 0,4 6M4,10V8A8,8 0,0 1,12 16H10A6,6 0,0 0,4 10M4,12A4,4 0,0 1,8 16H4V12M3,18H19V16L22,19L19,22V20H3V18Z"/>
</vector>
Binary file removed app/src/main/res/raw/shutter.wav
Binary file not shown.
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1376,4 +1376,7 @@
<string name="act_brapi_list_filter_reset_selection_message">This will clear the running list of selected items.</string>
<string name="pref_alpha_media_keycode_events_summary">Enable to use media commands for app interactions</string>
<string name="pref_alpha_media_keycode_events_title">Enable Media Commands</string>
<string name="pref_geonav_distance_threshold_summary">GeoNav automatically stops when distance from all plots exceeds this value in kilometers.</string>
<string name="pref_geonav_distance_threshold_title">Proximity Check</string>
<string name="activity_collect_proximity_warning">GeoNav Stopping, outside proximity of coordinates</string>
</resources>
8 changes: 8 additions & 0 deletions app/src/main/res/xml/preferences_location.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@
android:summary="@string/pref_geonav_search_angle_summary"
android:title="@string/pref_geonav_search_angle_title" />

<EditTextPreference
android:defaultValue="10.0"
android:icon="@drawable/signal_distance_variant"
android:key="com.fieldbook.tracker.geonav.DISTANCE_THRESHOLD"
android:inputType="numberDecimal"
android:summary="@string/pref_geonav_distance_threshold_summary"
android:title="@string/pref_geonav_distance_threshold_title" />

<ListPreference
android:defaultValue="0"
android:entries="@array/pref_geonav_logging_modes"
Expand Down

0 comments on commit ea1d232

Please sign in to comment.