-
Notifications
You must be signed in to change notification settings - Fork 678
Open
Description
I was trying to arm and control the drone via 3DR radio telemetry with this code
from pymavlink import mavutil
import time
def connect_drone(connection_string, baud_rate=57600):
print(f"Connecting to drone on {connection_string} at {baud_rate} baud")
drone = mavutil.mavlink_connection(connection_string, baud=baud_rate)
drone.wait_heartbeat()
print("Heartbeat received from system (system %u component %u)" % (drone.target_system, drone.target_component))
return drone
def set_mode(drone, mode):
if mode not in drone.mode_mapping():
print(f"Mode {mode} not found in mode mapping")
return False
mode_id = drone.mode_mapping()[mode]
drone.mav.set_mode_send(drone.target_system, mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED, mode_id)
print(f"Mode set to {mode}")
return True
def arm_drone(drone):
print("Arming the drone...")
drone.mav.command_long_send(
drone.target_system,
drone.target_component,
mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM,
0,
1, 0, 0, 0, 0, 0, 0
)
drone.motors_armed_wait()
print("Drone armed!")
def disarm_drone(drone):
print("Disarming the drone...")
drone.mav.command_long_send(
drone.target_system,
drone.target_component,
mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM,
0,
0, 0, 0, 0, 0, 0, 0
)
drone.motors_disarmed_wait()
print("Drone disarmed!")
def set_throttle(drone, pwm_value):
print(f"Setting throttle to PWM value: {pwm_value}")
drone.mav.rc_channels_override_send(
drone.target_system,
drone.target_component,
65535, 65535, pwm_value, 65535,
65535, 65535, 65535, 65535
)
if __name__ == "__main__":
connection_string = '/dev/ttyUSB0' # Replace with your connection string
baud_rate = 57600 # Replace with your baud rate if different
drone = connect_drone(connection_string, baud_rate)
# Set the desired mode (e.g., 'GUIDED', 'STABILIZE')
desired_mode = 'GUIDED'
if set_mode(drone, desired_mode):
arm_drone(drone)
set_throttle(drone, 2000)
time.sleep(5) # Keep the drone armed for 5 seconds
disarm_drone(drone)
When the script was in arming mode it sends the AT command but it doesn't arm until I arm the drone with the RC.
Metadata
Metadata
Assignees
Labels
No labels