Skip to content

Commit 2578dbb

Browse files
peterbarkertridge
authored andcommitted
fence: add options to change circle radii
1 parent dce61d6 commit 2578dbb

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

MAVProxy/modules/mavproxy_fence.py

+53-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def cmd_addcircle(self, args):
288288
if not self.check_have_list():
289289
return
290290
if len(args) < 2:
291-
print("Need 2 arguments")
291+
print("Usage: fence setcircle inclusion|exclusion RADIUS")
292292
return
293293
t = args[0]
294294
radius = float(args[1])
@@ -445,6 +445,18 @@ def removereturnpoint(self, seq):
445445
self.wploader.last_change = time.time()
446446
self.send_all_items()
447447

448+
def cmd_setcircleradius(self, args):
449+
if len(args) < 1:
450+
print("fence setcircleradius INDEX RADIUS")
451+
return
452+
453+
if len(args) < 2:
454+
# this one will use the click position:
455+
self.setcircleradius(int(args[0]))
456+
return
457+
458+
self.setcircleradius(int(args[0]), radius=float(args[1]))
459+
448460
def cmd_movecircle(self, args):
449461
self.movecircle(int(args[0]))
450462

@@ -499,6 +511,45 @@ def movecircle(self, seq):
499511

500512
self.send_single_waypoint(moving_item.seq)
501513

514+
def setcircleradius(self, seq, radius=None):
515+
'''change radius of circle at seq to radius
516+
'''
517+
if not self.check_have_list():
518+
return
519+
520+
item = self.wploader.item(seq)
521+
if item is None:
522+
print("No item %s" % str(seq))
523+
return
524+
525+
if not self.is_circle_item(item):
526+
print("Item %u is not a circle" % seq)
527+
return
528+
529+
if radius is None:
530+
# calculate radius from clock position:
531+
latlon = self.mpstate.click_location
532+
if latlon is None:
533+
print("No click position available")
534+
return
535+
item_x = item.x
536+
item_y = item.y
537+
if item.get_type() == 'MISSION_ITEM_INT':
538+
item_x *= 1e-7
539+
item_y *= 1e-7
540+
radius = mavextra.distance_lat_lon(latlon[0], latlon[1], item_x, item_y)
541+
elif radius <= 0:
542+
print("radius must be positive")
543+
return
544+
545+
changing_item = self.wploader.item(seq)
546+
changing_item.param1 = radius
547+
548+
self.wploader.set(changing_item, changing_item.seq)
549+
self.wploader.last_change = time.time()
550+
551+
self.send_single_waypoint(changing_item.seq)
552+
502553
def is_circle_item(self, item):
503554
return item.command in [
504555
mavutil.mavlink.MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION,
@@ -719,6 +770,7 @@ def commands(self):
719770
ret.update({
720771
'addcircle': (self.cmd_addcircle, ["<inclusion|inc|exclusion|exc>", "RADIUS"]),
721772
'movecircle': (self.cmd_movecircle, []),
773+
'setcircleradius': (self.cmd_setcircleradius, ["seq radius"]),
722774
'addpoly': (self.cmd_addpoly, ["<inclusion|inc|exclusion|exc>", "<radius>" "<pointcount>", "<rotation>"]),
723775
'movepolypoint': (self.cmd_movepolypoint, ["POLY_FIRSTPOINT", "POINT_OFFSET"]),
724776
'addreturnpoint': (self.cmd_addreturnpoint, []),

0 commit comments

Comments
 (0)