Introduction: #ActiveSemi -- Hydra-X Build Competition: Quadcopter

Welcome to the Cinnamon Buns' DIY quadcopter tutorial! No, this Instructable is not about defeating a mythical beast or making mythically delicious pastries. I am going to detail my teams experience working with the Active-Semi PAC5210 on their HydraX10 development platform to design and build a quadcopter with Bluetooth control.

Originally we wanted to tackle the design from each aspect: mechanical, software and electrical, including 3D printing the chassis and hand weaving the motors, but eventually conceded to simply build off of an ARF kit due to the complexity of working with the Hydra-X platform, and the copious amounts of free time available to Engineering students. Here is an amazon link to the kit that I purchased:

http://amzn.to/1ya6qj0

Even with the mostly pre-built kit, the project required a lot of new knowledge which I will try to summarize here, but I will advise you to complete your first couple builds with a kit and an R/C Controller or, at least, with a flight controller with a GUI that you can use to design the control scheme.

The brain of our quadcopter is the Active Semi PAC5210. Basically what it does is power a plethora of high voltage outputs using its 9 analog I/O pins and 24 digital I/O pins with an Analog-to-Digital Converter. The board is designed to be used in high voltage applications, though it is also entirely capable of running on the 11.1V Lipo battery we connected making it a highly versatile device useful for a variety of different applications.

All of my experience with embedded systems was on the Arduino micro, so I caution the reader to be aware that my perspective is not that of an industry professional or even an experienced developer. That being said, I am an amateur tinkerer and I give my abundant thanks to Max Roycroft and Jose Quinoñes for their invaluable efforts both in assisting myself and my group as well as in orchestrating the HydraX Competition in conjunction with The University of Texas at Dallas. Hopefully, this competition will be a building block towards more events in-house that are engaging and allow students and industry professionals to meet and network.

Step 1: Kit: Parts, Components, and Peripherals

We used the ST360 ARF Quadcopter kit purchased from Amazon for about $200 with tax. If this is your first build, or you don't have someone to walk you through the electronics and coding, I recommend using a Ready-To-Fly (RTF) kit, and you should go with the included flight controller. Later you can get a separate microcontroller for wireless or, autonomous control and, if it is compatible with your board, use the included wireless transmitter. Also, I would recommend starting with a micro-copter. You can get a 250 kit for cheap and they are really stable and you can learn the basics of controlling the copter. You'll want some practice before buying into more expensive props and motors and whatnot.

Our kit came with four ESCs, 2 CW props, 2 CCW props, 4 motors, a chassis and a flight controller.

I could not find any specifications on the ESCs, though we determined they respond to pulse widths between roughly .25 ms and 1.5 ms. I will discuss the PAC and its PWM capabilities in a subsequent step.

The CW props are marked with their dimensions as 8045, while the CCW props are marked 8045P, where the 'p' stands for "pusher" prop which is what many hobbyists call the CCW props.
This kit has 8045 props, meaning 8 inch diameter with 4.5 inch pitch. Basically, the diameter of a prop determines the agility of the copter: longer props change speed more slowly, but they are far more stable. Additionally, the pitch determines the amount of air displaced with one turn of the propeller. So, a longer pitch length will require more electrical power running through the motors at a given speed.

The motors are KT2210 which are rated at 1050kV. Essentially, the kV rating is the voltage:rpm ratio; 1 volt will drive the motor at 1050rpm. Because the dimensions of the propeller affect the amount of torque the motor can apply, it is necessary to pair the motors with an appropriate size propeller. Here are some resources to help if you want to select your own motors/props setup:
I started here:

http://www.tomshardware.com/reviews/multi-rotor-qu...

Then, I did a broad sweep through a bunch of google searches and /r/quadcopter. Between my understanding of the underlying physics and the recommendations of these sources, I believe larger motors have lower kV ratings and are typically paired with large propellers and they can lift larger loads, but cannot change speed very quickly so they are not particularly agile. Smaller motors are paired with smaller propellers and cannot carry as much load, though they are far more agile than the larger setups. Additionally, larger propellers will require higher capacity batteries.

The batteries used in most multicopter setups are Lithium Polymer, or LiPo, batteries. The capacity of a battery is determined by the current rating multiplied by the charge rating. For example, a battery rated at 2200 mAh at 20C will have 44000mAh total capacity. The S number is the number of cells in the battery where each cell holds 3.7 V on average. The most common is the 3S which holds 11.1V. Most builds will use 2-3S and between 1200-2200 mAh.

