0
0
Pcb-designHow-ToBeginner · 3 min read

How to Set Home Location Using DroneKit: Simple Guide

To set the home location in DroneKit, use the vehicle.home_location attribute by assigning it a LocationGlobal or LocationGlobalRelative object with latitude, longitude, and altitude. Then call vehicle.home_location = new_location to update the home point before arming or takeoff.
📐

Syntax

Use the vehicle.home_location property to get or set the drone's home location. Assign it a LocationGlobal or LocationGlobalRelative object with latitude, longitude, and altitude values.

  • vehicle: Your connected drone object.
  • home_location: Property representing the home point.
  • LocationGlobal / LocationGlobalRelative: Classes to specify GPS coordinates.
python
from dronekit import LocationGlobal

# Create a new home location
new_home = LocationGlobal(latitude, longitude, altitude)

# Set the vehicle's home location
vehicle.home_location = new_home
💻

Example

This example connects to a vehicle, sets a new home location, and prints the updated home location coordinates.

python
from dronekit import connect, LocationGlobal
import time

# Connect to the vehicle (replace with your connection string)
vehicle = connect('127.0.0.1:14550', wait_ready=True)

# Define new home location (latitude, longitude, altitude in meters)
new_home = LocationGlobal(37.4289, -122.1760, 20)

# Set the home location
vehicle.home_location = new_home

# Wait a moment for the change to take effect
time.sleep(1)

# Print the updated home location
print(f"New Home Location: Lat={vehicle.home_location.lat}, Lon={vehicle.home_location.lon}, Alt={vehicle.home_location.alt}")

# Close vehicle connection
vehicle.close()
Output
New Home Location: Lat=37.4289, Lon=-122.176, Alt=20
⚠️

Common Pitfalls

Common mistakes when setting home location include:

  • Not waiting for the vehicle to be ready before setting home_location.
  • Using incorrect coordinate types or forgetting altitude.
  • Setting home location after arming or takeoff, which may not update the stored home point.
  • Not verifying the new home location by reading back vehicle.home_location.
python
from dronekit import LocationGlobal

# Wrong: Setting home location before vehicle is ready
# vehicle.home_location = LocationGlobal(37.0, -122.0, 10)  # May fail if vehicle not ready

# Right: Wait for vehicle to be ready
# vehicle.wait_ready('home_location')
# vehicle.home_location = LocationGlobal(37.0, -122.0, 10)
📊

Quick Reference

ActionCode ExampleNotes
Create LocationLocationGlobal(lat, lon, alt)Use GPS coordinates in degrees and altitude in meters
Set Home Locationvehicle.home_location = LocationGlobal(...)Set before arming or takeoff
Check Home Locationprint(vehicle.home_location.lat, vehicle.home_location.lon)Verify the set location
Wait for Readyvehicle.wait_ready('home_location')Ensure vehicle is ready before setting

Key Takeaways

Set the home location using vehicle.home_location with a LocationGlobal object.
Always wait for the vehicle to be ready before setting the home location.
Set the home location before arming or taking off to ensure it updates correctly.
Verify the home location by reading vehicle.home_location after setting it.
Use correct latitude, longitude, and altitude values in degrees and meters.