Scripts Update 2
This commit is contained in:
@@ -93,30 +93,63 @@ class AutonomousController:
|
||||
time.sleep(0.3)
|
||||
|
||||
def setup_for_flight(self):
|
||||
"""Configure ArduPilot for simulated GPS-denied flight.
|
||||
"""Configure ArduPilot for simulation flight.
|
||||
|
||||
GPS stays enabled in EKF for geofence safety, but we use
|
||||
GUIDED_NOGPS mode which doesn't require GPS for control.
|
||||
For Gazebo simulation, we use GPS (provided by Gazebo) for position.
|
||||
We disable the fence to avoid position requirement conflicts.
|
||||
"""
|
||||
print("[CTRL] Configuring for simulated GPS-denied flight...")
|
||||
print("[CTRL] Configuring for simulation...")
|
||||
|
||||
# Disable arming checks
|
||||
# Disable ALL arming checks for simulation
|
||||
self.set_param("ARMING_CHECK", 0)
|
||||
|
||||
# Keep GPS enabled in EKF for geofence
|
||||
# Enable GPS (Gazebo provides simulated GPS)
|
||||
self.set_param("GPS_TYPE", 1) # Auto
|
||||
|
||||
# Configure EKF to use GPS
|
||||
self.set_param("EK3_SRC1_POSXY", 3) # GPS
|
||||
self.set_param("EK3_SRC1_VELXY", 3) # GPS
|
||||
self.set_param("EK3_SRC1_POSZ", 1) # Baro
|
||||
|
||||
# Setup geofence
|
||||
self.set_param("FENCE_ENABLE", 1)
|
||||
self.set_param("FENCE_TYPE", 3) # Alt + Circle
|
||||
self.set_param("FENCE_ACTION", 2) # Land on breach
|
||||
self.set_param("FENCE_ALT_MAX", 15)
|
||||
self.set_param("FENCE_RADIUS", 30)
|
||||
# Disable fence to avoid "fence requires position" error
|
||||
self.set_param("FENCE_ENABLE", 0)
|
||||
|
||||
print("[CTRL] Setup complete (GPS enabled for geofence, using GUIDED_NOGPS for control)")
|
||||
# Disable vision odometry requirement
|
||||
self.set_param("VISO_TYPE", 0)
|
||||
|
||||
# Disable GPS failsafe
|
||||
self.set_param("FS_GPS_ENABLE", 0)
|
||||
|
||||
print("[CTRL] Setup complete")
|
||||
time.sleep(1)
|
||||
|
||||
# Wait for GPS lock and home position
|
||||
print("[CTRL] Waiting for GPS lock and home position...")
|
||||
for i in range(60): # 60 second timeout
|
||||
self.update_state()
|
||||
|
||||
# Check for GPS_RAW_INT message
|
||||
msg = self.mav.recv_match(type=['GPS_RAW_INT', 'HOME_POSITION', 'STATUSTEXT'], blocking=True, timeout=1)
|
||||
if msg:
|
||||
msg_type = msg.get_type()
|
||||
if msg_type == 'GPS_RAW_INT':
|
||||
fix = msg.fix_type
|
||||
if fix >= 3: # 3D fix
|
||||
print(f"[CTRL] GPS fix: {fix} (satellites: {msg.satellites_visible})")
|
||||
return True
|
||||
elif msg_type == 'HOME_POSITION':
|
||||
print("[CTRL] Home position set")
|
||||
return True
|
||||
elif msg_type == 'STATUSTEXT':
|
||||
text = msg.text if isinstance(msg.text, str) else msg.text.decode('utf-8', errors='ignore')
|
||||
if text.strip():
|
||||
print(f"[SITL] {text.strip()}")
|
||||
|
||||
if i % 10 == 0:
|
||||
print(f"[CTRL] Waiting for GPS... ({i}s)")
|
||||
|
||||
print("[CTRL] GPS timeout - continuing anyway")
|
||||
return True
|
||||
|
||||
def wait_for_ekf(self, timeout=60):
|
||||
"""Wait for EKF to initialize."""
|
||||
|
||||
Reference in New Issue
Block a user