Month: April 2015

The PiDrone Update #6

With a bit more work, I’ve created a companion iOS app for the Drone and also given it WiFi capabilities (it formerly ran on ethernet).

The iOS App

The PiDrone’s iOS app is completely written in Swift and retrieves live data from the drone by fetching JSON data from a webpage every quarter second.  Download it: PiDrone

Screen Shot 2015-04-25 at 4.02.00 PM

Current Features Include:

  • Altitude, Speed, Yaw, Pitch, and Roll measurements displayed
  • Displays WiFi speed (amount of time it takes for the request to be made)
  • Arming and Disarming
  • Taking a Picture and saving it to the camera roll
  • Live Stream displayed in a Web View

I currently have two classes, WebModel.swift for accessing the JSON web page, and ViewController.swift to display the stats in a UI from the WebModel

Inside WebModel.swift

Here is the code for synchronously (doesn’t need to be asynchronous since it only takes <0.1 seconds) retrieving the JSON text:

The code for parsing the JSON in to a more accessible swift dictionary:

To invoke some action, such as arming the quadcopter, the code simply access a specific URL on the Pi’s CherryPy web server, which then causes the python code to use the DroneKit libraries to set the quadcopter as armed. I made a simple request method that makes a request to any url asynchronously:

The code for downloading the picture asynchronously and saving it to the Photos library:

To save the picture to the camera roll, I am downloading a still shot provided by the MJPG web application. This process needs to be asynchronous since downloading images takes a significant amount of time and downloading in synchronously causes the button press animation to hang up.

Inside ViewController.swift

The code for displaying the live stream video:

I haven’t quite figured out yet how to center the video feed perfectly with no white space on the screen, so I’m now stuck with having to using the pinch and pan gestures to manually arrange the stream.

To create the nice rounded rect effect around each of the label/buttons, I created outlets to each of the UI elements and a method named roundView which rounds the UIView it receives.

I then individually call roundView on all of the different UIViews I want rounded on the storyboard. I could have also subclassed UILabel and UIButton as UIRoundedLabel and UIButton for cleaner code.

To update the statistics live, I set a NSTimer that “rings” every 0.25 seconds by calling the method update.

A quick look at the Storyboard

Screen Shot 2015-04-25 at 4.03.22 PM

Since none of the Apple UI objects were perfect, I made my own combobox type object for selecting the Flight mode. Its very simple and there is a just a group of other possible flight modes to choose hanging under the current flight mode that are usually hidden.

Screen Shot 2015-04-29 at 5.42.51 PM

When the current flight mode is clicked, the other flight modes unhide themselves, When one of these alternate flight modes are chosen, the group hides again. Instead of updating the current flight mode immediately after the new flight mode is chosen, the program instead waits for the next time update() is called to update the current flight mode when the drone’s flight mode has already been changed.

Next Up:

  • Maps integration with MapKit
    • Location of Drone
    • Location of User
  • Signal Strength

The PiDrone Update #5

Over the past few weeks, I’ve been working hard on the drone side of things for The PiDrone. Right now, I have a CherryPy Web Server running on the onboard RaspberryPi that displays information about the drone and allows you to do basic interactions with it.

On The Drone

The Raspberry Pi is currently connected through a Telemetry Port of the Pixhawk. I took a 6 pin DF13 cable that came with the Pixhawk and stripped of one end to attach the Raspberry Pi friendly connectors. Extra DF13 Cables can be easily purchased on ebay or from 3DR Robotics.

I used this tutorial to set it up.

 

RaspberryPi_Pixhawk_wiring

The Raspberry Pi is powered using a LM2596 DC Adjustable Step-Down Converter that steps the 11V of the LiPo battery down to the 5V required to the Raspberry Pi. I had to set the voltage at 5.25 volts since as the Raspberry Pi drew more current, the voltage would sometimes drop. I discovered that when the voltage drops below approximately 4.96V, the Raspberry Pi will complain with a mini rainbow gradient icon that is usually seen as the splash screen.  Even with the rainbow icon at the corner, the Pi will continue to work, but operation may become unstable and the red power LED will no longer stay on.

$_57

 

I have ordered a nicer 3-amp 12V to 5V module that will hopefully solve the power problems I have encountered. Although the current module is advertised to be able to provide 2 Amps, I think the big gap between 11V to 5V is causing it issues.

To communicate between the Pi and the Pixhawk Flight Controller, I am using 3DR’s brand new open source DroneKit-Python library (installation). Currently, I have a python program that has both CherryPy (web server) and DroneKit code. They seemed to conflict at first, but I solved the issue by initializing the CherryPy server manually with:

To set up the communications with the drone, heres what I did:

Download the full code: pyserver

