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.send_mavlink(msg)
vehicle.flush()
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.
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
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
TRIG = 27 # Trigger pin of the Ultrasonic Sensor
ECHO = 17 #Echo pin of the Ultrasonic Sensor
GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)
#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):
msg=vehicle.message_factory.distance_sensor_encode(
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.
)
print(msg)
vehicle.send_mavlink(msg) #Simple function to measure the distance using ultrasonic sensor
vehicle.flush
return
def measure():
dist1=250
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)
echo_state=0
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
dist1=distance
sensor_data(dist1,4) #Sends measured distance(dist1) and orientation(0) as a mavlink message.
return
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...")
time.sleep(1)
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")
break
time.sleep(1)
print("vehicle started ")
arm_and_takeoff(1.5)
time.sleep(3)
while True:
print("started")
d = measure()
time.sleep(1)
print(d)
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