Some peripherals you want to look into are an IMU (Interail Measurement Unit) and a wireless receiver/transceiver. The IMU is a device which typically includes a gyroscope, altimeter and compass. The gyroscope measures rotational velocity, the compass measures orientation and the altimeter measures how high the multicopter from a given reference point. For the wireless receiver/transceiver, or rx/tx as they are called, can be any wireless module paired with a controller. We went with a Bluetooth module which connects to an android app as the controller. While that solution has very little cost, you need to put together the app that controls it. There are examples available on Google Play and, again, Reddit is a great resource, but you would need to make sure the app and the flight controller are sending messages in the same format. I'll discuss some of this more in detail in a later section.

Step 2: ESCs, Flight Control, and Power Distribution

This section will give a brief overview of how to connect ESCs and how to control the quadcopter using individual motor output.
First thing to notice when working with brushless motors is that there are three lines and they are all the same color. No your merchandise is not defective; this is by design. The ESCs work in a similar fashion to a maglev; the motion is generated by electromagnets being switch on and off at a high rate. The order in which the lines are connected will determine whether the motor spins clockwise or counterclockwise. And, you can reverse the direction of rotation by switching any two of the lines to the ESC.

When the ESCs are powered, there should be some LED blinking at a constant rate on each one. I am not sure of the significance of the blinking rate, differing rate may indicate differing charge levels on the cells within your battery, i.e. the LED will blink faster when your battery is lower; though, that is just speculation.

Typically, ESCs are designed to receive a Pulse-Width Modulated (PWM) signal into the data pin, the white one. Generating that signal can be handled by the flight controller and modified through included software. If you are using a standard microcontroller to control the multicopter, then you will be controlling the PWM explicitly in your code. This will include the use of timers and interrupts which I will discuss when reviewing the Hydra-X PAC 5210.

The batteries I bought were really nifty:

http://amzn.to/1FGu9qa

It's a two-pack and I got it while on sale; figured it would be nice to have less downtime between flights. The neat thing is the universal plug system that Venom includes with their batteries. Most batteries require a 4mm bullet connector or something similar, but the "universal plug system" lets the Venom batteries adapt to a couple different types of plugs. That being said, most ESCs are designed for use with bullet connectors. If you're getting a kit, all these details will be taken care of, but if you want to piece together a multicopter, you'll need to do some extra research and make sure you get a large enough battery and ESCs that can connect to it without too much trouble. For most, you'll just need some basic soldering skill, though you'll want to make sure you can get a solid connection without using too much solder.

If you are using a pre-built flight controller, the yaw/pitch/etc should already be encoded in the controller. If you have decided to design your own flight controller, the last picture above gives a description of the speed differentials between the four motors which will produce motion in each axis.
If motor 1 is North, motor 2 is East, motor 3 is South, and motor 4 is West, then:

Tilt forward is Pitch = motor 3 - motor 1; ie for increased pitch, motor 3 > motor 1

Turn counterclockwise is Yaw = (motor 2 + motor 4) - (motor 3 + motor 1); ie motor2, motor 4 > motor 1, motor 3, respectively

Rotate clockwise is Roll = motor 4 - motor 2;

You'll want to determine the minimum resolution that causes a noticeable change in the motor speed. For my setup, changing the pulse width by .2 milliseconds was the smallest noticeable change.

Step 3: Hydra X PAC5210

This section will give a brief overview of the PAC and the use of timers and interrupts.

And, I want to re-iterate here, all of my experience with embedded systems was on the Arduino micro, so I caution the reader to be aware that my perspective is not that of an industry professional or even an experienced developer. That being said, I am an amateur tinkerer and I give my abundant thanks to Max Roycroft and Jose Quinoñes for their invaluable efforts both in assisting myself and my group as well as in orchestrating the HydraX Competition in conjunction with The University of Texas at Dallas. Hopefully, this competition will be a building block towards more events that are engaging and allow students and industry professionals to meet and network.

The Hydra-X10 is a development platform equipped with the PAC5210 microcontroller. The PAC5xxx line of devices are what we call Power Application microControllers. In contrast to all other microcontrollers, this line of controllers from Active-Semi is designed to run on up to 52V input. That means, the user can drive nearly 52V worth of device load. It has 37 general purpose I/O pins including 14 PWM-enabled pins, and 11 Analog pins with Analog-to-digital conversion, two of which have Digital to Analog Conversion capabilities as well as some other functionality with which I am yet unfamiliar.

The evaluation setup did have some quirks, though. The HydraX10 platform is designed to run on at least 16V be default due to the circuitry that allows the 52V maximum. A "low-voltage" mode is available and described in the user manual, but that one does still require 12V to run, which means you will need an external power source to even start tinkering with it. That was a hassle for me until I decided which batteries to use. Of course, testing could not start until I had those components in order, but I would have liked to be able to tinker with the board itself without needing to find a power supply. To be fair, a pair of 9 Volts in series would have been sufficient if I just went and purchased the necessary connectors.

