-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy paththesis.tex
1913 lines (1595 loc) · 121 KB
/
thesis.tex
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% uWaterloo Thesis Template for LaTeX
% Last Updated May 24, 2011 by Stephen Carr, IST Client Services
% FOR ASSISTANCE, please send mail to [email protected]
% Effective October 2006, the University of Waterloo
% requires electronic thesis submission. See the uWaterloo thesis regulations at
% http://www.grad.uwaterloo.ca/Thesis_Regs/thesistofc.asp.
% DON'T FORGET TO ADD YOUR OWN NAME AND TITLE in the "hyperref" package
% configuration below. THIS INFORMATION GETS EMBEDDED IN THE PDF FINAL PDF DOCUMENT.
% You can view the information if you view Properties of the PDF document.
% Many faculties/departments also require one or more printed
% copies. This template attempts to satisfy both types of output.
% It is based on the standard "book" document class which provides all necessary
% sectioning structures and allows multi-part theses.
% DISCLAIMER
% To the best of our knowledge, this template satisfies the current uWaterloo requirements.
% However, it is your responsibility to assure that you have met all
% requirements of the University and your particular department.
% Many thanks to the feedback from many graduates that assisted the development of this template.
% -----------------------------------------------------------------------
% By default, output is produced that is geared toward generating a PDF
% version optimized for viewing on an electronic display, including
% hyperlinks within the PDF.
% E.g. to process a thesis called "mythesis.tex" based on this template, run:
% pdflatex mythesis -- first pass of the pdflatex processor
% bibtex mythesis -- generates bibliography from .bib data file(s)
% pdflatex mythesis -- fixes cross-references, bibliographic references, etc
% pdflatex mythesis -- fixes cross-references, bibliographic references, etc
% If you use the recommended LaTeX editor, Texmaker, you would open the mythesis.tex
% file, then click the pdflatex button. Then run BibTeX (under the Tools menu).
% Then click the pdflatex button two more times. If you have an index as well,
% you'll need to run MakeIndex from the Tools menu as well, before running pdflatex
% the last two times.
% N.B. The "pdftex" program allows graphics in the following formats to be
% included with the "\includegraphics" command: PNG, PDF, JPEG, TIFF
% Tip 1: Generate your figures and photos in the size you want them to appear
% in your thesis, rather than scaling them with \includegraphics options.
% Tip 2: Any drawings you do should be in scalable vector graphic formats:
% SVG, PNG, WMF, EPS and then converted to PNG or PDF, so they are scalable in
% the final PDF as well.
% Tip 3: Photographs should be cropped and compressed so as not to be too large.
% To create a PDF output that is optimized for double-sided printing:
%
% 1) comment-out the \documentclass statement in the preamble below, and
% un-comment the second \documentclass line.
%
% 2) change the value assigned below to the boolean variable
% "PrintVersion" from "false" to "true".
% --------------------- Start of Document Preamble -----------------------
% Specify the document class, default style attributes, and page dimensions
% For hyperlinked PDF, suitable for viewing on a computer, use this:
\documentclass[letterpaper,12pt,titlepage,oneside,final]{book}
% For PDF, suitable for double-sided printing, change the PrintVersion variable below
% to "true" and use this \documentclass line instead of the one above:
%\documentclass[letterpaper,12pt,titlepage,openright,twoside,final]{book}
% Some LaTeX commands I define for my own nomenclature.
% If you have to, it's better to change nomenclature once here than in a
% million places throughout your thesis!
\newcommand{\package}[1]{\textbf{#1}} % package names in bold text
\newcommand{\cmmd}[1]{\textbackslash\texttt{#1}} % command name in tt font
\newcommand{\href}[1]{#1} % does nothing, but defines the command so the
% print-optimized version will ignore \href tags (redefined by hyperref pkg).
%\newcommand{\texorpdfstring}[2]{#1} % does nothing, but defines the command
% Anything defined here may be redefined by packages added below...
% This package allows if-then-else control structures.
\usepackage{ifthen}
\newboolean{PrintVersion}
\setboolean{PrintVersion}{false}
% CHANGE THIS VALUE TO "true" as necessary, to improve printed results for hard copies
% by overriding some options of the hyperref package below.
\usepackage{nomencl} % For a nomenclature (optional; available from ctan.org)
\usepackage{amsmath,amssymb,amstext} % Lots of math symbols and environments
\usepackage[pdftex]{graphicx} % For including graphics N.B. pdftex graphics driver
% Hyperlinks make it very easy to navigate an electronic document.
% In addition, this is where you should specify the thesis title
% and author as they appear in the properties of the PDF document.
% Use the "hyperref" package
% N.B. HYPERREF MUST BE THE LAST PACKAGE LOADED; ADD ADDITIONAL PKGS ABOVE
\usepackage[pdftex,letterpaper=true,pagebackref=false]{hyperref} % with basic options
% N.B. pagebackref=true provides links back from the References to the body text. This can cause trouble for printing.
\hypersetup{
plainpages=false, % needed if Roman numbers in frontpages
pdfpagelabels=true, % adds page number as label in Acrobat's page count
bookmarks=true, % show bookmarks bar?
unicode=false, % non-Latin characters in Acrobat’s bookmarks
pdftoolbar=true, % show Acrobat’s toolbar?
pdfmenubar=true, % show Acrobat’s menu?
pdffitwindow=false, % window fit to page when opened
pdfstartview={FitH}, % fits the width of the page to the window
pdftitle={Biologically Inspired Adaptive Control of Quadcopter Flight}, % title
pdfauthor={Brent Komer}, % author
% pdfsubject={Subject}, % subject: CHANGE THIS TEXT! and uncomment this line
% pdfkeywords={keyword1} {key2} {key3}, % list of keywords, and uncomment this line if desired
pdfnewwindow=true, % links in new window
colorlinks=true, % false: boxed links; true: colored links
linkcolor=blue, % color of internal links
citecolor=green, % color of links to bibliography
filecolor=magenta, % color of file links
urlcolor=cyan % color of external links
}
\ifthenelse{\boolean{PrintVersion}}{ % for improved print quality, change some hyperref options
\hypersetup{ % override some previously defined hyperref options
% colorlinks,%
citecolor=black,%
filecolor=black,%
linkcolor=black,%
urlcolor=black}
}{} % end of ifthenelse (no else)
% Setting up the page margins...
% uWaterloo thesis requirements specify a minimum of 1 inch (72pt) margin at the
% top, bottom, and outside page edges and a 1.125 in. (81pt) gutter
% margin (on binding side). While this is not an issue for electronic
% viewing, a PDF may be printed, and so we have the same page layout for
% both printed and electronic versions, we leave the gutter margin in.
% Set margins to minimum permitted by uWaterloo thesis regulations:
\setlength{\marginparwidth}{0pt} % width of margin notes
% N.B. If margin notes are used, you must adjust \textwidth, \marginparwidth
% and \marginparsep so that the space left between the margin notes and page
% edge is less than 15 mm (0.6 in.)
\setlength{\marginparsep}{0pt} % width of space between body text and margin notes
\setlength{\evensidemargin}{0.125in} % Adds 1/8 in. to binding side of all
% even-numbered pages when the "twoside" printing option is selected
\setlength{\oddsidemargin}{0.125in} % Adds 1/8 in. to the left of all pages
% when "oneside" printing is selected, and to the left of all odd-numbered
% pages when "twoside" printing is selected
\setlength{\textwidth}{6.375in} % assuming US letter paper (8.5 in. x 11 in.) and
% side margins as above
\raggedbottom
% The following statement specifies the amount of space between
% paragraphs. Other reasonable specifications are \bigskipamount and \smallskipamount.
\setlength{\parskip}{\medskipamount}
% The following statement controls the line spacing. The default
% spacing corresponds to good typographic conventions and only slight
% changes (e.g., perhaps "1.2"), if any, should be made.
\renewcommand{\baselinestretch}{1} % this is the default line space setting
% By default, each chapter will start on a recto (right-hand side)
% page. We also force each section of the front pages to start on
% a recto page by inserting \cleardoublepage commands.
% In many cases, this will require that the verso page be
% blank and, while it should be counted, a page number should not be
% printed. The following statements ensure a page number is not
% printed on an otherwise blank verso page.
\let\origdoublepage\cleardoublepage
\newcommand{\clearemptydoublepage}{%
\clearpage{\pagestyle{empty}\origdoublepage}}
\let\cleardoublepage\clearemptydoublepage
% Allow chapter references to be capitalized
\newcommand{\Chapref}[1]{Chapter~\ref{#1}}
\newcommand{\Tabref}[1]{Table~\ref{#1}}
% Allow subfigures
\usepackage{subcaption}
% Allow multi-references
\usepackage{cleveref}
% Allow descriptions under tables
\usepackage[flushleft]{threeparttable}
% Allow symbol for degrees
\usepackage{gensymb}
% For tables to be able to fill the whole text width
\usepackage{tabularx}
% Include a Glossary
%\usepackage[acronym]{glossaries}
%\makeglossaries
%\newglossaryentry{Nengo}{name=Nengo,description={blabla}}
%\newglossaryentry{decoder}{name=Decoders,description={blablazzzz}}
% Find the figures stored in this folder
\graphicspath{./figures/}
% Uncomment these to remove all figures and tables for a print version for editing
%\usepackage{comment}
%\excludecomment{figure}
%\excludecomment{table}
%\let\endfigure\relax
%\let\endtable\relax
%======================================================================
% L O G I C A L D O C U M E N T -- the content of your thesis
%======================================================================
\begin{document}
% For a large document, it is a good idea to divide your thesis
% into several files, each one containing one chapter.
% To illustrate this idea, the "front pages" (i.e., title page,
% declaration, borrowers' page, abstract, acknowledgements,
% dedication, table of contents, list of tables, list of figures,
% nomenclature) are contained within the file "uw-ethesis-frontpgs.tex" which is
% included into the document by the following statement.
%----------------------------------------------------------------------
% FRONT MATERIAL
%----------------------------------------------------------------------
\input{thesis-frontpgs}
%----------------------------------------------------------------------
% MAIN BODY
%----------------------------------------------------------------------
% Because this is a short document, and to reduce the number of files
% needed for this template, the chapters are not separate
% documents as suggested above, but you get the idea. If they were
% separate documents, they would each start with the \chapter command, i.e,
% do not contain \documentclass or \begin{document} and \end{document} commands.
%======================================================================
\chapter{Introduction}
%======================================================================
\section{Motivation}
%[talk about humans being a very good control system, want to build a robotic system that leverages some of the abilities humans have, by building it with a biologically realistic neural simulator. Can also be run on low power neural hardware in the future]
Humans have an exceptional ability to be able to adapt to their surroundings.
In particular the human motor control system is able to compensate for changes in forces, torques, and inertial effects on the body.
For example, when picking up an object such as a hammer, the weight of the hammer will apply external forces to the hand.
This will change the dynamic properties of the hand and arm movements, yet the human motor control system is able to easily compensate for these changes and accurately control movement with the object.
Even if an object has never been encountered before, the human brain is able to calculate the correct changes in timing and muscle tensions in order to skilfully manipulate the object.
The predictive capabilities of the brain, along with the plasticity of neural connections in the motor area help guide these sophisticated behaviours.
This ability for quick and easy adaptation to new dynamic properties of a system would be extremely useful in robotics.
Applying similar methods of control that have been developed over millions of years of evolution in the brain to a robotic control system could result in major improvements.
This is especially useful now that the demands of many robotic systems are now more general purpose than they were in the past.
Robots started out mainly performing simple and repetitive tasks in stable environments, such as automation in manufacturing \cite{garcia2007evolution}.
Now they are being used increasingly in more complex situations requiring a diverse amount of control, such as search and rescue missions, performing medical procedures, and assisting the elderly \cite{garcia2007evolution, hockstein2007history, nourbakhsh2005human, lacey1998application}.
When the precise environment that the robot will operate in is not fully known, it is useful for any control system that the robot uses to be adaptable to those environments.
Another advantage the brain has when it comes to control, is that it uses very little power, about 20 Watts on average \cite{hart1975brain}.
% the motor is the majority of the power on a quadcopter, so neuromorphic hardware might not help much here
Hardware inspired by the brain is being designed to take advantage of this low power paradigm.
This style of hardware, known as neuromorphic hardware, is typically massively parallel and consumes much less power than traditional hardware.
The algorithms explored in this thesis focus on being adaptive and biologically inspired in order to take advantage of such hardware.
\section{Quadcopters}
%[basic characteristics, four rotors, rotating different ways]
%[something about vertical take off and landing]
%[light-weight]
%[very maneuverable]
Quadcopters are very versatile aerial vehicles, typically consisting of a central body with four upright rotors equally spaced around the body.
This configuration allows them to be lightweight and simplifies construction.
They also have the ability to take off and land vertically without external assistance, meaning they can be used in a lot more situations than aircraft that require a runway or other particular conditions to take off.
They can also change directions fairly easily mid flight, and have the ability to hover at a particular location. Due to their low cost, light weight, and ease of use, they are an excellent aircraft to use for research purposes.
%[battery heaviest part, low power controller means it can last longer and/or be lighter, good candidate for neural control]
Despite all of these positive qualities, one of the main weaknesses of quadcopters is their short battery life.
Small and simple quadcopters used by hobbyists typically last only 5 to 10 minutes before they run out of power \cite{batterylife}.
The more expensive industrial grade quadcopters typically last up to 30 minutes before they need to be recharged, but this duration is still not long enough for some applications.
For example, if a quadcopter is being used in a search and rescue mission it may need to remain flying for a long time without recharging, especially if it is operating in a remote area.
Battery weight is one of the main issues hindering the maximum flight time of quadcopters.
If a larger battery is used in attempts to increase the maximum flight time, the quadcopter will be heavier and therefore require more power to fly, which in turn will drain the battery faster.
Two possible solutions to this problem are lighter batteries and more energy-efficient operation.
The latter can be achieved by the use of neuromorphic hardware to run the flight control system.
While the majority of the power consumed by a quadcopter goes towards the rotors, some is still used by the on-board control system.
As the sophistication of the control system increases, the computational demands will follow, leading to less overall flight time.
Computational efficiency improvements in traditional digital computation is beginning to stagnate and is expected to soon approach a limit where minimal improvement is expected.
On the contrary, computational power efficiency for biological systems is 8-9 orders of magnitude better than the power efficiency for digital computation \cite{hasler2013finding}.
Reducing the power required for the control system can allow more of the power from the batteries to be used for the rotors.
%TODO this seems like a really weak claim, and isn't the main focus of the thesis, should it still be included here as a possibility?
%[something about how adaptive control is awesome]
In addition to the low power consumption of neuromorphic hardware, they also have the advantage of using various types of neural algorithms that can be extremely useful for control.
In particular, the learning capabilities of brain-like algorithms can be used to develop controllers that are able to adapt to unknown environments with non-linear dynamics.
This thesis explores an adaptive control algorithm for quadcopter flight constructed using simulated biologically plausible neurons.
%[talk about what each section of the thesis will talk about]
\Chapref{chap:background} gives an overview of how quadcopters are able to fly, followed by a section detailing the mathematics underlying the dynamics of a quadcopter system.
Following the mathematical characterization is a description of how the quadcopter is modelled in a simulation environment.
\Chapref{chap:control} gives an overview of the control theory used in developing the control system, including standard PID control, adaptive control, and adaptive control in a simulated biological neural system.
\Chapref{chap:implementation} covers the initial design of the controller model, as well as many of the iterations of improvements leading to the final design.
\Chapref{chap:analysis} describes the set of experiments performed and metrics used to quantify performance of the various controllers.
The final section discusses the results and outlines areas of future work.
%======================================================================
\chapter{Background Information} \label{chap:background}
%======================================================================
\section{Flight Control}
%[mention the six states: x,y,z,roll,pitch,yaw -> have a diagram to explain them]
%[different modes of flight control (up/down, horizontal, rotate, hover), diagrams for each]
%[thrust is always perpendicular to the body]
%[two ways to do it, rotor aligned axis, and 45 degrees from that]
The system state of a quadcopter is six dimensional: three for position ($x$, $y$, and $z$) and three for orientation (roll, pitch, and yaw).
There are four control inputs, which are typically taken to be the rotational velocity of each of the four rotors.
For a physical quadcopter, these inputs are the voltages applied to each of these rotors.
A transformation in these voltages can be obtained using the physical rotor parameters to estimate the rotor velocity.
For simplicity of the simulation, the velocity is used directly as the control input in this thesis.
%TODO [continue...]
%[talk about perpendicular thrust, as well as torque on the body, and that is how each of the movements is done]
The rotors will always generate a thrust that is perpendicular to the body of the aircraft.
In addition to this thrust, torque is generated by each rotor based on their spin direction as well as their distance from the center of the body.
For the quadcopter to be able to control its orientation, half of the rotors spin clockwise and the other half spin counter-clockwise.
The pairs diagonally opposite each other across the body spin in the same direction, allowing the torques to balance one another out and the quadcopter to maintain a steady orientation.
By varying the relative speeds of each rotor, the quadcopter is able to create a net torque in a specific direction, causing a rotation about any axis.
A quadcopter performs four common actions to move around in its environment, with a distinct pattern of rotor actuation for each one:
tilt forward/backward, tilt left/right, rotate, and move up/down.
A quadcopter can perform any combination of these actions, and with different magnitudes of each. The relative rotor speeds required for each are shown in \autoref{fig:actions}. This set of actions make up what is referred to as the `task space' of the quadcopter in the remainder of this thesis.
\begin{figure}
\centering
\includegraphics[height=0.3\textheight]{./figures/QuadcopterMovements.JPG}
\caption{Four Primary Quadcopter Movements. Taken from \cite{harsha}}
\label{fig:actions}
\end{figure}
\section{Dynamics} \label{sec:dynamics}
%[go through all of the equations for dynamics]
The structure of a quadcopter is shown in \autoref{fig:FBD}, along with the coordinate frame and relevant forces and torques created by the rotors.
%TODO [fix this phrase a ton]
Two important frames of reference are involved when studying quadcopters: the inertial frame is used to represent the state of the quadcopter relative to the outside world, and the body frame is fixed around the center of mass of the quadcopter and used to represent local effects on the quadcopter.
%Typically you are interested in the state of the quadcopter in the inertial frame, but the control of the quadcopter is easier to represent in the body frame.
Typically, the inertial frame is the focus when researchers are interested in the state of the quadcopter, but the body frame is more useful when considering control of the quadcopter.
%[put diagram around here]
\begin{figure}
\centering
\includegraphics[width=0.8\textwidth]{./figures/QuadcopterFBD.png}
\caption{The Inertial and Body Frames of a Quadcopter. Taken from \cite{luukkonen2011modelling} } %TODO get a better caption
\label{fig:FBD}
\end{figure}
A rotation matrix \eqref{eq:rotation_matrix} can be used to convert coordinates from the body frame to the inertial frame.
Here, $C_{x}$ represents $\cos{x}$ and $S_{x}$ represents $\sin{x}$.
To convert the other way, from inertial frame to body frame, the inverse of the matrix is used.
Since this matrix is orthogonal, its inverse is equal to its transpose.
%[rotation matrix here]
\begin{equation} \label{eq:rotation_matrix}
R =
\begin{bmatrix}
C_{\psi}C_{\theta} & C_{\psi}S_{\theta}S_{\phi} - S_{\psi}C_{\phi} & C_{\psi}S_{\theta}C_{\phi} + S_{\psi}S_{\phi} \\
S_{\psi}C_{\theta} & S_{\psi}S_{\theta}S_{\phi} + C_{\psi}C_{\phi} & S_{\psi}S_{\theta}C_{\phi} - C_{\psi}S_{\phi} \\
-S_{\theta} & C_{\theta}S_{\phi} & C_{\theta}C_{\phi}
\end{bmatrix}
\end{equation}
% %TODO I don't use these matrices anywhere, so there probably isn't a need to include them
%The transformation matrices for the angular velocities between the inertial and body frames are shown in \eqref{eq:global_angular_velocity} and \eqref{eq:local_angular_velocity}.
%%[matrices here]
%\begin{equation} \label{eq:global_angular_velocity}
%\dot{\eta} = W_{\eta}^{-1}\nu,
%\begin{bmatrix}
%\dot{\phi} \\
%\dot{\theta} \\
%\dot{\psi}
%\end{bmatrix}
%=
%\begin{bmatrix}
%1 & S_{\phi}T_{\theta} & C_{\phi}T_{\theta} \\
%0 & C_{\phi} & -S_{\phi} \\
%0 & S_{\phi}/C_{\theta} & C_{\phi}/C_{\theta}
%\end{bmatrix}
%\begin{bmatrix}
%p \\
%q \\
%r
%\end{bmatrix}
%\end{equation}
%\begin{equation} \label{eq:local_angular_velocity}
%\nu = W_{\eta}\dot{\eta},
%\begin{bmatrix}
%p \\
%q \\
%r
%\end{bmatrix}
%=
%\begin{bmatrix}
%1 & 0 & -S_{\theta} \\
%0 & C_{\phi} & C_{\theta}S_{\phi} \\
%0 & -S_{\phi} & C_{\theta}C_{\phi}
%\end{bmatrix}
%\begin{bmatrix}
%\dot{\phi} \\
%\dot{\theta} \\
%\dot{\psi}
%\end{bmatrix}
%\end{equation}
The quadcopter is assumed to be symmetrical with equal length arms for each rotor.
Aligning the arms along the body's $x$ and $y$ axes gives the diagonal inertia matrix in \eqref{eq:inertia_matrix}.
Due to symmetry, $I_{xx} = I_{yy}$.
%[put inertial matrix here]
\begin{equation} \label{eq:inertia_matrix}
\begin{bmatrix}
I_{xx} & 0 & 0 \\
0 & I_{yy} & 0 \\
0 & 0 & I_{zz}
\end{bmatrix}
\end{equation}
The angular velocity of each rotor generates a thrust force perpendicular to the body frame, as well as a torque about the rotor axis.
This relationship is shown in \eqref{eq:rotor_force} and \eqref{eq:rotor_torque},
where $\omega$ is the angular velocity of the $i$th rotor, $k$ is the lift constant, $b$ is the drag constant, and $I_{M}$ is the rotor's moment of inertia.
%[equations here]
\begin{equation} \label{eq:rotor_force}
f_{i} = kw_{i}^{2}
\end{equation}
\begin{equation} \label{eq:rotor_torque}
\tau_{M_{i}} = b\omega_{i}^{2} + I_{M}\dot{\omega_{i}}
\end{equation}
Typically the effect of the angular acceleration is considered small and is omitted in most analyses, so it will not be present in the remainder of the dynamics derivations. This is because during steady state flight the rotors will be maintaining a constant (or almost constant) velocity and will have approximately zero acceleration \cite{gibiansky}.
Note that the forces and torques generated are always proportional to the square of the rotor's angular velocity, thus working with this term instead of the angular velocity itself is simpler. %[put this part under simulation instead]?
The set of values making up the square of the rotor angular velocities is referred to as the `rotor space' in the remainder of this thesis.
Combining the forces of all four rotors leads to \eqref{eq:thrust}, where $T$ is the thrust in the direction of the z-axis of the body.
Combining the torques of all four rotors leads to \eqref{eq:torque}, where the vector $\tau_{B}$ represents the torques across each of the principal body axes ($\tau_{\phi}$ for roll, $\tau_{\theta}$ for pitch, and $\tau_{\psi}$ for yaw).
The distance between the rotor and the center of mass of the quadcopter is denoted by $l$.
%[put the two equations here]
\begin{equation} \label{eq:thrust}
T = \sum_{i=1}^{4} f_{i} = k\sum_{i=1}^{4} w^{2}_{i} , T_{B} =
\begin{bmatrix}
0 \\
0 \\
T
\end{bmatrix}
\end{equation}
\begin{equation} \label{eq:torque}
\tau_{B} =
\begin{bmatrix}
\tau_{\phi} \\
\tau_{\theta} \\
\tau_{\psi}
\end{bmatrix}
=
\begin{bmatrix}
lk(-w_{2}^{2}+w_{4}^{2}) \\
lk(-w_{1}^{2}+w_{3}^{2}) \\
\sum_{i=1}^{4}\tau_{M_{i}}
\end{bmatrix}
\end{equation}
The governing equation for translational motion is \eqref{eq:translation}; where $\xi$ is the linear position vector, $T_{B}$ is the thrust from \eqref{eq:thrust}, $R$ is the rotation matrix from \eqref{eq:rotation_matrix}, $A(\dot{\xi})$ is a matrix containing the drag force, and $G$ is the gravitational force.
\begin{equation} \label{eq:translation}
m\ddot{\xi} = T_{B}R - A(\dot{\xi})\dot{\xi} - G
\end{equation}
Expanding \eqref{eq:translation} and setting the equation in terms of translational acceleration leads to \eqref{eq:translation_expanded}.
\begin{equation} \label{eq:translation_expanded}
\begin{bmatrix}
\ddot{x} \\
\ddot{y} \\
\ddot{z}
\end{bmatrix}
=
\dfrac{T}{m}
\begin{bmatrix}
C_{\psi}S_{\theta}C_{\phi} + S_{\psi}S_{\phi} \\
S_{\psi}S_{\theta}C_{\phi} - S_{\psi}S_{\phi} \\
C_{\theta}C_{\phi}
\end{bmatrix}
-
\dfrac{1}{m}
\begin{bmatrix}
A_{x}|\dot{x}| & 0 & 0 \\
0 & A_{y}|\dot{y}| & 0 \\
0 & 0 & A_{z}|\dot{z}|
\end{bmatrix}
\begin{bmatrix}
\dot{x} \\
\dot{y} \\
\dot{z}
\end{bmatrix}
-
\begin{bmatrix}
0 \\
0 \\
g
\end{bmatrix}
\end{equation}
The governing equation for rotational motion is \eqref{eq:rotation_expanded}; where $\eta$ is the Euler angle vector, $I$ is the inertia matrix from \eqref{eq:inertia_matrix}, $\tau_{B}$ is the applied torque from \eqref{eq:torque}, and $C(\dot{\eta})\dot{\eta}$ is the centripetal force.
\begin{equation} \label{eq:rotation}
I\ddot{\eta} = C(\dot{\eta})\dot{\eta} + \tau_{B}
\end{equation}
Expanding \eqref{eq:rotation} and setting the equation in terms of angular acceleration leads to \eqref{eq:rotation_expanded}.
\begin{equation} \label{eq:rotation_expanded}
\begin{bmatrix}
\ddot{\phi} \\
\ddot{\theta} \\
\ddot{\psi}
\end{bmatrix}
=
\begin{bmatrix}
(I_{yy} - I_{zz})\dot{\theta}\dot{\psi}/I_{xx} \\
(I_{zz} - I_{xx})\dot{\phi}\dot{\psi}/I_{yy} \\
(I_{xx} - I_{yy})\dot{\phi}\dot{\theta}/I_{zz}
\end{bmatrix}
+
\begin{bmatrix}
\tau_{\phi}/I_{xx} \\
\tau_{\theta}/I_{yy} \\
\tau_{\psi}/I_{zz}
\end{bmatrix}
\end{equation}
Equations \eqref{eq:translation_expanded} and \eqref{eq:rotation_expanded} are used throughout the remainder of this thesis to model the dynamics of the quadcopter during flight.
\section{Simulation}
%[maybe move this section later in the thesis, possibly put pure python sim here and v-rep sim elsewhere (with implementation?)]
%[talk about V-REP, throw in a reference for it]
%[possibly mention MORSE and choosing VREP over it]
%[talk about pure python simulator built from dynamics equations]
%[VREP is used because it allows complex environments and sensors]
%should probably include somewhere what values were used for each of the 'parameters' in the simulation, i.e. mass, inertia, lengths of rotor arms, etc
The quadcopter model was validated and tested using a computer simulation environment.
The advantage of starting with a simulation rather than going straight to physical hardware is that it is quicker and easier to prototype new control algorithms, and it is much less costly to do so.
There are three robot simulators that were considered: Virtual Robotics Experimentation Platform (V-REP)\cite{vrep}, Modular Open Robotics Simulator Engine (MORSE)\cite{echeverria2011modular}, and Gazebo\cite{koenig2004design}. All three simulators were experimented with during the beginning of this work and a qualitative summary of the relative strengths of each approach is shown in \autoref{table:robot_simulators}.
%TODO fix up alignment of this table, and possibly put the description text into the actual body
\begin{table}
\begin{threeparttable}
\caption{Robotic Simulator Candidates} \label{table:robot_simulators}
%\begin{center}
\begin{tabularx}{\textwidth}{| X | l | l | l |}
\hline
\textbf{Feature} & \textbf{V-REP} & \textbf{MORSE} & \textbf{Gazebo} \\ \hline
Python Support & **** & *** & * \\ \hline
Ease of Model Creation & *** & **** & ** \\ \hline
Quality of Available Quadcopter Models & *** & ** & **** \\ \hline
Timing Control & **** & * & ** \\ \hline
Interactivity with Simulation & **** & ** & ** \\ \hline
Community Support & **** & **** & **** \\ \hline
\end{tabularx}
\begin{tablenotes}
\footnotesize
\item The number of stars indicate the extent to which the simulator demonstrates a particular feature.
Descriptions for each feature are given below.
\textit{Python Support}: the extent in which the simulator supports control from an external Python script.
\textit{Ease of Model Creation}: how easy it is to build a virtual environment and add sensors and actuators to robots in this environment.
\textit{Quality of Available Quadcopter Models}: how realistic the publicly available quadcopter models are.
\textit{Timing Control}: how much control the programmer has on the physics simulation steps and synchronization with Nengo.
\textit{Interactivity with Simulation}: degree in which the simulation can be interacted with once it is built and running.
\textit{Community Support}: available online resources to get help with using the simulator.
\end{tablenotes}
%\end{center}
\end{threeparttable}
\end{table}
For this project the Virtual Robotics Experimentation Platform (V-REP) was chosen as the physical simulation environment.
This open-source software package is free to use for educational purposes;
contains models of various robotic platforms, including a model of a quadcopter;
and allows the construction of intricate 3D virtual environments for the quadcopter to interact with, as well as many virtual sensors with which to equip the quadcopter, such as cameras.
%[possible table comparing V-REP/MORSE/Gazebo with pros and cons of each]
The simulation environment in V-REP is set up to be a large open space with small obstacles and walls along the ground.
The quadcopter model was initialized to start in the center of the space, 0.5 meters above the ground.
This model is the one provided with the V-REP software courtesy of Eric Rohmer and Lyall Randell.
The quadcopter's target is a small semi-transparent green sphere. The goal of the control system is to make the quadcopter move to the target's location with the target's orientation.
For this thesis, an environment was created which includes various wind tunnels, which are zones of space which will exert an external force on the quadcopter in a particular direction if the quadcopter is within the zone.
There are also zones that can exert various nonlinear forces on the quadcopter.
For example, one zone could push the quadcopter in the $z$ direction with a force proportional to the square of its horizontal velocity.
In addition to these zones, the quadcopter can also pick up and drop off boxes of various mass.
These wind zones and boxes are used to test how well the controller can adapt to changes in its dynamics.
An example of a region within the simulation environment is shown in \autoref{fig:vrep_screenshot}.
\begin{figure}
\centering
\includegraphics[height=0.3\textheight]{./figures/VREPScreenshot.png}
\caption{Simulation Environment in V-REP}
\label{fig:vrep_screenshot}
\captionsetup{singlelinecheck=off,font=footnotesize}
\caption*{
Screen capture of an example environment in V-REP. The coloured areas with arrows represent regions of space where a wind force is applied to the quadcopter in the direction of the arrows. The blue region resembling a circuit board represents an area where an unknown non-linear force will be applied to the quadcopter. The semi-transparent green sphere is the target location. The quadcopter has reached its target in this example.}
\end{figure}
\chapter{Control} \label{chap:control}
\section{PID Control}
%[go over standard control, talk about PD and PID systems]
%[put in a block diagram of a simple PID system -> maybe show spots where disturbances can enter]
%[talk about applying PD and PID control to a quadcopter]
%[mention limits of PID control that adaptive control is trying to solve]
The canonical method for building a control system is to use a PID controller.
This is a closed loop controller that works by applying gains to an error signal and feeding the result as input to the plant (system being controlled).
PID stands for Proportional, Integral, and Derivative, referring to the three types of gains used.
One gain is applied directly to the error (proportional); a second gain is applied to the derivative of the error, and the third gain is applied to the integral of the error.
Each of these gains serves a unique purpose, and the careful tuning of all three is required to get the desired performance of the controller.
The proportional gain is the main driver of the system and responds directly to the error to bring the system towards its target point.
The larger the gain, the faster this response will be.
However, using only this gain will not account for any inertia in the system and will often cause the system being controlled to overshoot its target, especially when the gain is large.
In some cases, the overshoot can be so large that the system becomes unstable and oscillates out of control.
Thus, the derivative gain is usually used in addition, because it is sensitive to the rate of change of the error, and attempts to bring this rate towards zero.
The faster the system is moving towards its target state, the more this gain acts to slow it down, by effectively providing a form of damping and so reducing the amount of overshoot.
Depending on how this parameter is tuned, and the properties of the system at hand, it can remove overshooting entirely.
Due to unmodelled disturbances or changing external inputs, there may be a steady-state error in the system, wherein the controller has reached a stable state, yet there is still an error being measured.
The integral term is designed to account for this steady-state error by keeping a running sum of the error over time.
Eventually, this integral error should be large enough that it will drive the system to close the steady-state error gap.
\section{Adaptive Control} \label{sec:adaptive_control}
%[name a few other adaptive control methods and give references]
%[go over the slotine adaptive control stuff, throw in a bunch of references]
%[maybe throw in a bunch of the equations and derivations I did on paper]
%[mention getting the slotine stuff working on the python simulator]
%[talk about how Nengo can be used to do adaptive control with learning]
Sometimes the kinematics and dynamics of the system being controlled are unknown, or change over time in an unknown fashion.
A controller that works well for the system initially may not be well suited when the system undergoes changes.
In this situation, it is useful to have a controller that can adapt to these changes.
The foundation of adaptive control is based on parameter estimation.
First, a mathematical model of the system to be controlled is generated based on physical laws.
This model is typically of the form shown in \eqref{eq:physical_equation}, where $q$ is the vector of state variables, $M(q)$ is a mass/inertia matrix, $C(q,\dot{q})$ is the coriolis-drag term, $g(q)$ is the gravitational force, and $\tau$ is a vector representing the input force/torque to the system.
\begin{equation} \label{eq:physical_equation}
M(q)\ddot{q} + C(q,\dot{q})\dot{q} + g(q) = \tau
\end{equation}
%TODO
%[[[[[a lot more stuff to go here, need to understand it more first]]]]]
The goal of the controller is to bring the system to a particular target state.
Typically the state as well as its derivative is desired to be controlled.
Thus, the second derivative of the state will be zero when the system has arrived at the target state.
Setting $\ddot{q}$ to be zero gives the relationship of the inputs to the rest of the state shown in \eqref{eq:input_equation}.
\begin{equation} \label{eq:input_equation}
\tau = C(q,\dot{q})\dot{q} + g(q)
\end{equation}
An estimate of $q$ and $\dot{q}$ can typically be measured, leaving the only potentially unknown quantities in the right-hand side of the equation to be the physical parameters of the system.
If these physical parameters are constant and linear with respect to the system state, the equation can be reorganized as in \eqref{eq:Y_equation}.
Here $\theta$ is a vector of constant system parameters and $Y(q,\dot{q})$ is a known matrix dependent on the system state.
$\tau$ is the input required to keep the system in a steady state.
\begin{equation} \label{eq:Y_equation}
\tau = C(q,\dot{q})\dot{q} + g(q) = Y(q,\dot{q})\theta
\end{equation}
Often the system parameters are not fully known and an estimate needs to be used instead.
Many control applications also require the system to be able to transition to different states, rather than remain at a particular state.
The adaptive control law in \eqref{eq:Y_and_control_law} uses an estimate of the parameter vector, $\hat{\theta}$, along with a standard control law to compute the desired input to the system. Here $e$ is the state error and $K$ is a gain matrix.
More detail on this style of adaptive control law can be found in \cite{slotine1987adaptive, slotine1991applied, cheah2006adaptive}.
%TODO EDIT1 add references to Slotine papers as well as a couple quick comments about the strengths of those controllers (guaranteed to converge with sufficient exploration of space, etc)
\begin{equation} \label{eq:Y_and_control_law}
\tau = Y(q,\dot{q})\hat{\theta} + Ke
\end{equation}
The parameter estimates can be initialized to any stable value and are updated according to the relationship in \eqref{eq:Y_update_equation}.
$L$ is a learning rate parameter that determines how quickly the parameter estimates change over time in proportion to the measured error.
The parameter estimates will eventually converge on values that allow the system to be controlled with minimal error.
Given sufficient exploration of the state space, the parameter estimates are guaranteed to converge to the real values if the real values are required for optimal control \cite{slotine1987adaptive}.
\begin{equation} \label{eq:Y_update_equation}
\dot{\hat{\theta}} = LY(q,\dot{q})^{T}Ke
\end{equation}
Creating a mathematical model of a system with enough detail to account for everything is difficult.
Assumptions and approximations must be made if the model is to be tractable.
Moreover, external forces from the environment may influence the model, and their form may be unknown as the environment can be largely unknown.
One way to overcome this problem is to use a set of basis functions as the model, and the weights applied to each element of the basis as the constant parameters.
If the basis is designed such that it can represent any computable function to a reasonable degree of accuracy, it will be effective in the adaptive control problem.
Gaussian basis functions are commonly used in adaptive control \cite{sanner1992gaussian}, but neural networks may be used as well \cite{barto1983neuronlike}.
This thesis explores the application of this form of control law using basis functions that are biologically plausible spiking neurons.
\section{Neural Simulation}
%[brief description of the NEF and Nengo and how it can be used, mostly just put references here]
%put a reference to Travis' thesis as an example of how Nengo's learning can be used for motor control
% Maybe this section shouldn't be here at all, and just have a brief description at the start of the next section?
%TODO go through and edit this section later for those common grammar things
The Neural Engineering Framework (NEF)\cite{eliasmith2004neural} provides a means of representing arbitrary vectors using the properties of neurons as a basis.
This is done through a nonlinear encoding mechanism carried out by the tuning curves of the neurons, and a weighted linear decoding of the responses of the neurons to retrieve an approximation of the vector being encoded.
A transformation can be applied to the underlying representation by specifying different weights on the linear decoding.
Any computable function can be approximated through a transform, and the degree of accuracy of the decoding is dependent on the number of neurons used and the complexity of the function.
%TODO put some simple example here about x and x**2?
%TODO talk about dynamics here, might need to fix wording, and talk about recurrent connections?
The neurons themselves are a part of a dynamical system where timing effects and filters across connections play a role in the behaviour of the system.
%It also specifies a means of performing transformation
For more detail on the NEF, see \cite{eliasmith2007build, stewart2011neural, eliasmith2013build}. % put this line in if you think the reader might want more details.
Simulation of biological neurons is carried out by the software package Nengo \cite{bekolay2013nengo}.
This software implements the algorithms in the NEF and provides an easy to use Python interface for building complex models under this framework.
The core components of Nengo are networks, nodes, ensembles, and connections.
A network is a container for all of the components, it can contain any number of nodes, ensembles, connections, and even other networks.
There is always one base network from which the rest of the model is built.
Ensembles are groups of neurons representing a single vector.
The dimensionality of this vector can be any positive integer.
Nodes are used when a particular part of the network is doing a computation without using neurons as the underlying representation.
Typically nodes are used as the inputs and outputs to a neural system.
Connections specify transformations between representational components (ensembles and nodes) through one-way links where the information flows from the output of the first representational component (origin) to the input of the second representational component (termination).
Connections may have a synapse model applied to them, where the information from one end of the connection is delayed by a time-step before reaching the other end and a filter with a particular time constant may be applied.
If no synaptic filter is applied, the value from the origin of the connection is sent directly to the termination of the connection during the same time step.
Nengo supports a variety of underlying neuron models for its Ensembles.
The most commonly used is the Leaky Integrate-and-Fire (LIF) neuron \cite{burkitt2006review}.
%[add a brief description?]. %TODO add this description
Ensembles can also be run in direct mode, in which functions are computed explicitly rather than with neurons.
However, models in this mode are not implementable directly on neuromorphic hardware, and the behaviour of the system can be significantly different.
Nevertheless, it can be useful for constructing working prototypes in simulation before converting the entire system to an underlying neural model. %TODO: this sounds gross, fix it... %TODO EDIT1
Once the network structure has been specified, Nengo can build and run a simulation of this network for either a specified duration of time, or until a stop signal is generated.
All timing is measured as `simulated time' with a specific time-step.
If the time-step is short, the simulation can capture minute timing details more accurately, but the system as a whole will run slower with respect to real-time. A default time step of 1ms is typically used in Nengo models, which provides a reasonable trade-off between accuracy and run-time.
%TODO is there any justification for this?
\section{Adaptive Control in Nengo}
%[Brief overview of Nengo (can be made longer with subsections if need be)]
%[Talk about the PES rule, how it relates to the slotine stuff]
%[talk about how there is no need to tune the KI term with the PES rule, this adaptive I term is easier to use]
In this thesis, we use the adaptive control methods described above to build a quadcopter controller using Nengo.
An ensemble of simulated neurons is used as the set of basis functions for the physical model, and the decoders of these neurons are used as the vector of unknown constant parameters.
A biologically plausible learning rule known as the Prescribed Error Sensitivity (PES) rule is used to update the decoder values \cite{bekolay2013simultaneous}.
This learning method works by first creating a connection from an ensemble of spiking neurons representing the state of the system to an ensemble or node representing the output of the controller.
This is known as the `learned connection' and can be initially set to perform any transformation, but is typically initialized for the output to be random or zero.
If the designer has an approximation of what the final learned transformation should look like, they can set this as the initial transformation.
Doing so will allow the system to converge to the final transformation more quickly.
The learned connection will be modulated by an error signal, which can come from anywhere in the network.
The PES learning rule will attempt to reduce the error signal by changing the value of the decoders on the learned connection.
The direction in which the decoder values change is dependent on the sign of the error.
The magnitude of the change in decoder values at each time step is dependent on both the magnitude of the error and a learning-rate parameter.
The learning rate is a dimensionless parameter that needs to be tuned for the specific application.
It is dependent on the simulation time step, the number of neurons in the state ensemble, as well as how responsive the model needs to be to changes.
%TODO [[check to make sure this is true!!]]
A larger learning rate will cause larger reactions to error, effectively making the system trust its current measurements more than historical ones.
A smaller time-step means that these changes will occur more frequently, so the net change over time will be greater.
A larger number of neurons means that the changes will be greater, as there will be more decoders changing. The overall transformation is a sum of these decoders.
%TODO [[check to make sure this is true!!]].
%[[talk about differing dimensions in these populations?]]
%TODO TODO TODO should this example go here???
%A simple example of using the PES learning rule to control an inverted pendulum is shown in Figure XXX for clarification before employing the rule the more high dimensional case of a quadcopter controller. [[describe how the model works in the figure description, talk about the different dimensionalities of each population]]
%[put in a simple network diagram showing the PES rule, and possibly an equation with its math]
% Should a chapter on simulation go here??
%======================================================================
%\chapter{Simulation} \label{chap:simulation}
%======================================================================
%======================================================================
\chapter{Design} \label{chap:implementation}
%======================================================================
%TODO should the pure math adaptive controller be talked about here? Maybe put this as a subsection in adaptive control? This might make more sense to be after the basic controller model is introduced, but before all of the iterations
\section{Derivation of Non-Neural Adaptive Controller} \label{chap:nonneuraladaptive} %TODO pick a better title
%this section will be heavy on math, and go through how the adaptive python model was formed (from the equations on all of those sheets of paper)
Based on the dynamics equations in \autoref{sec:dynamics} and the adaptive control theory presented in \autoref{sec:adaptive_control}, an adaptive controller for a quadcopter can be generated using the methods described in \cite{cheah2006adaptive}.
The first step is to set up the governing equation for the system \eqref{eq:starting_equation}, and rearrange it so that the right side is in terms of the second derivative of the state \eqref{eq:rearranged_starting_equation}.
\begin{equation} \label{eq:starting_equation}
M(q)\ddot{q} + C(q,\dot{q})\dot{q} + g(q) = B(q)u
\end{equation}
\begin{equation} \label{eq:rearranged_starting_equation}
\ddot{q} = M(q)^{-1}(-C(q,\dot{q})\dot{q} - g(q) + B(q)u)
\end{equation}
We can then choose the relationship in \eqref{eq:internal_starting_equation} which allows $\ddot{q}$ to be zero, given the values of the terms in \eqref{eq:C} and \eqref{eq:g}.
\begin{equation} \label{eq:internal_starting_equation}
B(q)u = C(q,\dot{q})\dot{q} + g(q)
\end{equation}
\begin{equation} \label{eq:C}
C(q,\dot{q}) =
\begin{bmatrix}
A_{x}|\dot{x}| & 0 & 0 & 0 & 0 & 0 \\
0 & A_{y}|\dot{y}| & 0 & 0 & 0 & 0 \\
0 & 0 & A_{z}|\dot{z}| & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & I_{zz}\dot{\psi} & -I_{yy}\dot{\theta} \\
0 & 0 & 0 & -I_{zz}\dot{\psi} & 0 & I_{xx}\dot{\phi} \\
0 & 0 & 0 & I_{yy}\dot{\theta} & -I_{xx}\dot{\phi} & 0 \\
\end{bmatrix}
\end{equation}
\begin{equation} \label{eq:g}
g(q) =
\begin{bmatrix}
0 \\
0 \\
mg \\
0 \\
0 \\
0 \\
\end{bmatrix}
\end{equation}
Here, $u$ is a vector containing the thrust force and the rotational torque in the body frame, $B(q)$ is the transformation matrix of the force and torque from the body frame to the inertial frame, and $\omega$ is a vector containing the squared angular velocities of each rotor.
Consequently, we can write:
\begin{equation} \label{eq:u}
u =
\begin{bmatrix}
u_{1} \\
u_{2} \\
u_{3} \\
u_{4} \\
\end{bmatrix}
=
A\omega
=
\begin{bmatrix}
k & k & k & k \\
0 & -lk & 0 & lk \\
-lk & 0 & lk & 0 \\
-b & b & -b & b \\
\end{bmatrix}
\begin{bmatrix}
\omega_{1}^{2} \\
\omega_{2}^{2} \\
\omega_{3}^{2} \\
\omega_{4}^{2} \\
\end{bmatrix}
\end{equation}
\begin{equation} \label{eq:b}
B(q) =
\begin{bmatrix}
\cos{\phi}\sin{\theta}\cos{\psi} + \sin{\theta}\sin{\psi} & 0 & 0 & 0 \\
\cos{\phi}\sin{\theta}\sin{\psi} - \sin{\theta}\cos{\psi} & 0 & 0 & 0 \\
\cos{\phi}\cos{\theta} & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\end{equation}
Expanding \eqref{eq:internal_starting_equation} and rearranging the equation in terms of $\omega$ results in \eqref{eq:Y}.
%TODO find a good letter name for w->u
\begin{equation} \label{eq:Y}
\omega = Y(q,\dot{q})\hat{\theta} = A^{-1}B(q)^{-1}[C(q,\dot{q})\dot{q} + g(q)]
\end{equation}
The form of $Y(q,\dot{q})$ can be determined as in \eqref{eq:Y_expanded} by pulling out a vector of the unknown constant parameters. The true value of these parameters assuming the model is perfect is shown in \eqref{eq:parameters}.
%TODO may need to rearrange this equation to reflect the rotor orientation
\begin{equation} \label{eq:Y_expanded}
Y(q,\dot{q})\hat{\theta} =
\begin{bmatrix}
a|\dot{x}|\dot{x} & b|\dot{y}|\dot{y} & c|\dot{z}|\dot{z} & c & 0 & -\dot{\phi}\dot{\psi} & -\dot{\phi}\dot{\theta} \\
a|\dot{x}|\dot{x} & b|\dot{y}|\dot{y} & c|\dot{z}|\dot{z} & c & -\dot{\theta}\dot{\psi} & 0 & \dot{\phi}\dot{\theta} \\
a|\dot{x}|\dot{x} & b|\dot{y}|\dot{y} & c|\dot{z}|\dot{z} & c & 0 & \dot{\phi}\dot{\psi} & -\dot{\phi}\dot{\theta} \\
a|\dot{x}|\dot{x} & b|\dot{y}|\dot{y} & c|\dot{z}|\dot{z} & c & \dot{\theta}\dot{\psi} & 0 & \dot{\phi}\dot{\theta} \\
\end{bmatrix}
\begin{bmatrix}
\hat{\theta_{1}} \\
\hat{\theta_{2}} \\
\hat{\theta_{3}} \\
\hat{\theta_{4}} \\
\hat{\theta_{5}} \\
\hat{\theta_{6}} \\
\hat{\theta_{7}} \\
\end{bmatrix}
\end{equation}
\begin{subequations} \label{eq:abc_definitions}
\begin{equation}
d = (\cos{\phi}\sin{\theta}\cos{\psi} + \sin{\theta}\sin{\psi})^{2} + (\cos{\phi}\sin{\theta}\sin{\psi} - \sin{\theta}\cos{\psi})^{2} + (\cos{\phi}\cos{\theta})^{2}
\end{equation}
\begin{equation}
a = (\cos{\phi}\sin{\theta}\cos{\psi} + \sin{\theta}\sin{\psi}) / d
\end{equation}
\begin{equation}
b = (\cos{\phi}\sin{\theta}\sin{\psi} - \sin{\theta}\cos{\psi}) / d
\end{equation}
\begin{equation}
c = (\cos{\phi}\cos{\theta}) / d
\end{equation}
\end{subequations}
%TODO may need to change this slightly to reflect the rotor orientation
\begin{equation} \label{eq:parameters}
\theta =
\begin{bmatrix}
A_{x}/4k \\
A_{y}/4k \\
A_{z}/4k \\
mg/4k \\
(I_{zz}-I_{yy})/2kl \\
(I_{xx}-I_{zz})/2kl \\
(I_{yy}-I_{xx})/2kl \\
\end{bmatrix}
\end{equation}
The adaptive controller and parameter update equations are shown in \eqref{eq:adaptive_control_equation} and \eqref{eq:adaptive_update_equation} respectively.
$K$ is the control gain matrix \eqref{eq:gain_matrix}, $T_{R}$ is the transformation from task space to rotor space \eqref{eq:rotor_transform}, $e$ is the state error, and $L$ is the learning rate.
The value of $L$ can either be a constant or a 4x4 matrix.
For simplicity a constant value of one is used.
%TODO need to mention and reference what K and e are in the text
\begin{equation} \label{eq:adaptive_control_equation}
\omega = Y(q,\dot{q})\hat{\theta} + T_{R}Ke
\end{equation}
\begin{equation} \label{eq:adaptive_update_equation}
\dot{\hat{\theta}} = LY^{T}T_{R}Ke
\end{equation}
\section{Controller Implementation}
%[show one model of the controller, the original one, talk about how it works]
%[something about how it is a target controller, rather than path]
%[maybe put some bit explaining the rationale behind the gains? Stuff like what increasing and decreasing specific gains does (might be better to just have this in the PID control section above)]
The goal of the controller is to actuate the quadcopter in such a way that it travels to a desired position in a reasonable amount of time.
This position is specified as a set of $x$, $y$, and $z$ coordinates and a particular yaw direction.
The controller is given the state error of the quadcopter and its target, as well as the current linear and angular velocities of the quadcopter.
It needs to use this information to generate a suitable control signal.
The adaptive controller here consists of two parts. The first is a standard PD controller that generates a four-dimensional output signal in the space of possible quadcopter motions (task space).
The gain matrix that performs this operation can be seen in \eqref{eq:gain_matrix}.
This signal is then multiplied by the matrix in \eqref{eq:rotor_transform} to transform it into the four dimensional rotor velocity space, providing the actuation associated with the desired movement commands.
The design of this matrix depends upon the orientation of the rotor blades to the $x$ and $y$ axes.
This transformation matrix assumes that the rotor axes are offset from the $x$ and $y$ axes by 45 degrees as the V-REP model used here.
\begin{equation} \label{eq:gain_matrix}
K =
\setcounter{MaxMatrixCols}{12}
\begin{bmatrix}
0 & 0 & k_{2} & 0 & 0 & -k_{4} & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & k_{1} & 0 & 0 & -k_{3} & 0 & -k_{5} & 0 & 0 & k_{7} & 0 & 0 \\
-k_{1} & 0 & 0 & k_{3} & 0 & 0 & 0 & -k_{5} & 0 & 0 & k_{7} & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -k_{6} & 0 & 0 & k_{8}
\end{bmatrix}
\end{equation}
\begin{equation} \label{eq:rotor_transform}
T_{R} =
\begin{bmatrix}
1 & -1 & 1 & 1 \\
1 & -1 & -1 & -1 \\
1 & 1 & -1 & 1 \\
1 & 1 & 1 & -1
\end{bmatrix}