Skip to content

Commit 56e0333

Browse files
committed
Scripting: SorNav V0.9.41
Fixed a critical logic bug in the anti-stuck feature where the script would not re-engage the original waypoint after completing an upwind repositioning maneuver. Update the readme.md.
1 parent f27545c commit 56e0333

File tree

2 files changed

+52
-41
lines changed

2 files changed

+52
-41
lines changed

libraries/AP_Scripting/applets/SoarNav.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--[[
22
SoarNav: an advanced feature for hunting thermals by Marco Robustini.
3-
-- Version 0.9.4 - 2025/07/31
3+
-- Version 0.9.41 - 2025/08/01
44
55
In early versions of SOAR mode in Ardupilot, which I collaborated on with
66
the author, when the glider exited THERMAL mode the heading pointed
@@ -130,6 +130,9 @@ Script Parameters (SNAV_*)
130130
================================================================================
131131
CHANGELOG / DEVELOPER NOTES
132132
================================================================================
133+
- v0.9.41 (2025/08/01): Fixed a critical logic bug in the anti-stuck feature
134+
where the script would not re-engage the original waypoint after completing
135+
an upwind repositioning maneuver.
133136
- v0.9.4 (2025/07/31): Major refactoring to leverage native ArduPilot APIs
134137
(e.g., Location objects, get_distance, offset_bearing) instead of manual
135138
Lua calculations. This drastically improves precision, performance, and
@@ -422,6 +425,7 @@ local function calculate_bearing(lat1, lon1, lat2, lon2)
422425
end
423426
return t
424427
end
428+
425429
local brng = math.deg(atan2(y, x))
426430
if brng < 0 then brng = brng + 360 end
427431
return brng
@@ -1601,6 +1605,15 @@ update_body = function()
16011605

16021606
if SoarNavGlobals.distance_to_wp ~= -1 and SoarNavGlobals.distance_to_wp < (p_wp_radius:get()) then
16031607
if SoarNavGlobals.is_repositioning then
1608+
log_gcs(MAV_SEVERITY.INFO, 1, "Repositioned. Re-engaging original target.")
1609+
SoarNavGlobals.target_loc = SoarNavGlobals.original_target_loc
1610+
SoarNavGlobals.is_repositioning = false
1611+
SoarNavGlobals.original_target_loc = nil
1612+
SoarNavGlobals.waypoint_start_time_ms = millis()
1613+
SoarNavGlobals.distance_to_wp = -1
1614+
SoarNavGlobals.stuck_counter = 0
1615+
SoarNavGlobals.last_progress_check_ms = 0
1616+
SoarNavGlobals.distance_at_last_check = -1
16041617
else
16051618
log_gcs(MAV_SEVERITY.INFO, 1, "Waypoint reached.")
16061619
if SoarNavGlobals.current_selected_hotspot

libraries/AP_Scripting/applets/SoarNav.md

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ completely.
3030
## SNAV_LOG_LVL
3131

3232
Sets the verbosity level of messages sent to the Ground Control Station.
33-
A value of 0 (Silent) reports only critical script errors. A value of 1
34-
(Events) is the default and reports key events like script start/stop,
35-
waypoint reached, new waypoint generation, and thermal memory
36-
recording; this is ideal for standard use. A value of 2 (Detailed Status)
37-
includes all Level 1 events plus a periodic status report with detailed
38-
navigation, grid, and thermal memory data for in-depth debugging.
33+
34+
0 (Silent): Only critical script errors are reported.
35+
36+
1 (Events): [Default] Reports key events like script start#stop,
37+
waypoint reached, new waypoint generation, and thermal memory
38+
recording; this is ideal for standard use.
39+
40+
2 (Detailed Status): Includes all Level 1 events plus a periodic
41+
status report with detailed navigation, grid, and thermal memory
42+
data for in-depth debugging.
3943

4044
## SNAV_MAX_DIST
4145

@@ -55,26 +59,20 @@ The acceptance radius in meters. Defines the distance to a waypoint
5559
at which it is considered 'reached' and a new target is generated.
5660
The default is 30 meters.
5761

58-
## SNAV_NAV_P / SNAV_NAV_D
62+
## SNAV_NAV_P # SNAV_NAV_D
5963

6064
These are the gains for the script's internal PD (Proportional-Derivative)
6165
navigation controller, which commands roll based on heading error.
6266
SNAV_NAV_P is the proportional gain; higher values result in a more
63-
aggressive response to heading errors. The default is 0.6.
64-
SNAV_NAV_D is the derivative gain; this helps to dampen the
65-
response for smoother control and prevent overshoot. The default is 0.05.
67+
aggressive response. SNAV_NAV_D is the derivative gain, which helps to
68+
dampen the response for smoother control.
6669

6770
## SNAV_TMEM_ENABLE
6871

6972
Enables (1) or disables (0) the Thermal Memory feature. When enabled,
70-
the script will remember and return to previously found lift areas.
71-
72-
## SNAV_TMEM_CHANCE
73-
74-
The base probability, as a percentage (0-100), that the script will
75-
choose to navigate towards a known thermal instead of exploring a new
76-
grid cell. This chance is dynamically adjusted by the script based on
77-
recent success in finding thermals. Default is 50%.
73+
the script will remember and return to previously found lift areas. The
74+
probability of navigating to a known thermal versus exploring the grid
75+
is dynamically adjusted based on recent success.
7876

7977
## SNAV_TMEM_LIFE
8078

@@ -86,13 +84,13 @@ The default is 1200 seconds (20 minutes).
8684

8785
A compensation factor used to estimate the upwind position of a
8886
thermal relative to where it was detected. This improves the accuracy
89-
of the thermal memory by accounting for wind drift. The default is 60.
87+
of the thermal memory by accounting for wind drift.
9088

9189
# Operation
9290

9391
## Installation and Setup
9492

95-
Place the SoarNav.lua script into the APM/SCRIPTS directory
93+
Place the SoarNav.lua script into the APM#SCRIPTS directory
9694
on the flight controller's microSD card.
9795

9896
Set SCR_ENABLE to 1 and reboot the flight controller.
@@ -112,16 +110,16 @@ of the thermal memory by accounting for wind drift. The default is 60.
112110

113111
You must choose one of two methods to define the operational area.
114112

115-
Radius Mode is enabled by setting SNAV_MAX_DIST to your desired
116-
search radius in meters (e.g., 500). The script will operate within this
117-
circle.
118-
Polygon Mode is enabled by setting SNAV_MAX_DIST to 0. This requires
119-
a file named snav.poly in the root directory of the microSD card.
120-
This flight area file can be easily generated and saved using the
121-
Mission Planner interface. The file should contain a list of GPS
122-
coordinates (latitude longitude, space-separated) defining the
123-
vertices of your flight area, one vertex per line. The script will
124-
automatically close the polygon.
113+
Radius Mode is enabled by setting SNAV_MAX_DIST to your desired
114+
search radius in meters (e.g., 500). The script will operate within
115+
this circle.
116+
117+
Polygon Mode is enabled by setting SNAV_MAX_DIST to 0. This requires
118+
a file named snav.poly in the root directory of the microSD card.
119+
The file should contain a list of GPS coordinates (latitude
120+
longitude, space-separated) defining the vertices of your flight
121+
area, one vertex per line. The script will automatically close the
122+
polygon if the last point is not the same as the first.
125123

126124
## In-Flight Use
127125

@@ -153,16 +151,16 @@ navigation a few seconds after the sticks are returned to center.
153151

154152
## Persistent Manual Override (Roll Gesture)
155153

156-
A rapid sequence of full left-right-left-right roll stick
157-
movements toggles a persistent manual override. This allows the pilot
158-
to fly freely without the script resuming automatically. Repeat the
159-
gesture to deactivate the override and return control to SoarNav.
160-
GCS messages will confirm the state change.
154+
A rapid sequence of full roll stick movements toggles a
155+
persistent manual override. This allows the pilot to fly freely without
156+
the script resuming automatically. Repeat the gesture to deactivate the
157+
override and return control to SoarNav. GCS messages will confirm the
158+
state change.
161159

162160
## Area Re-Centering (Pitch Gesture)
163161

164-
If using Radius Mode, a rapid sequence of full
165-
up-down-up-down-up pitch stick movements will re-center the
166-
circular search area to the aircraft's current location. This is useful
167-
for shifting the focus of exploration during a long flight. This
168-
gesture is only active when you have temporary stick override.
162+
If using Radius Mode, a rapid sequence of full pitch stick
163+
movements will re-center the circular search area to the aircraft's
164+
current location. This is useful for shifting the focus of exploration
165+
during a long flight. This gesture is only active when you have a
166+
temporary stick override engaged.

0 commit comments

Comments
 (0)