diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 2 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, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4c2267b --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Scalable techniques for autonomous construction of a paraboloidal space telescope in an elliptic orbit + +Code for the paper 'Scalable techniques for autonomous construction of a paraboloidal space telescope in an elliptic orbit' by Aaron John Sabu and Dwaipayan Mukherjee + +*** +### Abstract + +It is well acknowledged that human-made technology is not always at par with human curiosity, and an example is the inability to send large telescopes to outer space despite their higher resolution and less atmospheric interference. In this paper, we develop a framework for autonomous in-orbit construction using spacecraft formation such that a large telescope can be built in an elliptic orbit using multiple spacecraft. We split this problem into four steps for converging the position and attitude of each spacecraft at predefined values around a central spacecraft. Each spacecraft performs attitude synchronization with its neighbors to match its three degrees of freedom in orientation as a parabolic mirror. Simulations validate our proposed methods and the paper concludes with an open possibility of using other techniques to improve upon existing results. + +*** +### Disclaimers + +The work was supported in part by an ISRO funded project bearing code RD/0120-ISROC00-007. Aaron John Sabu (

aaronjohnsabu1999@gmail.com

) is an undergraduate student and Dwaipayan Mukherjee (

dm@ee.iitb.ac.in

) is an Asst. Professor with the Dept. of Electrical Engineering, Indian Institute of Technology Bombay, Powai, Mumbai, Maharashtra, India} \ No newline at end of file diff --git a/results/Three-Layer Double-Auction/Case 1/Stage-01A.html b/results/Three-Layer Double-Auction/Case 1/Stage-01A.html new file mode 100644 index 0000000..759e551 --- /dev/null +++ b/results/Three-Layer Double-Auction/Case 1/Stage-01A.html @@ -0,0 +1,67 @@ + + + +
+
+ + \ No newline at end of file diff --git a/results/Three-Layer Double-Auction/Case 1/Stage-01B.html b/results/Three-Layer Double-Auction/Case 1/Stage-01B.html new file mode 100644 index 0000000..10431ff --- /dev/null +++ b/results/Three-Layer Double-Auction/Case 1/Stage-01B.html @@ -0,0 +1,67 @@ + + + +
+
+ + \ No newline at end of file diff --git a/results/Three-Layer Double-Auction/Case 1/Stage-02.html b/results/Three-Layer Double-Auction/Case 1/Stage-02.html new file mode 100644 index 0000000..dcbebf9 --- /dev/null +++ b/results/Three-Layer Double-Auction/Case 1/Stage-02.html @@ -0,0 +1,67 @@ + + + +
+
+ + \ No newline at end of file diff --git a/results/Three-Layer Double-Auction/Case 1/Stage-03-Pitch.png b/results/Three-Layer Double-Auction/Case 1/Stage-03-Pitch.png new file mode 100644 index 0000000..e8c2e9f Binary files /dev/null and b/results/Three-Layer Double-Auction/Case 1/Stage-03-Pitch.png differ diff --git a/results/Three-Layer Double-Auction/Case 1/Stage-03-Roll.png b/results/Three-Layer Double-Auction/Case 1/Stage-03-Roll.png new file mode 100644 index 0000000..d007538 Binary files /dev/null and b/results/Three-Layer Double-Auction/Case 1/Stage-03-Roll.png differ diff --git a/results/Three-Layer Double-Auction/Case 1/Stage-03-Yaw.png b/results/Three-Layer Double-Auction/Case 1/Stage-03-Yaw.png new file mode 100644 index 0000000..56c8673 Binary files /dev/null and b/results/Three-Layer Double-Auction/Case 1/Stage-03-Yaw.png differ diff --git a/results/Three-Layer Double-Auction/Case 2/Stage-01A.html b/results/Three-Layer Double-Auction/Case 2/Stage-01A.html new file mode 100644 index 0000000..fc6f876 --- /dev/null +++ b/results/Three-Layer Double-Auction/Case 2/Stage-01A.html @@ -0,0 +1,67 @@ + + + +
+
+ + \ No newline at end of file diff --git a/results/Three-Layer Double-Auction/Case 2/Stage-01B.html b/results/Three-Layer Double-Auction/Case 2/Stage-01B.html new file mode 100644 index 0000000..b5b75c8 --- /dev/null +++ b/results/Three-Layer Double-Auction/Case 2/Stage-01B.html @@ -0,0 +1,67 @@ + + + +
+
+ + \ No newline at end of file diff --git a/results/Three-Layer Double-Auction/Case 2/Stage-02.html b/results/Three-Layer Double-Auction/Case 2/Stage-02.html new file mode 100644 index 0000000..3ea046e --- /dev/null +++ b/results/Three-Layer Double-Auction/Case 2/Stage-02.html @@ -0,0 +1,67 @@ + + + +
+
+ + \ No newline at end of file diff --git a/results/Two-Layer Single-Auction/Stage-01-Angle1.gif b/results/Two-Layer Single-Auction/Stage-01-Angle1.gif new file mode 100644 index 0000000..8125992 Binary files /dev/null and b/results/Two-Layer Single-Auction/Stage-01-Angle1.gif differ diff --git a/results/Two-Layer Single-Auction/Stage-01-Angle2.gif b/results/Two-Layer Single-Auction/Stage-01-Angle2.gif new file mode 100644 index 0000000..1031664 Binary files /dev/null and b/results/Two-Layer Single-Auction/Stage-01-Angle2.gif differ diff --git a/results/Two-Layer Single-Auction/Stage-01-Angle3.gif b/results/Two-Layer Single-Auction/Stage-01-Angle3.gif new file mode 100644 index 0000000..9320f86 Binary files /dev/null and b/results/Two-Layer Single-Auction/Stage-01-Angle3.gif differ diff --git a/results/Two-Layer Single-Auction/Stage-01-Angle4.gif b/results/Two-Layer Single-Auction/Stage-01-Angle4.gif new file mode 100644 index 0000000..a3c7fed Binary files /dev/null and b/results/Two-Layer Single-Auction/Stage-01-Angle4.gif differ diff --git a/results/Two-Layer Single-Auction/Stage-01.html b/results/Two-Layer Single-Auction/Stage-01.html new file mode 100644 index 0000000..534615c --- /dev/null +++ b/results/Two-Layer Single-Auction/Stage-01.html @@ -0,0 +1,67 @@ + + + +
+
+ + \ No newline at end of file diff --git a/results/Two-Layer Single-Auction/Stage-02.html b/results/Two-Layer Single-Auction/Stage-02.html new file mode 100644 index 0000000..cd87cbc --- /dev/null +++ b/results/Two-Layer Single-Auction/Stage-02.html @@ -0,0 +1,67 @@ + + + +
+
+ + \ No newline at end of file diff --git a/results/Two-Layer Single-Auction/Stage-03-Pitch.png b/results/Two-Layer Single-Auction/Stage-03-Pitch.png new file mode 100644 index 0000000..a9158f9 Binary files /dev/null and b/results/Two-Layer Single-Auction/Stage-03-Pitch.png differ diff --git a/results/Two-Layer Single-Auction/Stage-03-Roll.png b/results/Two-Layer Single-Auction/Stage-03-Roll.png new file mode 100644 index 0000000..2573b72 Binary files /dev/null and b/results/Two-Layer Single-Auction/Stage-03-Roll.png differ diff --git a/results/Two-Layer Single-Auction/Stage-03-Yaw.png b/results/Two-Layer Single-Auction/Stage-03-Yaw.png new file mode 100644 index 0000000..e5a7542 Binary files /dev/null and b/results/Two-Layer Single-Auction/Stage-03-Yaw.png differ diff --git a/src/algoCompare-cases.txt b/src/algoCompare-cases.txt new file mode 100644 index 0000000..e8d5ee0 --- /dev/null +++ b/src/algoCompare-cases.txt @@ -0,0 +1,131 @@ +3.0 + +--A-- +D > G > S +[[-1.99784066, 0.61604728, 1.44877280], + [ 0.43721149, -1.30390749, 1.55301486], + [ 0.55915338, 2.13624886, -0.14987920], + [ 0.74984804, -0.75304311, -0.66474228], + [ 0.77075604, 0.87307288, -1.74438445], + [-2.48796971, 0.33908818, 0.52480498], + [-1.44477932, 2.52165383, 2.41264048], + [ 1.55365393, -1.82890293, -0.55059913], + [ 1.45058134, 1.89266631, 0.43396470], + [ 0.22868990, 2.95146754, -2.74768372], + [-1.71631586, 2.58945856, -0.11163515], + [-0.84144055, -2.40168379, -2.58900144], + [-0.44148137, 1.84936233, 0.67115186], + [-0.06777739, 2.44530060, 2.95190673], + [ 0.14748820, 0.12127658, -0.61558311], + [-1.80767048, -1.17608603, -2.55560203], + [-1.34076421, -1.64031815, 0.73177507], + [ 2.53145494, -1.02498501, 1.35597693]] + +--B-- +D > G > S +[[ 2.46627585, -0.00365783, -0.86766388], + [ 1.38883444, -0.56932258, 0.85956188], + [-1.25104624, -2.68999598, -0.15664761], + [ 2.16808202, -0.95045921, 1.20754068], + [-1.08903682, 2.60837156, -2.49131614], + [-1.04670232, 1.20957410, -0.72505279], + [-0.84559224, 0.68161740, 2.11365239], + [ 0.64575732, -2.13576666, 0.09339260], + [-2.55221737, -1.67415379, 0.47248629], + [ 0.41558132, 1.75146335, 0.00541343], + [ 2.86279623, 1.26809123, -2.71293342], + [-2.88389105, -2.95786390, 2.92524385], + [ 0.84024423, 1.61057085, 0.91733068], + [ 0.10149796, -2.83326188, -1.57948462], + [-0.15197260, -0.44450887, 0.2405081 ], + [ 1.27905471, -0.58512968, -2.53469193], + [ 2.49569954, 1.30540283, 0.43167947], + [-2.65665346, 1.99028373, -0.42741740]] + +1.0 + +--C-- +D = G > S +[[-2.29364301, 1.26911104, -1.71273596], + [-0.30499439, 1.46048986, 0.84474138], + [ 1.20553178, 0.33463571, -0.45545043], + [ 0.00737466, 2.69883730, 2.20860278], + [-0.13433824, -2.45255776, 0.01869546], + [ 0.87274879, -1.20121056, -2.55504595], + [ 1.82212589, -2.88499068, -2.82692798], + [ 1.32413586, 1.38993451, -1.85659537], + [ 2.79356145, -1.84074991, 1.31134734], + [-2.45089991, 2.86245750, -0.92419686], + [ 0.15760877, -1.63576172, -0.10413470], + [ 0.22633934, 2.55351914, -2.75085611], + [-2.19934209, -1.28014131, 1.85593947], + [ 1.72048638, 1.75400878, -1.49284592], + [ 2.66459536, 0.56970289, -1.64283741], + [-0.26072675, 1.64575550, -1.69458091], + [-1.34255969, 2.06506644, -1.14374557], + [ 1.99163571, -0.24707069, 1.72698837]] + +--D-- +D = G > S +[[-0.19737204, -0.29886555, 0.36305570], + [ 0.30534063, -2.06205336, 0.85791965], + [-0.31816348, -1.50494332, 1.20013356], + [ 2.37388446, -0.77882058, -2.38966806], + [-1.26343545, 1.35004930, -2.50027709], + [-2.79467901, 1.98856370, -2.35316213], + [ 2.13003201, -1.86269152, 1.10253472], + [-0.67690309, 0.79051274, 2.26351260], + [-0.59926310, -1.34331266, 2.17618607], + [ 1.53274718, 2.75566058, -2.39949286], + [ 2.50468947, -0.79161118, 1.89192649], + [-1.34296578, -2.47305670, 0.32794480], + [ 0.04971921, 0.31507048, 1.23422994], + [-1.49500104, 1.42257160, 0.02548234], + [ 1.64378575, 0.50837734, -1.16396825], + [-0.15880788, -1.60500876, 0.57350283], + [ 1.97794503, -1.58259626, 0.98126498], + [-2.37234622, -2.92121553, -0.15240542]] + +0.25 + +--E-- +D = G = S +[[-1.92787107, 0.63939344, -1.74877778], + [-0.30968752, -2.78756743, -1.91208517], + [-1.69563097, -0.54375145, -2.04193897], + [-1.19935501, 1.31577906, -2.54588322], + [-2.98803831, -0.36685609, -2.54239741], + [ 1.12833730, -2.12756837, -1.36607097], + [ 1.61800051, 0.18784015, 0.28711688], + [ 1.92682527, 2.09294888, 0.98220375], + [ 1.97998589, 2.24655191, 0.14703710], + [ 0.47940243, 1.69466183, 0.05916908], + [-2.68327754, -1.14751618, 2.31631216], + [ 0.18796644, 2.84885841, 1.20630379], + [-1.69364916, 0.59877788, 2.61884078], + [ 1.43370002, 2.63335636, -1.51988725], + [-1.03356433, 2.15331561, -2.18635319], + [ 2.88018742, -2.11038576, -0.34113182], + [-2.52695979, 2.31005279, 1.70296583], + [-0.95626977, -1.69848325, 1.65944077]] + +--F-- +D = G = S +[[ 0.59172304, 2.18793548, 1.10135151], + [ 0.62986765, -0.44234319, -1.62572802], + [-0.95098904, -2.35326135, 0.49000436], + [-1.32871148, -2.64306835, -2.85634444], + [-1.09643693, -2.35856294, 0.17633947], + [ 0.3299397 , 2.37370064, 0.27763727], + [-2.69151347, -1.59395844, -2.30497489], + [ 1.08577260, -0.95740143, 2.48758025], + [ 2.67521330, 2.29325859, -1.98293085], + [ 2.43850247, 1.28220791, 2.44042221], + [-1.97818562, -0.47634221, -0.88855438], + [ 0.93433954, -0.24520145, 1.18601613], + [-1.60052782, 0.68527799, 1.53182175], + [-0.61836986, 0.16281878, 2.30119389], + [-0.09954839, 0.96592547, 0.57013133], + [ 2.62370233, 0.60724350, 2.32005221], + [ 1.13604260, 1.25932709, 1.28721869], + [ 0.79380202, -1.49476592, -0.22534066]] \ No newline at end of file diff --git a/src/algoCompare.py b/src/algoCompare.py new file mode 100644 index 0000000..da7cffa --- /dev/null +++ b/src/algoCompare.py @@ -0,0 +1,109 @@ +from copy import deepcopy +from math import sqrt, sin, cos, radians +from simulate import simulatePL +from glideslope import multiAgentGlideslope +from initializations import poseInit + +numAgents = 18 +numJumps = 5 + +innerRad = 0.4 +R_T = [[innerRad*1*sin(radians( 0)), innerRad*1*cos(radians( 0)), 0.000], + [innerRad*1*sin(radians( 60)), innerRad*1*cos(radians( 60)), 0.000], + [innerRad*1*sin(radians(120)), innerRad*1*cos(radians(120)), 0.000], + [innerRad*1*sin(radians(180)), innerRad*1*cos(radians(180)), 0.000], + [innerRad*1*sin(radians(240)), innerRad*1*cos(radians(240)), 0.000], + [innerRad*1*sin(radians(300)), innerRad*1*cos(radians(300)), 0.000], + + [innerRad*2*sin(radians( 0)), innerRad*2*cos(radians( 0)), 0.000], + [innerRad*2*sin(radians( 30)), innerRad*2*cos(radians( 30)), 0.000], + [innerRad*2*sin(radians( 60)), innerRad*2*cos(radians( 60)), 0.000], + [innerRad*2*sin(radians( 90)), innerRad*2*cos(radians( 90)), 0.000], + [innerRad*2*sin(radians(120)), innerRad*2*cos(radians(120)), 0.000], + [innerRad*2*sin(radians(150)), innerRad*2*cos(radians(150)), 0.000], + [innerRad*2*sin(radians(180)), innerRad*2*cos(radians(180)), 0.000], + [innerRad*2*sin(radians(210)), innerRad*2*cos(radians(210)), 0.000], + [innerRad*2*sin(radians(240)), innerRad*2*cos(radians(240)), 0.000], + [innerRad*2*sin(radians(270)), innerRad*2*cos(radians(270)), 0.000], + [innerRad*2*sin(radians(300)), innerRad*2*cos(radians(300)), 0.000], + [innerRad*2*sin(radians(330)), innerRad*2*cos(radians(330)), 0.000],] +Rdot0 = [[0.00, 0.00, 0.00] for i in range(numAgents)] +R = 6870 + 405 +mu = 398600.50 +omega = sqrt(mu/R**3) +nframes = 400 +dt = 4000.0/nframes +e = 0.05 +h = (R**2)*omega +config = [[1, 2, 1, 1, 1, 2], + [2, 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 2]] +fConfig = [i for i in range(numAgents)] + +Neighbors = [[0 for i in range(numAgents)] for i in range(numAgents)] +Nghradius = 3.00 + +# RRR, _ = poseInit(numAgents) +# print(RRR) + +RRR = [[ 2.29364301, 1.26911104, -1.71273596], + [-2.30499439, 1.46048986, 0.84474138], + [-2.20553178, 0.33463571, -0.45545043], + [-2.00737466, 2.69883730, 2.20860278], + [-2.13433824, -2.45255776, 0.01869546], + [-2.87274879, -1.20121056, -2.55504595], + [-2.82212589, -2.88499068, -2.82692798], + [-2.32413586, 1.38993451, -1.85659537], + [-2.79356145, -1.84074991, 1.31134734], + [-2.45089991, 2.86245750, -0.92419686], + [-2.15760877, -1.63576172, -0.10413470], + [-2.22633934, 2.55351914, -2.75085611], + [-2.19934209, -1.28014131, 1.85593947], + [-2.72048638, 1.75400878, -1.49284592], + [-2.66459536, 0.56970289, -1.64283741], + [-2.26072675, 1.64575550, -1.69458091], + [-2.34255969, 2.06506644, -1.14374557], + [-2.99163571, -0.24707069, 1.72698837]] + +R_0 = deepcopy(RRR) +Neighbors = [[0 for i in range(numAgents)] for i in range(numAgents)] +X, Y, Z, Deltav, Energy, NeighborsOutput = multiAgentGlideslope(Neighbors, Nghradius, + R_0, Rdot0, R_T, R, e, h, omega, + numJumps, dt, nframes, + auctionParams = (True, 'Standard', False), + Config = (config, fConfig)) +NeighborsDistanceOT = NeighborsOutput[0] +NeighborsConfigOT = NeighborsOutput[1] +simulatePL ('08A-Standard.html', X, Y, Z, ['Spacecraft '+str(agent) for agent in range(numAgents)]) + +R_0 = deepcopy(RRR) +Neighbors = [[0 for i in range(numAgents)] for i in range(numAgents)] +X, Y, Z, Deltav, Energy, NeighborsOutput = multiAgentGlideslope(Neighbors, Nghradius, + R_0, Rdot0, R_T, R, e, h, omega, + numJumps, dt, nframes, + auctionParams = (True, 'Distributed', False), + Config = (config, fConfig)) +NeighborsDistanceOT = NeighborsOutput[0] +NeighborsConfigOT = NeighborsOutput[1] +simulatePL ('08B-Distributed.html', X, Y, Z, ['Spacecraft '+str(agent) for agent in range(numAgents)]) + +# R_0 = deepcopy(RRR) +# Neighbors = [[0 for i in range(numAgents)] for i in range(numAgents)] +# X, Y, Z, Deltav, Energy, NeighborsOutput = multiAgentGlideslope(Neighbors, Nghradius, + # R_0, Rdot0, R_T, R, e, h, omega, + # numJumps, dt, nframes, + # auctionParams = (True, 'Consensus', False), + # Config = (config, fConfig)) +# NeighborsDistanceOT = NeighborsOutput[0] +# NeighborsConfigOT = NeighborsOutput[1] +# simulatePL ('08C-Consensus.html', X, Y, Z, ['Spacecraft '+str(agent) for agent in range(numAgents)]) + +R_0 = deepcopy(RRR) +Neighbors = [[0 for i in range(numAgents)] for i in range(numAgents)] +X, Y, Z, Deltav, Energy, NeighborsOutput = multiAgentGlideslope(Neighbors, Nghradius, + R_0, Rdot0, R_T, R, e, h, omega, + numJumps, dt, nframes, + auctionParams = (True, 'Greedy', False), + Config = (config, fConfig)) +NeighborsDistanceOT = NeighborsOutput[0] +NeighborsConfigOT = NeighborsOutput[1] +simulatePL ('08D-Greedy.html', X, Y, Z, ['Spacecraft '+str(agent) for agent in range(numAgents)]) \ No newline at end of file diff --git a/src/anomaly.py b/src/anomaly.py new file mode 100644 index 0000000..c02044e --- /dev/null +++ b/src/anomaly.py @@ -0,0 +1,18 @@ +from numpy import cos, sin, multiply + +# True Anomaly from Time +def getTrueAnomalyFromTime(omega, e, T, calcDerivs = False): + M = multiply(omega, T) + c1 = (2.0*e -(e**3.0)/4.0) + c2 = (5.0/4) *(e**2.0) + c3 = (13.0/12)*(e**3.0) + F = M + c1*sin(M) + c2*sin(2.0*M) + c3*sin(3.0*M) + if not calcDerivs: + return F + cd1 = (1.0+(e*cos(F)))**2 + cd2 = (1.0-(e**2.0)) **(3.0/2) + Fd = cd1*omega/cd2 + cdd1 = -2.0*e*(Fd**2.0) + cdd2 = (1+(e*cos(F))) + Fdd = cdd1*sin(F)/cdd2 + return F, Fd, Fdd \ No newline at end of file diff --git a/src/auction.py b/src/auction.py new file mode 100644 index 0000000..6521f4e --- /dev/null +++ b/src/auction.py @@ -0,0 +1,163 @@ +from numpy import max, sum, zeros, argmax, subtract, random +from numpy.linalg import norm, solve +from scipy.optimize import linear_sum_assignment + +## Generate cost of moving from a particular location to a list of target locations +def costGenerator(egoLocation, targetLocations, minValue): + return [(-1**(minValue-1))*norm(subtract(egoLocation, targetLocations[i])) for i in range(len(targetLocations))] + +## Check connectivity of graph +def isConnected(G): + numAgents = len(G) + metAgents = set() + toVisit = set() + visited = set() + allAgents = range(len(G)) + metAgents.add(0) + toVisit.add(0) + while len(toVisit) != 0: + ego = list(toVisit)[0] + if ego not in visited: + visited.add(ego) + metAgents.add(ego) + toVisit.remove(ego) + toVisit.update([agent for agent in range(numAgents) if G[ego][agent] > 0 and agent not in visited]) + if len(metAgents) == numAgents: + return True + return False + +## Standard Distributed Auction +def stdAuction(R_0, R_T, G): + numAgents = len(R_0) + for ego in range(numAgents): + R_Tn = [R_T[agent] for agent in range(numAgents) if G[ego][agent] > 0] + R_0n = [R_0[agent] for agent in range(numAgents) if G[ego][agent] > 0] + R_TnRange = [agent for agent in range(numAgents) if G[ego][agent] > 0] + numNbrs = len(R_Tn) + Auction_Values = [[] for i in range(numNbrs)] + for nbr, r_0n in enumerate(R_0n): + Auction_Values[nbr] = costGenerator(r_0n, R_Tn, True) + row_ind, col_ind = linear_sum_assignment(Auction_Values) # Hungarian Algorithm + newR_Tn = [] + for i in range(numNbrs): + newR_Tn.append(R_Tn[col_ind[i]]) + for newAgent, oldAgent in enumerate(R_TnRange): + R_T[oldAgent] = newR_Tn[newAgent] + return R_T + +## Distributed Greedy Algorithm +def checkIntersections(ego, R_0, R_T, G_ego): + intNeighbors = [] + r_0 = R_0[ego] + r_T = R_T[ego] + for agent, r_0n in enumerate(R_0): + if G_ego[agent] > 0 and agent != ego: + r_Tn = R_T[agent] + A = [[r_0[0]-r_T[0], -(r_0n[0]-r_Tn[0])], + [r_0[1]-r_T[1], -(r_0n[1]-r_Tn[1])]] + B = [r_T[0]-r_Tn[0], + r_T[1]-r_Tn[1]] + t, s = solve(A, B) + if abs(((r_0[2]-r_T[2])*t - (r_0n[2]-r_Tn[2])*s) - (r_T[2]-r_Tn[2])) < 0.001: + intNeighbors.append(agent) + check = bool(intNeighbors) + return check, intNeighbors + +def greedy(R_0, R_T, G): + numAgents = len(R_0) + while True: + intNeighbors, intersecting = [[] for agent in range(numAgents)], [False for agent in range(numAgents)] + for ego in range(numAgents): + intersecting[ego], intNeighbors[ego] = checkIntersections(ego, R_0, R_T, G[ego]) + if not bool(sum(intersecting)): + break + for ego in range(numAgents): + if intersecting[ego]: + for agent in intNeighbors[ego]: + R_T[ego], R_T[agent] = R_T[agent], R_T[ego] + intersecting[ego], intNeighbors[ego] = checkIntersections(ego, R_0, R_T, G[ego]) + if not intersecting[ego]: + break + return R_T + +### 'A Distributed Auction Algorithm for the Assignment Problem' - Zavlanos, Spesivtsev, Pappas +def disAuction(R_0, R_T, G): + if not isConnected(G): + return R_T + + numAgents = len(R_0) + beta = [costGenerator(agent, R_T, False) for agent in R_0] + p_prev = zeros((numAgents, numAgents)) + p_next = zeros((numAgents, numAgents)) + b_prev = zeros((numAgents, numAgents)) + b_next = zeros((numAgents, numAgents)) + a_prev = zeros( numAgents, dtype = int) + a_next = zeros( numAgents, dtype = int) + while len(a_prev) != len(set(a_prev)): + for ego in range(numAgents): + for j in range(numAgents): + p_next[ego][j] = max([p_prev[k][j] for k in range(numAgents) if G[ego][k] > 0]) + b_next[ego][j] = max([b_prev[k][j] for k in range(numAgents) if G[ego][k] > 0 and p_prev[k][j] == p_next[ego][j]]) + if p_prev[ego][a_prev[ego]] <= p_next[ego][a_prev[ego]] and b_next[ego][a_prev[ego]] != ego: + a_next[ego] = argmax([(beta[ego][k]-p_next[ego][k]) for k in range(numAgents)]) + b_next[ego][a_next[ego]] = ego + v_ego = max([beta[ego][k]-p_prev[ego][k] for k in range(numAgents)]) + w_ego = max([beta[ego][k]-p_prev[ego][k] for k in range(numAgents) if k != a_next[ego]]) + epsilon = random.rand()*0.05 #### epsilon-complementary slackness + gamma_ego = v_ego - w_ego + epsilon + p_next[ego][a_next[ego]] = p_prev[ego][a_next[ego]] + gamma_ego + else: + a_next[ego] = a_prev[ego] + a_prev = a_next + p_prev = p_next + b_prev = b_next + R_T_new = [R_T[a_ego] for a_ego in a_prev] + return R_T_new + +## 'Consensus-Based Decentralized Auctions for Robust Task Allocation' - Choi, Brunet, How +def selectTask(x_prev, y_prev, J_ego, c_ego, w_ego): + x_next = x_prev + y_next = y_prev + if sum(x_next) == 0: + h_ego = (c_ego >= y_next) + if any(h_ego): + J_ego = argmax([h_ego[k]*c_ego[k] for k in range(len(y_next))]) + x_next[J_ego] = 1 + y_next[J_ego] = c_ego[J_ego] + return x_next, y_next, J_ego, w_ego + +def updateTask(ego, x_prev, y, z_ego, J_ego, G_ego): + x_ego = x_prev + y_ego = y[ego] + for j in range(len(y)): + y_ego[j] = max ([y[k][j] for k in range(len(y)) if G_ego[k] == 1]) + z_ego[J_ego] = argmax([y[k][J_ego] for k in range(len(y)) if G_ego[k] == 1]) + if not z_ego[J_ego] == ego: + x_ego[J_ego] = 0 + return x_ego, y_ego, z_ego + +def cnsAuction(R_0, R_T, G): + if not isConnected(G): + return R_T + + numAgents = len(R_0) + c = [costGenerator(agent, R_T, True) for agent in R_0] + x = zeros((numAgents, numAgents)) + y = zeros((numAgents, numAgents)) + t = zeros((numAgents, numAgents)) + z = zeros((numAgents, numAgents)) + w = zeros((numAgents, numAgents)) + J = [0 for i in range(numAgents)] + while 0 in [(1 in x_agent) for x_agent in x]: + for ego in range(numAgents): + x[ego], y[ego], J[ego], w[ego] = selectTask(x[ego], y[ego], J[ego], c[ego], w[ego]) + for ego in range(numAgents): + x[ego], y[ego], z[ego] = updateTask(ego, x[ego], y, z[ego], J[ego], G[ego]) + print(z) + return R_T + +def hybAuction(R_0, R_T, G): + if not isConnected(G): + return greedy(R_0, R_T, G) + else: + return disAuction(R_0, R_T, G) \ No newline at end of file diff --git a/src/consensus.py b/src/consensus.py new file mode 100644 index 0000000..9709894 --- /dev/null +++ b/src/consensus.py @@ -0,0 +1,9 @@ +from numpy import subtract, multiply + +## Attitude Consensus +def stepUpdate(ego, Theta, Theta_d, N_ego, a_ego, step, iteration): + nextTheta_ego = Theta[ego][-1] + for nbr, a_ego_nbr in enumerate(a_ego): + if nbr in N_ego: + nextTheta_ego = subtract(nextTheta_ego, step * iteration * multiply(a_ego_nbr, subtract(subtract(Theta[ego][-1], Theta_d[ego]), subtract(Theta[nbr][-1], Theta_d[nbr])))) + return nextTheta_ego \ No newline at end of file diff --git a/src/glideslope.py b/src/glideslope.py new file mode 100644 index 0000000..694b622 --- /dev/null +++ b/src/glideslope.py @@ -0,0 +1,116 @@ +from copy import deepcopy +from numpy import add, dot, subtract, multiply +from auction import greedy, cnsAuction, disAuction, hybAuction, stdAuction +from anomaly import getTrueAnomalyFromTime +from maneuvers import getTransformMatrixTH, getManeuverPointsTH +from neighbors import neighborsConfig, neighborsDistance +from numpy.linalg import inv, norm + +## Reduction Functions +def reductionF(x, N): + return 1.0 - (x+1)/N + +def reductionG(x, N, r_T, r_k, r_0): + return reductionF(x, N)*norm(subtract(r_k, r_T)) + +## Glideslope Algorithm +def multiAgentGlideslope(InitNeighbors, Nghradius, R_0, Rdot0, R_T, R, e, h, omega, numJumps, dt, nframes, auctionParams = (True, 'Distributed', False), Config = ([], [])): + ### Position Initializations + numAgents = len(R_0) + R_k = deepcopy(R_0) + Rdot = deepcopy(Rdot0) + a_i = [0.00055 for agent in range(numAgents+1)] + xs, ys, zs = [ [[] for agent in range(numAgents)] for dim in range(3) ] + u_GLS = [subtract(R_0[agent], R_T[agent]) for agent in range(numAgents)] + rho_T = [norm(u) for u in u_GLS] + for agent in range(numAgents): + if norm(u_GLS[agent]) > 0.0001: + u_GLS[agent] /= rho_T[agent] + ### Timing Definitions + T = dt*(nframes-1) + deltaT = T/numJumps + ### Energy Initializations + deltavs = [] + energy = 0.0 + ### Neighbors Initializations + auction = auctionParams[0] + aucType = auctionParams[1] + conf = auctionParams[2] + NeighborsDistanceOT = [] + ### Finding Neighbors over Configuration + if conf: + NeighborsConfigOT = [] + config = Config[0] + fConfig = Config[1] + for firing in range(numJumps): + ### Orbit Parameter Update + t = deltaT*firing + tnext = t + deltaT + f, fnext = getTrueAnomalyFromTime(omega, e, [t, tnext]) + phi_r = getTransformMatrixTH(R, e, h, [tnext, t], [fnext, f])[0:3] + phi_r_r = [arr[0:3] for arr in phi_r] + phi_r_rdot = [arr[3:6] for arr in phi_r] + ### Distance-based Auction for Determination of Pre-Assembly Position + if auction: + NeighborsDistance = neighborsDistance(InitNeighbors, Nghradius, R_0) + if aucType == 'Standard': + R_T = stdAuction(R_k, R_T, NeighborsDistance) + elif aucType == 'Hybrid': + R_T = hybAuction(R_k, R_T, NeighborsDistance) + elif aucType == 'Distributed': + R_T = disAuction(R_k, R_T, NeighborsDistance) + elif aucType == 'Consensus': + R_T = cnsAuction(R_k, R_T, NeighborsDistance) + elif aucType == 'Greedy': + R_T = greedy (R_k, R_T, NeighborsDistance) + ### Configuration-based Auction for Determination of Communication Links + if conf: + NeighborsConfig = neighborsConfig(config, fConfig) + ### Individual Agent Update + for agent in range(numAgents): + ### Check if neighbor is not ego + if norm(u_GLS[agent]) > 0.0001: + ### Positional Parameter Initialization + r_T = R_T[agent] + r_k = R_k[agent] + r_0 = R_0[agent] + rdot = Rdot[agent] + rho_k = norm(subtract(r_k, r_T)) + r_k1 = add(r_T, multiply(reductionG(firing, numJumps, r_T, r_k, r_0), u_GLS[agent])) + ### Delta-V Calculation + deltav = subtract(dot(inv(phi_r_rdot), (r_k1 - dot(phi_r_r, r_k))), rdot) + deltavs.append(norm(deltav)) + energy += deltavs[-1] + rdot = add(rdot, deltav) + ### Timed Update of Positional Parameters + for i in range(int(nframes/numJumps)): + time = dt*i + rt, rdott = getManeuverPointsTH(r_k, rdot, [t + time, t], R, e, h) + xs[agent].append(rt[0]) + ys[agent].append(rt[1]) + zs[agent].append(rt[2]) + ### Positional Parameter Accumulation + R_k [agent] = rt + Rdot[agent] = rdott + ### If neighbor is ego, do nothing + else: + r_0 = R_0[agent] + xs[agent].append(r_0[0]) + ys[agent].append(r_0[1]) + zs[agent].append(r_0[2]) + ### Update Over-Time Collection of Neighbors + if aucType != '': + NeighborsDistanceOT.append((deltaT*firing, NeighborsDistance)) + if conf: + NeighborsConfigOT.append((deltaT*firing, NeighborsConfig)) + ### Return Output + NeighborsOutput = [] + if aucType != '': + NeighborsOutput.append(NeighborsDistanceOT) + else: + NeighborsOutput.append([]) + if conf: + NeighborsOutput.append(NeighborsConfigOT) + else: + NeighborsOutput.append([]) + return xs, ys, zs, deltavs, energy, NeighborsOutput \ No newline at end of file diff --git a/src/ifmea.py b/src/ifmea.py new file mode 100644 index 0000000..fd882ae --- /dev/null +++ b/src/ifmea.py @@ -0,0 +1,73 @@ +from math import floor + +def twoDimPointToListPoint(layerLens, presentLayerNum, presentPosNum): + sumUptoLayer = 0 + for layerLen in layerLens[:presentLayerNum]: + sumUptoLayer += layerLen + return sumUptoLayer + (presentPosNum % layerLens[presentLayerNum]) + +def listPointToTwoDimPoint(layerLens, listPoint): + for layerNum, layerLen in enumerate(layerLens): + if listPoint < layerLen: + return (layerNum, listPoint) + listPoint -= layerLen + +def findNearestMismatch(config, nextConfig, presentLayerNum, presentPosNum): + n_L_prst = len(config) + n_L_next = len(nextConfig) + for dist in range(0, int(n_L_next/2)+1): + upper = (presentPosNum*2 + dist)%n_L_next + lower = (presentPosNum*2 - dist)%n_L_next + if nextConfig[upper] != presentLayerNum + 2: + nextLayerMismatch = upper + break + elif nextConfig[lower] != presentLayerNum + 2: + nextLayerMismatch = lower + break + presLayerMMClosest = floor(nextLayerMismatch/2) + if presLayerMMClosest < presentPosNum: + presLayerMMClosest += nextLayerMismatch%2 + return nextLayerMismatch, presLayerMMClosest + +def rotateConfig(layer, diff): + for i in range(abs(diff)): + layer = layer[-int(diff/abs(diff)):] + layer[:-int(diff/abs(diff))] + return layer + +def exchangeConfig(config, P1, P2, P3): + config[P1[0]][P1[1]], config[P2[0]][P2[1]], config[P3[0]][P3[1]] = config[P3[0]][P3[1]], config[P1[0]][P1[1]], config[P2[0]][P2[1]] + return config + +def ifmea(config): + N = len(config) - 1 + commands = [] + layerLens = [len(layer) for layer in config] + while not N == 0: + i = N - 1 + while not i == -1: + try: + j = config[i].index(N+1) + except: + i -= 1 + continue + m, l = findNearestMismatch(config[i], config[i+1], i, j) + if l-j != 0: + config[i] = rotateConfig(config[i], l-j) + commands.append(('R', twoDimPointToListPoint(layerLens, i, 0), twoDimPointToListPoint(layerLens, i+1, 0) - 1, int(l-j/abs(l-j)), abs(l-j))) + if m < l*2: + config = exchangeConfig(config, (i,l), (i+1,m), (i,l-1)) + commands.append(('E', twoDimPointToListPoint(layerLens, i, l), twoDimPointToListPoint(layerLens, i+1, m), twoDimPointToListPoint(layerLens, i, l-1), 1)) + else: + config = exchangeConfig(config, (i,l), (i+1,m), (i,(l+1)%layerLens[i])) + commands.append(('E', twoDimPointToListPoint(layerLens, i, l), twoDimPointToListPoint(layerLens, i+1, m), twoDimPointToListPoint(layerLens, i, l+1), 1)) + if i < N - 1: + i = i + 1 + N = N - 1 + + return commands + +if __name__ == '__main__': + initConfig = [[1, 1, 3, 1, 2, 2], + [2, 2, 1, 2, 2, 2, 2, 3, 2, 2, 2, 1], + [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]] + print(ifmea(initConfig)) \ No newline at end of file diff --git a/src/initializations.py b/src/initializations.py new file mode 100644 index 0000000..368f396 --- /dev/null +++ b/src/initializations.py @@ -0,0 +1,15 @@ +from numpy import pi, multiply +from numpy.random import rand, seed, randint +seed(0) + +def randomNum(): + return ((-1)**randint(0, 2))*rand() + +## Random StartPose Assignment +def poseInit(numAgents, radius): + R_0, Theta = [], [] + for agent in range(numAgents): + R_0.append (multiply([randomNum(), randomNum(), randomNum()], radius)) + Theta.append([multiply([randomNum(), randomNum(), randomNum()], pi)]) + Theta.append([[0.0, 0.0, 0.0]]) + return R_0, Theta \ No newline at end of file diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..544e1bf --- /dev/null +++ b/src/main.py @@ -0,0 +1,131 @@ +from copy import deepcopy +from math import sqrt +from ifmea import ifmea, listPointToTwoDimPoint +from numpy import pi, argmin, random, subtract +from mirror import genR_T, layerCalc, calcTheta_d +from simulate import plotRPY, simulatePL, simulateMPL +from consensus import stepUpdate +from glideslope import multiAgentGlideslope +from numpy.linalg import norm +from numpy.random import seed, shuffle +from initializations import poseInit +seed(0) + +### Orbit Parameters +R = 6870 + 405 +mu = 398600.50 +omega = sqrt(mu/R**3) +e = 0.05 +h = (R**2)*omega +### Simulation Parameters +nframes = 800 +dt = 4000.0/nframes +### Configuration Parameters +numAgents = 36 +numJumps = 10 +Nghradius = 0.4 +clearAperture = 0.002 +parabolicRad = 0.003 +expansion = 3 +Neighbors = [[0 for i in range(numAgents)] for i in range(numAgents)] +a = [[[0.5*4e-6, 0.5*8e-6, 0.5*8e-6] for i in range(numAgents + 1)] for j in range(numAgents + 1)] +numLayers, LayerLens = layerCalc(numAgents) +### Position Parameters +R_T0 = genR_T(clearAperture, parabolicRad, numAgents, LayerLens, expansion) +R_T = deepcopy(R_T0) +Rdot0 = [[0.00, 0.00, 0.00] for i in range(numAgents)] +R_0, Theta = poseInit(numAgents, 5.00) +R_I, _ = poseInit(numAgents, 0.01) +individuals = [i for i in range(numAgents)] +trueMapping = [] +for layer in range(1, numLayers + 1): + trueMapping.extend([layer for i in range(LayerLens[layer-1])]) +# shuffle(trueMapping) + +### Glideslope with Hybrid Auction at jumps from Start Positions to Intermediate Positions +Xs, Ys, Zs, Deltav, Energy, NeighborsOutput = multiAgentGlideslope(Neighbors, Nghradius, + R_0, Rdot0, R_I, R, e, h, omega, + numJumps, dt, nframes, + auctionParams = (True, 'Hybrid', False), + Config = (trueMapping, individuals)) +NeighborsDistanceOT = NeighborsOutput[0] +NeighborsConfigOT = NeighborsOutput[1] +simulatePL('Stage-01A.html', Xs, Ys, Zs, + ['S/c '+str(agent) for agent in range(numAgents)]) +# simulateMPL('Stage-01A.gif', Xs, Ys, Zs, + # ['S/c '+str(agent) for agent in range(numAgents)], nframes) + +### Glideslope with Hybrid Auction at jumps from Intermediate Positions to R_T +Xs, Ys, Zs, Deltav, Energy, NeighborsOutput = multiAgentGlideslope(Neighbors, Nghradius, + R_I, Rdot0, R_T, R, e, h, omega, + numJumps, dt, nframes, + auctionParams = (True, 'Hybrid', False), + Config = (trueMapping, individuals)) +NeighborsDistanceOT = NeighborsOutput[0] +NeighborsConfigOT = NeighborsOutput[1] +simulatePL('Stage-01B.html', Xs, Ys, Zs, + ['S/c '+str(agent) for agent in range(numAgents)]) +# simulateMPL('Stage-01B.gif', Xs, Ys, Zs, + # ['S/c '+str(agent) for agent in range(numAgents)], nframes) + +### Determine present configuration of spacecraft +presentConfig = [[] for layer in range(len(LayerLens))] +for agent in range(numAgents): + r_0 = [Xs[agent][-1], Ys[agent][-1], Zs[agent][-1]] + presLayerNum, _ = listPointToTwoDimPoint(LayerLens, argmin([norm(subtract(r_0, r_T)) for r_T in R_T])) + trueLayer = trueMapping[agent] + presentConfig[presLayerNum].append(trueLayer) + +### Intra-Formation Mutual Exchange +Xs, Ys, Zs, Rolls, Pitches, Yaws = [[[] for agent in range(numAgents)] for i in range(6)] +AllNeighborsOverTime, FConfig = [ [] for i in range(2)] +IFMEACommands = ifmea(presentConfig) +R_0 = R_T +for step, command in enumerate(IFMEACommands): + for i in range(command[4]): + if command[0] == 'R': + rotInd = individuals[command[1]:command[2]+1] + rotInd = rotInd[-command[3]:] + rotInd[:-command[3]] + indTemp = deepcopy(individuals[:command[1]]) + indTemp.extend(rotInd) + indTemp.extend(individuals[command[2]+1:]) + individuals = indTemp + elif command[0] == 'E': + R_T = deepcopy(R_0) + ind1, ind2, ind3 = individuals[command[1]], individuals[command[2]], individuals[command[3]] + R_T[ind1], R_T[ind2], R_T[ind3] = R_T[ind2], R_T[ind3], R_T[ind1] + individuals[command[1]], individuals[command[2]], individuals[command[3]] = ind3, ind1, ind2 + FConfig.append(individuals) + for agent in individuals: + R_T[agent] = R_T0[individuals.index(agent)] + X, Y, Z, Deltav, Energy, NeighborsOutput = multiAgentGlideslope(Neighbors, Nghradius, + R_0, Rdot0, R_T, R, e, h, omega, + numJumps, dt, nframes, + auctionParams = (False, '', True), + Config = (presentConfig, individuals)) + NeighborsDistanceOT = NeighborsOutput[0] + NeighborsConfigOT = NeighborsOutput[1] + AllNeighborsOverTime.append(NeighborsConfigOT) + R_0 = R_T + for agent in range(numAgents): + Xs[agent].extend(X[agent]) + Ys[agent].extend(Y[agent]) + Zs[agent].extend(Z[agent]) +simulatePL('Stage-02.html', Xs, Ys, Zs, + ['S/c '+str(agent) for agent in range(numAgents)]) + +### Attitude Consensus +for command in range(len(AllNeighborsOverTime)): + time = 0 + fConfig = FConfig[command] + NeighborsConfigOT = AllNeighborsOverTime[command] + Theta_d = calcTheta_d(clearAperture, parabolicRad, LayerLens, FConfig[command]) + for i in range(nframes): + Neighbors = NeighborsConfigOT[0][1] + tempTheta = [] + for agent in range(numAgents): + tempTheta.append(stepUpdate(agent, Theta, Theta_d, Neighbors[agent], a[agent], dt, i)) + tempTheta.append([0.0, 0.0, 0.0]) + for agent in range(numAgents): + Theta[agent].append(tempTheta[agent]) +plotRPY(Theta) \ No newline at end of file diff --git a/src/maneuvers.py b/src/maneuvers.py new file mode 100644 index 0000000..5b7722d --- /dev/null +++ b/src/maneuvers.py @@ -0,0 +1,82 @@ +from numpy import cos, sin, dot, sqrt +from anomaly import getTrueAnomalyFromTime +mu = 398600.50 + +## Transform Matrices +def getTransformMatrixCWH(O, t): + OT = O*t + cOT = cos(OT) + sOT = sin(OT) + A = [[1.0, 0.0, 6.0*OT - 6.0*sOT, 4.0*sOT/O - 3.0*t, 0.0, 2.0*(1.0-cOT)/O], + [0.0, cOT, 0.0, 0.0, sOT/O, 0.0], + [0.0, 0.0, 4.0 - 3.0*cOT, 2.0*(cOT-1.0)/O, 0.0, sOT/O], + [0.0, 0.0, 6*O*(1.0-cOT), 4.0*cOT - 3.0, 0.0, 2.0*sOT], + [0.0, -O*sOT, 0.0, 0.0, cOT, 0.0], + [0.0, 0.0, 3.0*sOT*O, - 2.0*sOT, 0.0, cOT]] + return A + +def getTransformMatrixTH(R, e, h, T, F): + sf = [sin(f) for f in F] + cf = [cos(f) for f in F] + rho = [1 + e*cf[i] for i in [0, 1]] + p = [R*rho[i] for i in [0, 1]] + K1 = 1.0/(1.0-(e**2.0)) + K2 = [h / (p[i]**2) for i in [0, 1]] + K3 = [1.0 + (1.0/rho[i]) for i in [0, 1]] + + J = K2[0]*(T[0]-T[1]) + c = [rho[i]*cf[i] for i in [0, 1]] + s = [rho[i]*sf[i] for i in [0, 1]] + cd = [-(sf[i] + e*sin(2*F[i])) for i in [0, 1]] + sd = [ cf[i] + e*cos(2*F[i]) for i in [0, 1]] + + cY = cos(F[0]-F[1]) + sY = sin(F[0]-F[1]) + rhoY = 1 + e*cY + pY = R*rhoY + K2Y = h / pY**2 + + T1 = [[ 1.0/rho[0], 0.0, 0.0, 0.0, 0.0, 0.0], + [ 0.0, 1.0/rhoY, 0.0, 0.0, 0.0, 0.0], + [ 0.0, 0.0, 1.0/rho[0], 0.0, 0.0, 0.0], + [K2[0]*e*sf[0], 0.0, 0.0, rho[0]*K2[0], 0.0, 0.0], + [ 0.0, K2Y*e*sY, 0.0, 0.0, rhoY*K2Y, 0.0], + [ 0.0, 0.0, K2[0]*e*sf[0], 0.0, 0.0, rho[0]*K2[0]]] + + A1 = [[ 1.0, 0.0, -K3[0]*c[0], K3[0]*s[0], 0.0, 3.0*J*(rho[0]**2)], + [ 0.0, cY, 0.0, 0.0, sY, 0.0], + [ 0.0, 0.0, s[0], c[0], 0.0, 2.0-3.0*e*s[0]*J], + [ 0.0, 0.0, 2.0*s[0], (2*c[0]-e), 0.0, 3.0*(1.0-2.0*e*s[0]*J)], + [ 0.0, -sY, 0.0, 0.0, cY, 0.0], + [ 0.0, 0.0, sd[0], cd[0], 0.0, -3.0*e*(sd[0]*J + s[0]/(rho[0]**2))]] + + A2 = [[1.0, 0.0, 3.0*K1*K3[1]*e*s[1]/rho[1], -K1*K3[1]*e*s[1], 0.0, K1*(-e*c[1]+2.0)], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, -3.0*K1*s[1]*(1.0 + (e**2)/rho[1])/rho[1], K1*K3[1]*s[1], 0.0, K1*(c[1]-2.0*e)], + [0.0, 0.0, -3.0*K1*((c[1]/rho[1])+e), K1*(K3[1]*c[1]+e), 0.0, -K1*s[1]], + [0.0, 0.0, 0.0, 0.0, 1.0, 0.0], + [0.0, 0.0, K1*(3.0*rho[1]+(e**2)-1.0), -K1*(rho[1]**2), 0.0, K1*e*s[1]]] + + T2 = [[ rho[1], 0.0, 0.0, 0.0, 0.0, 0.0], + [ 0.0, rhoY, 0.0, 0.0, 0.0, 0.0], + [ 0.0, 0.0, rho[1], 0.0, 0.0, 0.0], + [-e*sf[1], 0.0, 0.0, 1.0/(rho[1]*K2[1]), 0.0, 0.0], + [ 0.0, -e*sY, 0.0, 0.0, 1.0/(rhoY*K2Y), 0.0], + [ 0.0, 0.0, -e*sf[1], 0.0, 0.0, 1.0/(rho[1]*K2[1])]] + + return dot(T1, dot(dot(A1,A2), T2)) + +## Maneuver Points +def getManeuverPointsCWH(r0, rdot0, t, omega): + P = getTransformMatrixCWH(omega, t) + a0 = [r0[0], r0[1], r0[2], rdot0[0], rdot0[1], rdot0[2]] + at = dot(P, a0) + return at[0:3], at[3:6] + +def getManeuverPointsTH(r0, rdot0, T, R, e, h): + omega = sqrt(mu/R**3) + F = getTrueAnomalyFromTime(omega, e, T) + P = getTransformMatrixTH(R, e, h, T, F) + a0 = [r0[0], r0[1], r0[2], rdot0[0], rdot0[1], rdot0[2]] + at = dot(P, a0) + return at[0:3], at[3:6] \ No newline at end of file diff --git a/src/mirror.py b/src/mirror.py new file mode 100644 index 0000000..77291ca --- /dev/null +++ b/src/mirror.py @@ -0,0 +1,59 @@ +from math import sin, cos +from ifmea import listPointToTwoDimPoint +from numpy import pi, sum +from scipy.optimize import fsolve + +## Calculate lengths of layers for given number of agents +def layerCalc(numAgents): + layer = 1 + layerLens = [] + while sum(layerLens) < numAgents: + layerLens.append(layer*6) + layer += 1 + return len(layerLens), layerLens + +## Calculate specific positions for all agents +def genR_T(CA, R, numAgents, LayerLens, expansion): + R_T, XY, Z = [[] for i in range(3)] + numLayers = len(LayerLens) + _, Ps = parabolicParams(CA, R, numLayers) + for layer in range(numLayers): + XY.append(Ps[layer][0]) + Z.append (Ps[layer][1]) + for agent in range(numAgents): + layerNum, pointNum = listPointToTwoDimPoint(LayerLens, agent) + circAngle = pointNum*2.0*pi/LayerLens[layerNum] + R_T.append([expansion*XY[layerNum]*sin(circAngle), + expansion*XY[layerNum]*cos(circAngle), + expansion* Z[layerNum]]) + return R_T + +## Calculate specific attitudes for all agents +def calcTheta_d(CA, R, LayerLens, fConfig): + Theta_d = [[0.0, 0.0, 0.0] for j in range(len(fConfig) + 1)] + Pitches, _ = parabolicParams(CA, R, len(LayerLens)) + for listPoint, agent in enumerate(fConfig): + presLayerNum, presPointNum = listPointToTwoDimPoint(LayerLens, listPoint) + trueLayerNum, truePointNum = listPointToTwoDimPoint(LayerLens, agent) + Theta_d[agent][1] = pi/2.0 - Pitches[trueLayerNum] + Theta_d[agent][2] = presPointNum*2.0*pi/LayerLens[presLayerNum] + if Theta_d[agent][2] > pi: + Theta_d[agent][2] -= 2.0*pi + return Theta_d + +## Generate generic positions and attitudes based on layer number +def parabolicParams(CA, R, l): + def equations(theta_i, Thetas): + lhs = CA * (0.5 + sum([sin(theta) for theta in Thetas]) + sin(theta_i)) + rhs = CA * (CA/(8.0*R) + sum([cos(theta) for theta in Thetas]) + cos(theta_i)) + return ((lhs**2)/(2.0*R) - rhs) + + Thetas = [] + Ps = [(CA/2.0, CA**2/(8.0*R))] + for i in range(l): + theta_i = fsolve(equations, 0, Thetas) + Thetas.append(theta_i[0]) + p_i = (CA * (0.5 + sum([sin(theta) for theta in Thetas])), + CA * (CA/(8.0*R) + sum([cos(theta) for theta in Thetas]))) + Ps.append(p_i) + return Thetas, Ps \ No newline at end of file diff --git a/src/neighbors.py b/src/neighbors.py new file mode 100644 index 0000000..0b3ddd7 --- /dev/null +++ b/src/neighbors.py @@ -0,0 +1,56 @@ +from ifmea import listPointToTwoDimPoint, twoDimPointToListPoint +from numpy import subtract +from numpy.linalg import norm + +## Determination of Neighbors based on Configuration +def neighborsConfig(config, fConfig): + LayerLens = [len(layer) for layer in config] + numAgents = len(fConfig) + + N = [[] for i in range(numAgents)] + for i in range(numAgents): + presentLayerNum, presentPositionNum = listPointToTwoDimPoint(LayerLens, i) + N[i] = [fConfig[twoDimPointToListPoint(LayerLens, + presentLayerNum, + (presentPositionNum-1)%LayerLens[presentLayerNum])], + fConfig[twoDimPointToListPoint(LayerLens, + presentLayerNum, + (presentPositionNum+1)%LayerLens[presentLayerNum])]] + if presentLayerNum != len(LayerLens) - 1: + N[i].append(fConfig[twoDimPointToListPoint(LayerLens, + presentLayerNum+1, + (presentPositionNum*2)-1)]) + N[i].append(fConfig[twoDimPointToListPoint(LayerLens, + presentLayerNum+1, + (presentPositionNum*2)+0)]) + N[i].append(fConfig[twoDimPointToListPoint(LayerLens, + presentLayerNum+1, + (presentPositionNum*2)+1)]) + if presentLayerNum != 0: + if presentPositionNum % 2: + N[i].append(fConfig[twoDimPointToListPoint(LayerLens, + presentLayerNum-1, + int((presentPositionNum-1)/2))]) + N[i].append(fConfig[twoDimPointToListPoint(LayerLens, + presentLayerNum-1, + int((presentPositionNum+1)/2))]) + else: + N[i].append(fConfig[twoDimPointToListPoint(LayerLens, + presentLayerNum-1, + int((presentPositionNum+0)/2))]) + else: + N[i].append(numAgents) + return N + +## Determination of Neighbors based on Distance +def neighborsDistance(Neighbors, Nghradius, R_0): + for egoCount, r_0 in enumerate(R_0): + for j, r_1 in enumerate(R_0[egoCount:]): + nghCount = egoCount + j + if norm(subtract(r_0, r_1)) < Nghradius: # and not(j == egoCount): + value = 1 + else: + value = 0 + Neighbors[egoCount][nghCount] = value + Neighbors[nghCount][egoCount] = value + return Neighbors \ No newline at end of file diff --git a/src/simulate.py b/src/simulate.py new file mode 100644 index 0000000..3490828 --- /dev/null +++ b/src/simulate.py @@ -0,0 +1,66 @@ +import math +import matplotlib.pyplot as mplplt +import plotly.offline as ptyplt +import plotly.graph_objects as go +from random import randint +from matplotlib import animation + +mplplt.style.use('fivethirtyeight') + +## Simulations +def simulateMPL(title, X, Y, Z, labels, nframes): # Simulate using Matplotlib + def init(): + return(ax) + def animate(frame): + plots = [] + for agent in range(numAgents): + plots.append(ax.plot(X[agent][frame], Y[agent][frame], Z[agent][frame], marker = '.', label = labels[agent])) + return plots + + numAgents = len(X) + xlim = (min(X[0]), max(X[0])) + ylim = (min(Y[0]), max(Y[0])) + zlim = (min(Z[0]), max(Z[0])) + for agent in range(numAgents): + xlim = (min(xlim[0], min(X[agent])), max(xlim[1], max(X[agent]))) + ylim = (min(ylim[0], min(Y[agent])), max(ylim[1], max(Y[agent]))) + zlim = (min(zlim[0], min(Z[agent])), max(zlim[1], max(Z[agent]))) + fig = mplplt.figure() + ax = fig.add_subplot(111, projection = '3d', xlim = xlim, ylim = ylim, zlim = zlim) + ax.legend(loc = 'upper right', shadow = True) + ax.set_xlabel('X') + ax.set_ylabel('Y') + ax.set_zlabel('Z') + ax.azim = 140 + ax.elev = -45 + anim = animation.FuncAnimation(fig, animate, init_func = init, frames = nframes) + anim.save(title, fps = 20, writer = 'Pillow', progress_callback = lambda i, n: print(i)) + +def simulatePL(title, X, Y, Z, labels): # Simulate using Plotly + markers = [] + for agent in range(len(X)): + markers.append(go.Scatter3d(mode = 'markers', + x = X[agent], y = Y[agent], z = Z[agent], + marker = dict(size = 3), name = labels[agent])) + ''' + numSplits = 5 + for agent in range(len(X)): + dist = len(X[agent]) + color = randint(0,255) + for point in range(numSplits): + size = 5.0*math.exp(-point/numSplits) + markers.append(go.Scatter3d(mode = 'markers', name = labels[agent], + x = [X[agent][i] for i in range(int(point*dist/numSplits), int((point+1)*dist/numSplits))], + y = [Y[agent][i] for i in range(int(point*dist/numSplits), int((point+1)*dist/numSplits))], + z = [Z[agent][i] for i in range(int(point*dist/numSplits), int((point+1)*dist/numSplits))], + marker = dict(size = size, color = color))) + ''' + fig = go.Figure(data = markers) + ptyplt.plot(fig, filename = title) + +def plotRPY(Theta): + numAgents = len(Theta) - 1 + for dim in range(3): + for agent in range(numAgents): + mplplt.plot([Theta[agent][i][dim] for i in range(len(Theta[agent]))]) + mplplt.show()