Quadcopter Controller Rev 1

As mentioned before I made a few mistakes on the first revision of the Quadcopter controller board. Although I was able to modify it and get it up and running, I decided to spin another board and do a second revision to fix the things I learned with the first revision.

The changes on this revision include:

  • Change the 5V Regulator (U3) to a TO-220 package LM7805
  • Increase the hole size on the power connection since the wire I used wouldn’t fit.
  • Change the Accelerometers from the Invensense IDG-500 and ISZ-500 analog to the Invensense ITG-3200
  • Change the Gyroscope from the Analog Devices ADXL 335 Anaglog gyroscope to the ADXL 345 Digital gyroscope
  • Since the sensors are digital I was also able to remove the precision voltage reference for the ADC.
  • I also fixed up the footprint on the compass. The newer version of the datasheet for the HMC5883 said that it required that no power traces run underneath the chip and that there in no copper planes underneath so I have removed both.
  • I removed the level shifter on the PWM lines that control the motors since I found that the ESCs would work with 3.3V logic.
  • I also added a few more testpoints and an LED that is controlled by the microcontroller

Once I build up the new boards I will post picture of the new board built up but here is a picture of thelayout an the schematics:


Schematic
Quadcopter Controller R1.0

Andrew

Quadcopter Wireless UART Gateway

Currently I am using a USB to TTL Serial cable to communicate between the computer and the microcontroller. This acts as a tether on the quadcopter and would be much better if it would be wireless to eliminate the leash on the quadcopter. To do this I designed a board that would stack onto to main board plugging into the UART port and would connect the UART port from the microcontroller to a Digi Xbee module like shown below:

These modules offer an easily configuralbe point to point wireless UART gateway. SnceI would need two modules; one on the quadcopter and one connected to the computer I also designed the board to e populated to connect up to a computer’s USB port. To do this I connected the UART port on the Digi module to an FTDI FT232RL USB to Serial chip and have that connect to a male USB A port which can then plug into the computer.

Schematic:
Wireless UART Gateway

Andrew

Quadcopter Construction

As mentioned before there were some modifications that were needed to make the first revision of the quadcopter controller work. I replaced the original 5V regulator with an LM7805 and I removed the level shifter on the PWM and connected the PWM lines up to the headers with wires. I also bought a Sparkfun Electronics breakout board with an Analog Devices ADXL 345 3-axis digital accelerometer and Invensense ITG-3200 3-axis digital Gyroscope, connected them to the I2C bus on the board, and hot glued the breakout board to the main PCB. The modified PCB is shown below:

I also bought a quadcopter frame, motors, ESCs and propellers from Aeroquad.com. Shown below is the assembled quadcopter.

Andrew

Quadcopter Software Overview

With any microcontroller project, you don’t get very far without software, my project is no different. In this section I will describe how the software to date works.

The software can be broken down into 3 main parts:

  • The Command Line Interface
  • The Kalman Filter
  • The Control Loop

The Command Line Interface

To interface from the PC to the microcontroller I implemented a simple command line interface to be able to send commands to the microcontroller and get information from it through a COM port Terminal program such as Tera Term. I chose to do things this way so I would not need to write a second program on the PC to interface to the microcontroller. This way quadcopter can easily communicate with any computer that supports the FTDI Virtual COM Port Drivers, which looks to be everything from Windows, Mac, Linux and even Android. When a character is typed into the COM port terminal it gets sent out the COM port in this case the USB port, which goes to an FTDI USB to UART chip. For convenience I use one of these FTDI USB to Serial cables:

Click to access DS_TTL-232R_CABLES.pdf

This then goes to the UART port on the microcontroller and causes an interrupt. In the interrupt service routine the received character is then sent back out the UART back to the computer, this echos the character back causing it to show up in the COM port terminal, the character is then stored in an array and the microcontroller waits to receive another character. If the microcontroller receives a carriage return from pressing enter on the keyboard the string is compared to a list of commands and if it matches a command it executes the code for that command. The array is then purged and the microcontroller waits to recieve another character.

