← Back to list

My First Experience Programming a Drone Simulator (Px4)

I still remember the moment when my drone first took off — not by remote control, but through a few lines of Python code I wrote myself…

Rahaf Mohammed · 2025-10-06 21:07 · 0 claps · 2.1 min read
#px4 #drones #mavsdk #qgroundcontrol #google-speech-to-text
Open on Medium ↗
Wiki topics: 💻 · Programming

My First Experience Programming a Drone Simulator — What I Learned

I still remember the moment when my drone first took off — not by remote control, but through a few lines of Python code I wrote myself. It was one of the most exciting and challenging experiences I’ve ever had.

This project was part of the Drone Programming & Operation Bootcamp at Tuwaiq Academy, where we learned how to combine software, hardware, and creativity to build real-world drone applications.

The Idea

My project was called “Guidance Drone” a drone that acts as a tour guide. The goal was to let the drone fly between two famous landmarks in AlUla, Saudi Arabia Elephant Rock (Jabal Al-Fil) and Jabal Al-Jarrah and explain the importance of each site to tourists through voice narration.

It’s a simple concept, but it taught me a lot about flight logic, waypoint control, and real-time simulation.

Tools & Technologies

To bring this idea to life, I used:

  • PX4 for flight simulation
  • MAVSDK (Python) to program and control the drone
  • QGroundControl (QGC) to monitor missions visually
  • gTTS and playsound libraries for voice narration

The Code

This script connects to PX4, takes off, flies to both landmarks, pauses to “speak,” and then returns home safely.

import asyncio
from mavsdk import System

async def main():
    drone = System()
    await drone.connect(system_address="udp://:14540")

    async for s in drone.core.connection_state():
        if s.is_connected:
            print("✅ Connected to PX4")
            break

    print("Arming...")
    await drone.action.arm()
    await asyncio.sleep(2)

    print("Taking off...")
    await drone.action.takeoff()
    await asyncio.sleep(8)

    # Elephant Rock
    await drone.action.goto_location(26.689204, 37.981599, 730, 0)
    print("Explaining Elephant Rock...")
    await asyncio.sleep(30)

    # Jabal Al-Jarrah
    await drone.action.goto_location(26.6818181, 37.9794269, 730, 0)
    print("Explaining Jabal Al-Jarrah...")
    await asyncio.sleep(30)

    print("Returning home...")
    await drone.action.return_to_launch()

asyncio.run(main())

Challenges I Faced

Like any first project, it wasn’t all smooth:

  • Waypoint Accuracy The drone didn’t always stop exactly at the desired coordinates, so I used the Haversine formula to measure distance.
  • Arabic Voice Limitations gTTS didn’t handle Arabic pronunciation perfectly, which made me explore alternatives like pyttsx3.
  • Connection Delay Sometimes there was a lag between PX4 and QGroundControl.
  • Altitude Calibration I had to fine-tune the absolute altitude to make sure the drone didn’t “land” too early in simulation.

My Learning Resources

  • PX4 Autopilot Documentation
  • MAVSDK Python API Guide
  • Tuwaiq Academy lessons and mentorship
  • Guidance and support from my instructor Mr. Abdulkarim alslaam

What I Learned

This was my first time programming a drone, and it taught me how software logic translates into physical movement. It also showed me how much patience and precision real-world robotics require.

I’m deeply thankful to Tuwaiq Academy and Mr. Abdulkarim for their continuous support throughout this journey. This project made me realize that drones aren’t just machines, they’re flying computers full of potential.


메타데이터
post_id
d2d6ce964f44
slug
my-first-experience-programming-a-drone-simulator-px4-d2d6ce964f44
url
https://medium.com/@zcygdr/my-first-experience-programming-a-drone-simulator-px4-d2d6ce964f44
canonical_url
https://medium.com/@zcygdr/my-first-experience-programming-a-drone-simulator-px4-d2d6ce964f44
author_url
https://medium.com/@zcygdr
status
ok
fetched_at
2026-06-21 07:44:09