mavlink / MAVSDK-Python

MAVSDK client for Python.
https://mavsdk.mavlink.io
BSD 3-Clause "New" or "Revised" License
311 stars 218 forks source link

Suggestion for goto location with indoor tracking #634

Open HenryInUtah opened 10 months ago

HenryInUtah commented 10 months ago

Hello,

We have been having some good success using our drone with an indoor (MoCap) tracking system. The positions are stable, and it will take off and land without issues. The problem that we have right now is telling the drone to go to a specific location. Starting with one of the example scripts, we created the script below. The XYZ positions in QGroundControl show as meters, so we tried to send the drone to 0,0,1.5 which is the same as our takeoff altitude. Instead, the drone starting going across the building and we had to stop it with the remote control.

So my question is - what is the best way to send the drone to a position when using an indoor tracking system? Our goal is to send it to a position and have it stay there until we send it to a new location.

Thanks in advance for your insight.

import asyncio
from mavsdk import System

# This script moved the drone in positive Y direction and we had to use the remote to stop it.

async def run():

    print('Creating the drone object')
    drone = System(mavsdk_server_address='localhost', port=50051)
    print('Trying to connect')
    await drone.connect()
    print('Connected')

    status_text_task = asyncio.ensure_future(print_status_text(drone))

    print("Waiting for drone to connect...")
    async for state in drone.core.connection_state():
        if state.is_connected:
            print(f"-- Connected to drone!")
            break

    print("Waiting for drone to have a global position estimate...")
    async for health in drone.telemetry.health():
        if health.is_global_position_ok and health.is_home_position_ok:
            print("-- Global position estimate OK")
            break

    print("-- Arming")
    await drone.action.arm()

    print("-- Taking off")
    await drone.action.takeoff()

    await asyncio.sleep(5)

    await drone.action.goto_location(0.0, 0.0, 1.5, 0)

    await asyncio.sleep(10)

    print("-- Landing")
    await drone.action.land()

    status_text_task.cancel()

async def print_status_text(drone):
    try:
        async for status_text in drone.telemetry.status_text():
            print(f"Status: {status_text.type}: {status_text.text}")
    except asyncio.CancelledError:
        return

if __name__ == "__main__":
    # Run the asyncio loop
    asyncio.run(run())
julianoes commented 10 months ago

You need to look at the API before using a function! http://mavsdk-python-docs.s3-website.eu-central-1.amazonaws.com/plugins/action.html#mavsdk.action.Action.goto_location

It's lat/lon in degrees, not meters!

You need to look at offboard position control instead.