From ede403613d96b3233e2c8f8be04dc4cb9efd7569 Mon Sep 17 00:00:00 2001 From: franchioping Date: Sun, 15 Mar 2026 23:42:55 +0000 Subject: [PATCH] separate repo --- Cargo.lock | 1497 +++++++++++++++++++++++++++ Cargo.toml | 21 + build.rs | 11 + cbindgen.toml | 36 + src/config.rs | 59 ++ src/controller.rs | 94 ++ src/input.rs | 172 +++ src/lib.rs | 115 ++ src/stacked.rs | 159 +++ src/stacked/mixer.rs | 234 +++++ src/stacked/modules.rs | 117 +++ src/stacked/modules/acceleration.rs | 47 + src/stacked/modules/angular_rate.rs | 25 + src/stacked/modules/rotation.rs | 29 + src/stacked/modules/velocity.rs | 23 + 15 files changed, 2639 insertions(+) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 build.rs create mode 100644 cbindgen.toml create mode 100644 src/config.rs create mode 100644 src/controller.rs create mode 100644 src/input.rs create mode 100644 src/lib.rs create mode 100644 src/stacked.rs create mode 100644 src/stacked/mixer.rs create mode 100644 src/stacked/modules.rs create mode 100644 src/stacked/modules/acceleration.rs create mode 100644 src/stacked/modules/angular_rate.rs create mode 100644 src/stacked/modules/rotation.rs create mode 100644 src/stacked/modules/velocity.rs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..25da3ce --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1497 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys", +] + +[[package]] +name = "approx" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bit-vec" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "bytemuck" +version = "1.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8efb64bd706a16a1bdde310ae86b351e4d21550d98d056f22f8a7f7a2183fec" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.2.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "chrono" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" +dependencies = [ + "iana-time-zone", + "num-traits", + "serde", + "windows-link", +] + +[[package]] +name = "clap" +version = "4.5.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2797f34da339ce31042b27d23607e051786132987f595b02ba4f6a6dffb7030a" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24a241312cea5059b13574bb9b3861cabf758b879c15190b37b6d6fd63ab6876" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831" + +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "darling" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1247195ecd7e3c85f83c8d2a366e4210d588e802133e1e355180a9870b517ea4" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "deranged" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +dependencies = [ + "powerfmt", + "serde_core", +] + +[[package]] +name = "downcast-rs" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117240f60069e65410b3ae1bb213295bd828f707b5bec6596a1afc8793ce0cbc" + +[[package]] +name = "drone_controller" +version = "0.1.0" +dependencies = [ + "clap", + "macroquad", + "nalgebra", + "rapier3d", + "serde", + "serde_json", + "serde_with", + "toml", +] + +[[package]] +name = "dyn-clone" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "ena" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabffdaee24bd1bf95c5ef7cec31260444317e72ea56c4c91750e8b7ee58d5f1" +dependencies = [ + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "fdeflate" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" +dependencies = [ + "simd-adler32", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "flate2" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "fontdue" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e57e16b3fe8ff4364c0661fdaac543fb38b29ea9bc9c2f45612d90adf931d2b" +dependencies = [ + "hashbrown 0.15.5", + "ttf-parser", +] + +[[package]] +name = "glam" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "333928d5eb103c5d4050533cec0384302db6be8ef7d3cebd30ec6a35350353da" + +[[package]] +name = "glam" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3abb554f8ee44336b72d522e0a7fe86a29e09f839a36022fa869a7dfe941a54b" + +[[package]] +name = "glam" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4126c0479ccf7e8664c36a2d719f5f2c140fbb4f9090008098d2c291fa5b3f16" + +[[package]] +name = "glam" +version = "0.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01732b97afd8508eee3333a541b9f7610f454bb818669e66e90f5f57c93a776" + +[[package]] +name = "glam" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525a3e490ba77b8e326fb67d4b44b4bd2f920f44d4cc73ccec50adc68e3bee34" + +[[package]] +name = "glam" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b8509e6791516e81c1a630d0bd7fbac36d2fa8712a9da8662e716b52d5051ca" + +[[package]] +name = "glam" +version = "0.20.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43e957e744be03f5801a55472f593d43fabdebf25a4585db250f04d86b1675f" + +[[package]] +name = "glam" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "518faa5064866338b013ff9b2350dc318e14cc4fcd6cb8206d7e7c9886c98815" + +[[package]] +name = "glam" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f597d56c1bd55a811a1be189459e8fad2bbc272616375602443bdfb37fa774" + +[[package]] +name = "glam" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e4afd9ad95555081e109fe1d21f2a30c691b5f0919c67dfa690a2e1eb6bd51c" + +[[package]] +name = "glam" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5418c17512bdf42730f9032c74e1ae39afc408745ebb2acf72fbc4691c17945" + +[[package]] +name = "glam" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151665d9be52f9bb40fc7966565d39666f2d1e69233571b71b87791c7e0528b3" + +[[package]] +name = "glam" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e05e7e6723e3455f4818c7b26e855439f7546cf617ef669d1adedb8669e5cb9" + +[[package]] +name = "glam" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "779ae4bf7e8421cf91c0b3b64e7e8b40b862fba4d393f59150042de7c4965a94" + +[[package]] +name = "glam" +version = "0.29.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8babf46d4c1c9d92deac9f7be466f76dfc4482b6452fc5024b5e8daf6ffeb3ee" + +[[package]] +name = "glam" +version = "0.30.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19fc433e8437a212d1b6f1e68c7824af3aed907da60afa994e7f542d18d12aa9" + +[[package]] +name = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash 0.1.5", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "foldhash 0.2.0", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "image" +version = "0.24.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d" +dependencies = [ + "bytemuck", + "byteorder", + "color_quant", + "num-traits", + "png", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown 0.16.1", + "serde", + "serde_core", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "js-sys" +version = "0.3.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.183" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" + +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "macroquad" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2befbae373456143ef55aa93a73594d080adfb111dc32ec96a1123a3e4ff4ae" +dependencies = [ + "fontdue", + "glam 0.27.0", + "image", + "macroquad_macro", + "miniquad", + "quad-rand", +] + +[[package]] +name = "macroquad_macro" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64b1d96218903768c1ce078b657c0d5965465c95a60d2682fd97443c9d2483dd" + +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + +[[package]] +name = "matrixmultiply" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06de3016e9fae57a36fd14dba131fccf49f74b40b7fbdb472f96e361ec71a08" +dependencies = [ + "autocfg", + "rawpointer", +] + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "miniquad" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fb3e758e46dbc45716a8a49ca9edc54b15bcca826277e80b1f690708f67f9e3" +dependencies = [ + "libc", + "ndk-sys", + "objc-rs", + "winapi", +] + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "nalgebra" +version = "0.34.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4d5b3eff5cd580f93da45e64715e8c20a3996342f1e466599cf7a267a0c2f5f" +dependencies = [ + "approx", + "glam 0.14.0", + "glam 0.15.2", + "glam 0.16.0", + "glam 0.17.3", + "glam 0.18.0", + "glam 0.19.0", + "glam 0.20.5", + "glam 0.21.3", + "glam 0.22.0", + "glam 0.23.0", + "glam 0.24.2", + "glam 0.25.0", + "glam 0.27.0", + "glam 0.28.0", + "glam 0.29.3", + "glam 0.30.10", + "matrixmultiply", + "nalgebra-macros", + "num-complex", + "num-rational", + "num-traits", + "simba", + "typenum", +] + +[[package]] +name = "nalgebra-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "973e7178a678cfd059ccec50887658d482ce16b0aa9da3888ddeab5cd5eb4889" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ndk-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1bcdd74c20ad5d95aacd60ef9ba40fdf77f767051040541df557b7a9b2a2121" + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-conv" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050" + +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "objc-rs" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a1e7069a2525126bf12a9f1f7916835fafade384fb27cabf698e745e2a1eb8" +dependencies = [ + "malloc_buf", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "ordered-float" +version = "5.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4779c6901a562440c3786d08192c6fbda7c1c2060edd10006b05ee35d10f2d" +dependencies = [ + "num-traits", +] + +[[package]] +name = "parry3d" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e99471b7b6870f7fe406d5611dd4b4c9b07aa3e5436b1d27e1515f9832bb0c6b" +dependencies = [ + "approx", + "arrayvec", + "bitflags 2.11.0", + "downcast-rs", + "either", + "ena", + "foldhash 0.2.0", + "glam 0.30.10", + "hashbrown 0.16.1", + "log", + "nalgebra", + "num-derive", + "num-traits", + "ordered-float", + "rstar", + "simba", + "slab", + "smallvec", + "spade", + "static_assertions", + "thiserror", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "png" +version = "0.17.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526" +dependencies = [ + "bitflags 1.3.2", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "profiling" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eb8486b569e12e2c32ad3e204dbaba5e4b5b216e9367044f25f1dba42341773" +dependencies = [ + "profiling-procmacros", +] + +[[package]] +name = "profiling-procmacros" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52717f9a02b6965224f95ca2a81e2e0c5c43baacd28ca057577988930b6c3d5b" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "quad-rand" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a651516ddc9168ebd67b24afd085a718be02f8858fe406591b013d101ce2f40" + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rapier3d" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68073fdc88f6b709002767ce8deffffb05ac06824bf9f98a23e270bcea64ba9f" +dependencies = [ + "approx", + "arrayvec", + "bit-vec", + "bitflags 2.11.0", + "downcast-rs", + "log", + "nalgebra", + "num-derive", + "num-traits", + "ordered-float", + "parry3d", + "profiling", + "rustc-hash", + "simba", + "static_assertions", + "thiserror", + "vec_map", + "wide", +] + +[[package]] +name = "rawpointer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" + +[[package]] +name = "ref-cast" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f354300ae66f76f1c85c5f84693f0ce81d747e2c3f21a45fef496d89c960bf7d" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "robust" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e27ee8bb91ca0adcf0ecb116293afa12d393f9c2b9b9cd54d33e8078fe19839" + +[[package]] +name = "rstar" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "421400d13ccfd26dfa5858199c30a5d76f9c54e0dba7575273025b43c5175dbb" +dependencies = [ + "heapless", + "num-traits", + "smallvec", +] + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "safe_arch" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b02de82ddbe1b636e6170c21be622223aea188ef2e139be0a5b219ec215323" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "schemars" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd191f9397d57d581cddd31014772520aa448f65ef991055d7f61582c65165f" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "schemars" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2b42f36aa1cd011945615b92222f6bf73c599a102a300334cd7f8dbeec726cc" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_spanned" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_with" +version = "3.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "381b283ce7bc6b476d903296fb59d0d36633652b633b27f64db4fb46dcbfc3b9" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.13.0", + "schemars 0.9.0", + "schemars 1.2.1", + "serde_core", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6d4e30573c8cb306ed6ab1dca8423eec9a463ea0e155f45399455e0368b27e0" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "simba" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c99284beb21666094ba2b75bbceda012e610f5479dfcc2d6e2426f53197ffd95" +dependencies = [ + "approx", + "num-complex", + "num-traits", + "paste", + "wide", +] + +[[package]] +name = "simd-adler32" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "spade" +version = "2.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb313e1c8afee5b5647e00ee0fe6855e3d529eb863a0fdae1d60006c4d1e9990" +dependencies = [ + "hashbrown 0.15.5", + "num-traits", + "robust", + "smallvec", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.3.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" + +[[package]] +name = "time-macros" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "toml" +version = "0.9.12+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf92845e79fc2e2def6a5d828f0801e29a2f8acc037becc5ab08595c7d5e9863" +dependencies = [ + "indexmap 2.13.0", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "0.7.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.0.9+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.0.6+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607" + +[[package]] +name = "ttf-parser" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c591d83f69777866b9126b24c6dd9a18351f177e49d625920d19f989fd31cf8" + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "wasm-bindgen" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wide" +version = "0.7.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce5da8ecb62bcd8ec8b7ea19f69a51275e91299be594ea5cc6ef7819e16cd03" +dependencies = [ + "bytemuck", + "safe_arch", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "winnow" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..5837d25 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "drone_controller" +version = "0.1.0" +edition = "2024" + +[dependencies] + +nalgebra = { version = "0.34" } +serde = { version = "1.0.228", features = ["serde_derive"] } +toml = "0.9.8" + +serde_with = "3" +serde_json = "1.0.149" + +clap = { version = "4", features = ["derive"] } + +[lib] +crate-type = ["lib", "cdylib"] + +[build-dependencies] +cbindgen = "0.29" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..3465469 --- /dev/null +++ b/build.rs @@ -0,0 +1,11 @@ +extern crate cbindgen; + +use std::env; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + + let _ = cbindgen::generate(crate_dir) + .unwrap() + .write_to_file("bindings.h"); +} diff --git a/cbindgen.toml b/cbindgen.toml new file mode 100644 index 0000000..94d7633 --- /dev/null +++ b/cbindgen.toml @@ -0,0 +1,36 @@ +# This is a template cbindgen.toml file with all of the default values. +# Some values are commented out because their absence is the real default. +# +# See https://github.com/mozilla/cbindgen/blob/main/docs.md#cbindgentoml +# for detailed documentation of every option here. + + +language = "C++" + + +include_guard = "my_bindings_h" +autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" +include_version = true + + +braces = "SameLine" +line_length = 100 +tab_width = 2 +documentation = true +documentation_style = "auto" +documentation_length = "full" +line_endings = "LF" + +namespace = "dcont" + + +style = "both" +sort_by = "Name" +usize_is_size_t = true + +[export] +include = [] +exclude = [] +# prefix = "DCONT_" +item_types = [] +renaming_overrides_prefixing = false diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..2409694 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,59 @@ +use nalgebra::{vector, Vector3}; +use serde::Deserialize; + +#[repr(C)] +#[derive(Debug, Deserialize, Clone)] +pub struct ControllerStackConfig { + /// PID for the rotation (angle → angular rate) layer + #[serde(default)] + pub rotation_pid: PidConfig, + + #[serde(default)] + pub linvel_pid: PidConfig, + + #[serde(default)] + pub position_pid: PidConfig, + + /// PID for the angular rate (angular rate → torque) layer + pub rate_pid: PidConfig, + + /// Maximum angular rate (rad/s) that joystick input maps to + pub max_rate: f32, +} + +#[repr(C)] +pub struct ControllerConfig { + pub stack: ControllerStackConfig, + + // For each motor, [Pitch, Roll, Yaw] (Rotation around x,y,z) + pub motor_map: [[f32; 3]; 4], + + pub mass: f32, + + // Per Motor + pub max_thrust: f32, + + // Per Motor + pub max_torque: f32, +} + +#[repr(C)] +#[derive(Default, Debug, Deserialize, Clone)] +pub struct PidConfig { + pub kp: [f32; 3], + pub ki: [f32; 3], + pub kd: [f32; 3], + pub frequency: f32, +} + +impl PidConfig { + pub fn p_vec(&self) -> Vector3 { + vector![self.kp[0], self.kp[1], self.kp[2]] + } + pub fn i_vec(&self) -> Vector3 { + vector![self.ki[0], self.ki[1], self.ki[2]] + } + pub fn d_vec(&self) -> Vector3 { + vector![self.kd[0], self.kd[1], self.kd[2]] + } +} diff --git a/src/controller.rs b/src/controller.rs new file mode 100644 index 0000000..bd931c8 --- /dev/null +++ b/src/controller.rs @@ -0,0 +1,94 @@ +use nalgebra as na; +use std::any::Any; + +pub trait DroneController { + // Allow downcast of trait -> class. + // + // This gives us the ability to have a Box + // And transform it into a pointer to its class. + fn as_any(&self) -> &dyn Any; + fn as_mut_any(&mut self) -> &mut dyn Any; + + /* + * Methods called by Drone, to transmit information to the controller. + */ + fn set_rotation(&mut self, _rotation: nalgebra::Unit>) {} + fn set_angular_velocity(&mut self, _angvel: nalgebra::Vector3) {} + + fn set_linvel(&mut self, _vel: na::Vector3) {} + fn set_pos(&mut self, _pos: na::Vector3) {} + fn set_time(&mut self, _time: f32) {} + fn set_motor_characteristics(&self, _motor_characteristics: &MotorCharacteristics) {} + + /* + * Throttle should be between 0 and 1. Values will be by the Drone class. + */ + fn get_motor_throttles(&mut self) -> [f32; 4]; +} + +/* +* DefaultController just sets throttle to motor_throttle, a parameter passed to it on its contructor +*/ +pub struct DefaultController { + motor_throttle: f32, +} + +impl DefaultController { + pub fn new(motor_speed: f32) -> DefaultController { + return DefaultController { + motor_throttle: motor_speed, + }; + } +} + +impl DroneController for DefaultController { + fn set_time(&mut self, _time: f32) {} + fn set_motor_characteristics(&self, _motor_characteristics: &MotorCharacteristics) {} + fn get_motor_throttles(&mut self) -> [f32; 4] { + return [self.motor_throttle; 4]; + } + + /* + * These should be implemented like this for all the classes that implement DroneController + * Works as an example implementation + */ + fn as_any(&self) -> &dyn Any { + self + } + fn as_mut_any(&mut self) -> &mut dyn Any { + self + } +} + +pub struct MotorCharacteristics { + pub relative_motor_positions: [na::OPoint>; 4], + pub max_thrust: f32, + pub max_torque: f32, + pub time_constant: f32, +} + +impl Default for MotorCharacteristics { + fn default() -> Self { + Self { + /* + * Motor position indices + * ^ - Front + * | + * | + * 1 --- 0 + * | | + * | | + * 2 --- 3 + */ + relative_motor_positions: [ + na::point![5.0, 5.0, 0.0], + na::point![5.0, -5.0, 0.0], + na::point![-5.0, -5.0, 0.0], + na::point![-5.0, 5.0, 0.0], + ], + max_thrust: 2.6, + max_torque: 0.5, + time_constant: 0.01, + } + } +} diff --git a/src/input.rs b/src/input.rs new file mode 100644 index 0000000..3f91d36 --- /dev/null +++ b/src/input.rs @@ -0,0 +1,172 @@ +use std::fs::File; +use std::io::{Read, Write}; + +#[repr(C)] +#[derive(Default, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] +pub struct JoystickInput { + pub throttle_input: f32, + pub roll_input: f32, + pub yaw_input: f32, + pub pitch_input: f32, +} + +#[repr(C)] +#[derive(Default, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] +pub struct PositionInput { + pub lat: f32, + pub long: f32, + pub alt: f32, +} + +#[repr(C)] +#[derive(Default, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] +pub struct AccelerationInput { + pub x: f32, + pub y: f32, + pub z: f32, +} + +#[repr(C)] +#[derive(Default, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] +pub struct VelocityInput { + pub x: f32, + pub y: f32, + pub z: f32, +} + +#[repr(C)] +#[derive(Default, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] +pub struct RotationInput { + pub roll: f32, + pub yaw: f32, + pub pitch: f32, +} + +#[repr(C)] +#[derive(Default, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] +pub enum ModeInput { + #[default] + Acro, + Rotation, + Acceleration, + Velocity, + Navigation, +} + +#[repr(C)] +#[derive(Default, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)] +pub struct Input { + #[serde(default)] + pub joystick: JoystickInput, + #[serde(default)] + pub acceleration: AccelerationInput, + #[serde(default)] + pub rotation: RotationInput, + #[serde(default)] + pub velocity: VelocityInput, + #[serde(default)] + pub position: PositionInput, + + pub mode: ModeInput, +} + +#[derive(Default, Clone, Copy, serde::Serialize, serde::Deserialize)] +pub struct InputRecord { + input: Input, + time: f32, +} + +#[derive(Default, Clone, serde::Serialize, serde::Deserialize)] +pub struct InputRecording { + records: Vec, +} + +impl InputRecording { + pub fn save_to_file(&self, path: &str) -> Result<(), Box> { + let json = serde_json::to_string_pretty(self)?; + let mut file = File::create(path)?; + file.write_all(json.as_bytes())?; + Ok(()) + } + + pub fn load_from_file(path: &str) -> Result> { + let mut file = File::open(path)?; + let mut contents = String::new(); + file.read_to_string(&mut contents)?; + let recording: Self = serde_json::from_str(&contents)?; + Ok(recording) + } + + pub fn has_ended(&self, time: f32) -> bool { + return self.records.last().unwrap_or(&InputRecord::default()).time < time; + } + pub fn get_input(&self, time: f32) -> Input { + /* + * Binary search returns index to element as OK, or where the element could be placed to + * keep order as Err, so if result is Ok return that input, if its Err, return the previous + * input if it exists, if it doesn't (because time is before the first action in the + * recorded sequence, return an empty input) + */ + let res = self + .records + .binary_search_by(|probe| probe.time.total_cmp(&time)); + match res { + Ok(res) => { + return self + .records + .get(res) + .unwrap_or(&InputRecord::default()) + .input; + } + Err(mut res) => { + if res > 0 { + res -= 1; + } + return self + .records + .get(0.max(res)) + .unwrap_or(&InputRecord::default()) + .input; + } + } + } + + /* + * Current time should always be larger thant the last input records time. + * This method is made for recording inputs in real time, not for retroactively adding + * + * Returns the addded Joystick Input + */ + pub fn add_input(&mut self, current_time: f32, inp: Input) -> Input { + let input = inp; + let last_input = self.records.last(); + match last_input { + Some(last_record) => { + if last_record.input != input { + self.records.push(InputRecord { + input, + time: current_time, + }); + } + } + None => { + self.records.push(InputRecord { + input, + time: current_time, + }); + } + } + return input; + } +} + +impl JoystickInput { + pub fn clamp(&self) -> JoystickInput { + return JoystickInput { + throttle_input: self.throttle_input.clamp(0.0, 1.0), + yaw_input: self.yaw_input.clamp(-1.0, 1.0), + pitch_input: self.pitch_input.clamp(-1.0, 1.0), + roll_input: self.roll_input.clamp(-1.0, 1.0), + }; + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..3ed0faf --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,115 @@ +use nalgebra::{self as na, Quaternion, Unit}; + +pub mod config; +pub mod controller; +pub mod input; +pub mod stacked; + +pub use config::*; +pub use controller::*; +pub use input::*; +pub use stacked::*; + +#[unsafe(no_mangle)] +pub extern "C" fn create(c: config::ControllerConfig) -> *mut StackedController { + return Box::into_raw(Box::new(StackedController::new(c))); +} + + +#[unsafe(no_mangle)] +pub unsafe extern "C" fn destroy(ptr: *mut ControllerConfig) { + assert!(!ptr.is_null()); + let _x = unsafe { Box::from_raw(ptr) }; +} + +#[repr(C)] +pub struct MotorThrottles { + pub values: [f32; 4], +} + +#[repr(C)] +pub struct Vec3C { + pub x: f32, + pub y: f32, + pub z: f32, +} + +impl Into> for Vec3C { + fn into(self) -> na::Vector3 { + na::vector![self.x, self.y, self.z] + } +} + +#[unsafe(no_mangle)] +pub extern "C" fn get_throttles(ptr: *mut StackedController) -> MotorThrottles { + let controller = unsafe { + assert!(!ptr.is_null()); + &mut *ptr + }; + + return MotorThrottles { + values: controller.get_motor_throttles(), + }; +} + +#[unsafe(no_mangle)] +pub extern "C" fn set_cur_time(ptr: *mut StackedController, time: f32) { + let controller = unsafe { + assert!(!ptr.is_null()); + &mut *ptr + }; + + controller.set_time(time); +} + +#[unsafe(no_mangle)] +pub extern "C" fn set_input(ptr: *mut StackedController, inp: Input) { + let controller = unsafe { + assert!(!ptr.is_null()); + &mut *ptr + }; + + controller.set_input(inp); +} + +#[unsafe(no_mangle)] +pub extern "C" fn set_cur_rot(ptr: *mut StackedController, parts: Vec3C, scalar: f32) { + let controller = unsafe { + assert!(!ptr.is_null()); + &mut *ptr + }; + + let quat: na::UnitQuaternion = + na::UnitQuaternion::from_quaternion(Quaternion::from_parts(scalar, parts.into())); + controller.set_rotation(quat); +} + +#[unsafe(no_mangle)] +pub extern "C" fn set_cur_angvel(ptr: *mut StackedController, angvel: Vec3C) { + let controller = unsafe { + assert!(!ptr.is_null()); + &mut *ptr + }; + + controller.set_angular_velocity(angvel.into()); +} + +#[unsafe(no_mangle)] +pub extern "C" fn set_cur_linvel(ptr: *mut StackedController, vel: Vec3C) { + let controller = unsafe { + assert!(!ptr.is_null()); + &mut *ptr + }; + + controller.set_linvel(vel.into()); +} + +#[unsafe(no_mangle)] +pub extern "C" fn set_cur_pos(ptr: *mut StackedController, pos: Vec3C) { + let controller = unsafe { + assert!(!ptr.is_null()); + &mut *ptr + }; + + controller.set_pos(pos.into()); +} diff --git a/src/stacked.rs b/src/stacked.rs new file mode 100644 index 0000000..5028770 --- /dev/null +++ b/src/stacked.rs @@ -0,0 +1,159 @@ +#![allow(dead_code)] + +use nalgebra as na; +use std::{any::Any, f32}; + +use crate::input::ModeInput; +use crate::stacked::modules::ModuleRuntime; +use crate::{input::Input, DroneController}; + +use crate::config::*; + +pub mod mixer; +pub mod modules; + +use mixer::MotorMixer; +use modules::*; + +#[derive(Default)] +pub struct DroneState { + pub rotation: na::UnitQuaternion, + pub angvel: na::Vector3, + pub linvel: na::Vector3, + pub position: na::Vector3, + pub mass: f32, +} + +pub struct StackedController { + pub rotation_rt: ModuleRuntime, + pub rate_rt: ModuleRuntime, + pub linaccel_rt: ModuleRuntime, + pub linvel_rt: ModuleRuntime, + + mixer: MotorMixer, + config: ControllerConfig, + + // State + drone_state: DroneState, + input: Input, + last_time: f32, + current_time: f32, +} + +impl StackedController { + pub fn new(config: ControllerConfig) -> Self { + let min_throttle = 0.0; + let max_throttle = 1.0; + + let lin_vel_ctrl = VelocityController::new(PidProcessor::new(&config.stack.linvel_pid)); + let lin_accel_ctrl = + AccelerationController::new(max_throttle, min_throttle, config.max_thrust); + let rotation_ctrl = RotationController::new(PidProcessor::new(&config.stack.rotation_pid)); + let rate_ctrl = AngularRateController::new(PidProcessor::new(&config.stack.rate_pid)); + + Self { + linaccel_rt: ModuleRuntime::new(lin_accel_ctrl, config.stack.rotation_pid.frequency), + rotation_rt: ModuleRuntime::new(rotation_ctrl, config.stack.rotation_pid.frequency), + rate_rt: ModuleRuntime::new(rate_ctrl, config.stack.rate_pid.frequency), + linvel_rt: ModuleRuntime::new(lin_vel_ctrl, config.stack.linvel_pid.frequency), + mixer: MotorMixer { + motor_map: config.motor_map, + min_throttle: 0.0, + max_throttle: 1.0, + mixing_mode: mixer::MotorMixingMode::default(), + }, + + drone_state: DroneState { + rotation: na::UnitQuaternion::identity(), + mass: config.mass, + ..Default::default() + }, + input: Input::default(), + last_time: 0.0, + current_time: 0.0, + + config: config, // Keep config copy for future uses + } + } + + pub fn set_input(&mut self, inp: Input) { + self.input = inp; + } +} + +impl DroneController for StackedController { + fn set_rotation(&mut self, rot: na::UnitQuaternion) { + self.drone_state.rotation = rot; + } + + fn set_angular_velocity(&mut self, vel: na::Vector3) { + self.drone_state.angvel = vel; + } + + fn set_linvel(&mut self, vel: na::Vector3) { + self.drone_state.linvel = vel; + } + + fn set_pos(&mut self, pos: na::Vector3) { + self.drone_state.position = pos; + } + + fn set_time(&mut self, t: f32) { + self.last_time = self.current_time; + self.current_time = t; + } + + fn get_motor_throttles(&mut self) -> [f32; 4] { + let frame_dt = (self.current_time - self.last_time).max(0.0); + let mut throttle = self.input.joystick.throttle_input; + + let angular_rate_setpoint = if self.input.mode != ModeInput::Acro { + let rotation_setpoint = if self.input.mode != ModeInput::Rotation { + let lin_accel_setpoint = if self.input.mode != ModeInput::Acceleration { + panic!("Not Implemented") + } else { + Acceleration(na::vector![ + self.input.acceleration.x, + self.input.acceleration.y, + self.input.acceleration.z + ]) + }; + let ret = self + .linaccel_rt + .update(lin_accel_setpoint, &self.drone_state, frame_dt); + throttle = ret.1 .0; + ret.0 + } else { + // println!("Rotation!"); + Rotation(na::vector![ + self.input.rotation.roll, + self.input.rotation.pitch, + self.input.rotation.yaw, + ]) + }; + self.rotation_rt + .update(rotation_setpoint, &self.drone_state, frame_dt) + } else { + AngularRate( + na::vector![ + self.input.joystick.roll_input, + self.input.joystick.pitch_input, + self.input.joystick.yaw_input, + ] * self.config.stack.max_rate, + ) + }; + + let torque = self + .rate_rt + .update(angular_rate_setpoint, &self.drone_state, frame_dt); + + self.mixer.mix(throttle, torque.0) + } + + fn as_any(&self) -> &dyn Any { + self + } + fn as_mut_any(&mut self) -> &mut dyn Any { + self + } +} diff --git a/src/stacked/mixer.rs b/src/stacked/mixer.rs new file mode 100644 index 0000000..1755241 --- /dev/null +++ b/src/stacked/mixer.rs @@ -0,0 +1,234 @@ +use nalgebra as na; + +pub enum MotorMixingMode { + ThrottleAuthority, + NoTorqueScalling, + ThrottleAuthorityReasonable { min_scale: f32 }, +} +impl Default for MotorMixingMode { + fn default() -> Self { + Self::ThrottleAuthorityReasonable { min_scale: 0.1 } + } +} + +pub struct MotorMixer { + pub motor_map: [[f32; 3]; 4], // roll, pitch, yaw + pub min_throttle: f32, + pub max_throttle: f32, + pub mixing_mode: MotorMixingMode, +} + +impl MotorMixer { + pub fn mix(&self, throttle: f32, torque: na::Vector3) -> [f32; 4] { + use MotorMixingMode::*; + match self.mixing_mode { + ThrottleAuthority => { + return self.mix_throttle_authority(throttle, torque).0; + } + NoTorqueScalling => { + return self.mix_no_torque_scalling(throttle, torque).0; + } + ThrottleAuthorityReasonable { min_scale } => { + return self + .mix_throttle_authority_reasonable(throttle, torque, min_scale) + .0; + } + } + } + + fn compute_delta(&self, torque: na::Vector3) -> [f32; 4] { + let mut delta = [0.0f32; 4]; + + for i in 0..4 { + delta[i] = self.motor_map[i][0] * torque.x + + self.motor_map[i][1] * torque.y + + self.motor_map[i][2] * torque.z; + } + + return delta; + } + + /// Unlike ThrottleAuthority, this implementation has a minimum scale. + /// That makes sure our torque is never below min_scale * torque. + /// + /// Throttle still has authority, this is, torque is limited by the throttle, but within reason, which makes it "reasonable" + /// + /// Avoids the downside of the previous implementation: At 100% Throttle, Torque would always be 0. This lowers the actual throttle. + pub fn mix_throttle_authority_reasonable( + &self, + throttle: f32, + torque: na::Vector3, + min_scale: f32, + ) -> ([f32; 4], bool) { + let mut delta = self.compute_delta(torque); + let throttle_range_len = self.max_throttle - self.min_throttle; + + delta.iter_mut().for_each(|x| *x *= 0.25); + + let mut scale = 1.0f32; + + for i in 0..4 { + if delta[i] > 0.0 { + scale = scale.min((self.max_throttle - throttle) / delta[i]); + } else if delta[i] < 0.0 { + scale = scale.min((self.min_throttle - throttle) / delta[i]); + } + } + + scale = scale.clamp(min_scale, 1.0); + + let mut max_delta = scale * delta.into_iter().reduce(f32::max).unwrap_or(0.0); + let mut min_delta = scale * delta.into_iter().reduce(f32::min).unwrap_or(0.0); + let delta_dif = max_delta - min_delta; + + if delta_dif > throttle_range_len { + scale *= throttle_range_len / delta_dif * 0.99; + max_delta *= throttle_range_len / delta_dif * 0.99; + min_delta *= throttle_range_len / delta_dif * 0.99; + } + + let lim_throttle = throttle.clamp( + self.min_throttle + min_delta.abs(), + self.max_throttle - max_delta.abs(), + ); + + let mut motors = [0.0f32; 4]; + for i in 0..4 { + motors[i] = lim_throttle + delta[i] * scale; + } + + let saturated = scale < 1.0; + + (motors, saturated) + } + + pub fn mix_attitude_authority(&self, throttle: f32, torque: na::Vector3) -> [f32; 4] { + return self + .mix_throttle_authority_reasonable(throttle, torque, 1.0) + .0; + } + + /// + /// Made by Chatgpt, unreliable as hell. Deltas try to fit within throttle, + /// so if throttle is the max, will simply not apply deltas. Shouldn't be used. + /// + /// Will actually kind of work if throttle_min + delta < throttle < throttle_max - delta, + /// Where delta is a value of headroom added so that we always have room to create torque + /// + pub fn mix_throttle_authority( + &self, + throttle: f32, + torque: na::Vector3, + ) -> ([f32; 4], bool) { + let mut delta = [0.0f32; 4]; + + // 1. Torque-only contribution + for i in 0..4 { + delta[i] = self.motor_map[i][0] * torque.x + + self.motor_map[i][1] * torque.y + + self.motor_map[i][2] * torque.z; + } + + // 2. Compute allowable scaling + let mut scale = 1.0f32; + + for i in 0..4 { + if delta[i] > 0.0 { + scale = scale.min((self.max_throttle - throttle) / delta[i]); + } else if delta[i] < 0.0 { + scale = scale.min((self.min_throttle - throttle) / delta[i]); + } + } + + scale = scale.clamp(0.0, 1.0); + + // 3. Apply + let mut motors = [0.0f32; 4]; + for i in 0..4 { + motors[i] = throttle + scale * delta[i]; + } + + let saturated = scale < 1.0; + (motors, saturated) + } + + /// Bad, not mine, used for testing and comparison + pub fn mix_no_torque_scalling( + &self, + throttle: f32, + torque: na::Vector3, + ) -> ([f32; 4], bool) { + let mut motors = [0.0f32; 4]; + + // -------------------------------------------------- + // 1. Raw mix: throttle + torque deltas + // -------------------------------------------------- + for i in 0..4 { + let delta = self.motor_map[i][0] * torque.x + + self.motor_map[i][1] * torque.y + + self.motor_map[i][2] * torque.z; + + motors[i] = throttle + delta; + } + + // -------------------------------------------------- + // 2. Find saturation + // -------------------------------------------------- + let mut max_motor = f32::MIN; + let mut min_motor = f32::MAX; + + for &m in motors.iter() { + max_motor = max_motor.max(m); + min_motor = min_motor.min(m); + } + + let mut saturated = false; + + // -------------------------------------------------- + // 3. Thrust-priority correction (shift down) + // Preserves all torque differences + // -------------------------------------------------- + if max_motor > self.max_throttle { + let excess = max_motor - self.max_throttle; + for m in motors.iter_mut() { + *m -= excess; + } + saturated = true; + } + + // -------------------------------------------------- + // 4. Recompute minimum after shift + // -------------------------------------------------- + min_motor = f32::MAX; + for &m in motors.iter() { + min_motor = min_motor.min(m); + } + + // -------------------------------------------------- + // 5. Bottom correction (shift up if possible) + // Still preserves torque + // -------------------------------------------------- + if min_motor < self.min_throttle { + let deficit = self.min_throttle - min_motor; + for m in motors.iter_mut() { + *m += deficit; + } + saturated = true; + } + + // -------------------------------------------------- + // 6. Final clamp (last resort — torque may be lost) + // -------------------------------------------------- + for m in motors.iter_mut() { + if *m > self.max_throttle { + *m = self.max_throttle; + saturated = true; + } else if *m < self.min_throttle { + *m = self.min_throttle; + saturated = true; + } + } + + (motors, saturated) + } +} diff --git a/src/stacked/modules.rs b/src/stacked/modules.rs new file mode 100644 index 0000000..d6c7a8e --- /dev/null +++ b/src/stacked/modules.rs @@ -0,0 +1,117 @@ +use crate::DroneState; +use crate::PidConfig; +use nalgebra as na; + +pub mod acceleration; +pub mod angular_rate; +pub mod rotation; +pub mod velocity; + +pub use acceleration::AccelerationController; +pub use angular_rate::AngularRateController; +pub use rotation::RotationController; +pub use velocity::VelocityController; + +pub trait ControllerModule { + type Input: Clone + Default; + type Output: Clone + Default; + + fn process(&mut self, input: Self::Input, state: &DroneState, dt: f32) -> Self::Output; +} + +pub struct ModuleRuntime +where + C: ControllerModule, +{ + pub module: C, + pub target_dt: f32, + pub accumulated_time: f32, + pub last_output: Option, +} + +impl ModuleRuntime +where + C: ControllerModule, +{ + pub fn update(&mut self, input: C::Input, state: &DroneState, dt: f32) -> C::Output { + self.accumulated_time += dt; + + if self.accumulated_time >= self.target_dt { + self.accumulated_time = 0.0; + + let output = self.module.process(input, state, self.target_dt); + self.last_output = Some(output.clone()); + output + } else { + self.last_output + .as_ref() + .unwrap_or(&C::Output::default()) + .clone() + } + } + pub fn new(module: C, frequency: f32) -> Self { + Self { + module, + target_dt: 1.0 / frequency, + accumulated_time: 0.0, + last_output: None, + } + } +} + +#[derive(Clone, Copy, Debug, Default)] +pub struct Position(pub na::Vector3); // meters + +#[derive(Clone, Copy, Debug, Default)] +pub struct Velocity(pub na::Vector3); // m/s + +#[derive(Clone, Copy, Debug, Default)] +pub struct Acceleration(pub na::Vector3); // m/s + +#[derive(Clone, Copy, Debug, Default)] +pub struct Rotation(pub na::Vector3); // radians + +#[derive(Clone, Copy, Debug, Default)] +pub struct AngularRate(pub na::Vector3); // rad/s + +#[derive(Clone, Copy, Debug, Default)] +pub struct Torque(pub na::Vector3); // control output + +#[derive(Clone, Copy, Debug, Default)] +pub struct Throttle(pub f32); + +pub struct PidProcessor { + kp: na::Vector3, + ki: na::Vector3, + kd: na::Vector3, + integral: na::Vector3, + last_error: na::Vector3, +} + +impl PidProcessor { + pub fn new(c: &PidConfig) -> Self { + Self { + kp: c.p_vec(), + ki: c.i_vec(), + kd: c.d_vec(), + integral: na::Vector3::zeros(), + last_error: na::Vector3::zeros(), + } + } + + pub fn update( + &mut self, + target: na::Vector3, + current: na::Vector3, + dt: f32, + ) -> na::Vector3 { + let error = target - current; + self.integral += error * dt; + let derivative = (error - self.last_error) / dt; + self.last_error = error; + + error.component_mul(&self.kp) + + self.integral.component_mul(&self.ki) + + derivative.component_mul(&self.kd) + } +} diff --git a/src/stacked/modules/acceleration.rs b/src/stacked/modules/acceleration.rs new file mode 100644 index 0000000..a24b65c --- /dev/null +++ b/src/stacked/modules/acceleration.rs @@ -0,0 +1,47 @@ +use crate::stacked::modules::*; + +pub struct AccelerationController { + max_throttle: f32, + min_throttle: f32, + throttle_thrust_multiplier: f32, +} + +impl AccelerationController { + pub fn new(max_throttle: f32, min_throttle: f32, throttle_thrust_multiplier: f32) -> Self { + Self { + max_throttle, + min_throttle, + throttle_thrust_multiplier, + } + } +} + +impl ControllerModule for AccelerationController { + type Input = Acceleration; + type Output = (Rotation, Throttle); + + fn process( + &mut self, + input: Acceleration, + state: &DroneState, + _dt: f32, + ) -> (Rotation, Throttle) { + // Thrust is on the Body Up direction + let body_up = na::Vector3::z(); + + let gravity_compensation = na::vector![0.0, 0.0, 9.8]; + // F=ma + let desired_force_vec = (input.0 + gravity_compensation) * state.mass; + + // 3. Find rotation to align Body-Z with Desired-Thrust-Vector + let rotation = + na::UnitQuaternion::rotation_between(&body_up, &desired_force_vec.normalize()) + .unwrap_or(state.rotation); + + let total_max_thrust = self.throttle_thrust_multiplier * 4.0; + let throttle = (desired_force_vec.norm() / total_max_thrust) + .clamp(self.min_throttle, self.max_throttle); + + (Rotation(rotation.scaled_axis()), Throttle(throttle)) + } +} diff --git a/src/stacked/modules/angular_rate.rs b/src/stacked/modules/angular_rate.rs new file mode 100644 index 0000000..5ebf2a5 --- /dev/null +++ b/src/stacked/modules/angular_rate.rs @@ -0,0 +1,25 @@ +use crate::stacked::modules::*; + +pub struct AngularRateController { + pid: PidProcessor, +} + +impl AngularRateController { + pub fn new(pid: PidProcessor) -> Self { + Self { pid } + } +} + +impl ControllerModule for AngularRateController { + type Input = AngularRate; + type Output = Torque; + + fn process(&mut self, input: AngularRate, state: &DroneState, dt: f32) -> Torque { + // Scale normalized rate command + let target_rate = input.0; + + let output = self.pid.update(target_rate, state.angvel, dt); + + Torque(output) + } +} diff --git a/src/stacked/modules/rotation.rs b/src/stacked/modules/rotation.rs new file mode 100644 index 0000000..51c99a1 --- /dev/null +++ b/src/stacked/modules/rotation.rs @@ -0,0 +1,29 @@ +use nalgebra::UnitQuaternion; + +use crate::stacked::modules::*; + +pub struct RotationController { + pid: PidProcessor, +} +impl RotationController { + pub fn new(pid: PidProcessor) -> Self { + Self { pid } + } +} + +impl ControllerModule for RotationController { + type Input = Rotation; + type Output = AngularRate; + + fn process(&mut self, input: Rotation, state: &DroneState, dt: f32) -> AngularRate { + let target_rot = UnitQuaternion::from_scaled_axis(input.0); + + let error_quat = state.rotation.rotation_to(&target_rot); + + let error_vector = error_quat.scaled_axis(); + + let output = self.pid.update(error_vector, na::Vector3::zeros(), dt); + + AngularRate(state.rotation.inverse_transform_vector(&output)) + } +} diff --git a/src/stacked/modules/velocity.rs b/src/stacked/modules/velocity.rs new file mode 100644 index 0000000..c1621f3 --- /dev/null +++ b/src/stacked/modules/velocity.rs @@ -0,0 +1,23 @@ +use crate::stacked::modules::*; + +pub struct VelocityController { + pid: PidProcessor, +} + +impl VelocityController { + pub fn new(pid: PidProcessor) -> Self { + Self { pid } + } +} + +impl ControllerModule for VelocityController { + type Input = Velocity; + type Output = Acceleration; + + fn process(&mut self, input: Velocity, state: &DroneState, dt: f32) -> Acceleration { + let target_rate = input.0; + + let output = self.pid.update(target_rate, state.linvel, dt); + Acceleration(output) + } +}