To start the code, first execute

sudo mavproxy.py –master=/dev/ttyAMA0 –baudrate 57600 –aircraft MyCopter

This starts a MAVProxy (command line ground station) connection between the Raspberry Pi and the drone. After a few seconds, the basic information for your drone should be displayed and you should be prompted with something like this when you press enter

STABILIZE>

If you see something like MAV>, the connection has not been established yet. Try checking the connection wires or restarting the system. Then, type:

module load droneapi.module.api

and to start the server:

api start drone.py

The Pi now starts a server at the location

<pi’s ip adress>:9090

To find the pi’s ip address, check out my ssh tutorial. I set up some really simple HTML code (No CSS yet) to control the drone and see stats coming back from it.

Screen Shot 2015-04-25 at 4.04.14 PM

The PiDrone Update #4

Test Flight

I went out and test flew the PiDrone today, and it performed fairly well in some slight winds. Using the “Save Trim” function of the Pixhawk, I was capable of keeping the drone in a relatively stable hover in the air.

I only flew in Altitude Hold and Stabilize modes. Next time, I’ll try out Loiter, which requires a good GPS signal. Out in the park, the Pixhawk gets a GPS signal almost instantly.

Here are the vibration logs:

Screen Shot 2015-04-08 at 5.50.23 PM

The acceptable ranges are:

  • X between -3 and 3
  • Y between -3 and 3
  • Z between -15 and 5

Both the X and Y axis are nearly entering the unacceptable range, which is a little bit worrying. However, the Z axis stays comfortably in the acceptable range most of the time. All three axis appear to suffer from massive spikes around the end of the flight, which is concerning.

To Log Vibrations, change the LOG_BITMASK paramater from default to Default + IMU. Then, when you view the logs, take a look at AccZ, AccX, and AccY under the IMU section. More info here.

I have purchased APC’s new multirotor propellers in an effort to reduce vibrations. They’ll come in a couple days and I’ll try them out. The current propellers and flimsy, unbalanced and not level.

 

 

The PiDrone Update #3

Main electronics and avionics have now been installed

Components I’m Using:

Turnigy D3536/9 910KV Brushless Outrunner Motor (US Warehouse)

Turnigy nano-tech 4000mah 3S 25~50C Lipo Pack (US Warehouse)

TURNIGY Plush 30amp Speed Controller

3DR Pixhawk (+ GPS and PPM Encoder)

12×4.5 SF Props 2pc CW and 2pc CCW Rotation (Black)

3DR Cloned Telemetry 915 mHZ

  • Almost everything is velcroed on to the acrylic (it sticks well) including the battery
  • Pixhawk is mounted on a square plate with 3DR anti-vibration foam
  • Most electronics are mounted on middle plate, except for GPS, which is mounted on the top place to reduce interference (no mast).
  • DIY Power distribution system with 10 AWG wire splitting in to 4 sets of 16AWG wire. The battery is connected with 4mm HXT plugs, while the motors and the ESCs are connected via 3.5mm bullet plugs
IMG_1058

Before

IMG_1218

After

The cheap plastic props had to be reamed with a prop reamer to fit the 8mm shaft of the prop adapter. Nobody sells a metric prop reamer with a starting shaft size of 6mm (they all start at 1/4″!) I had to use a standard prop reamer that produced horribly off centered shaft holes. I bought a Durbo Prop Balancer and balanced the blades with tape, but I doubt it will do much good.

Next up: Test Flights!

The PiDrone Update #2

I have now completed the new and redesigned laser-cut Acrylic Frame. The old frame was made of 1/8″ aluminum which made it quite indestructible, but also  caused interference with the flight controller avionics. Here are some of the improvements of the new design:

  • Mount for Pixhawk Safety Switch
  • Much, much more working space
  • Mounts for Raspberry Pi  and Pi Camera
  • Support for removable anti-vibration mount


IMG_1162

 

Everything is held together with 4-40 screws, and 1″ 4-40 hex standoffs. The 4 aluminum booms purchased from HobbyKing are sandwiched between the two plates securely.The acrylic turned out to be much bendier than I initially believed, so the frame is “squishy” at some areas.
IMG_1158

Download Ai Files: Quad Files

 

The PiDrone – Update #1

The PiDrone is a drone with a Raspberry Pi onboard that I hope to exhibit at Maker Faire Bay Area 2015.

My Goals for the Project Are:

  • Have the Pi and the Drone communicate through 3DR’s Drone Kit 
  • Have the Pi host a web based ground station
  • Create an iOS Ground Station for the drone

I already have a semi-working drone built up from last summer, but it will require extensive repairs and redesign.

 

© 2018 Andrew Ke

Theme by Anders NorenUp ↑