I built the drone in this post I still have to do the PID tuning, waiting for better weather, in the meantime I want to get communication between my Pi and Pixhawk working.
I am currently trying to get sensor data in a C++/Python script and command the drone to fly autonomously.
This is my setup:
Raspberry Pi 4B running Ubuntu 22.04 (ROS 2 Humble)
[10:21:33|Info ] MAVSDK version: v1.4.16 (mavsdk_impl.cpp:20)
[10:21:33|Info ] Waiting to discover system on serial:///dev/serial0:57600... (connection_initiator.h:20)
[10:21:33|Debug] New: System ID: 1 Comp ID: 1 (mavsdk_impl.cpp:496)
[10:21:33|Debug] Component Autopilot (1) added. (system_impl.cpp:377)
[10:21:33|Warn ] Vehicle type changed (new type: 2, old type: 0) (system_impl.cpp:225)
[10:21:33|Debug] Discovered 1 component(s) (system_impl.cpp:578)
[10:21:33|Info ] System discovered (connection_initiator.h:63)
[10:21:33|Info ] Server started (grpc_server.cpp:53)
[10:21:33|Info ] Server set to listen on 0.0.0.0:50051 (grpc_server.cpp:54)
Thoughts: Because I am running Ubuntu I have to run the code with sudo to access hardware pins.
Terminal 2 (Talk to the server with python)
Python code:
#!/usr/bin/env python3
# https://github.com/mavlink/MAVSDK-Python/blob/6955725b83314366e5448c6b12cde65f09791969/examples/all_params.py
import asyncio
from mavsdk import System
async def run():
# Connect to the drone
drone = System()
print(f"drone = {drone}")
await drone.connect(system_address="serial:///dev/serial0:57600")
print("Waiting for drone to connect...")
async for state in drone.core.connection_state():
if state.is_connected:
print(f"-- Connected to drone!")
break
# Get the list of parameters
all_params = await drone.param.get_all_params()
# Iterate through all int parameters
for param in all_params.int_params:
print(f"{param.name}: {param.value}")
for param in all_params.float_params:
print(f"{param.name}: {param.value}")
# Run the asyncio loop
asyncio.run(run())
I now get a successful connection to the drone and receive all the parameters!