Skip to content

Drone Control Blocks

The Drone Commands category provides blocks for controlling PMini drones through visual programming. These blocks generate Python code that uses the pmini_sdk_python library.

Overview

Drone blocks allow you to: - Control flight operations (takeoff, land, hover) - Navigate to specific positions - Move with velocity control - Rotate the drone - Monitor flight status

Block Reference

Takeoff Block

Purpose: Commands the drone to take off to a specified altitude.

Block: takeoff Category: Drone Commands Color: Orange (230)

Parameters: - altitude (number) - Target altitude in meters (default: 2.0)

Generated Code:

drone.takeoff(2.0)

Usage: 1. Drag the takeoff block to your workspace 2. Set the desired altitude (in meters) 3. Connect to other blocks as needed

Example:

takeoff to 3.0 meters

Land Block

Purpose: Commands the drone to land at its current position.

Block: land Category: Drone Commands Color: Orange (230)

Parameters: None

Generated Code:

drone.land()

Usage: 1. Drag the land block to your workspace 2. Connect to other blocks as needed 3. Usually placed at the end of flight sequences

Example:

land

Hover Block

Purpose: Makes the drone hover in place for a specified duration.

Block: hover Category: Drone Commands Color: Orange (230)

Parameters: - duration (number) - Hover duration in seconds (default: 3.0)

Generated Code:

time.sleep(3.0)

Usage: 1. Drag the hover block to your workspace 2. Set the desired hover duration 3. Connect to other blocks as needed

Example:

hover for 5.0 seconds

Goto Block

Purpose: Commands the drone to fly to a specific position.

Block: goto Category: Drone Commands Color: Orange (230)

Parameters: - x (number) - X coordinate in meters (North-South) - y (number) - Y coordinate in meters (East-West) - z (number) - Z coordinate in meters (Up-Down, negative is up)

Generated Code:

drone.goto(1.0, 1.0, -2.0)

Usage: 1. Drag the goto block to your workspace 2. Set the target coordinates 3. Connect to other blocks as needed

Example:

goto x: 1.0, y: 1.0, z: -2.0

Move Block

Purpose: Commands the drone to move with a specific velocity for a duration.

Block: move Category: Drone Commands Color: Orange (230)

Parameters: - vx (number) - Velocity in X direction (m/s) - vy (number) - Velocity in Y direction (m/s) - vz (number) - Velocity in Z direction (m/s) - duration (number) - Movement duration in seconds

Generated Code:

drone.move(1.0, 0.0, 0.0, 2.0)

Usage: 1. Drag the move block to your workspace 2. Set the velocity components and duration 3. Connect to other blocks as needed

Example:

move vx: 1.0, vy: 0.0, vz: 0.0 for 2.0 seconds

Move with Power Block

Purpose: Commands the drone to move with velocity control and adjustable power.

Block: move_with_power Category: Drone Commands Color: Orange (230)

Parameters: - vx (number) - Velocity in X direction (m/s) - vy (number) - Velocity in Y direction (m/s) - vz (number) - Velocity in Z direction (m/s) - power (number) - Power level (0.0 to 1.0) - duration (number) - Movement duration in seconds

Generated Code:

drone.move_with_power(1.0, 0.0, 0.0, 0.8, 2.0)

Usage: 1. Drag the move with power block to your workspace 2. Set the velocity components, power level, and duration 3. Connect to other blocks as needed

Example:

move vx: 1.0, vy: 0.0, vz: 0.0 with power 0.8 for 2.0 seconds

Turn Block

Purpose: Commands the drone to rotate left or right.

Block: turn Category: Drone Commands Color: Orange (230)

Parameters: - direction (dropdown) - "left" or "right" - angle (number) - Rotation angle in degrees (default: 90)

Generated Code:

drone.turn("left", 90)

Usage: 1. Drag the turn block to your workspace 2. Select the direction (left or right) 3. Set the rotation angle 4. Connect to other blocks as needed

Example:

turn left 90 degrees

Coordinate System

The drone uses a NED (North-East-Down) coordinate system:

  • X-axis: North-South (positive = North)
  • Y-axis: East-West (positive = East)
  • Z-axis: Up-Down (positive = Down, negative = Up)

Important Notes:

  • Altitude: Use negative Z values for altitude (e.g., -2.0 for 2 meters up)
  • Origin: The drone's starting position is (0, 0, 0)
  • Units: All distances are in meters, angles in degrees

Flight Sequences

Basic Flight Pattern

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

Square Flight Pattern

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

Spiral Flight Pattern

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

Safety Considerations

Pre-flight Checks

  • Battery level: Ensure sufficient power for the flight
  • Clear area: Verify no obstacles in the flight path
  • Weather conditions: Avoid flying in strong winds or rain
  • Connection status: Confirm stable connection to the drone

Emergency Procedures

  • Emergency land: Use the land block to immediately land
  • Stop execution: Click "Stop" in the terminal to halt code execution
  • Disconnect: Use "Disconnect Server" to stop the drone server

Best Practices

  • Start with low altitude: Begin with 1-2 meters for testing
  • Use hover blocks: Add pauses between commands for stability
  • Test incrementally: Build and test flight sequences step by step
  • Monitor telemetry: Watch the floating telemetry window for status

Error Handling

The generated Python code includes automatic error handling:

try:
    drone.takeoff(2.0)
    drone.hover(3.0)
    drone.land()
except Exception as e:
    print(f"Flight error: {e}")
finally:
    drone.disconnect()

Common Errors

  • Connection failed: Check drone power and network connection
  • Takeoff failed: Ensure clear area and sufficient battery
  • Goto failed: Verify coordinates are within safe limits
  • Land failed: Check for obstacles below the drone

Integration with Other Blocks

Drone blocks can be combined with other block types:

Conditional Flight

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

Looped Flight

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

Variable Flight Path

set target_x to 1.0
set target_y to 1.0
set target_z to -2.0
takeoff to 2.0 meters
goto x: target_x, y: target_y, z: target_z
land

Troubleshooting

Drone Won't Connect

  • Check if the drone is powered on
  • Verify network connectivity
  • Ensure the drone server is running
  • Check firewall settings

Commands Not Executing

  • Verify the drone is in the correct mode
  • Check for error messages in the terminal
  • Ensure all parameters are valid
  • Try restarting the connection

Unexpected Behavior

  • Check the generated Python code
  • Verify coordinate values are reasonable
  • Ensure sufficient battery power
  • Check for obstacles in the flight path