Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drone is not responding for the code #3

Open
suryadevelope opened this issue Oct 29, 2021 · 0 comments
Open

Drone is not responding for the code #3

suryadevelope opened this issue Oct 29, 2021 · 0 comments

Comments

@suryadevelope
Copy link

Hello @SohamKorgaonkar
My drone is not responding to the code given by you

I think I missed some thing could help me
My mission planner full parameters list below
suryaparams.txt

Proximity response below
Screenshot (40)

Raspberry Pi code below
`
from dronekit import connect, VehicleMode, LocationGlobalRelative
import RPi.GPIO as GPIO
from pymavlink import mavutil
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)

milliseconds=0

#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
)
print(msg)
vehicle.send_mavlink(msg) #Simple function to measure the distance using ultrasonic sensor
return

def measure():
dist1=250
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)
echo_state=0
pulse_end=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.
else:
    dist1=0
    sensor_data(0,4)
        
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...")
    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)

vehicle.parameters['AVOID_ENABLE'] = 7
vehicle.parameters['PRX_TYPE'] = 2
#time.sleep(3)

while True:

milliseconds = milliseconds+1
print("started")
d = measure()
time.sleep(0.3)
print(d)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant