11"""
22MAVProxy camera tracking module
33
4+ Examples
5+ ---------
6+
7+ localhost simulation
8+ rtsp_url = "rtsp://127.0.0.1:8554/camera"
9+
10+ home wifi
11+ rtsp_url = "rtsp://192.168.1.204:8554/fpv_stream"
12+
13+ herelink wifi access point
14+ rtsp_url = "rtsp://192.168.43.1:8554/fpv_stream"
15+
16+ SIYI A8 camera
17+ rtsp_url = "rtsp://192.168.144.25:8554/main.264"
18+
19+
420Reference
521---------
622
3652class CamTrackModule (mp_module .MPModule ):
3753 """A tool to control camera tracking"""
3854
55+ # Module defaults
56+ DEFAULT_RTSP_URL = "rtsp://127.0.0.1:8554/camera"
57+ DEFAULT_IMAGE_STATUS_RATE = 20.0
58+
3959 def __init__ (self , mpstate ):
4060 super (CamTrackModule , self ).__init__ (
4161 mpstate , "camtrack" , "camera tracking module"
@@ -44,23 +64,22 @@ def __init__(self, mpstate):
4464 self .mpstate = mpstate
4565
4666 # Settings
47- # TODO: provide args to set RTSP server location
48- # localhost simulation
49- rtsp_url = "rtsp://127.0.0.1:8554/camera"
50-
51- # home wifi
52- # rtsp_url = "rtsp://192.168.1.204:8554/fpv_stream"
53-
54- # herelink wifi access point
55- # rtsp_url = "rtsp://192.168.43.1:8554/fpv_stream"
67+ self .camtrack_settings = mp_settings .MPSettings (
68+ [
69+ ("rtsp_url" , str , CamTrackModule .DEFAULT_RTSP_URL ),
70+ ("image_status_rate" , float , CamTrackModule .DEFAULT_IMAGE_STATUS_RATE ),
71+ ]
72+ )
5673
57- # SIYI A8 camera
58- # rtsp_url = "rtsp://192.168.144.25:8554/main.264"
74+ # Commands
75+ self . add_command ( "camtrack" , self . cmd_camtrack , "camera tracking" )
5976
60- self ._camera_tracking_image_status_rate = 50 # Hz
77+ self ._camera_tracking_image_status_rate = (
78+ self .camtrack_settings .image_status_rate
79+ )
6180
6281 # GUI
63- self .camera_view = CameraView ( self . mpstate , "Camera Tracking" , rtsp_url )
82+ self .camera_view = None
6483
6584 # NOTE: unused except for status
6685 # mavlink messages
@@ -79,32 +98,36 @@ def __init__(self, mpstate):
7998 self ._do_request_camera_information = True
8099 self ._do_request_camera_tracking_image_status = True
81100
82- # commands
83- self .add_command ("camtrack" , self .cmd_camtrack , "camera tracking" )
84-
85101 def cmd_camtrack (self , args ):
86- """Control behaviour of commands """
102+ """Command parser """
87103 if len (args ) <= 0 :
88104 print (self .usage ())
89105 return
90-
91- if args [0 ] == "status" :
106+ if args [0 ] == "set" :
107+ if len (args ) < 3 :
108+ self .camtrack_settings .show_all ()
109+ return
110+ self .camtrack_settings .command (args [1 :])
111+ elif args [0 ] == "status" :
92112 print (self .status ())
93- return
94-
95- if args [0 ] == "start" :
96- print ("start tracking" )
97- return
113+ elif args [0 ] == "view" :
114+ self .cmd_view ()
115+ else :
116+ print (self .usage ())
98117
99- if args [0 ] == "stop" :
100- print ("stop tracking" )
118+ def cmd_view (self ):
119+ """Open camera view"""
120+ if self .camera_view is not None :
121+ print ("camtrack view already open" )
101122 return
102123
103- print (self .usage ())
124+ self .camera_view = CameraView (
125+ self .mpstate , "Camera Tracking" , self .camtrack_settings .rtsp_url
126+ )
104127
105128 def usage (self ):
106129 """Show help on command line options."""
107- return "Usage: camtrack <status|start|stop >"
130+ return "Usage: camtrack <set| status|view >"
108131
109132 def status (self ):
110133 """Return information about the camera tracking state"""
@@ -272,7 +295,9 @@ def handle_camera_information(self, msg):
272295 def handle_camera_tracking_image_status (self , msg ):
273296 # TODO: refactor to use enums in onboard_controller.py
274297 if (
275- msg .tracking_status == mavutil .mavlink .CAMERA_TRACKING_STATUS_FLAGS_ACTIVE
298+ self .camera_view is not None
299+ and msg .tracking_status
300+ == mavutil .mavlink .CAMERA_TRACKING_STATUS_FLAGS_ACTIVE
276301 and msg .tracking_mode == mavutil .mavlink .CAMERA_TRACKING_MODE_RECTANGLE
277302 and msg .target_data == mavutil .mavlink .CAMERA_TRACKING_TARGET_DATA_IN_STATUS
278303 ):
@@ -282,7 +307,8 @@ def handle_camera_tracking_image_status(self, msg):
282307
283308 def check_events (self ):
284309 """Check for events on the camera view"""
285- self .camera_view .check_events ()
310+ if self .camera_view is not None :
311+ self .camera_view .check_events ()
286312
287313 # TODO: check which shutdown events are available in MPImage
288314 # tell mavproxy to unload the module if the GUI is closed
@@ -328,7 +354,7 @@ def send_messages(self):
328354 self .send_set_message_interval_message (
329355 mavutil .mavlink .MAVLINK_MSG_ID_CAMERA_TRACKING_IMAGE_STATUS ,
330356 interval_us , # requested interval in microseconds
331- response_target = 1 , # flight-stack default
357+ response_target = 0 , # flight-stack default
332358 )
333359 self ._do_request_camera_tracking_image_status = False
334360
@@ -369,9 +395,9 @@ def send_request_message(self, message_id, p1=0):
369395 )
370396
371397 def send_set_message_interval_message (
372- self , message_id , interval_us , response_target = 1
398+ self , message_id , interval_us , response_target = 0
373399 ):
374- self .master .mav .command_long_send (
400+ msg = self .master .mav .command_long_encode (
375401 self .settings .target_system , # target_system
376402 self .settings .target_component , # target_component
377403 mavutil .mavlink .MAV_CMD_SET_MESSAGE_INTERVAL , # command
@@ -384,6 +410,7 @@ def send_set_message_interval_message(
384410 0 , # param6
385411 response_target , # param7
386412 )
413+ self .master .mav .send (msg )
387414
388415 def idle_task (self ):
389416 """Idle tasks"""
@@ -392,7 +419,9 @@ def idle_task(self):
392419
393420 def unload (self ):
394421 """Close the GUI and unload module"""
395- self .camera_view .close ()
422+ if self .camera_view is not None :
423+ self .camera_view .close ()
424+ self .camera_view = None
396425
397426
398427def init (mpstate ):
0 commit comments