Create a mavlink Camera server Component, cameras argument will normally be a gstreamer pipeline
Type
Default
Details
source_component
int
100
used for component indication
mav_type
int
30
used for heartbeat MAV_TYPE indication
camera
NoneType
None
cameras (or FakeCamera for testing)
loglevel
LogLevels | int
20
logging level
# run a server that can receive commands from a clientfrom UAV.logging import LogLevels# start a mavlink server that can receive commands from a clientwith MAVCom("udpout:localhost:14445", source_system=222, loglevel=LogLevels.DEBUG) as UAV_server:# add the camera server components to the server UAV_server.add_component(CameraServer(mav_type=mavlink.MAV_TYPE_CAMERA, source_component=mavlink.MAV_COMP_ID_CAMERA, camera=None)) UAV_server.add_component(CameraServer(mavlink.MAV_COMP_ID_CAMERA2)) UAV_server.add_component(CameraServer(mavlink.MAV_COMP_ID_CAMERA3)) time.sleep(1)
INFO |28.955| mavcom.MAVCom | mavcom.py :386 | Thread-6 ( | MainProces | MAVLink Mav2: True, source_system: 222
WARNI|28.957| mavcom.CameraSe | camera_ser:114 | MainThread | MainProces | Component has no cameras object
INFO |28.957| mavcom.CameraSe | basecompon:123 | MainThread | MainProces | Component Started self.source_component = 100, self.mav_type = 30, self.source_system = 222
WARNI|28.958| mavcom.CameraSe | camera_ser:114 | MainThread | MainProces | Component has no cameras object
INFO |28.958| mavcom.CameraSe | basecompon:123 | MainThread | MainProces | Component Started self.source_component = 101, self.mav_type = 30, self.source_system = 222
WARNI|28.959| mavcom.CameraSe | camera_ser:114 | MainThread | MainProces | Component has no cameras object
INFO |28.959| mavcom.CameraSe | basecompon:123 | MainThread | MainProces | Component Started self.source_component = 102, self.mav_type = 30, self.source_system = 222
INFO |30.959| mavcom.CameraSe | basecompon:417 | MainThread | MainProces | CameraServer closed (not waiting for _t_heartbeat daemon thread)
INFO |30.960| mavcom.CameraSe | basecompon:417 | MainThread | MainProces | CameraServer closed (not waiting for _t_heartbeat daemon thread)
INFO |30.960| mavcom.CameraSe | basecompon:417 | MainThread | MainProces | CameraServer closed (not waiting for _t_heartbeat daemon thread)
INFO |30.960| mavcom.MAVCom | mavcom.py :442 | MainThread | MainProces | MAVCom closed
Create a client component to send commands to a companion computer or GCS that will control a cameras via a CameraServer instance
Type
Default
Details
source_component
int
used for component indication
mav_type
int
used for heartbeat MAV_TYPE indication
loglevel
LogLevels | int
20
logging level
Example: CameraClient
# run a client that can send commands to a serverwith MAVCom("udpin:localhost:14445", source_system=111, loglevel=LogLevels.CRITICAL) as client: # add the camera client component to the client gcs:CameraClient = client.add_component( CameraClient(mav_type=mavlink.MAV_TYPE_GCS, source_component=11, loglevel=LogLevels.DEBUG) )
DEBUG|31.104| mavcom.CameraCl | basecompon:119 | MainThread | MainProces | set_mav_connection CameraClient general.py:119 self.mav_com = <MAVCom>
DEBUG|31.104| mavcom.CameraCl | basecompon:165 | Thread-16 | MainProces | Starting heartbeat type: 6 to all Systems and Components
DEBUG|31.105| mavcom.CameraCl | basecompon:127 | MainThread | MainProces | Called from Component.start_mav_connection(), override to add startup behaviour
DEBUG|31.105| mavcom.CameraCl | basecompon:168 | Thread-16 | MainProces | Sent heartbeat 6 self.source_system = 111 self.source_component = 11
INFO |31.105| mavcom.CameraCl | basecompon:123 | MainThread | MainProces | Component Started self.source_component = 11, self.mav_type = 6, self.source_system = 111
INFO |32.105| mavcom.CameraCl | basecompon:417 | MainThread | MainProces | CameraClient closed (not waiting for _t_heartbeat daemon thread)
DEBUG|32.107| mavcom.CameraCl | basecompon:168 | Thread-16 | MainProces | Sent heartbeat 6 self.source_system = 111 self.source_component = 11
Request the target system(s) emit a single instance of a specified message (i.e. a “one-shot” version of MAV_CMD_SET_MESSAGE_INTERVAL). https://mavlink.io/en/messages/common.html#MAV_CMD_REQUEST_MESSAGE
A system can request that additional messages are sent as a stream, or change the rate at which existing streamed messages are sent, using the MAV_CMD_SET_MESSAGE_INTERVAL command. A single instance of a message can be requested by sending MAV_CMD_REQUEST_MESSAGE. See https://mavlink.io/en/mavgen_python/howto_requestmessages.html See https://mavlink.io/en/messages/common.html#MAV_CMD_SET_MESSAGE_INTERVAL
Note: async function
BaseComponent.send_ack
BaseComponent.send_ack (msg, ack_result:object=0)
Send an ACK message to indicate a command was received.
Wait for the callback for a message received from a component server
Note: async function
Example: Test locally using UDP ports
on the same machine using UDP ports 14445 with server_system_ID=111, client_system_ID=222 CameraClient is set to udpin:localhost:14445 and CameraServer is set to udpout:localhost:14445 udpin is so that the client can receive UDP from the mavproxy server at localhost:14445 CameraClient uses async/await to send commands to the CameraServer
on the same machine using UDP ports 14445 with server_system_ID=111, client_system_ID=222
from UAV.mavlink import CameraClient, CameraServer, MAVCom, mavlink, GimbalServerViewsheenimport timedef on_message(message):print(f"on_message: {message}")returnTrue# Return True to indicate that command was ok and send ackclass Cam1(Component):def__init__(self, source_component, mav_type, debug=False):super().__init__(source_component=source_component, mav_type=mav_type)self.append_message_handler(on_message)class Cam2(Component):def__init__(self, source_component, mav_type, debug=False):super().__init__(source_component=source_component, mav_type=mav_type)self.append_message_handler(on_message)class Cli(Component):def__init__(self, source_component, mav_type, debug=False):super().__init__(source_component=source_component, mav_type=mav_type)self.append_message_handler(on_message)
# assert False, "Stop here"
Test with Serial ports
Test using a Pixhawk connected via telemetry 2 and USB serial ports. CamClient is set to udpin:localhost:14445 and CamServer is set to udpout:localhost:14435 udpin is so that the client can receive UDP from the mavproxy server at localhost:14445 mavproxy.py –master=/dev/ttyACM1 –baudrate 57600 –out udpout:localhost:14445 mavproxy.py –master=/dev/ttyACM3 –baudrate 57600 –out udpout:localhost:14435
# Test sending a command and receiving an ack from client to serverwith MAVCom("/dev/ttyACM0", source_system=111) as client:with MAVCom("/dev/ttyUSB0", source_system=222) as server: client.add_component(Cli(client, mav_type=mavlink.MAV_TYPE_GCS)) server.add_component(Cam1(server, mav_type=mavlink.MAV_TYPE_CAMERA)) server.add_component(Cam1(server, mav_type=mavlink.MAV_TYPE_CAMERA))for key, comp in client.component.items():if comp.wait_heartbeat(target_system=222, target_component=22, timeout=0.1):print ("*** Received heartbeat **** " ) NUM_TO_SEND =2for i inrange(NUM_TO_SEND): client.component[11]._test_command(222, 22, 1) client.component[11]._test_command(222, 23, 1) client.component[11]._test_command(222, 24, 1)print(f"{server.source_system =}; {server.message_cnts =}")print(f"{client.source_system =}; {client.message_cnts =}")print()print(f"{client.source_system =}\n{client.summary()}\n")print(f"{server.source_system =}\n{server.summary()}\n")assert client.component[11].num_cmds_sent == NUM_TO_SEND *2+1assert client.component[11].num_acks_rcvd == NUM_TO_SEND *2assert client.component[11].num_acks_drop ==1assert server.component[22].num_cmds_rcvd == NUM_TO_SENDassert server.component[23].num_cmds_rcvd == NUM_TO_SEND
ERROR|34.431| mavcom.MAVCom | mavcom.py :296 | MainThread | MainProces | [Errno 2] could not open port /dev/ttyACM0: [Errno 2] No such file or directory: '/dev/ttyACM0'
SerialException: [Errno 2] could not open port /dev/ttyACM0: [Errno 2] No such file or directory: '/dev/ttyACM0'
For debugging help see http://localhost:3000/tutorials/mavlink_doc&debug.html and http://localhost:3000/tutorials/mavlink_doc&debug.html#debugging