iNavFlight / inav

INAV: Navigation-enabled flight control software
https://inavflight.github.io
GNU General Public License v3.0
3.11k stars 1.47k forks source link

How to Control an iNav Drone with MAVLink and Raspberry Pi: Setup and Configuration Guid #10387

Open Alikavari opened 2 days ago

Alikavari commented 2 days ago

Hi everyone,

I’m working on configuring an iNav-based flight controller for my drone and aiming to control its movement using a Raspberry Pi with the pymavlink library. I’ve already connected the Raspberry Pi to the flight controller via UART, and I can communicate with the drone. However, I’m looking for guidance on the correct iNav Configurator setup, particularly how to configure the UART port for MAVLink communication and the necessary flight modes for smooth control.

Below is a sample pymavlink code I’ve been testing. The code arms the drone, takes off to 2 meters, moves it forward for 3 seconds, stops, and then lands. It works in theory, but I want to ensure I’ve configured everything properly on the iNav side to avoid any issues.

from pymavlink import mavutil
import time

# Connect to the vehicle on serial port
connection = mavutil.mavlink_connection('/dev/serial0', baud=57600)

# Wait for the first heartbeat 
print("Waiting for heartbeat...")
connection.wait_heartbeat()

# Arm the drone
print("Arming the drone...")
connection.mav.command_long_send(
    connection.target_system, 
    connection.target_component,
    mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM,
    0, 1, 0, 0, 0, 0, 0, 0)

# Confirm arming
connection.motors_armed_wait()
print("Drone armed!")

# Takeoff to a height of 2 meters
altitude = 2
print(f"Taking off to {altitude} meters...")
connection.mav.command_long_send(
    connection.target_system, 
    connection.target_component,
    mavutil.mavlink.MAV_CMD_NAV_TAKEOFF,
    0, 0, 0, 0, 0, 0, altitude)

time.sleep(5)

# Move forward
def send_velocity_command(vx, vy, vz):
    connection.mav.set_position_target_local_ned_send(
        0,  
        connection.target_system, connection.target_component,
        mavutil.mavlink.MAV_FRAME_LOCAL_NED, 
        0b0000111111000111, 
        0, 0, 0,  
        vx, vy, vz,  
        0, 0, 0,  
        0, 0)  

# Forward at 1 m/s
send_velocity_command(1, 0, 0)
time.sleep(3)

# Stop
send_velocity_command(0, 0, 0)
time.sleep(2)

# Land
connection.mav.command_long_send(
    connection.target_system, 
    connection.target_component,
    mavutil.mavlink.MAV_CMD_NAV_LAND,
    0, 0, 0, 0, 0, 0, 0, 0)

connection.motors_disarmed_wait()
print("Drone landed and disarmed.")

Specifically, I’d like to know how to set up UART for MAVLink and any flight modes or tuning that might be necessary for precise control. Thanks in advance!

sensei-hacker commented 2 days ago

If you haven't already read the wiki page on this topic, you might start there

https://github.com/iNavFlight/inav/wiki/INAV-Remote-Management%2C-Control-and-Telemetry

From what you posted, I'm guessing maybe you haven't seen that since you're speaking Ardupilot's language (Mavlink) to INAV. The native language of INAV is MSP.

If you have a need to speak in Ardupilot's language, INAV 8.0 will likely be better able to translate when it's released in roughly November or December. (Or you can experiment with the nightly build).

With INAV 7 in particular, it's kinda like you're speaking German in France - it may or may not work out okay for you.