Precision with companion computer not working , April Tag (Aruco Marker), Dronekit python

Hi everyone,
I am trying to do precision landing using companion computer and April Tag
so I enabled PLND_EN = 1 & PLND_TYPE = 1
I had found position of marker in the camera frame and converted them in to camera to uav frame then published these data to vehicle.message_factory.landing_target_encode but there is no behaviour in quad it just hovers from where it took off please help me

def send_land_message(x,y,z):
x = -y #camera frame to uav frame
y = x #camera frame to uav frame
x_offset_rad = math.atan(x / z)
y_offset_rad = math.atan(y / z)
distance = np.sqrt(x * x + y * y + z * z)

msg = vehicle.message_factory.landing_target_encode(
        0,                       # time target data was processed, as close to sensor capture as possible
        0,                                  # target num, not used
        mavutil.mavlink.MAV_FRAME_BODY_NED, # frame, not used
        x_offset_rad,                       # X-axis angular offset, in radians
        y_offset_rad,                       # Y-axis angular offset, in radians
        distance,                                  # distance, in meters
        0,                                  # Target x-axis size, in radians
        0,                                  # Target y-axis size, in radians

vehicle = connect(’/dev/serial0’, wait_ready=True, baud=921600)

while True:
marker_found, x, y, z,corner = aruco_tracker.track(loop=False)

how are you connected ?

Here is my code, that I used for the Jevois Experiments:
It show different method to connect to FC.

I am connected through
telemetry2 port ,raspberry pi tx rx
vehicle = connect(’/dev/serial0’, wait_ready=True, baud=921600)
@ppoirier @tiffo

Check if you can see your LANDING_TARGET messages in your GCS.

On Mission Planner use CTRL + F and then click on MAVlink Inspector.

On QGroundControl, go to Analyze tab and then use MAVLink Inspector.

Also, at least in my case, the serial0 on the Raspberry Pi doesn’t always work. I switched to a PL2303 USB to Serial converter and use /dev/ttyUSB* instead.

ok thank you ill try that and update you the details

I checked mavlink inspector it is receiving values but drone is not responding to its values
Drone just hovers over the target

Thank you

Have you configured a RC switch to enable Precision Landing?

No ,are there any references to do that please provide some details ill check with that thank you
Thank you

Look at option 39

1 Like

Thank ill go through it

hello @ppoirier

i am new to the dronekit i need to make obstacle avoidance and precision landing using qr code please help me

my code for precision landing

horizontal_fov = 118.2 * math.pi/180
vertical_fov = 69.5 * math.pi/180
horizontal_resolution = 1280
vertical_resolution = 720

 msg = vehicle.message_factory.landing_target_encode(
        0,       # time_boot_ms (not used)
        0,       # target num
        0,       # frame
        0,       # altitude.  Not supported.
        0,0)     # size of target in radians

my code for obstacle avoidance

        msg = vehicle.message_factory.distance_sensor_encode(


Can you explain what is your vehicle configuration, how many cameras you have and the companion computer configuration and code ?

Precision Landing is pretty well documented through the different discussions and for avoidance, you may experiments with different models from the wiki:


thank you for your early reply

my vehicle is an quadcopter with pixhawk4 and raspberrypi 3 as campanion computer
with one raspberry pi camera

my pi code for object detection is

from dronekit import connect, VehicleMode, LocationGlobalRelative
import RPi.GPIO as GPIO 

import time 


TRIG = 27  # Trigger pin of the Ultrasonic Sensor 
ECHO = 17 #Echo pin of the Ultrasonic Sensor 

#Connects to the vehicle using serial port. 
vehicle = connect('/dev/ttyAMA0', wait_ready=True, baud=921600) #Function to convert distance and orientation into a mavlink message 
#vehicle.wait_ready(True, raise_exception=False)
def sensor_data(d,o): 
        0, #time since boot , this is not used 
        10, #min distance in centimeters 
        260, #max distance of the sensor in cm 
        int(d), #distance of object detection. 
        0, #type 
        0, #onboard id, not used 
        int(o), # sector 
        0 # covariance, not used. 
    vehicle.send_mavlink(msg) #Simple function to measure the distance using ultrasonic sensor
def measure(): 
    GPIO.output(TRIG, True) 
    GPIO.output(TRIG, False) 
    while echo_state == 0: 
        echo_state = GPIO.input(ECHO) 
        pulse_start = time.time() 
    while GPIO.input(ECHO)==1: 
        pulse_end = time.time() 
    pulse_duration = pulse_end - pulse_start 
    distance = pulse_duration * 17150 
    distance = round(distance, 2) 
    if(distance<250 and distance>5): #To filter out junk values 
        sensor_data(dist1,4) #Sends measured distance(dist1) and orientation(0) as a mavlink message.

def arm_and_takeoff(aTargetAltitude):

    print("Basic pre-arm checks")
    # Don't try to arm until autopilot is ready
    # while not vehicle.is_armable:
    #     print(" Waiting for vehicle to initialise...")
    #     time.sleep(1)

    print("Arming motors")
    # Copter should arm in GUIDED mode
    vehicle.mode = VehicleMode("GUIDED")
    vehicle.armed = True

    # Confirm vehicle armed before attempting to take off
    while not vehicle.armed:
        print(" Waiting for arming...")

    print("Taking off!")
    vehicle.simple_takeoff(aTargetAltitude)  # Take off to target altitude

    # Wait until the vehicle reaches a safe height before processing the goto
    #  (otherwise the command after Vehicle.simple_takeoff will execute
    #   immediately).
    while True:
        print(" Altitude: ", vehicle.location.global_relative_frame.alt)
        # Break and return from function just below target altitude.
        if vehicle.location.global_relative_frame.alt >= aTargetAltitude * 0.95:
            print("Reached target altitude")

print("vehicle started ")


while True:
    d = measure()

also i made changes for RCx_OPTION in mission planner to 40 (x = 0-7)
i dont know exactly which rc option should i need to change for obstacle avoidance and for precesion landing so i made all my RC OPTIONS

i got the data output in mission planner mavlink inspector window and proximity sensor window

all though all the data is observed in the mission planner but drone does not respond according to the message

Avoidance with a sonar is not optimal, we prefer lidars.

WIKI is your friend , for rc switchs options , please refer to this:

|39|Precision Loiter|
|40|Object Avoidance

Yes of course lidar is best

But is my mavlink command is correct or not

If correct

which rc channel should I use for obstacle avoidance and which channel for precession landing

Did you read the link I posted above ?
I repeat , WIKI is your friend :wink:

yes i read but i dont understand which rc option should i choose for obstacle avoidance

It is option 40|Object Avoidance

yes of course option 40

but i dont know which RC channel i need to set option 40 and to which i need to set 39

hello @ppoirier

could you please tell me how to setup full parameters list in mission planner to perform obstacle avoidance and precision landing

i mean what are the options i need to change in full parameters list
what i tried are below

now can drone response for my mavlink message from dronekit raspberry pi3