dronekit / dronekit-python

DroneKit-Python library for communicating with Drones via MAVLink.
https://readthedocs.org/projects/dronekit-python/
Apache License 2.0
1.58k stars 1.44k forks source link

DroneKit condition_yaw() and NED_Velocity() not working #1218

Open freestuffasd opened 6 months ago

freestuffasd commented 6 months ago

A week ago my follow me program was working fine. Suddenly it started showing unexpected behavior. Only positive x velocity and positive yaw is working fine All other commands showing unexpected circular movement at a position.

def send_movement_command_YAW(heading): global vehicle speed = 0 direction = 1 #direction -1 ccw, 1 cw

#heading 0 to 360 degree. if negative then ccw 

print("Sending YAW movement command with heading: %f" % heading)

if heading < 0:
    heading = heading*-1
    direction = -1

#point drone into correct heading 
msg = vehicle.message_factory.command_long_encode(
    0, 0,       
    mavutil.mavlink.MAV_CMD_CONDITION_YAW, 
    0,          
    heading,    
    speed,      #speed deg/s
    direction,  
    1,          #relative offset 1
    0, 0, 0)    

# send command to vehicle
vehicle.send_mavlink(msg)
#Vehicle.commands.flush()

def send_movement_command_XYA(velocity_x, velocity_y, altitude): global vehicle

#velocity_x positive = forward. negative = backwards
#velocity_y positive = right. negative = left
#velocity_z positive = down. negative = up (Yes really!)

print("Sending XYZ movement command with v_x(forward/backward): %f v_y(right/left): %f " % (velocity_x,velocity_y))

msg = vehicle.message_factory.set_position_target_local_ned_encode(
    0,      
    0, 0,    
    mavutil.mavlink.MAV_FRAME_BODY_NED,  #relative to drone heading pos relative to EKF origin
    0b0000111111100011, #ignore velocity z and other pos arguments
    0, 0, altitude,
    velocity_x, velocity_y, 0, 
    0, 0, 0, 
    0, 0)    

vehicle.send_mavlink(msg)
#Vehicle.commands.flush()