In any case, once the board is powered up, you'll need to download the third party CooCox IDE as well as their CoLinkEx USB Driver. The CooCox IDE had some significant memory issues and only de-allocates on shutdown; that might be a fundamental problem with Java; I try to stick to C myself. It's not a big issue, however, and when the IDE inevitably gives an error that it's out of memory, just close and re-open it.

Once you have the platform powered and the IDE initialized, the next step is downloading the libraries for the PAC5210 controller. The first time you start up the IDE, it will ask you to load libraries and lists some of the chips and boards for which it has access to libraries. In case you need to get back to this page, you can go to the "View" dropdown menu and select "Repositories." Look for Active-Semi on the list; it should be at the bottom. If it does not show up, click the refresh button in the top right of the window. After you click Active-Semi, choose the appropriate controller; I was using the PAC5210. The main libraries you will need are the "CMSIS Core and BOOT", as well as the "LIB", the Active-Semi Library. Once these are downloaded and added, you will have everything you need to jump into the next section.

Step 4: Timers, PWM and More...

This section will discuss using the PAC's clocks and timers to initialize a PWM output.

One of the great features of the PAC is the plethora of PWM outputs it has and the number of separate timers available to run them amongst other interrupt-driven functionality. The controller has an oscillator which runs at 4MHz and drives two independent clocks each of which can be used as a reference by the four timers in the internal PWM Engine. This engine uses the timers to generate its 14 PWM outputs.

In both the low voltage and high voltage modes, the board generates a 5V, 3.3V and 1.8V output for use in powering peripherals and components.

The above picture is an example of the code I use to set up PWM outputs. You can do the same for timerB, C and D. And you can use HCLK or ACLK for the clock config. And the clock input may be divided by up to 2^7.

You'll notice there is a block of code referring to a System Ticker. This ticker is an internal timer that can be used to trigger events at regular intervals. I use it to update the speed of all my motors every 10ms. The ESC only receives a new pulse width every 21 ms, so the 10ms speed update should always be in time to update the PWM output.

Step 5: Communication

This section will give an overview of the UART peripheral and how to set up rx/tx on the PAC5210.

The UART peripheral is connected to the rx/tx ports on the board located at PE2 and PE1, respectively. This is where you would connect the RF receiver or the bluetooth module. The board is set up to connect UART to USB by default so you can debug your communications code before moving onto wireless communication. There is a block in the middle of the HydraX platform which has 4 switches. The top two correspond to the UART linkage and by changing those two switches, you enable the PE1 and PE2 to communicate with the UART peripheral.

The first picture above shows the code I use to configure the UART. I also have some example calculations for the latch and fractional divisor, which are used to describe the system configuration to the UART peripheral.

After the configuration you need to define a Handler which is called whenever a UART interrupt is triggered. It must be named defined as: void UART_IRQHandler(void). This is what the system looks for when the UART interrupt is triggered. The next picture shows some more code Max walked me through.

The last step is to write the function that processes the input message. In the code above, this function is called uart_messgae_process(), but it can be named anything. You will want to have a switch or some other flow control structure that will execute uniquely depending on what data was received. At the end of the processing, you should generate a return message to give feedback on what happened. Both the incoming and outgoing messages should have a "start message" byte that tells whichever device is receiving where the start of the message occurs. Next, a status message should be included, followed by whatever data you are sending. Finally, some data verification/validation method should be implemented to ensure the transmission was not corrupted en route. I used an 8-bit sum of the message as a checksum and saved it in the last byte of the message.

The next part of communication is getting the wireless transceiver set up to send and receive messages in the format you described in your UART code. There are plenty of guides available for writing Bluetooth apps and the majority of the transceiver message processing will be analogous to the UART message processing, so I'll leave you to customize that part.

Step 6: Concluding the Build

With the software all set up, what remains is the circuitry. The evaluation kit comes with a prototyping board which you can use to orient your connections before connecting to the HydraX Platform.

BE AWARE: the HydraX Platform has no circuitry to mitigate current overloads, so you'll want to make sure all your connecting wires are housed to prevent accidental crossing of Input and Outputs. If you do get a short THE BOARD IS DEAD. I would recommend against applying power again; some of the components may be salvaged from a fried board.

Of course, before you can do your connections, you will need to decide which pins to use. Keep in mind that a multicopter is very susceptible to changes in its center of gravity, so you want to make sure every component is counterbalanced as evenly as possible. Trim down your wires until you have a compact arrangement which will not negatively influence the airflow around the multicopter. Last, but not least, make some decals, have some fun and get ready to impress all the ladies, 'cause you've got wings! Four of them.