Skip to content

Drone Examples

This section provides practical examples of drone control programs using Blockly Python Executor.

Basic Flight Examples

Simple Takeoff and Land

Description: A basic flight that takes off, hovers briefly, and lands.

Blocks Used: - Takeoff block - Hover block
- Land block

Program:

takeoff to 2.0 meters
hover for 3.0 seconds
land

Generated Python Code:

from pmini_sdk_python import SyncDroneClient
import time

drone = SyncDroneClient("localhost:50051")
drone.connect()

drone.takeoff(2.0)
time.sleep(3.0)
drone.land()

drone.disconnect()

Square Flight Pattern

Description: Flies in a square pattern at 2 meters altitude.

Blocks Used: - Takeoff block - Goto blocks (4 times) - Hover blocks - Land block

Program:

takeoff to 2.0 meters
hover for 2.0 seconds
goto x: 1.0, y: 0.0, z: -2.0
hover for 1.0 seconds
goto x: 1.0, y: 1.0, z: -2.0
hover for 1.0 seconds
goto x: 0.0, y: 1.0, z: -2.0
hover for 1.0 seconds
goto x: 0.0, y: 0.0, z: -2.0
hover for 1.0 seconds
land

Generated Python Code:

from pmini_sdk_python import SyncDroneClient
import time

drone = SyncDroneClient("localhost:50051")
drone.connect()

drone.takeoff(2.0)
time.sleep(2.0)
drone.goto(1.0, 0.0, -2.0)
time.sleep(1.0)
drone.goto(1.0, 1.0, -2.0)
time.sleep(1.0)
drone.goto(0.0, 1.0, -2.0)
time.sleep(1.0)
drone.goto(0.0, 0.0, -2.0)
time.sleep(1.0)
drone.land()

drone.disconnect()

Spiral Flight Pattern

Description: Creates a spiral flight pattern using movement and rotation.

Blocks Used: - Takeoff block - Move blocks - Turn blocks - Land block

Program:

takeoff to 2.0 meters
hover for 2.0 seconds
move vx: 0.5, vy: 0.0, vz: 0.0 for 2.0 seconds
turn right 90 degrees
move vx: 0.0, vy: 0.5, vz: 0.0 for 2.0 seconds
turn right 90 degrees
move vx: -0.5, vy: 0.0, vz: 0.0 for 2.0 seconds
turn right 90 degrees
move vx: 0.0, vy: -0.5, vz: 0.0 for 2.0 seconds
land

Advanced Flight Examples

Conditional Flight Based on Battery

Description: Only flies if battery level is above 20%.

Blocks Used: - If-then block - Battery check (simulated) - Takeoff, hover, land blocks

Program:

set battery_level to 85
if battery_level > 20:
  takeoff to 2.0 meters
  hover for 5.0 seconds
  land
else:
  print "Battery too low for flight"

Generated Python Code:

from pmini_sdk_python import SyncDroneClient
import time

drone = SyncDroneClient("localhost:50051")
drone.connect()

battery_level = 85
if battery_level > 20:
    drone.takeoff(2.0)
    time.sleep(5.0)
    drone.land()
else:
    print("Battery too low for flight")

drone.disconnect()

Looped Flight Sequence

Description: Repeats a flight pattern 3 times.

Blocks Used: - Repeat block - Takeoff, hover, land blocks

Program:

repeat 3 times:
  takeoff to 1.0 meters
  hover for 2.0 seconds
  land
  hover for 1.0 seconds

Generated Python Code:

from pmini_sdk_python import SyncDroneClient
import time

drone = SyncDroneClient("localhost:50051")
drone.connect()

for i in range(3):
    drone.takeoff(1.0)
    time.sleep(2.0)
    drone.land()
    time.sleep(1.0)

drone.disconnect()

Variable Flight Path

Description: Uses variables to define a flight path that can be easily modified.

Blocks Used: - Variable blocks - Math blocks - Goto blocks

Program:

set target_x to 1.0
set target_y to 1.0
set target_z to -2.0
set hover_time to 3.0

takeoff to 2.0 meters
hover for 2.0 seconds
goto x: target_x, y: target_y, z: target_z
hover for hover_time seconds
land

Generated Python Code:

from pmini_sdk_python import SyncDroneClient
import time

drone = SyncDroneClient("localhost:50051")
drone.connect()

target_x = 1.0
target_y = 1.0
target_z = -2.0
hover_time = 3.0

drone.takeoff(2.0)
time.sleep(2.0)
drone.goto(target_x, target_y, target_z)
time.sleep(hover_time)
drone.land()

drone.disconnect()

Mission Planning Examples

Survey Pattern

Description: Flies a survey pattern to cover an area systematically.

Blocks Used: - Takeoff block - Multiple goto blocks - Hover blocks - Land block

Program:

takeoff to 3.0 meters
hover for 2.0 seconds

# Survey point 1
goto x: 0.0, y: 0.0, z: -3.0
hover for 1.0 seconds

# Survey point 2
goto x: 1.0, y: 0.0, z: -3.0
hover for 1.0 seconds

# Survey point 3
goto x: 1.0, y: 1.0, z: -3.0
hover for 1.0 seconds

# Survey point 4
goto x: 0.0, y: 1.0, z: -3.0
hover for 1.0 seconds

# Return to start
goto x: 0.0, y: 0.0, z: -3.0
hover for 1.0 seconds
land

Emergency Landing Sequence

Description: A safety sequence that can be triggered in case of emergency.

Blocks Used: - If-then block - Emergency condition check - Land block - Print blocks

Program:

set emergency to false
set battery_level to 85

if emergency or battery_level < 10:
  print "Emergency landing initiated"
  land
  print "Emergency landing complete"
else:
  print "Flight continuing normally"
  takeoff to 2.0 meters
  hover for 5.0 seconds
  land

Interactive Examples

User-Controlled Flight

Description: Allows user to input flight parameters.

Blocks Used: - Input blocks - Variable blocks - Goto blocks

Program:

set target_x to input("Enter X coordinate: ")
set target_y to input("Enter Y coordinate: ")
set target_z to input("Enter Z coordinate: ")

takeoff to 2.0 meters
hover for 2.0 seconds
goto x: target_x, y: target_y, z: target_z
hover for 3.0 seconds
land

Flight with Status Monitoring

Description: Monitors and displays flight status throughout the mission.

Blocks Used: - Print blocks - Variable blocks - Flight blocks

Program:

print "Starting flight mission"
takeoff to 2.0 meters
print "Takeoff complete"

print "Moving to position 1"
goto x: 1.0, y: 0.0, z: -2.0
print "Position 1 reached"

print "Moving to position 2"
goto x: 1.0, y: 1.0, z: -2.0
print "Position 2 reached"

print "Returning to start"
goto x: 0.0, y: 0.0, z: -2.0
print "Start position reached"

print "Landing"
land
print "Mission complete"

Safety Examples

Pre-flight Safety Check

Description: Performs safety checks before flight.

Blocks Used: - If-then blocks - Variable blocks - Print blocks

Program:

set battery_level to 85
set clear_area to true
set weather_ok to true

if battery_level < 20:
  print "Battery too low for flight"
else:
  if not clear_area:
    print "Area not clear for flight"
  else:
    if not weather_ok:
      print "Weather conditions not suitable"
    else:
      print "All checks passed, starting flight"
      takeoff to 2.0 meters
      hover for 5.0 seconds
      land
      print "Flight completed safely"

Gradual Altitude Change

Description: Changes altitude gradually for safety.

Blocks Used: - Variable blocks - Math blocks - Goto blocks

Program:

set current_altitude to 0.0
set target_altitude to -3.0
set step_size to -0.5

takeoff to 1.0 meters
set current_altitude to -1.0

while current_altitude > target_altitude:
  set current_altitude to current_altitude + step_size
  goto x: 0.0, y: 0.0, z: current_altitude
  hover for 1.0 seconds

hover for 3.0 seconds
land

Troubleshooting Examples

Connection Test

Description: Tests drone connection before attempting flight.

Blocks Used: - Try-catch blocks - Print blocks - Connection test

Program:

print "Testing drone connection"
try:
  takeoff to 0.1 meters
  print "Connection successful"
  land
  print "Ready for flight"
except:
  print "Connection failed, check drone status"

Flight Error Handling

Description: Handles errors during flight operations.

Blocks Used: - Try-catch blocks - Print blocks - Flight blocks

Program:

print "Starting flight with error handling"
try:
  takeoff to 2.0 meters
  print "Takeoff successful"

  try:
    goto x: 1.0, y: 1.0, z: -2.0
    print "Navigation successful"
  except:
    print "Navigation failed, returning to start"
    goto x: 0.0, y: 0.0, z: -2.0

  land
  print "Flight completed"
except:
  print "Flight failed, attempting emergency landing"
  land

Tips for Creating Drone Programs

Best Practices

  1. Start simple - Begin with basic takeoff/land sequences
  2. Test incrementally - Add one command at a time
  3. Use hover blocks - Add pauses between commands for stability
  4. Check coordinates - Verify all position values are reasonable
  5. Monitor battery - Always check battery level before flight

Common Patterns

  1. Takeoff → Hover → Land - Basic flight pattern
  2. Takeoff → Navigate → Hover → Land - Navigation pattern
  3. Takeoff → Loop → Land - Repeated operations
  4. Takeoff → Conditional → Land - Decision-based flight

Safety Considerations

  1. Always include land block - Ensure drone lands safely
  2. Use reasonable altitudes - Start with low altitudes
  3. Check clear area - Ensure no obstacles in flight path
  4. Monitor telemetry - Watch the floating telemetry window
  5. Have emergency procedures - Know how to stop execution

Debugging Tips

  1. Check generated code - Review the Python code for errors
  2. Use print blocks - Add status messages throughout your program
  3. Test in simulation - Use low altitudes for initial testing
  4. Monitor terminal output - Watch for error messages
  5. Check connection status - Ensure drone is properly connected