Hi,
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:
I followed this to setup the Pi:
Parameters set:
Following this post here and here
Only response I get working:
Run:
sudo mavproxy.py --master=/dev/serial0 --baudrate 57600
Output:
osprey@osprey:~$ sudo mavproxy.py --master=/dev/serial0 --baudrate 57600
Connect /dev/serial0 source_system=255
Log Directory:
Telemetry log: mav.tlog
Waiting for heartbeat from /dev/serial0
MAV> Detected vehicle 1:1 on link 0
online system 1
MANUAL> Mode MANUAL
fence breach
Received 932 parameters
Saved 932 parameters to mav.parm
I tried python mavsdk here:
When running the code below I get the result in the second box where it does not pickup the pixhawk.
I tried this all parms file and it just hangs with no response.
Lastly I also tried ROS example to read sensor data here and I’m getting compile error when I do colcon build.
I would appreciate guidance as I’m new to PX4/MavLink/SDK
My goal is to control the quad with the raspberry pi. What is the best way to do this and the steps to follow to get the necessary packages setup.
Best,
Marno
Ok, so the issue is that mavsdk_server
tries to connect to udp://:14540
. That address is usually only available in SITL.
If you have it connected via serial, you want to start it like this:
~/.local/lib/python3.9/site-packages-mavsdk/bin/mavsdk_server serial:///dev/serial0:57600
1 Like
Thank you for the reply.
When I run your cli line:
~/.local/lib/python3.10/site-packages-mavsdk/bin/mavsdk_server serial:///dev/serial0:57600
I get:
-bash: /home/osprey/.local/lib/python3.10/site-packages-mavsdk/bin/mavsdk_server: No such file or directory
When I cange it to where my mavsdk_server is:
~/.local/lib/python3.10/site-packages/mavsdk/bin/mavsdk_server serial:///dev/serial0:57600
I get:
[09:48:06|Info ] MAVSDK version: v1.4.16 (mavsdk_impl.cpp:20)
[09:48:06|Info ] Waiting to discover system on serial:///dev/serial0:57600... (connection_initiator.h:20)
[09:48:06|Error] open failed: Permission denied (serial_connection.cpp:88)
[09:48:06|Error] Connection failed: Connection error (connection_initiator.h:47)
Connections:
Okay so one step closer!
Code
Terminal 1 (Start the MavSDK_server)
sudo ~/.local/lib/python3.10/site-packages/mavsdk/bin/mavsdk_server serial:///dev/serial0:57600
Output:
[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!
1 Like