Skip to content

jeff14994/javascript-drones

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Drone!

The origin is JavaScript Drones; howerver, I intergrated the pre-trained Haar cascade classifier (haarcascade_frontalface_default.xml) to condtuct the face detection in the frame.

Why this project?

Overall, the script is designed to make the drone take specific actions (take off, move, rotate, land) when a face is detected in its camera feed, and simultaneously record this footage.

Demo

What I did

I've created a Python script that makes use of the djitellopy library to control a Tello drone and the cv2 library from OpenCV for video processing and face detection. Here's a summary of the code's functionalities:

  1. Initialization:

    • Required libraries like cv2 (OpenCV), numpy, djitellopy, time, and threading are imported.
    • Constants like ESC are defined.
    • A connection to the Tello drone is established, its battery status is printed, and its video streaming is started.
  2. Video Recording:

    • The function videoRecorder records the drone's video feed. It initializes a video writer object (video.avi using XVID codec at 30 fps) and records frames from the drone as long as keepRecording remains True.
  3. Main Functionality:

    • The main function continuously captures and processes video frames from the drone:
      • The frame is resized and flipped.
      • The frame is converted to grayscale.
      • A pre-trained Haar cascade classifier (haarcascade_frontalface_default.xml) is used for face detection in the frame.
      • If a face is detected in the frame:
        • The face's bounding box is drawn on the frame.
        • A new thread is started for video recording using the videoRecorder function.
        • The drone takes off, moves down a bit, rotates 360 degrees counter-clockwise, and then lands.
        • After landing, video recording is stopped.
      • The processed frame is displayed in a window named 'video'.
      • If the ESC key is pressed, all windows are destroyed and the program exits.

JavaScript Drones!

Watch the videos:

Part 1 → https://www.youtube.com/watch?v=JzFvGf7Ywkk

Part 2 → https://www.youtube.com/watch?v=ozMwRq-IT2w

⚠️️️ ⚠️ ️️⚠️️️ Use the codebase as your own risk. The drone can hurt you and I'm not responsible for that. Always test commands with the props removed first. Don't be dumb. ⚠️️️ ⚠️️️ ⚠️️️

Flying a Drone with React and Node.js

IBM is giving away 2,000 DJI Tello drones as part of a contest and I made this video to help them promote it.

Software Used

  • React (with React Hooks!)
  • Styled Components for styling
  • Node.js and UDP4 sockets for communicating with drone
  • Socket.io WebSockets for sending data to/from the browser
  • Next.js for easy react setup

Hardware Used

Using This Code

Frontend

  1. cd frontend
  2. npm install
  3. npm run dev

Backend

  1. cd backend
  2. npm install
  3. connect to drone via wifi
  4. npm start

Troubleshooting

Docs for Tello are available here

I had to update the firmware of my drone when it came in the mail before I could use this 1.3 API. Do this via the Tello app on your phone.

If you let the drone's WIFI connection lapse, you have to restart the server by typing rs into the terminal. This will re-run the command command that puts the drone in SDK mode. If you don't do this, it will ignore any commands you send it.

License — WTFPL

I want you to build cool stuff with this.

Please hack on it and make your own cool things.

Examples & Resources

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 50.5%
  • JavaScript 43.9%
  • EJS 4.3%
  • HTML 1.3%