Sunteți pe pagina 1din 22

Control Units & Experimental Results 1

Documentation for the ESC, IMU and Arduino IDE Code


for the Computer Systems

Morones, Rafael ID#006384220


EE 400D Senior Design & Project
Division: Computer Systems
Project: TinyQuad

Table of Contents

ESC AND IMU CONTROL GUIDELINES AND EXPERIMENT RESULTS ..................................................... 2

ELECTRONIC SPEED CONTROL (ESC) .............................................................................................................. 2

THE INERTIAL MEASUREMENT UNIT (IMU)................................................................................................. 8

THE ARDUINO IDE AND CODE EXAMPLE .................................................................................................... 12

EXPERIMENTAL RESULTS ................................................................................................................................ 16

REFERENCES: ........................................................................................................................................................ 22
Control Units & Experimental Results 2

ESC and IMU Control Guidelines and Experiment Results

During our experiment, after many trial-and-errors, our group (the TinyQuad), has gone

through two quadcopter frame-bodies consisting of three different microcontroller designs: The

Apollo mini-quadcopter, the TinyDuino mini-quadcopter with a PLA plastic frame, and the

Arduino Nano mini-quadcopter with the same PLA plastic frame.

There will be a discussion regarding how to use the ESC and its operations, the functions

of the IMU, and the Arduino code to control all of these components.

Figure 1. (Left) Arduino Nano used for Apollo. (Right)TinyDuino originally used with the PLA plastic frame model.

Electronic Speed Control (ESC)


In order to control all our motors for a suitable and effective operation time with each of

the quadcopter models, every operating motor requires its own Electronic Speed Control (ESC)

component. First, to understand an ESC, it must be stated that it doesn’t interpret mechanical

motion like a servo, but instead through varying the switching rate of a network of field effect

transistors (FETs). The fast switching of FET, allows for a smooth and precise variation of motor

speed (Brushed Motor, 2008).

Our ESCs run with DC voltage and require PWM signal controllers for our electrical

motors. It is important to utilize only the PWM signal controllers when connecting the motors to

the Arduino. This is necessary since the Pulse-width modulation (PWM) is a better controlling

technique when dealing with power-to-inertial electrical devices, such as in the case of our
Control Units & Experimental Results 3

motors. The PWM uses a digitally-generated rectangular-pulse waveform to employ the

switching between the supply and the load voltage. This ON and OFF (or HIGH and LOW)

switching is measured as a frequency in hertz (Hz) per time (in milli-seconds), and varies on the

duty cycle desired. Since the power supplied will be greater depending how long the switch stays

HIGH or ON, the corresponding duty cycle will enable more power into the motors. In order to

incorporate the PWM technique, the Arduino uses its clock and counter to increment the

frequency of the duty cycle periodically, and reset it at the end of every PWM period.

Additionally, the Arduino uses time proportioning to identify and compare the states of the

counter value and reference value, as a proportion to each other. It uses an analog comparator to

assign their proportionality, and allows only discrete steps when changing the PWM output state

from LOW to HIGH and vice-versa (Arduino PWM, 2012). Ultimately, this smooth mechanism

allows the Arduino to have a perfect control over the quadcopter’s ESC and motors.

Figure 2. PWM’s duty cycle in an Arduino to control the motors (Arduino PWM, 2012).

Generally, the ESC accepts a nominal servo input of 50 Hz PWM signal with a varying

pulse width from 1ms to 2ms. This is important, during the controls command, for the

calculating and ultimately the deciding process of which speed value is high enough to make the

quadcopter hover, and which speed is high enough to make it fly up high. At a 1ms width pulse,
Control Units & Experimental Results 4

the ESC turns off the DC motor attached to its output. At a 1.5ms pulse-width input signal, the

ECS runs a 50% duty cycle output signal which is interpreted at half of the maximum threshold

speed for the motors. Lastly, at a 2.0ms input signal, the ESC runs at 100% duty cycle and

provides the motors 100% of its maximum speed (Brushed Motor, 2008).

Figure 3. The ESC utilized to control the motors.

The ESC will provide the necessary command tool and communication for the

instructions given to the motors regarding their change of speed. The ESC is essential in

allowing the control systems representative to control the variance of the speed and altitude that

the quadcopter will undergo.

The ESC our group is using consists of three different groups of leads/connections:

1. The power connections/leads


2. The Arduino interface connection/leads
3. The motor control connections/leads

First, discussing the power connections, it is a basic power concept of positive and

negative leads draining their necessary power from the Lithium-Polymer (LiPo) batteries.

Basically, the red lead receives the positive current while the black lead receives the negative

current.
Control Units & Experimental Results 5

Figure 4. ESC connections with its corresponding LiPo Battery.

Second, the Arduino interface lead is the main control function of the ESC. This lead is

the interface to the Arduino and receives all the commands as instructed in the IDE code.

Although there are 3 connections in this lead, only two are being used (black and white). The

black cable is connected to the ground provided by the Arduino GND pin. While the white cable

is the main interface cable which receives all commands given in the IDE code. It is connected to

any of the Arduino’s PWM Digital Output Pins (Dpin). The red cable in this Arduino interface

lead is not being used since it may create harm to our Arduino USB port and possibly the entire

software board. The red cable would be connected to the 5v pin-out from the Arduino and this

together with the LiPo battery (as previously explained) could fry the entire Arduino port;

henceforth it is essential that this interface be connected to ground at all times (Fun Projects,

2012).

Figure 5. Image portraying clear connection using Arduino Uno (Fun Projects, 2012).
Control Units & Experimental Results 6

Figure 6. ESC connected to our Arduino Nano.

Lastly, the motor control connections are the interface between the ESC and the motors.

This lead includes of 3 connections which each control a specific rotation control for the motor.

Our ESC came with all non-color coded cables (all in red), but we managed to figured out their

identity through observation from given examples and trial and error. There is a desired order

which will cause the motors to rotate in a counterclockwise motion causing the propeller to lift-

off on the downward direction. This order of the ESC would consist of the yellow cable(center)

connected to the leftmost connection on the motor, then the black cable (right) connected to the

center connection on the motor, and finally the red cable (left) connected to the rightmost

connection on the motor. If the yellow and black cable were to be swapped, then the motor

would rotate in a clockwise direction. As a result, this causes the propellers to shoot-up air in the

upward direction which it’s undesired for our flight purposes.

Figure 7. A similar ESC connected to a motor for the sake of color representation (FunProjects, 2012).
Control Units & Experimental Results 7

In conclusion, the order of operation for each test flight it is the Arduino is connected via

USB to a computer which will provide all necessary control instructions, then the Arduino will

provide the ground pin and interface for the ESC. Then, the ESC is powered by the LiPo battery,

which will also power all the motors, and the ESC will control the speed and the direction of the

rotation for all motors. For our flight purposes and for flight symmetry, two motors in the x-axis

are made to rotate in the clockwise direction while the other two motors in the y-axis are

instructed to rotate in opposite direction; providing an equal power lift-off during each flight.

Figure 8. Image showing all ESCs connected to each motor in our first Apollo prototype.
Control Units & Experimental Results 8

The Inertial Measurement Unit (IMU)


The next factor to take for consideration was the inertial measurement unit (IMU) which

would be important for the balancing and flight controls of the quadcopter. The Pololu MinIMU-

9 v2 is a compact (0.8″ × 0.5″) board that combines a 3-axis gyroscope, a 3-axis accelerometer

and 3-axis magnetometer to form a sophisticated inertial measurement unit. This allows the IMU

to provide 90 degrees of freedom during flight operation due to its triple elements per each axis.

The MiniIMU s operates at voltages below 3.6 V, which made interfacing difficult for our

Arduino microcontrollers which normally operates at 5 V. However, The MinIMU addresses

these issues by incorporating additional electronics, including a voltage regulator and a level-

shifting circuit, while keeping the overall size as compact as possible (MiniIMU-9, 2012).

Figure 9. (Right)The Pololu MiniIMU-9. (Left) Interface connections (MiniIMU-9, 2012).

The IMU can also be separated in a few parts for their own analysis. First, the

accelerometer is an electromechanical device that measures different acceleration forces. The

Pololu 3-axis accelerometer reads dynamic forces that cause a change of speed in either the x-

axis, the y-axis or the z-axis. This accelerometer also uses PWM signals to detect the change of

speed due to the difference in the duty cycle. The next component is the 3-axis magnetometer
Control Units & Experimental Results 9

which measures the magnetic fields applied to a center of gravity. This component will measure

the negative and positive X, Y and Z direction/gradients (Beginner’s Guide, 2012). The

MinIMU-9 v2 features improved magnetic sensing resolution and a wider acceleration

measurement range (from ±2g to ±16g) (MiniIMU-9, 2012). Together with the accelerometer, the

magnetometer can measure sudden changes of acceleration in free-fall scenarios or right before a

crash, and protect and guide the TinyQuad away from harm.

Figure 10. Accelerometer/Magnetometer: (Left) Schematic (Right) Circuitry (MiniIMU-9, 2012).

Second, the gyroscope is a device that controls the flow of movement by measuring the

changes in displacement by applied forces in every direction of a gradient. These characteristics

are similar to the method that a digital compass uses to locate its location in the center of a

specific axis. The 3-axis gyroscope is able to measure every degree of movement by a tolerance

of +2 degrees as it was previously described. In addition, the gyro uses a higher resonant

frequency that makes it more resistant to audio noise and vibration from exterior devices. In this

manner, the 3-axis gyroscope and the implemented compass are able to keep our quadcopter in a

steady, balanced position; always remaining within the center/origin of the X-Y-Z axis. This

allows our TinyQuad to fly in a straight and drifting-free manner (A Guide IMU, 2012).
Control Units & Experimental Results 10

Figure 11. Gyroscope: (Left) Schematic (Right) Circuitry (MiniIMU-9, 2012).

Lastly, the I²C interface accesses nine independent rotation, acceleration, and magnetic

measurements that can be used to calculate the sensor’s absolute orientation. Moreover, the I2C

interface of the IMU involves four different pins: the Vin power pin, the Ground (Vdd) pin and

the SCL and SDA communication pins. The SDA pin is the data line of the IMU which receives

and transmit data to the Arduino. Then, the SCL pin is the clock line that will control the timing

which the IMU is receiving and transmitting all its data (MiniIMU-9, 2012). The IMU will be

connected to the analog pins (Apin) in the Arduino. It uses all the PWM signals from the

Arduino together with its own clock signal to generate the data transmission and receiving.

Therefore, the data used to calculate the orientation and speed changes of the quadcopter is

constantly being exchanged among these two units; for acquiring the most precise results. Also,

its 0.1″ pin spacing makes it easy to use with a standard solder less breadboard which is

important factor to provide us with ease in compatibility (Wire Library, 2012).


Control Units & Experimental Results 11

Figure 12. SCL and SDA interface with Arduino analog pin-out (Apin) (MiniIMU-9, 2012).
Control Units & Experimental Results 12

The Arduino IDE and Code Example


As explained, the ESC works similarly as to the power transmitted from a servo yet

instead of associating the system as a mechanical source, it uses fast switching through several

FETs. This feature is quite essential since it requires an adept microcontroller system to control

the ESCs and ultimately each of the motors. It also must be noted that this “control code” is

simply the instructions for the TinyQuad in an open-loop context. During this entire operation,

the TinyQuad is only controlled to hover or fly for a small amount and will not give any

feedback; only follow the given instructions. As previously specified, all this ESC-to-motor

functions are all control with the Arduino processor board. The code, written in the Arduino 1.1

IDE software, follows easy coding (Brushed Motor, 2008).

To start off, we start by retrieving files and data from the library. An example is the

servo.h library used for motor identification. The next step, after loading from the necessary

libraries, is to start the initialization of the class names. This last step is important to organize

each motor used, and to identify it with a specific name that would be used to call during flight

operations. Examples of the code used are provided below for each previously given step.

Calling the Libraries used to extract data for necessary files:

#include <Servo.h>
#include <SoftwareSerial.h>

Initializing the motor names to be used while in operation:

// These are our motors


Servo L_Motor;
Servo R_Motor;
Servo F_Motor;
Servo B_Motor;
Control Units & Experimental Results 13

Assigning each motor to the digital PWM pins on the Arduino:

// Put the motor’s locations to Arduino (Motors assigned to PWM Dpins)


L_Motor.attach(3);
R_Motor.attach(9);
F_Motor.attach(10);
B_Motor.attach(11);
delay(3000);

Figure 13. Screenshot of the Arduino IDE compiler window

Continuing with the code, we assign these class names and objects to a specific digital

pin (Dpin) to receive and ask for instructions to the ESCs and ultimately the motors. For our

benefit, the only Dpin used for the Arduino Nano are the PWM pins which are pin3, pin4, pin 9

and pin 10, among others.

