Minh Quý LêNguyễn Hữu VinhKhang Trần
Published © MIT

MediCopter

A Drone Delivering Medical Supply in Emergency.

IntermediateFull instructions providedOver 10 days419
MediCopter

Things used in this project

Hardware components

Raspberry Pi 4 Model B
Raspberry Pi 4 Model B
×1
Pixhawk 2.4.8 Kit
×1
F450 Frame
×1
SunnySky Brushless Motor - 950kv
×1
Camera Module
Raspberry Pi Camera Module
×2
Solo Propellers
3DR Solo Propellers
×4
Humidity and Temperature Sensor
Adafruit Humidity and Temperature Sensor
×1

Software apps and online services

OpenCV
OpenCV – Open Source Computer Vision Library OpenCV

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Legs for Drone

We use this 3D sketch for 4 legs of our drone. This makes room for a webcam below my drone to capture the ground in the future.

Raspberry Pi Camera Case

We use this 3D sketch for the case of the Raspberry Pi camera.

Vibration Dampening Plate for Raspberry Pi - top part

We use a plate to avoid vibration for the Raspberry Pi when the drone fly. This works by connect 2 part of the plate by 4 pieces of rubber. The 3D file is made by @DroneDojo.

Vibration Dampening Plate for Raspberry Pi - bottom part

We use a plate to avoid vibration for the Raspberry Pi when the drone fly. This works by connect 2 part of the plate by 4 pieces of rubber. The 3D file is made by @DroneDojo

Code

FlyToTargetPoint.py

Python
This code is executed inside the Raspberry Pi and use DroneKit library to control the drone to fly to a target point.
from dronekit import connect, VehicleMode , LocationGlobal , LocationGlobalRelative
import time  
import dronekit_sitl    
import cv2 
import pyrebase
from geopy.distance import geodesic 

#INITIALIZE 
connecting_string = "/dev/ttyACM0" 
baud = 57600 
vehicle = connect(connecting_string,baud,wait_ready=True)  

#FIREBASE
config = {
  "apiKey": "AIzaSyBi24u8OlLlesdg_g_w4XfZuwttWCwHnSw",
  "authDomain": "droneai-c394f.firebaseapp.com",
  "databaseURL": "https://droneai-c394f-default-rtdb.asia-southeast1.firebasedatabase.app",
  "projectId" : "droneai-c394f",
  "storageBucket" : "droneai-c394f.appspot.com",
  "messagingSenderId" : "1043958961590",
  "appId" : "1:1043958961590:web:318bf9d30904beeee3dd17",
  "measurementId" : "G-JFZ5YSZSVE"
} 
firebase = pyrebase.initialize_app(config)
db = firebase.database()

def firebase_data():
    Lat = vehicle.location.global_frame.lat 
    Lon = vehicle.location.global_frame.lon
    data = {"LAT": Lat, "LNG": Lon}
    db.update(data)

def camera(): 
    global video_capture , output_file
    ret, frame = video_capture.read()
    if ret:
        frame = cv2.flip(frame, 0)
        output_file.write(frame)

def arm_and_takeoff(h):

    while not vehicle.is_armable:
        print(" Waiting for vehicle to initialise...")
        time.sleep(1)
    print("Arming motors")

    vehicle.mode = VehicleMode("GUIDED")
    vehicle.armed = True

    while not vehicle.armed:
        print(" Waiting for arming...")
        time.sleep(1)

    print("Takeoff")
    vehicle.simple_takeoff(h)  

    while True:
        print(" Altitude: ", vehicle.location.global_relative_frame.alt)
        camera() 
        firebase_data()
        if vehicle.location.global_relative_frame.alt >= h * 0.95:
            print("Reached target altitude")
            break

    return None 

def Fly_to_target_point(Latitude, Longtitude):         
    vehicle.airspeed = 10 #set the speed during the flight
    altitude = 30 #set the desired altitude during the flight
    tartgetPoint = LocationGlobalRelative(Latitude,Longtitude, altitude) 
    vehicle.simple_goto(tartgetPoint) 
    while True:
        # get the current location
        current_location = vehicle.location.global_relative_frame
        current_latitude = current_location.lat
        current_longtitude = current_location.lon
        current_point = (current_latitude, current_longtitude)

        # Calculate the remain distance to the tartget point
        remain_distance = geodesic(current_point, current_point).meters

        if remain_distance < 0.25 :
            print("Drone Reached Target Location")
            break


def Land(): 
    vehicle.mode = VehicleMode("LAND")
    while True : 
        camera()
        firebase_data()
        attitude = vehicle.location.global_frame.alt
        if attitude < 0.2:
            print("Drone On the Ground")
            break 
def back() :
    vehicle.mode = VehicleMode('RTL') 
    while True : 
        camera()
        firebase_data() 
        attitude = vehicle.location.global_frame.alt
        if attitude < 0.2:
            print("Drone Land Safely")
            break 


def get_parameter():      
    print("DRONE STATUS:")
    print("1. Firmware Version:", vehicle.version )
    print("2. Global location:", vehicle.location.global_frame) 
    print("3. Battery:", vehicle.battery)  
    print("4. Mode:", vehicle.mode.name) 
    print("5. Armed Status:", vehicle.armed)



if __name__ == "__main__":
    array_point = [] #store target points
    point1 = (10.80477, 106.71871) #example coordinate
    desired_altitude = 30
    array_point.append(point1)
    get_parameter() 
    arm_and_takeoff(desired_altitude)
    Fly_to_target_point(array_point) 
    back()

Credits

Minh Quý Lê
1 project • 1 follower
Contact
Nguyễn Hữu Vinh
2 projects • 1 follower
Robotic & AI Developer, Maker & Designer Robotic
Contact
Khang Trần
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.