Showing posts with label Copter. Show all posts
Showing posts with label Copter. Show all posts

Saturday, June 6, 2015

Quadcopter Project

Quadcopter

The quad, controller, and camera


Flight Control Board

The flight control board is based on FreeIMU and built onto an Arduino Mega 2560 running MultiWii. The main goals were to build a customizeable and affordable quadcopter using mainly open source hardware and software, and learn a bit about how it all works. Bugs and design issues seem to have been worked out now, so it looks like this will be the base design for my board. Video

Since it is all open source, adding additional custom components to control lights, sound, servos, etc. is about as easy as it gets. For anybody already familiar with Arduino, it's just a matter of  choosing what customizations to add.

The top picture on the right shows the simplicity of  the FC board, using only a few modules. A previous mock-up of the board was scrapped due to some simple design flaws. The current version attempts to address some of those problems:

a: Although the shield fits tight, secure mounting is a must, and nylon standoffs are used to secure the shield to the Arduino.

b: Here I am using a cheap, single sided prototyping board, but we'll see how long it lasts...

c: The first mock-up used the female header pins as shown on the right of the bottom pic, but they aren't made for Arduinos (too thin), and caused I2C errors and subsequent crashes. The header pins shown on the left are thicker and fit snug every time.

d: The GPS module was left out since GPS nav won't be something I'll be using right away.

The ESCs connect to pins exposed on the top of the board, which are hard to see since the angle of the bottom pic purposely hides my shoddy looking soldering work. The Arduino gets fastened to the frame using rubber mounts taken from broken CD/DVD players to minimize vibration.

Notes:

FC Board:
The board is intially based on a FreeIMU board as mentioned previously, and is actually pretty simple to build at this point, with only 3 modules. The HMC5883L magnetometer module is connected to the aux. I2C lines of the MPU-6050, and running on 3.3V. An APC220 module is connected to the fourth serial port (serial3), and a GPS module can go on serial2 or via I2C if desired. The best part of the flight controller and quadcopter is that it is all based on open source software and hardware, so customization and prototyping like this is actually possible without spending huge amounts of money or time.

FC Board/Arduino Mega Connections:
pin2: front motor
pin3: rear motor
pin5: right motor
pin6: left motor
pin14: APC220 RX pin
pin15: APC220 TX pin
pin16: GPS RX pin
pin17: GPS TX pin
pin18: MPU6050 interrupt
pin20: MPU6050 SDA (I2C)
pin21: MPU6050 SDL (I2C)
pinA0: Voltage divider (battery monitor)
MPU6050: Aux SDA to HMC5883L SDA
MPU6050: Aux SDL to HMC5883L SDL