These are our libraries to retrieve data when connecting to the Arduino and the IMU:

#include <Wire.h> //Pinout location library


#include <Servo.h> //Motor control files
#include <SoftwareSerial.h> //Command files
#include <L3G.h> //Gyroscope library content
#include <LSM303.h> //Accelerometer and compass library files
Control Units & Experimental Results 14

The motors assigned are getting ready to be armed for flight operation:

printf("Arming");
setSpeed(L_Motor,10);
setSpeed(R_Motor,10);
setSpeed(F_Motor,10);
setSpeed(B_Motor,10);

Once the set-up code is compiled and run through the Arduino software board, the next

essential control command begins. The control of the quadcopter during flight operation is

managed through a “command window,” serial monitor display, where the Arduino

communicates to the ESCs in order for an effective motor control. It is imperative to have the

correct communication settings, starting with assigning the communication port to Com 4. The

next communication step is setting the communication range (com range) to a value of 14400

baud or 9600 baud. The baud unit used for communication values refers to symbols per

second or pulses per second; also known as baud rate or modulation rate (Brushed Motor, 2008).

Lastly, the line ending setting must be selected for the Newline interface. Once all these settings

are selected correctly, the speed control begins.

The next step is to declare that the speed for each motor will be specified on the “serial

monitor.” These values will vary from a number ranging from 0 to 180 which correlate to the

pulse-width input signal value from the ESCs as previously stated. The lowest speed number

accepted by any of the ESCs is 63 being due to its equivalence to the pulse width of 1.25ms of

the ESCs. The highest speed number accepted by the ESCs is 180 also due to its correlating

value to pulse width of 2ms or 100% duty cycle of the ESCs. The speed value of 10 will always

cancel all motor functions (representing the 1ms pulse width value), as well as inputting any

other value lower than “63,” since not enough power is getting through for the duty cycle

necessary (Fun Projects, 2012).


Control Units & Experimental Results 15

Therefore, the range of speed varies in functionality desired are listed as: the speed value

of 63 being starting and low speed. Then, a speed value between 70-110 is considered to being

about the hovering speed (greater than half of the maximum duty cycle). And finally, a speed

value between 120-180 is being considered the high-speed to carry the quadcopter high up for a

fast, flight control. Finally, the correct use and programming of all these control commands will

allow for a successful flight time.


Control Units & Experimental Results 16

Experimental Results
Now that there has been a thorough discussion about all the control components being

used, I will start explaining the results our group got at each stage of the controls part, and how

changes were made accordingly.

Once our group received the ESCs and the rest of the control components, it was

important to test them. At first, we started with a single motor control at a time. There were some

complications with the ESC communication to the motors initially. Yet, once we adjusted the

communication settings to the correct modulation range, the ESCs started working properly. At

this time, we started to control two motors a time.

Figure 14. Testing three of the motors (Note: third motor has no propeller due to limited space)

At this moment, we realized that the minimum pulse-width speed value was different between

two of the ESCs. One had its minimum speed value at “63,” while the rest had their minimum at

the speed value of “64.” Therefore, we had to learn to control all the ESCs with this difference.
Control Units & Experimental Results 17

Figure 15. Instructing the motors to rotate with the minimum pulse-width value

Once we manage to work with up to three motors, we then attempted to control all four

motors at a time. Here was where we encountered our first issue: the many connections of the

ESCs scattered around were causing shorts and communication interferences when they would

touch each other. We did not have a frame to mount all the motors and their corresponding

ESCs, which could eliminate the excessive wires entanglement causing all the shorts. This led us

to the building of the Apollo prototype quadcopter with the Arduino Nano mounted a small

breadboard.

Figure 16. (Left) Our first quadcopter frame: The Apollo prototype. (Right) Final Apollo model.

However, there was another issue: the interface cables from the motors were too thin and

would keep getting loose when we would connect them to their ESCs. In order to solve this, we

soldered an extension wire with a 3-pin header to every one of the motor control cables. This
Control Units & Experimental Results 18

proved to make the connections much easier and easy to identify between the ESC and the

motors, and good communication signal was established.

Figure 17. Extension Cable with 3-pin Header for our motors (Fun Projects, 2012).

Now that we got all the communications running smoothly, we focused on the test flight

for the TynyQuad using the Apollo quadcopter frame with cut-out detailed arms. During our test,

we found that the control of the quadcopter was almost futile since we didn’t have the IMU

