Open alireza787b opened 4 months ago
Unified Event Loop: Ensured that the main application and FastAPI server use the same event loop by starting the FastAPI server within the main event loop.
That would have been my guess as well. You made sure that's the case?
I tried that.. and push to latest commit you can check that out
It works... but now it became so slow and laggy ... the video is no longer real time over http ... not applicable... Do you think, is there a way we can have mavsdk and fastapi on different thread and run a command of mavsdk from fast api routes?
Unified Event Loop: Ensured that the main application and FastAPI server use the same event loop by starting the FastAPI server within the main event loop.
That would have been my guess as well. You made sure that's the case?
RuntimeError: Task pending got Future attached to a different loop during Offboard control with FastAPI and MAVSDK
Description
I am working on a Python application that integrates FastAPI for web-based control and MAVSDK for controlling a PX4 drone. The application handles video processing with OpenCV and allows for user input to control drone tracking and segmentation. However, I encountered a
RuntimeError
related to asynchronous programming and event loop management when trying to send velocity commands to the drone in offboard mode. But when starting the mavsdk offboard commands from the terminal (instead of the web app) wi...Repo URL: https://github.com/alireza787b/PixEagle
Implementation
main.py
:px4_controller.py
:Problem Encountered
When attempting to send velocity commands to the drone in offboard mode, I encountered the following
RuntimeError
:This error indicates that the coroutine is trying to await a Future that is attached to a different event loop. This might be caused by the threading used to run the FastAPI server or some issue with the integration between FastAPI and MAVSDK's asyncio operations.
Steps Taken and Debugging Ideas
main.py
andpx4_controller.py
.connect_px4
) from the FastAPI endpoint.Possible Problems
PX4Controller
.Request for Assistance
I would appreciate any recommendations or solutions to handle this situation effectively. Specifically:
Thank you for your assistance.