Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to manual control #681

Open
13eav1s opened this issue Apr 17, 2024 · 0 comments
Open

How to manual control #681

13eav1s opened this issue Apr 17, 2024 · 0 comments

Comments

@13eav1s
Copy link

13eav1s commented Apr 17, 2024

Hello, I can't to manual control the drone I am 100% sure that drone in Manual flight mode

import random

from mavsdk import System
import asyncio

manual_inputs = [
    [0, 0, 0.5, 0],  # no movement
    [-1, 0, 0.5, 0],  # minimum roll
    [1, 0, 0.5, 0],  # maximum roll
    [0, -1, 0.5, 0],  # minimum pitch
    [0, 1, 0.5, 0],  # maximum pitch
    [0, 0, 0.5, -1],  # minimum yaw
    [0, 0, 0.5, 1],  # maximum yaw
    [0, 0, 1, 0],  # max throttle
    [0, 0, 0, 0],  # minimum throttle
]


async def run():
    drone = System(mavsdk_server_address='localhost', port=50051)
    # await drone.connect(system_address='serial:///dev/ttyACM0')
    print('Connecting to drone')

    await drone.connect(system_address='serial:///dev/tty.usbmodem1103')

    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("-- set manual control values")
    await drone.manual_control.set_manual_control_input(
        float(0), float(0), float(0.5), float(0)
    )

    # start manual control
    print("-- Starting manual control")
    await drone.manual_control.start_position_control()

    while True:
        # grabs a random input from the test list
        # WARNING - your simulation vehicle may crash if its unlucky enough
        input_index = random.randint(0, len(manual_inputs) - 1)
        input_list = manual_inputs[input_index]

        # get current state of roll axis (between -1 and 1)
        roll = float(input_list[0])
        # get current state of pitch axis (between -1 and 1)
        pitch = float(input_list[1])
        # get current state of throttle axis
        # (between -1 and 1, but between 0 and 1 is expected)
        throttle = float(input_list[2])
        # get current state of yaw axis (between -1 and 1)
        yaw = float(input_list[3])

        await drone.manual_control.set_manual_control_input(
            pitch, roll, throttle, yaw)

        await asyncio.sleep(0.1)

    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__':
    asyncio.run(run())

but when I try to but when I try to start_position_control I get the following:
image

and in mavsdk server I get this
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant