-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
95 lines (51 loc) · 3.18 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
A quaternion based quadrotor flight control software implementation.
Copyright (C) 2014 Andrew Pratt
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Target Board: Teensy 3.1
Compiled with arm-none-eabi toolchain distributed with the Teensy3.1
./hw contains code for enabling the processor's timers, busses and other features
./quadcore contains the code for the control software
Basic Description of How it Works:
1.reads and adjusts all the sensor values
2.updates the current state with the values from the gyro
3.corrects the current state with the values from the magnetometer and accelerometer
(effectively a complimentary filter between (acc and mag) and the gyro
4.computes the desired attitude from the RC controller input
5.computes the rotation necessary to rotate from the quad's reference frame into the desired reference frame
6.turns this rotation into individual correcting rotations on each axis
7.calculates the speed for each motor based on the correcting rotations using a PD controller
8.sends the desired motor speeds to the ESCs
9.repeats
Timing:
1.The main loop executes at ~1000hz
2.The ESCs are updated at 250hz
3.The control inputs are received at ~20hz
4.The sensors update rates are independent (Don't really care about dropped readings)
A note on the combination of rotations:
rotation1 = q1;
rotation2 = q2;
Because rotations are non-commutative q1*q2 != q2*q1
This will be the most commonly used form.
To find the rotation equivalent to two consecutive rotations defined in the local reference frame:
q3 = q1*q2
To find the rotation equivalent to two consecutive rotations defined in the global reference frame:
q3 = q2*q1
A note on the naming of quaternions:
Names are usually two letters followed by quat to signify that it is a quaternion
The first and second letters represent coordinate systems and are usually b = body, g = global/earth, t = target
The quaternion describes the rotation necessary to rotate the first coordinate system into alignment with the second coordinate system.
EX:
bgquat = the rotation necessary to rotate the body coordinate system into alignment with the global coordinate system
btquat = the rotation necessary to rotate the body coordinate system into alignment with the target coordinate system
To describe a vector in a second coordinate system given a first it is necessary to apply the OPPOSITE ROTATION
to that required to rotate the first coordinate system into alignment with the second
To describe vector v in global coordinates given body coordinates we multiply by gbquat NOT bgquat