## 使用硬體 pixhawk、 Raspi Raspberry pi5 python venv install pymavlink pixhawk 6x connect use usb or uart [Companion Computers Communicating with Raspberry Pi via MAVLink](https://ardupilot.org/dev/docs/raspberry-pi-via-mavlink.html) ``` listen.py ------------------------------------------ from pymavlink import mavutil the_connection = mavutil.mavlink_connection("/dev/ttyACM0") the_connection.wait_heartbeat() print("Heartbeat from system (system %u component %u)" % (the_connection.target_system, the_connection.target_component)) --------------------------------------------- (yolov7) richard@raspberrypi5:~/pymavlink $ python listen.py Heartbeat from system (system 1 component 0) ``` 連線成功的輸出如下圖 ![image](https://hackmd.io/_uploads/HJ_mvmBx0.png) 使用 mavproxy.py 的輸出如下圖 ![image](https://hackmd.io/_uploads/ByY_DQSg0.png) mavlink_connection()參數: ![image](https://hackmd.io/_uploads/HkbhPQrx0.png) connection string: ![image](https://hackmd.io/_uploads/HykxuQHl0.png) 從 pixhawk 收資訊: ``` # listen.py from pymavlink import mavutil import time the_connection = mavutil.mavlink_connection('/dev/ttyACM1') # 'udpin:localhost:14550' # '/dev/ttyACM0' the_connection.wait_heartbeat() print("Heartbeat from system (system %u component %u)" % (the_connection.target_system, the_connection.target_component)) # the_connection.mav.system_time_send(int(time.time()), int(time.time())) while 1: msg = the_connection.recv_match(type='SYS_STATUS', blocking=True) print(msg) ``` ![image](https://hackmd.io/_uploads/BJl6u_SlA.png) ## 如何使用虛擬環境 sim_vehcile.py & sitl 安裝: ardupilot & submodule git clone https://github.com/ArduPilot/ardupilot.git 安裝 submodule (因為ardupilot github裡面沒有這些submodule) git submodule update --recursive git submodule init 安裝後才能執行 sim_vehcile.py ![image](https://hackmd.io/_uploads/Sk52KXBe0.png) 執行後如下 ![image](https://hackmd.io/_uploads/Skr-9QBgC.png) ![image](https://hackmd.io/_uploads/Sy-S5QBgR.png) 執行 mavproxy.py ![image](https://hackmd.io/_uploads/H15R9mHeR.png) 執行 listen.py ``` from pymavlink import mavutil the_connection = mavutil.mavlink_connection('udpin:localhost:14550') the_connection.wait_heartbeat() print("Heartbeat from system (system %u component %u)" % (the_connection.target_system, the_connection.target_component)) ``` ![image](https://hackmd.io/_uploads/r13xnXSx0.png) ## sim_7600x minicom -D /dev/ttyUSB3 ![image](https://hackmd.io/_uploads/r1Yp5OHlR.png) ## usbcam install picamera2 https://datasheets.raspberrypi.com/camera/picamera2-manual.pdf ``` sudo apt install -y python3-picamera2 ... ``` 注意: picamera2 對 usb 的支援有限制,需進一步測試! ![image](https://hackmd.io/_uploads/BJxLvKBxA.png)