1717 from MAVProxy .modules .lib .mp_menu import MPMenuCallTextDialog
1818 from MAVProxy .modules .lib .mp_menu import MPMenuItem
1919
20+ DEFAULT_CIRCLE_SIZE = 500
21+
2022
2123class FenceModule (mission_item_protocol .MissionItemProtocolModule ):
2224 '''uses common MISSION_ITEM protocol base class to provide fence
@@ -36,14 +38,14 @@ def gui_menu_items(self):
3638 'Add Inclusion Circle' , 'Add Inclusion Circle' , '# fence addcircle inc ' ,
3739 handler = MPMenuCallTextDialog (
3840 title = 'Radius (m)' ,
39- default = 500
41+ default = DEFAULT_CIRCLE_SIZE
4042 )
4143 ),
4244 MPMenuItem (
4345 'Add Exclusion Circle' , 'Add Exclusion Circle' , '# fence addcircle exc ' ,
4446 handler = MPMenuCallTextDialog (
4547 title = 'Radius (m)' ,
46- default = 500
48+ default = DEFAULT_CIRCLE_SIZE
4749 )
4850 ),
4951 MPMenuItem (
@@ -55,6 +57,13 @@ def gui_menu_items(self):
5557 MPMenuItem (
5658 'Add Return Point' , 'Add Return Point' , '# fence addreturnpoint' ,
5759 ),
60+ MPMenuItem (
61+ 'Add Home Centered Inclusion Circle' , 'Add Home Inclusion Circle' , '# fence addhomecircle ' ,
62+ handler = MPMenuCallTextDialog (
63+ title = 'Radius (m)' ,
64+ default = DEFAULT_CIRCLE_SIZE
65+ )
66+ ),
5867 ])
5968 return ret
6069
@@ -82,12 +91,17 @@ def circles_of_type(self, t):
8291 if p .command != t :
8392 continue
8493 ret .append (p )
94+
8595 return ret
8696
8797 def inclusion_circles (self ):
8898 '''return a list of Circle inclusion fences - a single MISSION_ITEM each'''
8999 return self .circles_of_type (mavutil .mavlink .MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION )
90100
101+ def home_inclusion_circles (self ):
102+ '''return a list of around-home Circle inclusion fences - a single MISSION_ITEM each'''
103+ return self .circles_of_type (mavutil .mavlink .MAV_CMD_NAV_FENCE_HOME_CIRCLE_INCLUSION )
104+
91105 def exclusion_circles (self ):
92106 '''return a list of Circle exclusion fences - a single MISSION_ITEM each'''
93107 return self .circles_of_type (mavutil .mavlink .MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION )
@@ -341,6 +355,35 @@ def cmd_addcircle(self, args):
341355 self .append (m )
342356 self .send_all_items ()
343357
358+ def cmd_addhomecircle (self , args ):
359+ '''adds a home-centered circle to the map with given radius'''
360+ if not self .check_have_list ():
361+ return
362+ if len (args ) < 1 :
363+ print ("Usage: fence addhomecircle RADIUS" )
364+ return
365+ radius = float (args [0 ])
366+
367+ m = mavutil .mavlink .MAVLink_mission_item_int_message (
368+ self .target_system ,
369+ self .target_component ,
370+ 0 , # seq
371+ mavutil .mavlink .MAV_FRAME_GLOBAL , # frame
372+ mavutil .mavlink .MAV_CMD_NAV_FENCE_HOME_CIRCLE_INCLUSION , # command
373+ 0 , # current
374+ 0 , # autocontinue
375+ radius , # param1,
376+ 0.0 , # param2,
377+ 0.0 , # param3
378+ 0.0 , # param4
379+ 0 , # x (latitude), ignored
380+ 0 , # y (longitude), ignored
381+ 0 , # z (altitude)
382+ self .mav_mission_type (),
383+ )
384+ self .append (m )
385+ self .send_all_items ()
386+
344387 def cmd_addreturnpoint (self , args ):
345388 '''adds a returnpoint at the map click location'''
346389 if not self .check_have_list ():
@@ -569,6 +612,7 @@ def is_circle_item(self, item):
569612 return item .command in [
570613 mavutil .mavlink .MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION ,
571614 mavutil .mavlink .MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION ,
615+ mavutil .mavlink .MAV_CMD_NAV_FENCE_HOME_CIRCLE_INCLUSION ,
572616 ]
573617
574618 def find_polygon_point (self , polygon_start_seq , item_offset ):
@@ -784,6 +828,7 @@ def commands(self):
784828 ret = super (FenceModule , self ).commands ()
785829 ret .update ({
786830 'addcircle' : (self .cmd_addcircle , ["<inclusion|inc|exclusion|exc>" , "RADIUS" ]),
831+ 'addhomecircle' : (self .cmd_addhomecircle , ["RADIUS" ]),
787832 'movecircle' : (self .cmd_movecircle , []),
788833 'setcircleradius' : (self .cmd_setcircleradius , ["seq radius" ]),
789834 'addpoly' : (self .cmd_addpoly , ["<inclusion|inc|exclusion|exc>" , "<radius>" "<pointcount>" , "<rotation>" ]),
0 commit comments