I am trying to control the drone without RC controller, without GPS.
I understand that I will have to bypass the radio failsafe and GPS requirements with:
vehicle.parameters[‘FS_THR_ENABLE’] = 0
vehicle.parameters[‘ARMING_CHECK’] = 0
I also understand that will have to use a Vehicle mode outside of Guided (because it requires GPS lock). Alt hold or Stabalize will do.
For now I am simulating it in ArduPilot.
The roadblock I am having is:
- when I try to roll left, the drone re-orients (yaws) 90 degress to the left then go. Same for right.
- same thing with backwards movement. It yaws 180 degrees to its back and then go.
Any ideas on how to tackle that?
Here is my script if someone wants to run in it in simulator:
from dronekit import connect, VehicleMode
from pymavlink import mavutil
import time
####### Connect to the simulated Vehicle via TCP (for the drone simulator)
print("Connecting to vehicle...")
vehicle = connect('tcp:127.0.0.1:5762', wait_ready=True) # Change to the simulator's connection string
####### Function to send velocity commands in the NED frame
def send_ned_velocity(velocity_x, velocity_y, velocity_z, duration):
"""
Move vehicle in direction based on specified velocity vectors.
velocity_x: velocity in the North direction (m/s)
velocity_y: velocity in the East direction (m/s)
velocity_z: velocity in the Down direction (m/s, positive is downward)
duration: time to apply the movement (seconds)
"""
print(f"Setting NED velocity: x={velocity_x}, y={velocity_y}, z={velocity_z} for {duration} seconds")
# Send the velocity command once
msg = vehicle.message_factory.set_position_target_local_ned_encode(
0, # time_boot_ms (not used)
0, 0, # target system, target component
mavutil.mavlink.MAV_FRAME_BODY_NED, # frame relative to drone's orientation
0b0000111111000111, # type_mask (only velocity enabled)
0, 0, 0, # x, y, z positions (not used)
velocity_x, velocity_y, velocity_z, # x, y, z velocity in m/s
0, 0, 0, # x, y, z acceleration (not used)
0, 0) # yaw, yaw_rate (not used, no yaw change)
vehicle.send_mavlink(msg)
# Let the drone move for the specified duration
time.sleep(duration)
# Send zero velocity to stop the drone after the duration has passed
msg = vehicle.message_factory.set_position_target_local_ned_encode(
0, # time_boot_ms (not used)
0, 0, # target system, target component
mavutil.mavlink.MAV_FRAME_BODY_NED, # frame relative to drone's orientation
0b0000111111000111, # type_mask (only velocity enabled)
0, 0, 0, # x, y, z positions (not used)
0, 0, 0, # stop the velocity
0, 0, 0, # x, y, z acceleration (not used)
0, 0) # yaw, yaw_rate (not used, no yaw change)
vehicle.send_mavlink(msg)
# Function to arm the drone
def arm_drone():
print("Arming the drone...")
vehicle.mode = VehicleMode("GUIDED") # Using GUIDED mode for better control
time.sleep(2) # Allow mode change to take effect
vehicle.armed = True
while not vehicle.armed:
print(" Waiting for arming...")
time.sleep(1)
print("Drone armed.")
# Function to perform a movement sequence
def move_drone():
print("Starting movement sequence...")
# Move right for 5 seconds (East in NED frame, no yaw change)
send_ned_velocity(0, 1, 0, 5) # Positive Y for right
# Move left for 5 seconds (East in NED frame, no yaw change)
send_ned_velocity(0, -1, 0, 5) # Negative Y for left
# Move forward for 5 seconds (North in NED frame, no yaw change)
send_ned_velocity(1, 0, 0, 5) # Positive X for forward
# Move backward for 5 seconds (North in NED frame, no yaw change)
send_ned_velocity(-1, 0, 0, 5) # Negative X for backward
# Main execution
try:
arm_drone()
move_drone()
finally:
# Disarm the vehicle and clean up
print("Disarming the drone...")
vehicle.armed = False
vehicle.channels.overrides = {} # Clear all overrides
vehicle.close()
print("Drone disarmed. Script complete.")