Difference between revisions of "S14: Tricopter"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Algorithm type 2: Adjusting motor speeds in response to orientation and angular velocity)
(Algorithm Type II: Adjusting motor speeds in response to orientation and angular velocity)
 
(176 intermediate revisions by the same user not shown)
Line 1: Line 1:
=== Grading Criteria ===
 
<font color="green">
 
*  How well is Software & Hardware Design described?
 
*  How well can this report be used to reproduce this project?
 
*  Code Quality
 
*  Overall Report Quality:
 
**  Software Block Diagrams
 
**  Hardware Block Diagrams
 
**:  Schematic Quality
 
**  Quality of technical challenges and solutions adopted.
 
</font>
 
 
 
== Code name Cerberus ==
 
== Code name Cerberus ==
 +
[[File:CmpE146_s14_tricopter_Cerberus-Blake.jpeg|400px|center]]
  
 
== Abstract ==
 
== Abstract ==
Line 17: Line 6:
  
 
== Introduction ==  
 
== Introduction ==  
[[File:S2014TRI2.png|400px|thumb|right|Fig 1.Orientation]]
+
[[File:S2014TRI2.png|280px|thumb|right|Fig 1.Orientation]]
 
Multrirotor unmanned arial vehicles (UAV), have recently grown in popularity due to the reduced cost in parts. A highly agile variation of these multirotor copters are the tricopters. Tricopters apply equivalent principles of balance and orientation to that of traditional multirotors. Unlike symmetrical multirotors, tricopters require an additional servo to counteract yaw. Roll is controlled exclusively by the front left and right motors, where pitch is adjusted through a combination of all three.
 
Multrirotor unmanned arial vehicles (UAV), have recently grown in popularity due to the reduced cost in parts. A highly agile variation of these multirotor copters are the tricopters. Tricopters apply equivalent principles of balance and orientation to that of traditional multirotors. Unlike symmetrical multirotors, tricopters require an additional servo to counteract yaw. Roll is controlled exclusively by the front left and right motors, where pitch is adjusted through a combination of all three.
<br/>
+
<br />
<br/>
+
<br />
 +
<br />
  
 
== Objectives ==                                                                           
 
== Objectives ==                                                                           
Line 33: Line 23:
  
 
== Schedule ==
 
== Schedule ==
Show a simple table or figures that show your scheduled as planned before you started working on the project.  Then in another table column, write down the actual schedule so that readers can see the planned vs. actual goals.  The point of the schedule is for readers to assess how to pace themselves if they are doing a similar project.
 
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 74: Line 63:
  
 
== Parts List & Cost ==
 
== Parts List & Cost ==
Give a simple list of the cost of your project broken down by components.  Do not write long stories here.
 
 
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 126: Line 113:
  
 
== Design & Implementation ==
 
== Design & Implementation ==
The design section can go over your hardware and software design.  Organize this section using sub-sections that go over your design and implementation.
+
 
  
 
=== Hardware Design ===
 
=== Hardware Design ===
Discuss your hardware design here.  Show detailed schematics, and the interface here.
 
  
=== Hardware Interface ===
+
<br clear=all>
In this section, you can describe how your hardware communicates, such as which BUSes used. You can discuss your driver implementation here, such that the '''Software Design''' section is isolated to talk about high level workings rather than inner working of your project.
+
 
 +
==== Construction ====
 +
 
 +
All components were attached to the tricopter frame. The SJOne board and Sunkee 10DOF board were both bolted to the center section of the frame. The frame was lacking a mounting point for the ultrasonic sensor, so it was taped on.
 +
 
 +
All three motors were attached to the frame with a motor mount and two screws. The servo was mounted at a dedicated servo mount point provided on the frame. The motor speed controllers were attached with zip ties, due to a lack of good mounting options both on the frame and on the speed controllers themselves. Wires for PWM control and power were routed along the tricopter arms, and also attached with zip ties.
 +
 
 +
[[File:CmpE146_s13_tricotper_motor.jpg|500px|thumb|left|Fig 2.Motor Attachment]]
 +
 
 +
[[File:CmpE146_s13_tricotper_built_frame.jpg|500px|thumb|right|Fig 3.Built Frame]]
 +
 
 +
<br clear=all>
 +
 
 +
==== Interfaces ====
 +
----
 +
[[File:CmpE146_s14_tricopter_Total_wiring_diagram.png|500px|thumb|center|Fig 4.System Wiring]]
 +
<br clear=all>
 +
 
 +
===== IMU =====
 +
----
 +
[[File:CmpE146_s14_tricopter_imu_hardware.jpg|200px|thumb|left|Fig 5. IMU mounted upside down on Tricopter]]
 +
<br />
 +
The Inertial Measurement Unit (IMU) we used is the SUNKEE 10DOF. It has an Accelerometer, Gyroscope, and Barometer accessible via an I2C bus. For our project we only used the Accelerometer and the Gyroscope. I2C uses only two signals: data and clock. We used I2C port 2 on the SJOne board to interface with the IMU.
 +
 
 +
The IMU is mounted upside down on a perforated prototyping board. Cables connect 3.3V power, ground, data, and clock lines to the IMU. The 3.3V supply pin on the SJOne board was used to power the IMU for sake of convenience.
 +
 
 +
<br clear=all>
 +
 
 +
===== Ultrasonic Sensor =====
 +
----
 +
[[File:CmpE146 s14 tricopter ultrasonic.jpg|150px|thumb|left|Fig 6. Ultrasonic Sensor]]
 +
<br />
 +
Originally, height for the tricopter was to be determined using the Z-axis of the accelermoter. However, this method proved inaccurate. A HC-SR04 Ultrasonic sensor was chosen to determine the height. Height was determined by measuring the time delta from the echo's rising edge to the falling edge. To ensure accuracy in a multi-threaded environment, hardware timers and interrupts were used to track this timing interval. Time was kept by marking a timer register on the rise of every system clock edge. Once timing was captured it was converted from system clicks to seconds using the formula:
 +
<br clear=all>
 +
                                                    read_height = ((.120 * total) / 148);
  
