@@ -288,7 +288,7 @@ def cmd_addcircle(self, args):
288
288
if not self .check_have_list ():
289
289
return
290
290
if len (args ) < 2 :
291
- print ("Need 2 arguments " )
291
+ print ("Usage: fence setcircle inclusion|exclusion RADIUS " )
292
292
return
293
293
t = args [0 ]
294
294
radius = float (args [1 ])
@@ -445,6 +445,18 @@ def removereturnpoint(self, seq):
445
445
self .wploader .last_change = time .time ()
446
446
self .send_all_items ()
447
447
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
+
448
460
def cmd_movecircle (self , args ):
449
461
self .movecircle (int (args [0 ]))
450
462
@@ -499,6 +511,45 @@ def movecircle(self, seq):
499
511
500
512
self .send_single_waypoint (moving_item .seq )
501
513
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
+
502
553
def is_circle_item (self , item ):
503
554
return item .command in [
504
555
mavutil .mavlink .MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION ,
@@ -719,6 +770,7 @@ def commands(self):
719
770
ret .update ({
720
771
'addcircle' : (self .cmd_addcircle , ["<inclusion|inc|exclusion|exc>" , "RADIUS" ]),
721
772
'movecircle' : (self .cmd_movecircle , []),
773
+ 'setcircleradius' : (self .cmd_setcircleradius , ["seq radius" ]),
722
774
'addpoly' : (self .cmd_addpoly , ["<inclusion|inc|exclusion|exc>" , "<radius>" "<pointcount>" , "<rotation>" ]),
723
775
'movepolypoint' : (self .cmd_movepolypoint , ["POLY_FIRSTPOINT" , "POINT_OFFSET" ]),
724
776
'addreturnpoint' : (self .cmd_addreturnpoint , []),
0 commit comments