Power Configuration
Optimal Power Levels
Configure power levels based on your environment and flight requirements.
# Indoor flight configuration
INDOOR_POWER = 25 # Lower power for indoor safety
INDOOR_DURATION = 0.8 # Shorter duration for precision
# Outdoor flight configuration
OUTDOOR_POWER = 40 # Higher power for outdoor
OUTDOOR_DURATION = 1.2 # Longer duration for distance
# Use configuration
drone.go("forward", INDOOR_POWER, INDOOR_DURATION)
💡 Configuration Tip
Create separate configuration profiles for different environments (indoor, outdoor, testing) to easily switch between them.
Power Level Ranges
Recommended power level ranges for different operations:
- Hovering: 0% (automatic)
- Precise movements: 20-30%
- Normal flight: 30-50%
- Fast flight: 50-70%
- Maximum speed: 70-100% (use with caution)
Sensor Configuration
Range Sensor Settings
Configure range sensor thresholds for obstacle avoidance.
# Range sensor configuration
SAFE_DISTANCE = 50 # cm - Safe distance from obstacles
WARNING_DISTANCE = 30 # cm - Warning threshold
CRITICAL_DISTANCE = 20 # cm - Critical, must stop
while True:
distance = drone.get_front_range()
if distance < CRITICAL_DISTANCE:
drone.go("backward", 30, 1)
elif distance < WARNING_DISTANCE:
drone.go("right", 25, 0.5)
elif distance > SAFE_DISTANCE:
drone.go("forward", 30, 1)
time.sleep(0.1)
Color Sensor Configuration
Configure color detection thresholds for reliable color recognition.
# Color sensor configuration
drone.new_color_data()
# Train colors with multiple samples
for i in range(5):
drone.append_color_data("red")
time.sleep(0.5)
# Use trained colors
color = drone.predict_colors()
if color == "red":
drone.go("right", 30, 1)
✅ Best Practice
Train color sensors with multiple samples in different lighting conditions for better accuracy.
Flight Configuration
Hover Timing Configuration
Configure hover times for different flight scenarios.
# Hover timing configuration
STABILIZATION_HOVER = 2 # Seconds after takeoff
BETWEEN_MOVES_HOVER = 0.5 # Seconds between movements
BEFORE_LAND_HOVER = 1 # Seconds before landing
drone.takeoff()
drone.hover(STABILIZATION_HOVER)
drone.go("forward", 30, 1)
drone.hover(BETWEEN_MOVES_HOVER)
drone.hover(BEFORE_LAND_HOVER)
drone.land()
Trim Configuration
Configure trim values to compensate for drone imbalance.
# Get current trim values
trim_values = drone.get_trim()
print(f"Current trim: Pitch={trim_values[0]}, Roll={trim_values[1]}, Yaw={trim_values[2]}")
# Adjust trim if needed (example: drone drifts right)
# drone.set_trim(pitch=0, roll=-5, yaw=0) # Negative roll to compensate right drift
# Reset trim to default
# drone.reset_trim()
⚠️ Important
Only adjust trim if the drone consistently drifts in one direction. Test thoroughly before using trim values in production code.
LED Configuration
LED Color Configuration
Configure LED colors for visual feedback and status indication.
# LED color configuration
LED_RED = (255, 0, 0)
LED_GREEN = (0, 255, 0)
LED_BLUE = (0, 0, 255)
LED_BRIGHTNESS = 100
# Status indicators
def set_status_led(status):
if status == "ready":
drone.set_drone_LED(*LED_GREEN, LED_BRIGHTNESS)
elif status == "warning":
drone.set_drone_LED(*LED_RED, LED_BRIGHTNESS)
elif status == "active":
drone.set_drone_LED(*LED_BLUE, LED_BRIGHTNESS)
set_status_led("ready")
Connection Configuration
Port Configuration
Configure USB port settings for reliable connections.
# Platform-specific port configuration
import platform
def get_default_port():
system = platform.system()
if system == "Windows":
return "COM3" # Adjust based on your system
elif system == "Linux" or system == "Darwin":
return "/dev/ttyUSB0" # Adjust based on your system
return None
port = get_default_port()
if port:
drone.pair(port)
else:
drone.pair() # Auto-detect
Connection Timeout Configuration
Configure timeouts for connection attempts.
# Connection configuration with retry
MAX_RETRIES = 3
RETRY_DELAY = 2 # seconds
for attempt in range(MAX_RETRIES):
try:
drone.pair()
if drone.get_flight_state() == "connected":
print("Connected successfully")
break
except Exception as e:
print(f"Attempt {attempt + 1} failed: {e}")
if attempt < MAX_RETRIES - 1:
time.sleep(RETRY_DELAY)
Complete Configuration Example
Full Configuration Template
A complete configuration template for CoDrone EDU projects.
from codrone_edu.drone import *
import time
# ============================================
# CODRONE EDU CONFIGURATION
# ============================================
# Flight Configuration
FLIGHT_MODE = "indoor" # "indoor" or "outdoor"
if FLIGHT_MODE == "indoor":
POWER_LEVEL = 25
DURATION = 0.8
HOVER_TIME = 0.5
else:
POWER_LEVEL = 40
DURATION = 1.2
HOVER_TIME = 0.8
# Sensor Configuration
SAFE_DISTANCE = 50
WARNING_DISTANCE = 30
CRITICAL_DISTANCE = 20
# LED Configuration
LED_BRIGHTNESS = 100
LED_READY = (0, 255, 0)
LED_WARNING = (255, 165, 0)
LED_ERROR = (255, 0, 0)
# Connection Configuration
USB_PORT = None # Set to specific port if needed
CONNECTION_RETRIES = 3
# ============================================
# MAIN PROGRAM
# ============================================
drone = Drone()
try:
# Connect
if USB_PORT:
drone.pair(USB_PORT)
else:
drone.pair()
# Set status LED
drone.set_drone_LED(*LED_READY, LED_BRIGHTNESS)
# Flight sequence
drone.takeoff()
drone.hover(2)
# Use configured values
drone.go("forward", POWER_LEVEL, DURATION)
drone.hover(HOVER_TIME)
drone.hover(1)
drone.land()
except Exception as e:
print(f"Error: {e}")
drone.set_drone_LED(*LED_ERROR, LED_BRIGHTNESS)
finally:
drone.close()
✅ Configuration Template
This template provides a complete configuration structure that you can customize for your specific project needs.
Configuration Tips
Environment-Based Configuration
Use different configurations for different environments.
# Configuration profiles
CONFIGS = {{
"testing": {{
"power": 20,
"duration": 0.5,
"hover": 0.3
}},
"indoor": {{
"power": 25,
"duration": 0.8,
"hover": 0.5
}},
"outdoor": {{
"power": 40,
"duration": 1.2,
"hover": 0.8
}}
}}
# Select configuration
config = CONFIGS["indoor"]
drone.go("forward", config["power"], config["duration"])
Configuration Validation
Validate configuration values before use.
def validate_config(power, duration):
if not (0 <= power <= 100):
raise ValueError("Power must be between 0 and 100")
if duration <= 0:
raise ValueError("Duration must be positive")
return True
# Use validation
validate_config(POWER_LEVEL, DURATION)
Summary
✅ Configuration Best Practices
- Use constants for all configuration values
- Create environment-specific configurations
- Validate configuration values before use
- Document configuration options clearly
- Use configuration profiles for different scenarios
- Test configurations in safe environments
- Keep configuration at the top of your code
- Use meaningful variable names for configurations
← Main Documentation | ← Best Practices | Version: 2.6 | Last Updated: 2024