Skip to content

Commit a159319

Browse files
committed
terrain_nav: add setting callback
- Ensure the planner is updated when a setting changes. Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
1 parent 385ec2a commit a159319

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

MAVProxy/modules/mavproxy_terrainnav/terrainnav.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import time
88
import threading
99

10+
from functools import partial
11+
1012
from MAVProxy.mavproxy import MPState
1113

1214
from MAVProxy.modules.lib import multiproc
@@ -304,7 +306,7 @@ def process_ui_msgs(self):
304306
elif isinstance(msg, terrainnav_msgs.MoveBoundary):
305307
self.move_planner_boundary()
306308
elif isinstance(msg, terrainnav_msgs.Settings):
307-
self.edit_settings()
309+
self.settings_dialog()
308310
else:
309311
# TODO: raise an exception
310312
if self.is_debug:
@@ -426,10 +428,43 @@ def move_planner_boundary(self):
426428

427429
self._parent_pipe_send.send(PlannerGridLatLon((lat, lon)))
428430

429-
def edit_settings(self):
431+
@staticmethod
432+
def setting_callback(pipe, setting):
433+
"""
434+
Called when a setting is updated
435+
436+
:param pipe: pipe used to send setting to the planner
437+
:type pipe: multiproc.Pipe
438+
:param setting: the setting that has changed
439+
:type setting: MPSetting
440+
"""
441+
print(f"setting changed: name: {setting.name}, value: {setting.value}")
442+
# TODO: find more compact way to ensure all settings are sent to planner
443+
if setting.name == "loiter_agl_alt":
444+
pipe.send(PlannerLoiterAglAlt(setting.value))
445+
elif setting.name == "loiter_radius":
446+
pipe.send(PlannerLoiterRadius(setting.value))
447+
elif setting.name == "turning_radius":
448+
pipe.send(PlannerTurningRadius(setting.value))
449+
elif setting.name == "climb_angle_deg":
450+
pipe.send(PlannerClimbAngleDeg(setting.value))
451+
elif setting.name == "max_agl_alt":
452+
pipe.send(PlannerMaxAglAlt(setting.value))
453+
elif setting.name == "min_agl_alt":
454+
pipe.send(PlannerMinAglAlt(setting.value))
455+
elif setting.name == "grid_spacing":
456+
pipe.send(PlannerGridSpacing(setting.value))
457+
elif setting.name == "grid_length":
458+
pipe.send(PlannerGridLength(setting.value))
459+
elif setting.name == "time_budget":
460+
pipe.send(PlannerTimeBudget(setting.value))
461+
462+
def settings_dialog(self):
430463
"""
431464
Open the settings dialog
432465
"""
466+
cb = partial(TerrainNavModule.setting_callback, self._parent_pipe_send)
467+
self.terrainnav_settings.set_callback(cb)
433468
WXSettings(self.terrainnav_settings)
434469

435470
def draw_circle(self, id, lat, lon, radius, colour):
@@ -708,7 +743,7 @@ def generate_waypoints(self):
708743
wp_gen = self.terrainnav_settings.wp_generator
709744
if wp_gen == "SimpleWaypoints":
710745
self.wp_gen_simple_waypoints()
711-
elif wp_gen =="UseLoiterToAlt":
746+
elif wp_gen == "UseLoiterToAlt":
712747
self.wp_gen_use_loiter_to_alt()
713748
else:
714749
print(f"[terrainnav] invalid WP generator: {wp_gen}")

0 commit comments

Comments
 (0)