Saturday, May 18, 2013

Making the Frame

For the frame of the quadcopter, I wanted to use a 3D printer because many hobbyists either have one or access to one. This would allow anyone to print out the frame and simply attach the electronics and start flying. So I taught myself how to use SolidWorks and designed a frame to be printed. My design was based off of a design by an MIT student who attempted a similar project. It consists of a central holder for the electronics and places the motors in an X configuration, complete with landing gears.

The quadcopter frame in SolidWorks
The design from MIT

I then printed the part at Stanford's PRL (Product Realization Lab) using their ProJet 3D printer which uses wax support material so it would be easy to melt away after the print. After the print finished, the part looked great but I quickly realized some flaws in the design. The biggest flaw was that it just seemed too heavy. The printing material was heavier than I anticipated and as a result I had serious doubts about its ability to fly. Another problem that was made clear was that it wasn't the most sturdy design. I carelessly dropped it from my bed and one of the arms broke. If this quadcopter was to fly, it would often be dropping from height and would most likely break upon impact and since the frame was a single 3D print it wouldn't be easily fixed.

Fresh out of the printer

Melting off the wax

Quadcopter

So it was back to the drawing board. Armed with the lessons I learned from my previous design, I decided the new version had to have several key features. It had to be lighter, this meant less plastic or at least a lighter plastic. It had to be stronger and more easily fixed. Finally it had to be more easily printed. The first version was a difficult print and may be too hard to do with a hobbyist grade machine. With these parameters in mind, I decided that the best way to do this was use carbon fiber rods for the arms and only 3D print the base that held the electronics and motor holders. This decision had several advantages. First, the carbon fiber meant less plastic and made it much lighter while also stronger. By printing out only the motor holders and electronics base, the prints were simpler, cheaper, and easily replaceable. As an added bonus, the entire frame ended up being cheaper because I only had to use about a dollar of carbon fiber and the print only took 0.66 cubic inches of support and printing material so it was a fraction of the cost of the old frame.

Check out the CAD files at: https://sourceforge.net/projects/nanoquad/files/?source=navbar.

The revised design (the square rods are carbon fiber)
The printed parts. One of the problems was the support material was inside the holes which made it difficult to clean out.

Post support material

The assembled frame

The final quadcopter


Testing the IMU

After I soldered the board together, it was time for me to test all of the sensors and implement an IMU (inertial measurement unit). The gyro and accelerometer both use I2C communication, so I had to get familiar with the Wire library for the Arduino. I quickly wrote up some test programs for the Arduino to make sure that the communication worked and sure enough it did! The only unintuitive thing I had to do was call endTransmission(false) because the communication didn't want a stop message after querying for the data registers when reading the measurements.

After proving that the sensors worked, I wanted to test my algorithm for measuring orientation. I decided to implement it in Processing for the time being so that I could tweak it without having to reprogram the board. So I wrote a program that simply would send the readings over Serial to the computer to be processed.

For my orientation detection, I use a Kalman filter to integrate the readings from the gyro and accelerometer together to get a better approximation of the board's orientation. For those who don't know, a Kalman filter is a very powerful tool that can be used to combine two different sensors and get a better approximation of your position or orientation than either could do individually. Because of this, Kalman filters are used extensively in localization. Essentially, Kalman filters work by combining two sensors, one that directly measures the information and another that indirectly can be used to correct for errors. So in the case of a quadcopter, where I want to measure the roll, pitch, and yaw of the board, I use the gyroscope to directly measure the angular acceleration. Then through basic kinematics, it is easy to convert these accelerations to angles accurately. However, a problem with the gyroscope is that it drifts making it inaccurate over long periods. Meanwhile, the accelerometer can be used to measure the tilt of the board using the gravitational acceleration. While it doesn't drift over time, it is very noisy because it is sensitive to any other linear motion the board is subjected to. By combining the two, you get the best of both worlds. They gyro provides the immediate, precise readings while the accelerometer corrects for its drift over time.

In my Processing sketch, I query the Arduino for sensor readings and then pass them through a Kalman filter and display the results on my computer. This allows me to test the filter's functionality and tweak the filter parameters. I based my code off of the examples from this forum. I also have attached all of my code below. Enjoy!

Check out my code at: https://sourceforge.net/projects/nanoquad/?source=directory