Main Parts:
1x Turnigy Talon carbon fiber frame
4x Turnigy 20Amp MultiStar ESCs
1x Turnigy ESC programmer
4x NTM Prop Drive Series 28-26A 1200kv/250W Motors
2x Slow Fly 8045 propellers
2x Slow Fly 8045R propellers
1x 4000mAh 3S LiPo battery pack
1x Arduino Mega
1x GY-521 Gyro Module (MPU-6050
1x HMC5883L Magnetometer module 
1x APC220 serial data wireless transceiver
Uses Modified XBox controller for RC (previous post)


XBox Controller:
Prev post. Uses the MultiWii RCSerial protocol
Quad can easily be controled by a PC via RCSerial protocol and APC220 transceiver

Frame/Physical Assembly:

Since the controller and FC board are both custom made, I had to code and then debug the controller during flight in some cases, and had no failsafe at the time. The initial assembly of the central parts of the frame used all nylon bolts. This was to prevent damage to the frame and motors when big crashes happened, since parts would usually break away before breaking or bending much. It currently uses a combination of metal and nylon connectors to provide rigidity and allow for some give on big impacts. As can be seen in the picture above, I have also made my own motor mounts.
ESC Calibration:

One of the problems I ran into in some of the first flights was individual motors cutting out seemingly randomly. The quad uses 20A Turnigy MultiStar ESCs, and gives a choice between slow-down of motors, and hard cutoff when the voltage is low. This caused a bit of frustration since the motors would start cutting out when the voltage was low, regardless of the setting via programming card.

I was confused by the MultiWii calibration code at first since, according to the ESC manual, it would basically just set the programming of the ESCs to the LiPo battery setting, and that hardly seemed like 'calibration':

ESC Programming: 
a: Power ESCs on while receiving max throttle signal
b: These ESC will beep accordingly, move throttle to min to select what option to set in the programming 

The ESCs apparently use this interaction for calibration as well, and it made a big difference once I programmed them this way. The motors seemed to sound a bit smoother afterward, and they slow down nicely to force a landing once the battery is low.

Always remove your propellers before uncommenting this line in 'config.h':
#define ESC_CALIB_CANNOT_FLY 

Propeller Balancing:

Another important factor that was initially overlooked was propeller balancing. This made a big difference in the stability of the craft, as well as reducing vibrations. I followed this tutorial and had some good results on my first shot at it. Videos from the previous post show the vibration evident from unbalanced propellers, and a motor wire breaks in the second one, likely related to the vibration issues.

MultiWii Config and GUI:

The videos in the previous post were shot using the PID settings shown in the pic to the right and with the low-pass filter enabled for the MPU-6050 at 20Hz in 'config.h'. Higher values for the filter makes for 'tighter' controls, but is more susceptible to vibration and affects PID. Mitigating vibration issues should allow a higher setting. 

MultiWii Code:
Code base is MultiWii_dev_r1240
Uses slightly modified version, but can work with original:
  • Supports serial rc cmds with smaller payloads
  • Supports failsafe when using serial rc
  • Supports basic monitoring during flight via processing gui and existing transceiver (prev. post)
  • Still unsure whether to remove or work with test code to control a music player from alarms and controls, so left it in for now (alarm buzzer timing is changed)
  • Longer delay for ESC calibration code specific to MultiStar ESCs (see esc manual below)



Reference Material:
MultiWii - Code w/Modifications
MultiWii - Arduino Mega pin layout
MultiWii Wiki

Friday, December 20, 2013

Quadrocopters for beginners

Quadrocopters for beginners

Intro to quadrocopters

Quadrocopters, also known and quadrotors, are one of the most interesting little flying machines ever imagined; yet there's a load of disperse and almost undecipherable amount of information that comes from hobbyists' and builder's gut feeling on what seems to be the right thing to do.

This is my attempt at bringing all that information together in a simple to understand version for beginners to get designing their own quadrotors.

How they work

Quadrotor diagram showing forces and torques

The concept is a flying machine with four motors aligned in a square; two on opposite sides of the square rotate in one direction and the other two rotate in the opposite direction.

This four rotor helicopter gives us some interesting properties:

1.- each motor lifts only a quarter of the weight of the heli, so we can potentially use less powerful motors

2.- the rotation or torque of the first pair of motors is canceled by the rotation of the second pair that goes in the opposite direction. Let me explain how this works:

On a regular helicopter, you have one big rotor to provide the lifting power and a little tail rotor; this one counteracts the rotation that the main big rotor would otherwise pass on to the structure of the helicopter (making it rotate almost as fast as the propeller)

On a quadrotor, if all motors turned on the same direction the thing would rotate same as a regular heli without tail rotor; the clever thing is that since one pair create a torque or rotation on one direction, the motors turning on the opposite direction create a torque also but on the opposite direction. These torques tend to cancel out and the quadrocopter stays facing the same direction without any rolling around.
Quadrotor control; arrow thickness denotes power

3.- control becomes a matter of which motor gets more power and which one gets less.

Yaw (where the thing is "facing"; using your head, yaw is when turning left and right) is controlled by turning up the speed of the regular rotating motors and taking away power from the counter rotating; by taking away the same amount that you put in on the regular rotors produces no extra lift (it won't go higher) but since the counter torque is now less, the quadrotor rotates as explained earlier.

Roll (how tilted to the side it is while still facing the same direction; using your head, roll is turning it so that your chin is parallel to the ground) is controlled by increasing speed on one motor and lowering on the opposite one.

Pitch (how tilted it is; using your head is moving it up and down, similar to nodding) is controlled the same way as roll, but using the second set of motors. This may be kinda confusing, but roll and pitch are determined from where the "front" of the thing is, and in a quadrotor they are basically interchangeable; but do take note that you have to decide which way is front and be consistent or your control may go out of control.

These three can be controlled at the same time to give all the range of motion you could ever need from a flying thing


Now, building and flying a quadrotor from a remote control is simple and fun and stuff, but people noting the inherently stable flight (in theory with equal speed of the motors the thing keeps itself level) and ease of control (only three functions and they are all basically take speed from one and put in the other), people love to make them autonomous (flies itself) and semi-autonomous (at least keeps itself level by responding to disturbances and error).

Common sensors (Gyro, Accelerometer, Sonar/Rangefinder)

A gyroscope is a device that tells you the difference in angle from a reference one: this is useful in keeping the quadrocopter level so it won't fall or go sideways when we don't want it to.
Micro ElectroMechanic Mechanism (MEMS) gyroscope
as found in Integrated Circuit (IC) sensors

The accelerometer tells us which way the quadrotor is accelerating. This is useful because we can get an idea of how much the thing has moved by looking at acceleration over time (position is mathematically represented as the double integral of acceleration) so that we can move it back and keep it hovering on a steady position.

MEMS Accelerometer based on capacitive effects


A sonar is used to determine the distance from the sensor to an object. This helps in object detection an avoidance and is mostly used in fully autonomous quadcopters.



All these sensors are connected to a microcontroller or other control circuitry to make the decision as to how to control the motors (and therefore the quadrotor itself) according to plan.

Depending on how autonomous you want it to be, one or more of these sensors are used in combination; sometimes more sensors are used or more processing is done on the signals to get more information about the environment: creating maps, computer vision and navigation systems.

The flight mechanics of the quadrocopter, as explained in the how it works section, are not that difficult, but a "design" limitation is the choosing of motor/propeller.

Choosing a motor/propeller combo (prop size and RPM: lift vs torque)

There's something about aerodynamics that is just way too complex for beginners to get a working understanding of in a few words, all the fluxes and stuff makes it hard enough that even designers of commercial propellers bunch a lot of things into "constants" or "factors" that they arrive at experimentally.

But generally, the importan stuff depends largely on two things: the effective area of the propeller and RPM (revolutions per minute).

Revolutions per minute are largely dependent on the motor, in fact, it is one of the parameters used in their marketing; usually expressed as Kv, RPM per volt applied.

The propeller is marketed in terms of diameter x "pitch". the higher diameter means higher area; higher pitch also means higher effective area because more of the propeller is pushing air to create lift.
Various propeller sizes and pitches

In choosing a motor/propeller combination, you have to figure out what you actually need or want out of the quadrotor:

A higher RPM of the propeller will give you more speed and maneuverability, but it is limited in the amount of weight it will be able to lift for any given power. Also, the power drawn (and torque required) by the motor increases as the effective area of the propeller increases, so a bigger diameter or higher pitch one will draw more power at the same RPM, but will also produce much more lift (meaning it will be able to actually lift more weight). [Torque is like the rotating power of the motor]

A slower rotating propeller is used when you have a motor that manages less revolutions but can provide more torque. In this case using a longer or higher pitched propeller (which uses more torque to move more air in order to create lift) will give you a similar lift to a higher rotating one of less length/pitch.

The choice depends on both motor availability and weight requirements.

Motor technologies: Brushed vs brushless motors

There's a debate regarding the use of brushed or brushed motor. First, a brief explanation of both:
Brushed motor

A brushed motor is your regular $1 toy car motor. They are called brushed because of the way the motor works: the direction of current in the rotating part (rotor) is changed using a mechanical switching mechanism, a pair of moving contacts called brushes disconnect from one side and connect to the other with every half rotation. This is done so the electric current keeps the rotor energized in such a way so as to keep being attracted to the permanent magnets, thus keeping it rolling.
Brushless motor inside view

A brushless motor is one where the commutation mechanism is outside the motor itself, most often electronic. The thing with brushless motors is that there are no moving parts in the electrical path of current, so it generates less electromagnetic noise as there are no sparks (which happens in brushed motors when the brushes disconnect and connect on the other side).

The debate goes about how brushless motors, with its fewer moving or parts, requires less maintenance and has higher performance for size and that brushed motors are "old", obsolete technology.

For the most part, the actual gains in performance come from the thermal characteristics of the motor: given the same power, a brushless motor will probably be smaller due to the fact that the heat dissipates through the mounting (remember, the windings are stationary and attached to the motor frame), a bigger motor. This means that for the same size motor, you can push much more current through a brushless to get more power.

Now here comes the big "but": since they have been around the longest, brushed motors have become very cheap to manufacture, which means prices are very low. Also, since the commutation in brushless motors is external, there's an added cost of buying and/or building the Electronic Speed Controller (ESC), which could cost as much or even more than the motor itself (which even on the lower range are more expensive than brushed motors), also with the increased complexity that comes with more components to deal with.

Brushed motors use a relatively simple speed control technique known as Pulse Width Modulation (PWM) that controls the effective power that the motor gets by quickly switching the power on and off.

So as you can see, there's a lot to dig into when working in quadrocopters. Next up, assembling our own quadrotor and the whole design process.