1717 from MAVProxy .modules .lib .mp_menu import MPMenuCallTextDialog
1818 from MAVProxy .modules .lib .mp_menu import MPMenuItem
1919
20+ DEFAULT_CIRCLE_SIZE = 500
2021
2122class FenceModule (mission_item_protocol .MissionItemProtocolModule ):
2223 '''uses common MISSION_ITEM protocol base class to provide fence
@@ -36,14 +37,14 @@ def gui_menu_items(self):
3637 'Add Inclusion Circle' , 'Add Inclusion Circle' , '# fence addcircle inc ' ,
3738 handler = MPMenuCallTextDialog (
3839 title = 'Radius (m)' ,
39- default = 500
40+ default = DEFAULT_CIRCLE_SIZE
4041 )
4142 ),
4243 MPMenuItem (
4344 'Add Exclusion Circle' , 'Add Exclusion Circle' , '# fence addcircle exc ' ,
4445 handler = MPMenuCallTextDialog (
4546 title = 'Radius (m)' ,
46- default = 500
47+ default = DEFAULT_CIRCLE_SIZE
4748 )
4849 ),
4950 MPMenuItem (
@@ -55,6 +56,13 @@ def gui_menu_items(self):
5556 MPMenuItem (
5657 'Add Return Point' , 'Add Return Point' , '# fence addreturnpoint' ,
5758 ),
59+ MPMenuItem (
60+ 'Add Home Centered Inclusion Circle' , 'Add Home Inclusion Circle' , '# fence addhomecircle ' ,
61+ handler = MPMenuCallTextDialog (
62+ title = 'Radius (m)' ,
63+ default = DEFAULT_CIRCLE_SIZE
64+ )
65+ ),
5866 ])
5967 return ret
6068
@@ -81,12 +89,38 @@ def circles_of_type(self, t):
8189 return []
8290 if p .command != t :
8391 continue
92+ if t == mavutil .mavlink .MAV_CMD_NAV_FENCE_HOME_CIRCLE_INCLUSION :
93+ def no_home_error ():
94+ print ("Error - no home yet. Try again later." )
95+
96+ if self .module ('wp' ) is not None :
97+ print ("wp m" )
98+ home = self .module ('wp' ).get_home ()
99+ print ("gh" )
100+ if home is not None :
101+ print ("nh" )
102+ # latlon = home.x, home.y)
103+ # print(latlon)
104+ else :
105+ no_home_error ()
106+ return
107+ else :
108+ no_home_error ()
109+ return
110+ print ("initial" , p )
111+ print (home .x , home .y )
112+ print (type (home .x ))
113+ p .x = home .x # x (latitude)
114+ p .y = home .y # y (longitude)
115+ print ("after" , p )
116+
117+ print (p )
84118 ret .append (p )
85119 return ret
86120
87121 def inclusion_circles (self ):
88122 '''return a list of Circle inclusion fences - a single MISSION_ITEM each'''
89- return self .circles_of_type (mavutil .mavlink .MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION )
123+ return self .circles_of_type (mavutil .mavlink .MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION ) + self . circles_of_type ( mavutil . mavlink . MAV_CMD_NAV_FENCE_HOME_CIRCLE_INCLUSION )
90124
91125 def exclusion_circles (self ):
92126 '''return a list of Circle exclusion fences - a single MISSION_ITEM each'''
@@ -341,6 +375,35 @@ def cmd_addcircle(self, args):
341375 self .append (m )
342376 self .send_all_items ()
343377
378+ def cmd_addhomecircle (self , args ):
379+ '''adds a home-centered circle to the map with given radius'''
380+ if not self .check_have_list ():
381+ return
382+ if len (args ) < 1 :
383+ print ("Usage: fence addhomecircle RADIUS" )
384+ return
385+ radius = float (args [0 ])
386+
387+ m = mavutil .mavlink .MAVLink_mission_item_int_message (
388+ self .target_system ,
389+ self .target_component ,
390+ 0 , # seq
391+ mavutil .mavlink .MAV_FRAME_GLOBAL , # frame
392+ mavutil .mavlink .MAV_CMD_NAV_FENCE_HOME_CIRCLE_INCLUSION , # command
393+ 0 , # current
394+ 0 , # autocontinue
395+ radius , # param1,
396+ 0.0 , # param2,
397+ 0.0 , # param3
398+ 0.0 , # param4
399+ 0 , # x (latitude), ignored
400+ 0 , # y (longitude), ignored
401+ 0 , # z (altitude)
402+ self .mav_mission_type (),
403+ )
404+ self .append (m )
405+ self .send_all_items ()
406+
344407 def cmd_addreturnpoint (self , args ):
345408 '''adds a returnpoint at the map click location'''
346409 if not self .check_have_list ():
@@ -569,6 +632,7 @@ def is_circle_item(self, item):
569632 return item .command in [
570633 mavutil .mavlink .MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION ,
571634 mavutil .mavlink .MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION ,
635+ mavutil .mavlink .MAV_CMD_NAV_FENCE_HOME_CIRCLE_INCLUSION ,
572636 ]
573637
574638 def find_polygon_point (self , polygon_start_seq , item_offset ):
@@ -784,6 +848,7 @@ def commands(self):
784848 ret = super (FenceModule , self ).commands ()
785849 ret .update ({
786850 'addcircle' : (self .cmd_addcircle , ["<inclusion|inc|exclusion|exc>" , "RADIUS" ]),
851+ 'addhomecircle' : (self .cmd_addhomecircle , ["RADIUS" ]),
787852 'movecircle' : (self .cmd_movecircle , []),
788853 'setcircleradius' : (self .cmd_setcircleradius , ["seq radius" ]),
789854 'addpoly' : (self .cmd_addpoly , ["<inclusion|inc|exclusion|exc>" , "<radius>" "<pointcount>" , "<rotation>" ]),
0 commit comments