Currently the software only supports very basic commands such as ones to set and store new PID constants in the EEPROM, Start and Stop the PID Loop control. Although this list may grow in the future.

I also used this interface to get the sensor and Kalman Filter data to do the graphs in previous blog posts.

The Kalman Filter

The next main part of the software is the Kalman Filter. The Kalman Filter is a mathematical method for combining multiple inaccurate measurements and getting a more accurate measurement. In my system I have an accelerometer and a gyroscope both which have their own quirks which make them inaccurate on their own. The accelerometer measures linear acceleration in 3 orthogonal planes (X, Y and Z). Since the earth provides 1G of acceleration towards its surface this can be uses as a tilt or angle sensor by taking the Tangent of  the two linear axis’ you want to get the angle between. his works great as long as there is no vibration or other linear acceleration that would affect the reading. I also have a gyroscope which gives angular velocity in 3 orthogonal rotational axis about the sensor. If velocity is integrated over time one can calculate the position.  The only problem with integrating the output of the gyroscope is that due to manufacturing process of the sensor they are not ideal and the output does not go to 0 when the sensor is stationary this causes the output of the integrator to drift slowly increasing the error over time. These can be seen in the graph below. The data was taken with the quadcopter propellers running so the accelerometer (Green) picked up all the vibration from the propellers and motors, which makes the accelerometer data on its own useless. The gyroscope (red) on the other hand had no problem with the vibration but you can see over time it had a downward trend due to the integrator drift. The output of the Kalman Filter has the best of both worlds it has little noise like the gyroscope but it doesn’t drift like the accelerometer.

The Control Loop

Currently to control the angle of the Quadcopter I am using a PID or Proportional, Integral, Derivative controller. I am currently experimenting on it in one axis and once that is working well it should be easy to implement in other axis’. Right now I just want the quadcopter to maintain an angle of 0°. Shown below is the basic block diagram of a PID control loop.

A control loop has 4 main signals (Shown above):

  • Setpoint: Where you want tobe.
  • Output: Where you currently are.
  • Feedback: Usually sensor data transduced from your output.
  • Error: How far you are from where you want to be.

In a PID control loop you have a set point which in my system I want the quadcopter to maintain an angle of 0° so it remains flat o the set point is 0°. I can measure the angle from the data of the accelerometer and gyroscope which has one through the Kalman filter as described above; this provides the feedback. The feedback angle is subtracted from the set point to product the Error which goes to the PID controller. The error is then multiplied by KP which is the proportional gain constant, the derivative of the error which essentially is the change in the error divided by time (Current_Error – Prev_Error)/Time_Step is multiplied by KD; the derivative gain constant, and the integral of the error is multiplied by KI; the integral gain constant. The output of the proportional part is added to the output of the derivative and integral parts and then this goes to the system as the control signal; in my system this is the throttle signal to the motors which adjusts the output.

Essentially what the three parts of the system; proportional, derivative and integral do are:

  • Proportional:   Corrects current error; the larger the error, the larger the output of the proportional section which moves the output toward the setpoint as it moves to the setpoint the output of the proportional section gets smaller slowing the output down.
  • Derivative:  Corrects future error; the Derivative takes the change in error overtime which in my system is essentially the angular velocity of the output. Now if the angular velocity was high when the error is near zero the output will just overshoot causing oscillation. The derivative section slows down the output thus reducing overshoot and oscillation.
  • Integral: Corrects Previous error; the Integral adds up error over time so if there is  error in one direction for a long period of time the output of the integrator will continually add up until the output reaches or passes the set point. his can be used to eliminate steady state error where the system is close but not at the set point and not moving so the output of the proportional section isn’t enough to overcome the force holding it back such as friction or gravity and since it is not moving the derivative is zero and therefore the derivative section does not help. Overtime the error will add up in the integrator increasing the control signal and moving the system to the set point.

Andrew