component to balance and control the orientation of the quadcopter during flight. We were able

to get the Apollo to hover while it was tethered to an extension we created between two tables.

Yet, it would drift off course since it had no guidance to provide it with direction or any

feedback; this was after all just an open-loop context experiment.

Figure 18. Testing the flight control and balance without the IMU using the tethered Apollo
Control Units & Experimental Results 19

This then led us to the creation of our TinyDuino PLA plastic frame quadcopter model.

The TinyDuino was a much smaller version of the Arduino microcontroller and it was slightly

smaller than the Arduino Nano. It came with various tiny shields: one with an USB connection to

program it, another with a coin cell battery holder for power, and the protoboard shield for

prototyping. After we finished the building of this model, we had a circular slot to place the

TinyDuino processor board.

Figure 19. Final TinyDuino PLA Plastic quadcopter model with unconnected ESC connections

Then, several difficulties came when we had to solder pin-outs for the protoboard shield:

the pin spacing was much too small and there were not enough output Dpins for our

communication. We manage to solder all the pin-out regardless of the irregular spacing. We were

also able to accommodate the changes for the ESCs Dpins to the limited number that was

provided by the Tiny protoshield. Yet, we then encountered the worst problem: the only Dpins

for the ESCs interface that were PWM signal outputs were not working properly. None of the

PWM DPins would control the ESCs or motors, and we didn’t have any more TinyDuino shields

to test for flight purposes. Due to this severe problem, we had to dismiss the use of the

TinyDuino processor and returned to using the Arduino Nano board.


Control Units & Experimental Results 20

Figure 20. (Left) TinyDuino protoboard pinouts. (Right) Protoboard used (TinyShield, 2012).

Our only choice now was to find a way to incorporate the TinyDuino PLA plastic frame

model with the Arduino Nano. The best way to connect these two components was to use a

circular PCB board and solder all the pins of the Arduino Nano.

Figure 21. Circular PCB Board used when we replaced the TinyDuino with Arduino Nano

We used header pins to attach the Nano for easy removal. We then created a bridge to

another set of header pins where the output interfaces would be connected for an efficient

communication among all the control components. There was also a set of header pins for the

IMU-Arduino connections and one for the Xbee-Arduino communication. Lasly, an individual

set of header pins for the ground connection for all the devices.
Control Units & Experimental Results 21

Figure 22. Male and female header pins (Fun Projects, 2012).

Our last part for the control unit was to continue the flight testing with this new Arduino

Nano PLA plastic frame model. The communication among all the control components was

smoother and easy to control, especially with the Xbee communication. As we executed the

flight commands from the open-loop context, we realized it was time to make a good use of the

IMU and start controlling the TinyQuad flight direction. This is all covered and discussed in a

separate, more complex document that describes all the details needed for the final control of our

TinyQuad.

Figure 23. Final Arduino Nano PLA plastic quadcopter model


Control Units & Experimental Results 22

References:

1. A Beginner's Guide to Accelerometers. (n.p.), (n.d.). Retrieved December 11, 2012, from
http://www.dimensionengineering.com/info/accelerometers

2. A Guide to Using IMU (Accelerometer and Gyroscope Devices) in Embedded


Applications. Starlino Electronics. (n.p.), (n.d.). Retrieved December 10 2012, from
http://www.starlino.com/imu_guide.html

3. Arduino - PWM. ( n.p.), (n.d.). Retrieved December 10, 2012, from


http://www.arduino.cc/en/Tutorial/PWM

4. Brushed Motor Control through ESC – Arduino. (2008). Retrieved November 29, 2012,
from http://www.polecataero.com/wp-content/uploads/2008/01/esc.pdf

5. Fun Projects of Various Types: Arduino. (2012) Retrieved November 10, 2012, from
http://techvalleyprojects.blogspot.com/2012/06/arduino-control-escmotor-
tutorial.html

6. "MinIMU-9 V2 Gyro, Accelerometer, and Compass." Pololu. (n.p.), (n.d.). Retrieved


November 29 2012, from <http://www.pololu.com/catalog/product/1268>.

7. TinyShield Proto Board. (2012). Retrieved December 9, 2012, from http://tiny-


circuits.com/products/tinyduino/asd2002/

8. Wire Library – Arduino. Retrieved December 10, 2012, from http://www.arduino.cc/en/


Reference/Wire

S-ar putea să vă placă și