=== Software Design ===
+
===== Motors/Servo =====
''
+
----
--
+
[[File:CmpE146_s14_tricopter_pwm_signal.jpg|300px|thumb|left|Fig 7. PWM signals sent to servo and ESCs]]
  
Show your software design. For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level.  Do not show the details of the code.  For example, do not show exact code, but you may show psuedocode and fragments of code.  Keep in mind that you are showing DESIGN of your software, not the inner workings of it.
+
[[File:CmpE146_s13_tricotper_wiring_diagram_esc.png|300px|thumb|right|Fig 8.ESC Wiring]]
  
--
+
The motors are controlled using electronic speed controllers (ESC). The motors themselves are brush-less out-runner motors. The ESCs are controlled using the servo motor PWM interface. This interface expects a high pulse every 20 milliseconds. The width of this pulse dictates the motor speed. When the pulse is 1ms wide, the ESC interprets this as throttle of 0%. When the pulse is 2ms wide the ESC interprets this as a throttle of 100%.
''
 
  
 +
The ESCs will not start running until the throttle position is set to 0% until the ESC stop its start up beeping routine. This is a safety feature that prevents the motor from spinning up unexpectedly. Our software sets the throttle position to 0% when it boots, and it holds this position for 5 seconds before spinning up the motors. This is enough time for the ESCs to complete their start up beep sequence.
  
Major Tasks:
+
The servo motor takes the same PWM signal. A pulse width of 1ms tells the servo to be rotated fully one direction, and a pulse width of 2ms has it rotated fully the opposite direction. Our software sets this signal to 46% at boot, which we determined was the most level position.
Orientation  (incl. sensor data acquisition, orientation calcs)
+
<br clear=all>
  
Motor Control (incl. motors & servo control, fail safe, timer)
+
=== Software Design ===
  
=== Orientation ===
+
==== Orientation ====
 
----
 
----
 +
[[File:CmpE146 Sunkee 10dof.jpg|250px|thumb|right|Fig 9. Sunkee 10dof]]
 
The orientation is calculated with a combination of the accelerometer and gyroscope readings.
 
The orientation is calculated with a combination of the accelerometer and gyroscope readings.
  
Line 191: Line 212:
 
|}
 
|}
  
==== Accelerometer ====
+
===== Accelerometer =====
 +
----
 +
The accelerometer readings give the instantaneous acceleration. When the accelerometer is not moving, the only acceleration comes from gravity. If the device is flat, the entire gravitational acceleration is in the vertical (Z) component of acceleration, as shown on the left:
  
The accelerometer readings give the instantaneous acceleration. When the accelerometer is not moving, the only acceleration comes from gravity. If the device is flat, the entire gravitational acceleration is in the vertical (Z) component of acceleration, as shown below:
+
[[File:146_s14_tricopter_acceleration_flat.png|thumb|250px|left|Fig 10. Flat acceleration]]
  
<<pic flat acceleration>>
+
The accelerometer reading in this instance would be <0g, 0g, 1g>, where g ~= 9.8m/s^2. However, if the accelerometer is not flat, the gravitational acceleration splits into both horizontal and vertical components, as shown on the right:
  
The accelerometer reading in this instance would be <0g, 0g, 1g>, where g ~= 9.8m/s^2. However, if the accelerometer is not flat, the gravitational acceleration splits into both horizontal and vertical components, as shown below:
+
[[File:146_s14_tricopter_acceleration_tilted.png|thumb|250px|right|Fig 11. Tilted acceleration]]
  
<<pic tilted acceleration>>
+
With simple trigonometry, the angle that the accelerometer is at can be calculated using these two components and an inverse tangent function:
  
With simple trigonometry, the angle that the accelerometer is at can be calculated using these two components and an inverse tangent function:
+
[[File:146_s14_tricopter_accel_angle_calc.png‎|center]]
  
[[File:146_s14_tricopter_accel_angle_calc.png‎]]
+
<br clear=all>
==== Gyroscope ====
 
  
 +
===== Gyroscope =====
 +
----
 
The gyroscope readings give the angular  velocity. To calculate an angle, these readings can be integrated:
 
The gyroscope readings give the angular  velocity. To calculate an angle, these readings can be integrated:
  
[[File:146_s14_tricopter_angle_calculation.png‎]]
+
[[File:146_s14_tricopter_angle_calculation.png‎|center]]
  
 
However, these readings are subject to "drift", where they do not return back to 0 due to small errors in the integration process.
 
However, these readings are subject to "drift", where they do not return back to 0 due to small errors in the integration process.
==== Orientation Calculation ====
+
 
 +
===== Orientation Calculation =====
  
 
The solution to both of the accelerometer and gyroscope shortcomings is to filter and combine them. The accelerometer data can be trusted in the long term, since it is accurate when the craft is stable. Therefore the accelerometer data is low pass filtered. The gyroscope data can be trusted in the short term, since it is accurate when the craft is moving. Therefore, the gyroscope data is high pass filtered. The two are then combined to produce a fairly accurate orientation value.
 
The solution to both of the accelerometer and gyroscope shortcomings is to filter and combine them. The accelerometer data can be trusted in the long term, since it is accurate when the craft is stable. Therefore the accelerometer data is low pass filtered. The gyroscope data can be trusted in the short term, since it is accurate when the craft is moving. Therefore, the gyroscope data is high pass filtered. The two are then combined to produce a fairly accurate orientation value.
  
[[File:146_s14_tricopter_orientation_x_formula.png‎]]
+
[[File:146_s14_tricopter_orientation_x_formula.png|center]]
 +
[[File:146_s14_tricopter_orientation_y_formula.png|center]]
 +
 
 +
 
  
[[File:146_s14_tricopter_orientation_y_formula.png]]
 
  
 
The accelerometer cannot give any acceleration data for the Z (yaw) axis, so the orientation is only calculated using the integral of the gyroscope data. In testing, this proved to be accurate enough for our uses since the craft does not yaw significantly.
 
The accelerometer cannot give any acceleration data for the Z (yaw) axis, so the orientation is only calculated using the integral of the gyroscope data. In testing, this proved to be accurate enough for our uses since the craft does not yaw significantly.
  
