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

As for proximity type wiki says

  • set AVOID_ENABLE = 7 (“All”) to use all sources of barrier information including “Proximity” sensors.
  • set PRX_TYPE = “4” to enable using range finders as “proximity sensors”

As for the RangeFinder type, Mavlink is OK (considering the SERIAl port is MAvlink and speed is equal to your speed set in your script.

As for the Python script, I think you might have issue if you just pass orientation as number.
You might have better result if passing the full description:

Look at @tiffo code here:

Thank you @ppoirier

precision landing has been solved but the obstacle avoidance is not working with ultrasonic sensor

i tried what you told me above

below image BAD_PROXIMITY

 msg = vehicle.message_factory.distance_sensor_encode(
        0,          # time since system boot, not used
        5,          # min distance cm
        10000,      # max distance cm
        int(d),       # current distance, must be int
        0,          # type = laser?
        0,          # onboard id, not used
        mavutil.mavlink.MAV_SENSOR_ROTATION_YAW_45, #direction
        0           # covariance, not used

could you please help me with this also

Check if you can read message with mavlink inspector ( CTRL-F on Mission Planner)

yes i can read

1 hz is not very as , try faster like 10 hz
@rishabsingh3003 do you have any comment, its been a long time I played with it…

but how can make it to 10hz

Time sleep in your main loop reduce to 0.1 sec

ok thank you i will try it

@suryaprakash_lokula what Firmware version are you running? Copter 4.1?
Can you send your param list? I think @ppoirier is right. As far as I remember, we have hardcoded a minimum 2hz limit. Anything below that, and your vehicle will throw a pre arm error.

@rishabsingh3003 @ppoirier

Thank q for your response

my param list is
suryaparams.param (18.4 KB)

my response with this params is below

@rishabsingh3003 could help with my parameters list if i miss anything

@suryaprakash_lokula why are you using PRX_TYPE 4?
For mavlink, its PRX_TYPE = 2

@rishabsingh3003 even with PRX_TYPE = 2 also not working i checked with both

do all my parameters are correct

Set PRX_TYPE = 2, and then increase your rate of sending those mavlink messages to anything beyond 2 HZ, it should work fine. Make sure you’re also fill time_boot_ms mavlink field; in the screenshot its 0.

ok @rishabsingh3003 now its with a speed of 7.0HZ

and secondly you mean i would like to calculate the running time of the system and send it in the mavlink command
By the way i am using ultrasonic sensor

@ppoirier @rishabsingh3003

i tried your suggestion but drone did not respond for the message

my drone kit code is below

from dronekit import connect, VehicleMode, LocationGlobalRelative
import RPi.GPIO as GPIO 
from pymavlink import mavutil 
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. 
print('Connecting to vehicle on: %s' % "/dev/ttyAMA0")
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): 
    msg = vehicle.message_factory.distance_sensor_encode(
        milliseconds,          # time since system boot
        5,          # min distance cm
        10000,      # max distance cm
        int(d),       # current distance, must be int
        0,          # type = laser?
        0,          # onboard id, not used
        mavutil.mavlink.MAV_SENSOR_ROTATION_YAW_45, #direction
        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.
    return dist1

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 ")

vehicle.parameters['AVOID_ENABLE'] = 7
vehicle.parameters['PRX_TYPE'] = 2

while True:
    milliseconds = milliseconds+1
    d = measure()

You have the avoidance running now :slight_smile:
3 Hz is not very fast and I suspect it will degrade once in flight as sonar and propellers don’t mix

You need to activate in flight to test… Just like in the wiki ( yep the WIKI ).


i am sorry i didn’t get you

i tried RC7_option to 40 but its pwm is not increasing > 1800
mine is a flysky rc with 6 channels
how can i make it

@ppoirier @rishabsingh3003
could you help me with this thing please

Sorry but there is not much we can do for your equipment, you need 8 channels in order to accomplish this and finally try using SONAR is a waste of time. Over and Out… good luck :wink: