Мой симулятор дронов DJI не может переключиться в режим «управляемого»Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Мой симулятор дронов DJI не может переключиться в режим «управляемого»

Сообщение Anonymous »

Я использую симулятор для своего беспилотника DJI, чтобы я мог научиться использовать беспилотник, прежде чем летать лично. Однако всякий раз, когда я инициализирую код, беспилотник не может ввести режим управляемого. Это мой код: < /p>
import collections
import collections.abc
collections.MutableMapping = collections.abc.MutableMapping #this is a technical issue. might actually affect a future issue
#there was some sort of update that switched around the files, and this switches it back

from dronekit import connect, VehicleMode, LocationGlobalRelative
import dronekit_sitl

import time
import math
import threading
from pymavlink import mavutil
from pynput import keyboard
import dronekit_sitl

sitl = dronekit_sitl.start_default(lat=0, lon=0)
connection_string = sitl.connection_string()

class Location:
def __init__(self, lat, lon, alt):
self.lat = lat
self.lon = lon
self.alt = alt
def __repr__(self):
return "Location(%s, %s, %s)" % (self.lat, self.lon, self.alt)

class DroneController:
def __init__(self, connection_string=""):
print(f"Attempting to connect to {connection_string}")
self.vehicle = connect(connection_string, wait_ready=True, timeout=60)
print("Successfully connected to the vehicle")

def get_location(self):
return Location(self.vehicle.location.global_relative_frame.lat,
self.vehicle.location.global_relative_frame.lon,
self.vehicle.location.global_relative_frame.alt)

def arm_and_takeoff(self, target_altitude):
print("Basic pre-arm checks")
while not self.vehicle.is_armable:
print(" Waiting for vehicle to initialise...")
time.sleep(1)

if not self.set_guided_mode():
print("not guieded mode")
return False

print("Arming motors")
self.vehicle.armed = True

arming_timeout = 60
start_time = time.time()
while not self.vehicle.armed:
if time.time() - start_time > arming_timeout:
print("Failed to arm within timeout period")
return False
print(" Waiting for arming...")
time.sleep(1)

print("Taking off!")
self.vehicle.simple_takeoff(target_altitude)

takeoff_timeout = 30
start_time = time.time()

while True:
current_altitude = self.vehicle.location.global_relative_frame.alt
print(f" Altitude: {current_altitude}")
if current_altitude >= target_altitude * 0.95:
print("Reached target altitude")
return True
elif time.time() - start_time > takeoff_timeout:
print("Takeoff failed, timeout reached")
return False
time.sleep(1)

def pre_arm_check(self):
print("waiting for vehicle to initialise")
while not self.vehicle.is_armable:
print("waiting for vehicle to initialise...")
time.sleep(1)
print("vehicle is ready to arm")

def set_guided_mode(self):
print("Attempting to set GUIDED mode")

# Try to set mode using standard method
self.vehicle.mode = VehicleMode("GUIDED")
self.vehicle.flush()

start_time = time.time()
timeout = 10
while self.vehicle.mode.name != 'GUIDED':
if time.time() - start_time > timeout:
print("Failed to set GUIDED mode within timeout period")
print(f"Mode: {self.vehicle.mode.name}")
return False
time.sleep(1)
print("GUIDED mode set successfully")
return True

def fly_to_point(self, location: Location):
print("Flying to point")
point_end = LocationGlobalRelative(location.lat, location.lon, location.alt)
self.vehicle.simple_goto(point_end)

# Wait until the drone reaches the correct spot
while True:
distance = self.distance_to(location)
print(f"Distance to target: {distance:.2f} meters")
if distance
И это ошибка, которую я продолжаю получать: < /p>
Starting copter simulator (SITL)
SITL already Downloaded and Extracted.
Ready to boot.
Connecting to vehicle on: tcp:127.0.0.1:5760
Attempting to connect to tcp:127.0.0.1:5760
CRITICAL:autopilot:APM:Copter V3.3 (d6053245)
CRITICAL:autopilot:Frame: QUAD
CRITICAL:autopilot:Calibrating barometer
CRITICAL:autopilot:Initialising APM...
CRITICAL:autopilot:barometer calibration complete
CRITICAL:autopilot:GROUND START
Successfully connected to the vehicle
Performing pre-arm check
waiting for vehicle to initialise
waiting for vehicle to initialise...
waiting for vehicle to initialise...
waiting for vehicle to initialise...
waiting for vehicle to initialise...
waiting for vehicle to initialise...
vehicle is ready to arm
Pre-arm check completed. Attempting takeoff
Is Armable: True
System Status: STANDBY
Mode: STABILIZE
Basic pre-arm checks
Attempting to set GUIDED mode
Failed to set GUIDED mode within timeout period
Mode: STABILIZE
not guieded mode
Takeoff failed. Checking vehicle state:
Is Armed: False
System Status: STANDBY
Mode: STABILIZE
Aborting mission
Landing and closing connection
Traceback (most recent call last):
File "/Users/koviressler/Desktop/AeroCleanTech/Drone_Control/drone_controller.py", line 274, in
printer_thread.join()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1107, in join
raise RuntimeError("cannot join thread before it is started")
RuntimeError: cannot join thread before it is started
< /code>
Не беспокойтесь об ошибке потока. Я просто использую потоки, чтобы распечатать положение дрона каждую секунду, и ошибка возникает только потому, что я запускаю поток только в том случае, если дрон правильно принимает, а это не так. Раньше это работало, но однажды я добавил что -то, что сломало его, и с тех пор это не сработало. Это может быть проблемой совместимости.

Подробнее здесь: https://stackoverflow.com/questions/787 ... uided-mode
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»