[[File:146_s14_tricopter_orientation_z_calculation.png‎]]
+
[[File:146_s14_tricopter_orientation_z_calculation.png‎|center]]
  
=== Motor Control ===
+
==== Motor Control ====
 
----
 
----
 
Motor speeds are increased and decreased to get back to an orientation of (0,0,0) (level flight). The motors are controlled by electronic speed controllers (ESC's). These take a servo PWM signal as input and use the pulse width to control the speed of a 3-wire brush-less motor. The tricopter has three motor/ESC pairs. The tricopter also has a servo which takes the PWM signal directly
 
Motor speeds are increased and decreased to get back to an orientation of (0,0,0) (level flight). The motors are controlled by electronic speed controllers (ESC's). These take a servo PWM signal as input and use the pulse width to control the speed of a 3-wire brush-less motor. The tricopter has three motor/ESC pairs. The tricopter also has a servo which takes the PWM signal directly
Line 239: Line 266:
  
 
Each motor is controlled by setting a percentage. 0% is the lowest speed, and 100% is the highest speed. Each motor's speed is set by adding a baseMotorPercentage with the motor's specific correction.
 
Each motor is controlled by setting a percentage. 0% is the lowest speed, and 100% is the highest speed. Each motor's speed is set by adding a baseMotorPercentage with the motor's specific correction.
The base motor percentage is used to set the throttle of the tricopter, while the correction terms are used for balancing. There are four correction terms: frontLeftCorrection, frontRightCorrection, backCenterCorrection, and servoCorrection. These correction values are set according to axis output values. The axis outputs are roll_output, pitch_output, and yaw_output. These output values are explained in the balancing section. They are used to adjust the motor speeds to maintain balance.
+
The base motor percentage is used to set the throttle of the tricopter, while the correction terms are used for balancing. The base motor percentage was intended to be set by the term height_output. This was intended to control how high the tricopter would fly. Unfortunately our balancing algorithm takes too long to stabilize to allow for flight, so when balancing on the stand the base motor percentage is set to a fixed value: 20%;
  
The following describes how the correction terms are formed.
+
==== Balancing Algorithm ====
{| class="wikitable"
+
----
| '''Correction terms'''
 
| '''Equation'''
 
|-
 
| Front Left
 
| -roll_output + pitch_output/2
 
|-
 
| Front Right
 
| roll_output + pitch_output/2
 
|-
 
| Back Center
 
| -pitch_output
 
|-
 
| Servo
 
| yaw_output
 
|}
 
 
 
The base motor percentage was intended to be set by the term height_output. This was intended to control how high the tricopter would fly. Unfortunately our balancing algorithm takes too long to stabilize to allow for flight, so when balancing on the stand the base motor percentage is set to a fixed value: 20%;
 
  
=== Balancing Algorithm ===
 
----
 
 
We came up with many algorithms while working on this project. They can be divided into two families: the first are all algorithms that adjusted motor speeds based only on our current orientation, and the second are all algorithms that adjusted motor speeds based on our angular velocity and our orientation.
 
We came up with many algorithms while working on this project. They can be divided into two families: the first are all algorithms that adjusted motor speeds based only on our current orientation, and the second are all algorithms that adjusted motor speeds based on our angular velocity and our orientation.
  
==== Algorithm type 1: Adjusting motor speeds in response to just our orientation ====
+
===== Algorithm Type I: Adjusting motor speeds in response to just our orientation =====
===== Accumulating motor speed to target orientation =====
+
====== Accumulating motor speed to target orientation ======
 
One of the earliest algorithms we tried was extremely simple. It Increased or decreased motor speeds by a fixed amount based on the current orientation. While the craft was rolled right, it would increase the front right motor and decrease the front left motor by a fixed amount. The same was implemented on the pitch axis.  
 
One of the earliest algorithms we tried was extremely simple. It Increased or decreased motor speeds by a fixed amount based on the current orientation. While the craft was rolled right, it would increase the front right motor and decrease the front left motor by a fixed amount. The same was implemented on the pitch axis.  
  
 
This algorithm resulted in a thrashing behavior. One motor would wind up and tilt the craft quickly. While the craft was rolled right, the right motor speed would be increasing quickly. The roll angular velocity would increase until the craft was rolling left, but as long as it was still rolled to the right, the velocity at which it rolled left would continue to increase. This caused it to over shoot the target orientation. This process repeated itself and the tricopter would continue to thrash back and forth.
 
This algorithm resulted in a thrashing behavior. One motor would wind up and tilt the craft quickly. While the craft was rolled right, the right motor speed would be increasing quickly. The roll angular velocity would increase until the craft was rolling left, but as long as it was still rolled to the right, the velocity at which it rolled left would continue to increase. This caused it to over shoot the target orientation. This process repeated itself and the tricopter would continue to thrash back and forth.
  
===== Fixed motor speed adjustments to maintain orientation =====
+
====== Fixed motor speed adjustments to maintain orientation ======
 
Another algorithm we tried in this family relied on knowing what motor percentages were needed for the craft to hover normally. We tested the tricopter on the ground and adjusted the motor speeds until it just lifted off. We hard coded these values in our algorithm.
 
Another algorithm we tried in this family relied on knowing what motor percentages were needed for the craft to hover normally. We tested the tricopter on the ground and adjusted the motor speeds until it just lifted off. We hard coded these values in our algorithm.
  
Line 278: Line 286:
 
This algorithm also did not work. It has some obvious problems. The craft would still overshoot the target orientation because the fixed adjustments were the same at all orientations no matter how great or small. Our hover motor speeds were inaccurate, and didn't account for ground effect. Closer to the ground our motors generate more lift, so the motor speeds are smaller to maintain hovering. The motor speeds also did not differ by a fixed amount. At higher speeds, the difference between motor speeds to maintain level flight was much higher than at lower speeds.
 
This algorithm also did not work. It has some obvious problems. The craft would still overshoot the target orientation because the fixed adjustments were the same at all orientations no matter how great or small. Our hover motor speeds were inaccurate, and didn't account for ground effect. Closer to the ground our motors generate more lift, so the motor speeds are smaller to maintain hovering. The motor speeds also did not differ by a fixed amount. At higher speeds, the difference between motor speeds to maintain level flight was much higher than at lower speeds.
  
===== Change motor speeds that scale based on how far off the orientation is =====
+
====== Change motor speeds that scale based on how far off the orientation is ======
 
This is an important concept that is used in our final balancing algorithm. Variations of the above algorithms were tried that scaled the corrections to the motor speeds based on how far off the orientation was. When our orientation was just a little off, our corrections would be smaller. This still did not solve the fundamental problem with this family of algorithms. By targeting orientation only, our angular velocity went unchecked. We would still overshoot our target orientation and get an oscillating or thrashing behavior.
 
This is an important concept that is used in our final balancing algorithm. Variations of the above algorithms were tried that scaled the corrections to the motor speeds based on how far off the orientation was. When our orientation was just a little off, our corrections would be smaller. This still did not solve the fundamental problem with this family of algorithms. By targeting orientation only, our angular velocity went unchecked. We would still overshoot our target orientation and get an oscillating or thrashing behavior.
  
==== Algorithm type 2: Adjusting motor speeds in response to orientation and angular velocity ====
+
===== Algorithm Type II: Adjusting motor speeds in response to orientation and angular velocity =====
 +
[[File:Cmpe146_s13_tricopter_Orientation_vs_velocity.png|300px|thumb|left|Fig 12. Orientation Coordinate System]]
 
This family of algorithms divides balancing into two steps. The first step used current orientation to create target angular velocities, and the second step compared our actual angular velocities to our target angular velocities and adjust the motor speeds until to make them match. Three angular velocities were considered: roll, pitch, and yaw. Our actual velocities come from the gyroscope and are converted to radians per second before they are used.
 
This family of algorithms divides balancing into two steps. The first step used current orientation to create target angular velocities, and the second step compared our actual angular velocities to our target angular velocities and adjust the motor speeds until to make them match. Three angular velocities were considered: roll, pitch, and yaw. Our actual velocities come from the gyroscope and are converted to radians per second before they are used.
  
Our target velocities were set depending on our current orientation. We tried different variants just like the type 1 algorithms. We tried setting the target angular velocities to fixed values depending on our current orientation. Later we tried setting our target velocities based on the magnitude of our orientation error. This concept is what we stuck with.  
+
Our target velocities were set depending on our current orientation. We tried different variants just like the Type I algorithms. We tried setting the target angular velocities to fixed values depending on our current orientation. Later we tried setting our target velocities based on the magnitude of our orientation error. This concept is what we stuck with.  
  
 
We tried many different ways of adjusting our motor speed based on our target and actual velocities. They can be divided into the next two groups
 
We tried many different ways of adjusting our motor speed based on our target and actual velocities. They can be divided into the next two groups
  
===== Setting motor speeds based on the difference between target and actual angular velocities =====
+
====== Setting motor speeds based on the difference between target and actual angular velocities ======
 
We tried setting our motor speeds directly based on the difference between our actual and target velocities. If we were rolled right our target_roll would be set to rolling left at a speed depending on our orientation. While our actual_roll was not rolling left as fast as our target specified, our front right motor correction would be set to a higher value and our front left value would be set to a lower value depending on the magnitude of the error between the actual and target angular velocity.  
 
We tried setting our motor speeds directly based on the difference between our actual and target velocities. If we were rolled right our target_roll would be set to rolling left at a speed depending on our orientation. While our actual_roll was not rolling left as fast as our target specified, our front right motor correction would be set to a higher value and our front left value would be set to a lower value depending on the magnitude of the error between the actual and target angular velocity.  
  
===== Increasing and decreasing motors speeds based on angular velocity differences. =====
+
====== Increasing and decreasing motors speeds based on angular velocity differences. ======
 +
The next variant of the Type II algorithms accumulated motor speeds by amounts that depend on the magnitude of the error between the target and actual values. While the actual_roll was less than the target roll, the motor speeds would be incremented by an amount that scaled with the error.
 +
 
 +
====== PID control of motor corrections ======
 +
At this point in the project we decided to look at the source code for ArduCopter for ideas. Looking through the code we discovered that ArduCopter also adjusts motor speeds to target an angular velocity. We discovered that ArduCopter used something called a PID controller to accomplish this. A PID controller is a closed loop controller used to guide industrial processes. It works by adjusting a term based on the magnitude of the current error (P), the accumulation of past errors (I), and the expected future error (D). We modified our project to operate on the same principles as ArduCopter. We implemented a PID controller class and used it to control four axis outputs: roll_output, pitch_output, yaw_output, and height_output.
 +
 
 +
There are four correction terms: frontLeftCorrection, frontRightCorrection, backCenterCorrection, and servoCorrection. These correction values are set according to axis output values.
 +
 
 +
Each output term is the value determined by the PID controller at each motor control step. These values are calculated 50 times per second. The PID controller is fed the target angular velocity, the actual angular velocity, and the time elapsed since the last output calculation. The PID controller uses these values to calculate the next axis output. These are factored into the motor correction terms as shown in the following table.
  
=== Fail safe ===
+
{| class="wikitable"
 +
| '''Correction terms'''
 +
| '''Equation'''
 +
|-
 +
| Front Left
 +
| -roll_output + pitch_output/2
 +
|-
 +
| Front Right
 +
| roll_output + pitch_output/2
 +
|-
 +
| Back Center
 +
| -pitch_output
 +
|-
 +
| Servo
 +
| yaw_output
 +
|}
 +
 
 +
The height_output is the base motor percentage. All motors are are set to the base motor percentage plus their correction term.
 +
 
 +
==== Fail safe ====
 
----
 
----
 
The fail safe kills all power to the motors by sending the lowest throttle position signal to the ESCs
 
The fail safe kills all power to the motors by sending the lowest throttle position signal to the ESCs
  
==== Reasons fail safe activates ====
+
The following conditions trigger the fail safe:
* X orientation exceeds 45 degrees
+
* Orientation roll or pitch tilted beyond configured value
* Y orientation exceeds 45 degrees
+
* Height above configured value
Height exceeds 18 inches
+
* Time elapsed since boot longer than configured value
* Time is less than 5 seconds since bootup
 
*  Time is greater than 30 seconds since bootup
 
  
=== Implementation ===
+
The failsafe is disabled while the tricopter is mounted on the stand.
----
 
This section includes implementation, but again, not the details, just the high level.  For example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI Flash.  You can include sub-sections for each of your component implementation.
 
  
 
== Testing & Technical Challenges ==
 
== Testing & Technical Challenges ==
Describe the challenges of your project.  What advise would you give yourself or someone else if your project can be started from scratch again?
 
Make a smooth transition to testing section and described what it took to test your project.
 
  
Include sub-sections that list out a problem and solution, such as:
+
 
 +
 
 +
=== Testing Methodologies ===
 +
 
 +
=== Phase #1 ===
 +
Initial testing of the Tricopter was purely electrical. Being that all the components where purchased individually, custom wiring was needed to interconnect the components. As each component was connected and shrink tubed, continuity tests where performed to ensure no shorts existed. To power the system a variable 17AMP external power supply. By using a power supply in place of a battery back, we were provided the ability to current limit and thus protect the various components.
 +
 
 +
=== Phase #2 ===
 +
[[File:CmpE146_s13_tricotper_phase2_testing.jpg|300px|thumb|right|Fig 13.Motor Testing]]
 +
Following the verification of the electrical components, rudimentary flight and motor control tests began. During this phase no propellers were attached to the motors due to safety concerns. The main objective was to fully comprehend the correlation between motor speed and pulse width percentage. It was during this phase that the team encountered issues with the included PWM class. The issue and solution are documented in [[S14:_Tricopter#Issue #1|Issue #1]], below. Once PWM had been calibrated to function properly, motor speed was configured to be controlled by the SJSUone Board accelerometer.
 +
 
 +
=== Phase #3 ===
 +
Following the integration the Sunke10dof IMU, elementary fight tests began. To ensure a safe testing environment the tricopter was tied down to weights. This approach allowed for testing of the full range of motion, while preventing the tricopter from flying out of control. This method in the end proved ineffective as it only accommodated short testing periods. Footage from this can be found
 +
[http://www.youtube.com/embed/vJenMvLrU74 here.]
 +
=== Phase #4 ===
 +
[[File:CmpE146_s13_tricotper_testing_rig.jpg|300px|thumb|left|Fig 14.[http://youtu.be/2Lcv9S_CL9s Testing Rig]]]
 +
<br />
 +
After various days of testing utilizing a tied down approach, ultimately making minimal progress, the team decided to switch a more flexible solution. A testing apparatus was devised using a ball bearing and a metal tower to allow prolonged testing of the tricopter. After a short period of testing, the team discovered a flaw in the approach we had used for balancing. Once the flaw had been rectified the tricopter began to self balance on the testing apparatus.
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
  
 
=== Issue #1 ===
 
=== Issue #1 ===
 +
     
 
The first issue encountered was related to interfacing the ESCs with the SJSU-ONE PWM driver. The PWM driver would provide a pulse-width of 5ms, thus exceeding the required 1-2ms range. To resolve this issue, the team wrote a new driver in order to preserve the 1-2ms pulse-width range. The new driver largely mimicked the provided one, however the calculation for the pulse-width was modified to:
 
The first issue encountered was related to interfacing the ESCs with the SJSU-ONE PWM driver. The PWM driver would provide a pulse-width of 5ms, thus exceeding the required 1-2ms range. To resolve this issue, the team wrote a new driver in order to preserve the 1-2ms pulse-width range. The new driver largely mimicked the provided one, however the calculation for the pulse-width was modified to:
                     
+
<br clear=all>
 +
             
 
                           pulseWidth = sys_get_cpu_clock() * ( (percent/100 * (MAX_PULSE - MIN_PULSE) ) + MIN_PULSE );
 
                           pulseWidth = sys_get_cpu_clock() * ( (percent/100 * (MAX_PULSE - MIN_PULSE) ) + MIN_PULSE );
  
 +
=== Issue #2 ===
 +
As a result of being a low end device, the Sunkee 10DOF IMU proved to be susceptible to the vibrations from the motor. This susceptibility lead to erratic measurements. To resolve this issue the motors and IMU were placed on rubber mounts. This aided in reducing the erratic measurements, however due to the severe vibrations induced by the motors additional software filtering was needed. Both the gyroscope and accelerometer data where placed through a rudimentary low-pass software filter. To further counteract system noise, an average of the calculated orientation value is computed prior to being sent to the balancing algorithm.
  
=== Issue #2 ===
+
== Conclusion ==
The Sunkee 10DOF IMU being a low end device, proved to be susceptible to the vibrations from the motor. This susceptibility lead to erratic measurements. To resolve this issue the motors and IMU where placed on rubber mounts. This aided in reducing the erratic measurements, however due to the severe vibrations induced by the motors additional software filtering was needed. Both the gyroscope and accelemoter data where placed through a rudimentary low-pass software filter. To further counteract system noise, a average of the calculated orientation value is computed prior to being sent to the balancing algorithm.
+
 
 +
Although the project ultimately did not achieve its goal of stable hovering, a large amount of information and concepts were learned in the process of building and testing the tricopter.
  
=== Issue #3 ===
+
The initial testing and development of our sensor drivers and orientation function taught and/or reinforced the following concepts:
 +
* I2C bus
 +
* PWM control of motors and servos
 +
* Driver development for ARM processor peripheral hardware
 +
* Accelerometer and gyroscope sensors
 +
* Basic calculus, trigonometry, and physics (for orientation calculation)
  
== Conclusion ==
+
The second phase of testing and developing the balancing function and integrating it with the orientation function taught and/or reinforced the following concepts:
Conclude your project here.  You can recap your testing and problems.  You should address the "so what" part here to indicate what you ultimately learnt from this project.  How has this project increased your knowledge?
+
* Real time operating systems concepts, including tasks and queues
 +
* FreeRTOS API
 +
* PID controllers
 +
* Flight dynamics, including the ground effect and induced yaw
  
 
=== Project Video ===
 
=== Project Video ===
Upload a video of your project and post the link here.
+
[http://youtu.be/_uyEkIfmVZA Tricopter final video]
  
 
=== Project Source Code ===
 
=== Project Source Code ===
Send me your zipped source code and I will upload this to SourceForge and link it for you.
+
https://github.com/carlosfm1989/Tricopter/tree/ang_vel
  
 
== References ==
 
== References ==
Line 340: Line 406:
 
=== References Used ===
 
=== References Used ===
 
*  Hobby servo fundamentals http://www.princeton.edu/~mae412/TEXT/NTRAK2002/292-302.pdf
 
*  Hobby servo fundamentals http://www.princeton.edu/~mae412/TEXT/NTRAK2002/292-302.pdf
 +
* ArduCopter Project https://github.com/diydrones/ardupilot
 +
* Open source PID controller http://www.ospid.com/blog/
  
 
=== Appendix ===
 
=== Appendix ===
 
You can list the references you used.
 
You can list the references you used.

Latest revision as of 22:58, 22 May 2014

Code name Cerberus

CmpE146 s14 tricopter Cerberus-Blake.jpeg

Abstract

The goal of this project is to produce a stable hovering tricopter. This craft will hover using three motors with three propellers, one of which is mounted on a swivelling piece that allows the raft to have more yaw control. The plan for this project is to use COTS parts for all but the flight controller which will be our software on an SJOne board. The flight controller is responsible for determining how fast each motor spins and the angle of the swivelling motor using inputted data from an accelerometer, a gyroscope, and possibly a magnetometer. The tricopter will elevate itself to a fixed height and using a barometer will stay stabilized at this height.

Introduction

Fig 1.Orientation

Multrirotor unmanned arial vehicles (UAV), have recently grown in popularity due to the reduced cost in parts. A highly agile variation of these multirotor copters are the tricopters. Tricopters apply equivalent principles of balance and orientation to that of traditional multirotors. Unlike symmetrical multirotors, tricopters require an additional servo to counteract yaw. Roll is controlled exclusively by the front left and right motors, where pitch is adjusted through a combination of all three.


Objectives

The objective of this project is to produce a Tricopter capable of rising to a given altitude, hovering in one position for at least 15 seconds, and then landing safely in the same position it took off from.

Maintaining stable flight is the key requirement for this project. Orientation is calculated using an accelerometer and gyroscope. The height above ground is determined using the output of an ultrasonic sensor.

Team Members & Responsibilities

  • Carlos Fernandez-Martinez
  • Shane Loretz
  • Michael Schneider

Schedule

Week# Date Task Actual
1 3/21 Create schedule Delayed due to wiki-login issues
2 3/28 Build Tricopter frame, establish PWM communication Completed, PWM driver had to be replaced
3 4/4 Establish connection with IMU, create an orientation task Completed, no issues encountered
4 4/11 Complete the wiring of the frame, build power regulator for 5v Completed, regulator circuit unneeded, ESCs provide adequate power
5 4/18 Integrate motor control task with orientation task Completed, no issues encountered
6 4/25 Balancing and orientation test In progress

Parts List & Cost

Name Quantity Price
Turnigy Park480 3 $61.47
Hobby King 30A ESC 3 $30.45
Corona 919MG Servo 1 $7.01
Sunkee 10DOF 1 $20.00
Hobbyking X900 1 $32.16
Prop 9047 3 $9.48
Truningy 5800mah 1 $27.85
Cables / Connectors N/A $20.00
SJSU One Board 1 $80.00
Total $292.00

Design & Implementation

Hardware Design


Construction

All components were attached to the tricopter frame. The SJOne board and Sunkee 10DOF board were both bolted to the center section of the frame. The frame was lacking a mounting point for the ultrasonic sensor, so it was taped on.

All three motors were attached to the frame with a motor mount and two screws. The servo was mounted at a dedicated servo mount point provided on the frame. The motor speed controllers were attached with zip ties, due to a lack of good mounting options both on the frame and on the speed controllers themselves. Wires for PWM control and power were routed along the tricopter arms, and also attached with zip ties.

Fig 2.Motor Attachment
Fig 3.Built Frame


Interfaces


Fig 4.System Wiring


IMU

Fig 5. IMU mounted upside down on Tricopter


The Inertial Measurement Unit (IMU) we used is the SUNKEE 10DOF. It has an Accelerometer, Gyroscope, and Barometer accessible via an I2C bus. For our project we only used the Accelerometer and the Gyroscope. I2C uses only two signals: data and clock. We used I2C port 2 on the SJOne board to interface with the IMU.

The IMU is mounted upside down on a perforated prototyping board. Cables connect 3.3V power, ground, data, and clock lines to the IMU. The 3.3V supply pin on the SJOne board was used to power the IMU for sake of convenience.


Ultrasonic Sensor

Fig 6. Ultrasonic Sensor


Originally, height for the tricopter was to be determined using the Z-axis of the accelermoter. However, this method proved inaccurate. A HC-SR04 Ultrasonic sensor was chosen to determine the height. Height was determined by measuring the time delta from the echo's rising edge to the falling edge. To ensure accuracy in a multi-threaded environment, hardware timers and interrupts were used to track this timing interval. Time was kept by marking a timer register on the rise of every system clock edge. Once timing was captured it was converted from system clicks to seconds using the formula:

                                                   read_height = ((.120 * total) / 148);
Motors/Servo

Fig 7. PWM signals sent to servo and ESCs
Fig 8.ESC Wiring

The motors are controlled using electronic speed controllers (ESC). The motors themselves are brush-less out-runner motors. The ESCs are controlled using the servo motor PWM interface. This interface expects a high pulse every 20 milliseconds. The width of this pulse dictates the motor speed. When the pulse is 1ms wide, the ESC interprets this as throttle of 0%. When the pulse is 2ms wide the ESC interprets this as a throttle of 100%.

The ESCs will not start running until the throttle position is set to 0% until the ESC stop its start up beeping routine. This is a safety feature that prevents the motor from spinning up unexpectedly. Our software sets the throttle position to 0% when it boots, and it holds this position for 5 seconds before spinning up the motors. This is enough time for the ESCs to complete their start up beep sequence.

The servo motor takes the same PWM signal. A pulse width of 1ms tells the servo to be rotated fully one direction, and a pulse width of 2ms has it rotated fully the opposite direction. Our software sets this signal to 46% at boot, which we determined was the most level position.

Software Design

Orientation


Fig 9. Sunkee 10dof

The orientation is calculated with a combination of the accelerometer and gyroscope readings.

Orientation is expressed in radians from a level position

X (roll) Y (pitch) Z (yaw)
Positive Rolled left Pitched down Yawed counter clock wise
Negative Rolled right Pitched up Yawed clock wise

Angular velocity is specified in radians per second

X (roll) Y (pitch) Z (yaw)
Positive Rolling left Pitching up Yawing counter clock wise
Negative Rolling right Pitching down Yawing clock wise
Accelerometer

The accelerometer readings give the instantaneous acceleration. When the accelerometer is not moving, the only acceleration comes from gravity. If the device is flat, the entire gravitational acceleration is in the vertical (Z) component of acceleration, as shown on the left:

Fig 10. Flat acceleration

The accelerometer reading in this instance would be <0g, 0g, 1g>, where g ~= 9.8m/s^2. However, if the accelerometer is not flat, the gravitational acceleration splits into both horizontal and vertical components, as shown on the right:

Fig 11. Tilted acceleration

With simple trigonometry, the angle that the accelerometer is at can be calculated using these two components and an inverse tangent function:

146 s14 tricopter accel angle calc.png


Gyroscope

The gyroscope readings give the angular velocity. To calculate an angle, these readings can be integrated:

146 s14 tricopter angle calculation.png

However, these readings are subject to "drift", where they do not return back to 0 due to small errors in the integration process.

Orientation Calculation

The solution to both of the accelerometer and gyroscope shortcomings is to filter and combine them. The accelerometer data can be trusted in the long term, since it is accurate when the craft is stable. Therefore the accelerometer data is low pass filtered. The gyroscope data can be trusted in the short term, since it is accurate when the craft is moving. Therefore, the gyroscope data is high pass filtered. The two are then combined to produce a fairly accurate orientation value.

146 s14 tricopter orientation x formula.png
146 s14 tricopter orientation y formula.png



The accelerometer cannot give any acceleration data for the Z (yaw) axis, so the orientation is only calculated using the integral of the gyroscope data. In testing, this proved to be accurate enough for our uses since the craft does not yaw significantly.

146 s14 tricopter orientation z calculation.png

Motor Control


Motor speeds are increased and decreased to get back to an orientation of (0,0,0) (level flight). The motors are controlled by electronic speed controllers (ESC's). These take a servo PWM signal as input and use the pulse width to control the speed of a 3-wire brush-less motor. The tricopter has three motor/ESC pairs. The tricopter also has a servo which takes the PWM signal directly

Motor 1 Front left
Motor 2 Front right
Motor 3 back (with servo)

Each motor is controlled by setting a percentage. 0% is the lowest speed, and 100% is the highest speed. Each motor's speed is set by adding a baseMotorPercentage with the motor's specific correction. The base motor percentage is used to set the throttle of the tricopter, while the correction terms are used for balancing. The base motor percentage was intended to be set by the term height_output. This was intended to control how high the tricopter would fly. Unfortunately our balancing algorithm takes too long to stabilize to allow for flight, so when balancing on the stand the base motor percentage is set to a fixed value: 20%;

Balancing Algorithm


We came up with many algorithms while working on this project. They can be divided into two families: the first are all algorithms that adjusted motor speeds based only on our current orientation, and the second are all algorithms that adjusted motor speeds based on our angular velocity and our orientation.

Algorithm Type I: Adjusting motor speeds in response to just our orientation
Accumulating motor speed to target orientation

One of the earliest algorithms we tried was extremely simple. It Increased or decreased motor speeds by a fixed amount based on the current orientation. While the craft was rolled right, it would increase the front right motor and decrease the front left motor by a fixed amount. The same was implemented on the pitch axis.

This algorithm resulted in a thrashing behavior. One motor would wind up and tilt the craft quickly. While the craft was rolled right, the right motor speed would be increasing quickly. The roll angular velocity would increase until the craft was rolling left, but as long as it was still rolled to the right, the velocity at which it rolled left would continue to increase. This caused it to over shoot the target orientation. This process repeated itself and the tricopter would continue to thrash back and forth.

Fixed motor speed adjustments to maintain orientation

Another algorithm we tried in this family relied on knowing what motor percentages were needed for the craft to hover normally. We tested the tricopter on the ground and adjusted the motor speeds until it just lifted off. We hard coded these values in our algorithm.

We used these values in our balancing algorithm as the normal motor speeds. Increasing height was done by increasing the motor speeds by a fixed amount. If the craft was rolled right, the left motor would be decreased by a fixed amount from the hover value and the right motor would be increased by a fixed amount. The same was done on the pitch and yaw axes.

This algorithm also did not work. It has some obvious problems. The craft would still overshoot the target orientation because the fixed adjustments were the same at all orientations no matter how great or small. Our hover motor speeds were inaccurate, and didn't account for ground effect. Closer to the ground our motors generate more lift, so the motor speeds are smaller to maintain hovering. The motor speeds also did not differ by a fixed amount. At higher speeds, the difference between motor speeds to maintain level flight was much higher than at lower speeds.

Change motor speeds that scale based on how far off the orientation is

This is an important concept that is used in our final balancing algorithm. Variations of the above algorithms were tried that scaled the corrections to the motor speeds based on how far off the orientation was. When our orientation was just a little off, our corrections would be smaller. This still did not solve the fundamental problem with this family of algorithms. By targeting orientation only, our angular velocity went unchecked. We would still overshoot our target orientation and get an oscillating or thrashing behavior.

Algorithm Type II: Adjusting motor speeds in response to orientation and angular velocity
Fig 12. Orientation Coordinate System

This family of algorithms divides balancing into two steps. The first step used current orientation to create target angular velocities, and the second step compared our actual angular velocities to our target angular velocities and adjust the motor speeds until to make them match. Three angular velocities were considered: roll, pitch, and yaw. Our actual velocities come from the gyroscope and are converted to radians per second before they are used.

Our target velocities were set depending on our current orientation. We tried different variants just like the Type I algorithms. We tried setting the target angular velocities to fixed values depending on our current orientation. Later we tried setting our target velocities based on the magnitude of our orientation error. This concept is what we stuck with.

We tried many different ways of adjusting our motor speed based on our target and actual velocities. They can be divided into the next two groups

Setting motor speeds based on the difference between target and actual angular velocities

We tried setting our motor speeds directly based on the difference between our actual and target velocities. If we were rolled right our target_roll would be set to rolling left at a speed depending on our orientation. While our actual_roll was not rolling left as fast as our target specified, our front right motor correction would be set to a higher value and our front left value would be set to a lower value depending on the magnitude of the error between the actual and target angular velocity.

Increasing and decreasing motors speeds based on angular velocity differences.

The next variant of the Type II algorithms accumulated motor speeds by amounts that depend on the magnitude of the error between the target and actual values. While the actual_roll was less than the target roll, the motor speeds would be incremented by an amount that scaled with the error.

PID control of motor corrections

At this point in the project we decided to look at the source code for ArduCopter for ideas. Looking through the code we discovered that ArduCopter also adjusts motor speeds to target an angular velocity. We discovered that ArduCopter used something called a PID controller to accomplish this. A PID controller is a closed loop controller used to guide industrial processes. It works by adjusting a term based on the magnitude of the current error (P), the accumulation of past errors (I), and the expected future error (D). We modified our project to operate on the same principles as ArduCopter. We implemented a PID controller class and used it to control four axis outputs: roll_output, pitch_output, yaw_output, and height_output.

There are four correction terms: frontLeftCorrection, frontRightCorrection, backCenterCorrection, and servoCorrection. These correction values are set according to axis output values.

Each output term is the value determined by the PID controller at each motor control step. These values are calculated 50 times per second. The PID controller is fed the target angular velocity, the actual angular velocity, and the time elapsed since the last output calculation. The PID controller uses these values to calculate the next axis output. These are factored into the motor correction terms as shown in the following table.

Correction terms Equation
Front Left -roll_output + pitch_output/2
Front Right roll_output + pitch_output/2
Back Center -pitch_output
Servo yaw_output

The height_output is the base motor percentage. All motors are are set to the base motor percentage plus their correction term.

Fail safe


The fail safe kills all power to the motors by sending the lowest throttle position signal to the ESCs

The following conditions trigger the fail safe:

  • Orientation roll or pitch tilted beyond configured value
  • Height above configured value
  • Time elapsed since boot longer than configured value

The failsafe is disabled while the tricopter is mounted on the stand.

Testing & Technical Challenges

Testing Methodologies

Phase #1

Initial testing of the Tricopter was purely electrical. Being that all the components where purchased individually, custom wiring was needed to interconnect the components. As each component was connected and shrink tubed, continuity tests where performed to ensure no shorts existed. To power the system a variable 17AMP external power supply. By using a power supply in place of a battery back, we were provided the ability to current limit and thus protect the various components.

Phase #2

Fig 13.Motor Testing

Following the verification of the electrical components, rudimentary flight and motor control tests began. During this phase no propellers were attached to the motors due to safety concerns. The main objective was to fully comprehend the correlation between motor speed and pulse width percentage. It was during this phase that the team encountered issues with the included PWM class. The issue and solution are documented in Issue #1, below. Once PWM had been calibrated to function properly, motor speed was configured to be controlled by the SJSUone Board accelerometer.

Phase #3

Following the integration the Sunke10dof IMU, elementary fight tests began. To ensure a safe testing environment the tricopter was tied down to weights. This approach allowed for testing of the full range of motion, while preventing the tricopter from flying out of control. This method in the end proved ineffective as it only accommodated short testing periods. Footage from this can be found here.

Phase #4


After various days of testing utilizing a tied down approach, ultimately making minimal progress, the team decided to switch a more flexible solution. A testing apparatus was devised using a ball bearing and a metal tower to allow prolonged testing of the tricopter. After a short period of testing, the team discovered a flaw in the approach we had used for balancing. Once the flaw had been rectified the tricopter began to self balance on the testing apparatus.





Issue #1

The first issue encountered was related to interfacing the ESCs with the SJSU-ONE PWM driver. The PWM driver would provide a pulse-width of 5ms, thus exceeding the required 1-2ms range. To resolve this issue, the team wrote a new driver in order to preserve the 1-2ms pulse-width range. The new driver largely mimicked the provided one, however the calculation for the pulse-width was modified to:

                         pulseWidth = sys_get_cpu_clock() * ( (percent/100 * (MAX_PULSE - MIN_PULSE) ) + MIN_PULSE );

Issue #2

As a result of being a low end device, the Sunkee 10DOF IMU proved to be susceptible to the vibrations from the motor. This susceptibility lead to erratic measurements. To resolve this issue the motors and IMU were placed on rubber mounts. This aided in reducing the erratic measurements, however due to the severe vibrations induced by the motors additional software filtering was needed. Both the gyroscope and accelerometer data where placed through a rudimentary low-pass software filter. To further counteract system noise, an average of the calculated orientation value is computed prior to being sent to the balancing algorithm.

Conclusion

Although the project ultimately did not achieve its goal of stable hovering, a large amount of information and concepts were learned in the process of building and testing the tricopter.

The initial testing and development of our sensor drivers and orientation function taught and/or reinforced the following concepts:

  • I2C bus
  • PWM control of motors and servos
  • Driver development for ARM processor peripheral hardware
  • Accelerometer and gyroscope sensors
  • Basic calculus, trigonometry, and physics (for orientation calculation)

The second phase of testing and developing the balancing function and integrating it with the orientation function taught and/or reinforced the following concepts:

  • Real time operating systems concepts, including tasks and queues
  • FreeRTOS API
  • PID controllers
  • Flight dynamics, including the ground effect and induced yaw

Project Video

Tricopter final video

Project Source Code

https://github.com/carlosfm1989/Tricopter/tree/ang_vel

References

Acknowledgement

Any acknowledgement that you may wish to provide can be included here.

References Used

Appendix

You can list the references you used.