Compare commits

...
28 Commits
Author SHA1 Message Date
melfely 67c58dfc09 Updated the readme to a bit more sense. 2026-08-05 18:32:39 -05:00
melfely 90ba10125f Changed Main Workspace Readme to be the main readme 2026-08-02 12:02:15 -05:00
melfely 2e2694c68b Merge pull request 'Fixed a bit of a syntax issue' (#4) from Readme-update2 into master
Reviewed-on: #4
2026-07-31 02:49:08 +00:00
melfely 00ce10e3ab Fixed a bit of a syntax issue 2026-07-31 02:48:59 +00:00
melfely 47b67917d3 Merge pull request 'Update Readme.md' (#3) from Readme-update into master
Reviewed-on: #3
2026-07-31 02:47:16 +00:00
melfely 94d633dca7 Update Readme.md 2026-07-31 02:47:04 +00:00
melfely d4809beee7 Merge pull request 'Repo rebuild' (#2) from repo-rebuild into master
Reviewed-on: #2
2026-07-31 02:43:07 +00:00
melfely 69deda596e Merge branch 'repo-rebuild' 2026-07-30 21:38:16 -05:00
melfely 3703ca664e Added in the Pid and Motor Code
Pid was added to rnavp, since it can be used in alot of different things.
2026-07-30 21:20:30 -05:00
melfely 4b06468ff4 Rebuild the repo as a workspace
This replaces the existing single lib project repo, and replaces it with a workspace containing a large number of crates, this will allow for a much better structure and less feature flags being needed for reducing the feature scope for each user.
2026-07-30 20:35:13 -05:00
melfely ca5607ec25 Reset back to base version 2026-07-30 22:24:32 +00:00
melfely 50c77f7200 Update Readme.md 2026-07-04 15:33:25 +00:00
melfely b85d168b8e More license stuff Added to Cargo.toml 2026-07-04 15:28:08 +00:00
melfely f19b486cd0 Updated Readme 2026-07-04 15:25:48 +00:00
melfely 56acf0f9a1 Added Notice for Apache 2.0 License 2026-07-04 15:24:35 +00:00
melfely 8731f8eeba Actually add the Apache 2.0 license file 2026-07-04 15:23:58 +00:00
melfely 7181dac88c Actually add the Mit license file 2026-07-04 15:23:05 +00:00
melfely 5b69c961d2 Actually add the Mit license file 2026-07-04 15:19:03 +00:00
melfely 3d2399aaea shorted comment length so no scroll bar 2026-06-28 08:03:24 -05:00
melfely 14fb0899f3 Verison bump to 0.3.0 2026-06-14 14:24:39 -05:00
melfely 3df2334b10 Changed over to async functions
changed over all the classes in these files to use async based methods
rather than non. This SHOULD make the system more reliable with embassy
in the future, and hopefully prevent issues with blocking code and the
way embassy works.
2026-06-14 14:24:08 -05:00
melfely 6ade7615a7 version bump. 2026-06-13 13:54:28 -05:00
melfely 16107036e7 Changed internal PID math
The system new reduces itself by 1000 internally before output,
hopefully making the precision much higher (IE NOT needing to use tiny
ass inputs to make anything reasonable)
2026-06-13 13:53:22 -05:00
melfely 19bbcfd7ab version bump 2026-06-13 12:12:23 -05:00
melfely ff448bf1af Added a retrieve method
This will let you get the speed from the motor directly without the
future communication system being needed
2026-06-13 12:11:31 -05:00
melfely 58eb647507 added docs comments for new method 2026-06-12 19:08:07 -05:00
melfely 8631d9d2a1 Fixed a new() issue
where it took in a PID rather than a pid::PID rather than a pid::PID

Version Bump to 0.2.2
2026-06-12 19:07:37 -05:00
melfely eb7d4ca59a Version bump 2026-06-12 19:01:19 -05:00
31 changed files with 809 additions and 619 deletions
Generated
+237 -17
View File
@@ -3,35 +3,193 @@
version = 4 version = 4
[[package]] [[package]]
name = "proc-macro2" name = "atomic-polyfill"
version = "1.0.106" version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4"
dependencies = [
"critical-section",
]
[[package]]
name = "autocfg"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cobs"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1"
dependencies = [
"thiserror",
]
[[package]]
name = "critical-section"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
[[package]]
name = "hash32"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67"
dependencies = [
"byteorder",
]
[[package]]
name = "hash32"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606"
dependencies = [
"byteorder",
]
[[package]]
name = "heapless"
version = "0.7.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f"
dependencies = [
"atomic-polyfill",
"hash32 0.2.1",
"rustc_version",
"serde",
"spin",
"stable_deref_trait",
]
[[package]]
name = "heapless"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25ba4bd83f9415b58b4ed8dc5714c76e626a105be4646c02630ad730ad3b5aa4"
dependencies = [
"hash32 0.3.1",
"serde_core",
"stable_deref_trait",
]
[[package]]
name = "lock_api"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
dependencies = [
"scopeguard",
]
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]]
name = "postcard"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6764c3b5dd454e283a30e6dfe78e9b31096d9e32036b5d1eaac7a6119ccb9a24"
dependencies = [
"cobs",
"heapless 0.7.17",
"postcard-derive",
"serde",
]
[[package]]
name = "postcard-derive"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0232bd009a197ceec9cc881ba46f727fcd8060a2d8d6a9dde7a69030a6fe2bb"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.45" version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]] [[package]]
name = "rnavp" name = "rnavp"
version = "0.2.0" version = "0.1.0"
dependencies = [ dependencies = [
"heapless 0.9.3",
"postcard",
"serde", "serde",
"thiserror",
"uom",
] ]
[[package]] [[package]]
name = "serde" name = "rnavp_communication"
version = "1.0.228" version = "0.1.0"
[[package]]
name = "rnavp_logic"
version = "0.1.0"
dependencies = [
"rnavp",
"serde",
"uom",
]
[[package]]
name = "rustc_version"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
dependencies = [
"semver",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "semver"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
[[package]]
name = "serde"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
dependencies = [ dependencies = [
"serde_core", "serde_core",
"serde_derive", "serde_derive",
@@ -39,37 +197,99 @@ dependencies = [
[[package]] [[package]]
name = "serde_core" name = "serde_core"
version = "1.0.228" version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.228" version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 3.0.3",
] ]
[[package]] [[package]]
name = "syn" name = "spin"
version = "2.0.117" version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e"
dependencies = [
"lock_api",
]
[[package]]
name = "stable_deref_trait"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
[[package]]
name = "syn"
version = "2.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "syn"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thiserror"
version = "2.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09a43598840e33d5b0331f38c5e30d13bb11c11210a4b58f0d9b18a5a5eefcd9"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "2.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43cbfe0cf76104d42a574802844187e84a305e531ed54455f11fbde0f10541cd"
dependencies = [
"proc-macro2",
"quote",
"syn 3.0.3",
]
[[package]]
name = "typenum"
version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.24" version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "uom"
version = "0.38.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a739f83872836c82a4f2527d4e54b37007b3de68cafe7edde95fd695968bf4b9"
dependencies = [
"num-traits",
"typenum",
]
+4 -18
View File
@@ -1,18 +1,4 @@
[package] [workspace]
name = "rnavp" members = ["rnavp"
version = "0.2.0" , "rnavp_communication", "rnavp_controller"]
edition = "2024" resolver = "3"
publish = ["gitea"]
[features]
default= ["embassy"]
std = []
embassy = ["core_full"]
core = []
core_full = ["core_communication", "core_logic"]
core_communication = ["core"]
core_logic = ["core"]
host = ["std", "core_full"]
[dependencies]
serde = { version = "1.0.228", features = ["derive"], default-features = false }
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) [2026] [Zander Allen Johnson]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+1
View File
@@ -0,0 +1 @@
Copyright 2026 Zander Allen Johnson
+2 -28
View File
@@ -1,28 +1,2 @@
# *RNavP* # RNavP
**RNavP** - *Remote Node adaptive Protocl*
## Robotics Navigation and Control Via Postcard
This is a crate designed to assit in development for the entire stack from the MCU(Running Embassy) to a STD computer talking to that MCU Via postcard for Drivetrain control.
Designed for intergration with ROS2 but is *NOT* required and will work for any STD enviroment for the control system
## Highlights
Able to drive just about anything, 2 wheel differential drive, simple we got that. 4 Wheeled OmniDirectional? We got that to. 9 Wheeled Abomination? Why? But, *We gotcha bro!*
Simulation system, Define the upper level logic, and the placement of the wheels and the motor specs and we can give you a low fidilety simulation output on the Computer no MCU needed.
Want to see it ON something? Well use the outputs and hook into the SIM of your choice! Verify your robot design and logic systems, before even ordering the MCU, or having to design how the ESC works.
Entirely Rust, this uses a full RUST eco system from the ground up, keeping the Your code safe, and your robots doing exactly what you intended for them to do.
Uses Embassy. Since this is designed to have a single function init, you WILL have to pass in your embassy executor spawning item so you can't spawn anything new once this is started.
BUT, you can easily just throw this entire system on core 1 (Second core) of your MCU, and not care about it anymore. Handle the rest of your logic, read some data, run a HMI using the wonderful SLINT crate.
Who knows? What we do know is that, your entire drivetrain and sensor system you asked us to handle. We handled.
## Licensing
Dual Licensed Under
MIT and Apache-2.0
+11
View File
@@ -0,0 +1,11 @@
[package]
name = "rnavp"
version = "0.1.0"
edition = "2024"
[dependencies]
heapless = { version = "0.9.3", features = ["serde"] }
postcard = { version = "1.1.3", features = ["postcard-derive"] }
serde = { version = "1.0.229", default-features = false, features = ["derive"] }
thiserror = { version = "2.0.19", default-features = false }
uom = { version = "0.38.0", default-features = false, features = ["autoconvert", "f32", "si"] }
+69
View File
@@ -0,0 +1,69 @@
use serde::{Deserialize, Serialize};
///A simple enum for Counterclockwise or Clockwise direction semantics. Makes it easier much clear than a true/false bool
/// IF you use this to convert to a signed number note that CW is negative and CCW is positive
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub enum Direction {
///CounterClockWise
CCW,
///ClockWise
CW,
}
impl Direction {
///Inverts the direction currently stored in this.
/// Helps with a simple direction change without knowing the current direction.
pub fn inv_dir(&mut self) {
match *self {
Self::CCW => {
*self = Self::CW;
}
Self::CW => {
*self = Self::CCW;
}
}
}
///Changes the current direction based on the sign of the float.
///Recommended to use this over the "From" impl for directions that already exist, to prevent werid 0.0 case and NaN problems
/// This handles 0.0 and NaN by just doing nothing. The "From" impl defualts to CCW for both
pub fn dir_from_f32(&mut self, value: f32) {
if value == 0.0 || value.is_nan() {
return;
}
*self = value.into();
}
///Changes the current direction based on the sign of the int.
///Recommended to use this over the "From" impl for directions that already exist, to prevent weird 0 case problems
///This handles 0 by just doing nothing. The "From" impl defaults to CCW
pub fn dir_from_i32(&mut self, value: i32) {
if value == 0 {
return;
}
*self = value.into();
}
}
///Converts F32 to direction using the number's sign.
/// This defaults to CCW for 0.0 and NaN.
impl From<f32> for Direction {
fn from(value: f32) -> Self {
if value < 0.0 {
Direction::CW
} else {
Direction::CCW
}
}
}
/// Converts i32 to direction using the number's sign.
/// This defaults to CCW for 0.
impl From<i32> for Direction {
fn from(value: i32) -> Self {
if value < 0 {
Direction::CW
} else {
Direction::CCW
}
}
}
+5
View File
@@ -0,0 +1,5 @@
mod direction;
pub mod error;
pub mod motor;
pub mod pid;
pub mod positional;
+67
View File
@@ -0,0 +1,67 @@
use uom::si::f32::{Angle, AngularVelocity, ElectricCurrent, ElectricPotential};
pub use crate::direction::Direction;
/// # Motor Driver
///
/// This trait is implemented on a motor struct to implement the motor DRIVER (like an ESC) capabalities in how it should control the motor.
/// This will then let other systems use this trait and system to control your motor without needing to understand the hardware as much.
#[allow(async_fn_in_trait)]
pub trait Driver {
///Spins in the provided direction
/// Properly map each direction to CounterClockWise and Clockwise when LOOKING AT THE MOTOR SHAFT. This is VITAL for the way the systems within core::logic will work.
///This is best not called manually, use set_speed_and_direction_raw instead
async fn spin(&mut self, dir: Direction);
///Commands the motor to stop
/// This should stop the motor in what ever way you see fit.
/// Some hardware may have a proper "Stop" or "Off" Signal, some will not.
/// If there is no proper hardware stop, verify that 0 speed is actually a stopping command and you can easily just set speed to 0 via set_speed_raw in this method.
/// No default implementation (though this is easily something I could have done) because it SHOULD be something you notice and implement PROPERLY if applicable
async fn stop(&mut self);
///This method uses a full u16 to set the motor speed. This does not change spin direction.
/// You need to map 0 to 65535 properly to your specific hardware range, just because PWM is commonly 0 to 65535 do not assume that ALL ways of controlling a motor cleanly takes a value of 0 to 65535,
/// you need to verify and map properly.
/// 65535 should be the max possible speed, while 0 should be stopped.
///This is best to not call manually, use set_speed_and_direction_raw instead
async fn set_speed(&mut self, speed: u16);
///Commands the motors to use the speed and spin in the same command.
///Uses a number between 0 and 65535
///This should be used in most cases, unless the motor has the core::logic::motor::controller Trait, then the the methods from that should be used instead.
async fn set_speed_and_direction(&mut self, speed: u16, dir: Direction) {
//Set direction before speed, so it won't start spinning in one direction, then snap to the other.
//Most MCUs should execute these two lines of code so fast, that it should be neglible regardless.
self.spin(dir).await;
self.set_speed(speed).await;
}
}
/// # Motor Sensor
/// This trait is implemented on motors that have some form of sensory feedback. Note that this does not require the motor ITSELF provide feedback, just that the setup the motor is in supports it. IE, a Current draw based ESC
/// Speed Feedback is REQUIRED, if your device does not provide speed feedback directly,
/// Implement the other conditions and use them to then implement the speed method.
///
/// Some motors/sensors might have a direct "Current Angle" being reported, the option is there in case yours can, so the communication system can sync it to the host for you.
/// Some sensors may also provide current and voltage feedback, if implemented the communication system can sync them to the host you for.
/// Can also be used for other custom logic. They are unused by RNavP, entirely optional.
#[allow(async_fn_in_trait)]
pub trait Sensor {
///Returns the speed struct value from the motors sensor.
///
/// IF properly returned in the correct Enum Data field, all other systems will use the value propely, being unit agnostic later.
async fn get_speed(&self) -> AngularVelocity;
///Returns the current from the sensor, if it capable.
/// This should be non-blocking. Keep a cached value ready.
async fn get_current(&self) -> Option<ElectricCurrent>;
///Returns the current voltage from the sensro, if it is capable.
/// This should be non-blocking. Keep a cached value ready.
async fn get_voltage(&self) -> Option<ElectricPotential>;
///Returns the current angle from the sensor if it is capable.
/// This should be non-blocking. Keep a cached value ready.
async fn get_angle(&self) -> Option<Angle>;
}
+6 -6
View File
@@ -38,14 +38,14 @@ impl PID {
integral: 0.0, integral: 0.0,
prev_error: 0.0, prev_error: 0.0,
set_point: 0.0, set_point: 0.0,
output: 0.0 output: 0.0,
} }
} }
} }
impl Default for PID { impl Default for PID {
fn default() -> Self { fn default() -> Self {
PID::new(Config{ PID::new(Config {
kp: 0.0, kp: 0.0,
ki: 0.0, ki: 0.0,
kd: 0.0, kd: 0.0,
@@ -61,7 +61,7 @@ impl PID {
///Will output a float between -1.0 and 1.0 ///Will output a float between -1.0 and 1.0
///Current value is the current "position" of the system NOT the goal ///Current value is the current "position" of the system NOT the goal
/// Use set_point() method to change the "goal position" for the system /// Use set_point() method to change the "goal position" for the system
pub fn pid_step(&mut self, current_value: f32) -> f32 { pub async fn pid_step(&mut self, current_value: f32) -> f32 {
//If the values //If the values
let error = self.set_point - current_value; let error = self.set_point - current_value;
@@ -93,9 +93,9 @@ impl PID {
//Calculate and store the output //Calculate and store the output
let output = match self.config.accel { let output = match self.config.accel {
0.0 => f + p + i + d, 0.0 => (f + p + i + d) * 0.0001,
_ => { _ => {
let pre_output = f + p + i + d; let pre_output = (f + p + i + d) * 0.0001;
let change = pre_output - self.output; let change = pre_output - self.output;
let change = change.clamp(-self.config.accel, self.config.accel); let change = change.clamp(-self.config.accel, self.config.accel);
@@ -117,7 +117,7 @@ impl PID {
return self.output; return self.output;
} }
pub fn set_point(&mut self, set_point: f32) { pub async fn set_point(&mut self, set_point: f32) {
if set_point != self.set_point { if set_point != self.set_point {
//Update all internal fields //Update all internal fields
self.integral = 0.0; self.integral = 0.0;
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "rnavp_communication"
version = "0.1.0"
edition = "2024"
[dependencies]
+134
View File
@@ -0,0 +1,134 @@
## RNavP
**RNavP Communication** - *Remote Node adaptive Protocl*
The project is intended to be a Protocol layer between an MCU and a Host system. The system will support other systems including but not limited to; Host to Host, MCU to MCU. The system will be designed to accept a byte buffer from any transport layer. The transport layer is **NOT** a design part of RNavP it will support any transport layer that can implement the "Endpoint" trait.
## Concept
A discovery based, protocol layer that supports many generic byte based transport layer and many Serialization Codecs
Will be Server (MCU) <-> Client (Host).
A client will ask a server, what devices it has, the server will respond with a list of devices. The client can then inquire about more information about each device respectively.
The intended goal is for a Ros2 Based host SBC (Like a Rasbperry Pi5) communicating with a MCU (Like a Raspberry Pico 2) Over UART. The API will be designed to be INCREDIBLY generic, support many different device setups and frameworks.
## Basic Implementations
The basic idea is for there to be a simple header that heads EVERY packet. Extra data, but the cost gets paid for 10 fold later.
Basic header as a rust struct snippet
### Header
```rust
struct Header {
packet_size: u16, //Supports up to 65535 bytes, in a single packet. This value includes the entire header.
port: u16, //The communication port. Allows for multiple connections even on a simple protocol like UART
context: u8, //A simple short u8 rolling transfer count. Each type a transfer happens on the same port, this increments
packet_type: PacketType, // A u8 enum that defines the packet contents
}
#[repr(u8)]
enum PacketType {
CommunicationInfo,
Discovery,
Request,
Command,
Error,
ClosePort,
OpenPort,
Config,
Shutdown,
... //Many more
}
```
- Packet Size => The size of the packet, while it will technically be a u16 so therefore a packet size of 65535 bytes, this is INSANE sizes of packets. A packet should never need to be that large.
- Port => Supports a port number, working similar to TCP and UDP ports, allowing for multi device to device communication on a larger variety of protocols. Ports by default presume the common Privileged port concept from OS.
Where ports 0 to 1023 are Privileged, where they are only allowed by the MCU talking to itself. NOT allowed when an external device communicates with it.
- Context => A small rolling count of the communication state. This is intended just for a small syncing cost. Dropping a signifciant number of messages where a single byte u8 can't keep a sync means there is more wrong than that.
- Packet type. Will be a defined enum, that will contain all supported message types that can be sent.
### Packet Type Examples
An example of the CommunicationInfo Packet
```rust
struct CommunicationInfo {
codec: Codec,
version: u32,
magic_num: 0x1337,
}
```
An example of the Error Packet
The reasoning behind the error packet design is simple.
The error will always contain the magic num of 0x1337 at the end. Which is a simple 16 bit number. But why? Simple, the MCU (which is the server side) Should ONLY contain one codec (but can contain all), they will be set at COMPILE time. The host (which is the client side) should contain ALL (but can contain one) codecs. This allows for the host to send a invalid packet. Which will trigger an error response.
This error response will then broadcast out the generic error response. Which a host can then use to test all known codecs to attempt to decode the codec if it is unknown. This should NEVER be required, but WILL help someone at some point if it is ever needed. Errors should be RARE. So the cost of 2 bytes extra in a error packet should be low. If you have lots of errors. Fix the problem, that is usually a good idea.
```rust
struct ErrorPacket {
err: Error,
codec: Codec,
magic_num: u16 = 0x1337,
}
```
## Communication Start
Communication will start by the client (Host) sending a 5 byte magic packet
0x00 0x00 0x37 0x13 0xFF
This allows the MCU to know to respond to this packet, with a very simple response packet.
0x00 0x00 0x(number of codecs) (list of codec IDs) 0xFF
This will then allow for the host to know HOW to send a valid packet to the MCU which should then be a simpleCommunication Info Packet. Which is a the equal of a "ping" in this context
| | Packet Size | Port | Context | Packet Type | Codec | Version | Magic Num |
| ----- | ----------- | --------- | ------- | ----------------- | ------------------ | ------------------- | --------- |
| Hex | 0x0D 0x00 | 0x00 0x04 | 0x00 | 0x00 | 0x01 | 0x01 0x00 0x00 0x00 | 0x37 0x13 |
| Human | 13 | 1024 | 0 | CommunicationInfo | Postcard (Default) | 1 | 0x1337 |
Explanation of all the numbers
- Packet size -> there are 13 total bytes in this packet. Including the header
- Port -> Must be above 1023, as 1024 is the first non-privileged port.
- Context -> MCU (Server) starts context value, it will pick a random value within the 255 value range, expecting the Host (Client) to start from that, NOT 1 or 0. 0 Is ONLY valid for a CommunicationInfo Packet.
## Wire Rules
### Endianness
The protocol is strictly little-endian. Most modern systems are little-endian including micro-controllers, there is zero reason for a NEW protocol to come out as big-endian.
It is just another sync problem. For the most part, most Codec Library's for most languages support choosing the output mode, and they default to the same as the host system. Which in 95% of cases on modern devices, will be little-endian.
## Packet Header
The importance of the header design is vital in a good protocol. This header is designed to be short and sweet.
There is already a example of this in rust code in the [[#Basic Implementations]] section of the document this section will go into more detail about the concepts and the whys.
### Packet Size
The packet size, why a u 16? That is a giant packet size, most MCU will not be able to handle it. Yes, BUT the next size is a very restrictive u 8. 255 bytes is quite a few, until you need KB sized packets. Containing large states and device names.
Another thing, the Packet Size struct ALSO holds the header. Not the sync packet structure that starts with (0 x 00 0 x 00) no valid packet can start with this, why? Because the header is at least 6 bytes or (0 x 06 0 x 00). So there is NO way any valid communication can happen in the 1 to 5 byte "packet size" range.
### Port
To make things simple I am taking a Desktop OS style of port rules. Anything less than 1024 is privileged anything above it, is not.
Privileged ports will be designed for a specific things that only the MCU itself should be doing in most cases, or some form of external control should trigger it (IE an IRQ for a limit switch). These "Privileged" ports are HIGHER priority and control specific state levels that ONLY the device should control.
A good point of this, is privileged ports should be thought of as IRQ, only used by the MCU when things are going wrong or emergencies. NOT as a way to influence the devices, that should be left up to the host
### Context
The importance of communication order can be hard to keep track of. So this protocol is simple, the context MUST match the next expected one, for the MCU to execute, it will NOT execute anything out of order. Even a data request. This is to protect the integrity of expected state, thing A must happen before thing B.
To make this reasonable, we must queue a few packets. The number of packets queued will depend on the settings set by the MCU itself, along with a timeout. It will wait the Timeout duration for the expected packet, if not received it will Error DROPPING ALL PACKETS IT HAS RECEIVED.
This is again to protect the importance of state. Since the goal of this Protocol is to merge state between an MCU and a Host device. Making it SEEM like there is not even a wire bridge between them.
## Discovery
The MCU (Server) will on a basic discovery request will send the upper device tree. Which is the list of devices TYPES it has, along with the count of each.
This will let the Host (Client) Decided which devices it wants more information on. Rather than forcing a massive state sync upfront. The default will be Lazy Cache, where a device is only requested from the host on its first use, then stored. Rather than Upfront collection. This will make large massive device counts much more reliable while keeping the concept simple.
### The goal of Discovery
The MAJOR goal of discovery is to facilitate taking MCU devices, and giving them to a host for near transparent control. It should on the Host side, once setup feel like a native Object, rather than a
+14
View File
@@ -0,0 +1,14 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
+9
View File
@@ -0,0 +1,9 @@
[package]
name = "rnavp_logic"
version = "0.1.0"
edition = "2024"
[dependencies]
rnavp = {path = "../rnavp"}
serde = { version = "1.0.229", default-features = false, features = ["derive"] }
uom = { version = "0.38.0", default-features = false, features = ["si", "f32"] }
+1
View File
@@ -0,0 +1 @@
pub mod motor;
@@ -1,7 +1,6 @@
use crate::core::motor; use rnavp::motor::{self, Direction};
use crate::core::motor::{Direction, Speed}; use rnavp::pid;
use uom::si::f32::AngularVelocity;
use crate::core::logic::pid;
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
/// # Motor Controller /// # Motor Controller
@@ -17,7 +16,7 @@ where
T: motor::Driver + motor::Sensor, T: motor::Driver + motor::Sensor,
{ {
motor: T, motor: T,
max_speed: Speed, max_speed: AngularVelocity,
pid: pid::PID, pid: pid::PID,
current_direction: Direction, current_direction: Direction,
} }
@@ -25,26 +24,35 @@ where
///Controller Impl for the adding the PID logic for handling the motor compiston ///Controller Impl for the adding the PID logic for handling the motor compiston
impl<T: motor::Driver + motor::Sensor> Controller<T> { impl<T: motor::Driver + motor::Sensor> Controller<T> {
///Uses the given set_speed and then will handle the rest of the control logic to accurately* hit the requested speed ///Uses the given set_speed and then will handle the rest of the control logic to accurately* hit the requested speed
pub fn control(&mut self, set_speed: Speed) { pub async fn control(&mut self, set_speed: AngularVelocity) {
let max_speed_rads = self.max_speed.rads(); let max_speed_rads = self.max_speed.value;
let set_speed_rads = set_speed.rads().clamp(-max_speed_rads, max_speed_rads); let set_speed_rads = set_speed.value.clamp(-max_speed_rads, max_speed_rads);
self.pid.set_point(set_speed_rads); self.pid.set_point(set_speed_rads).await;
let pid_output = self.pid.pid_step(self.motor.get_speed().rads()); let pid_output = self.pid.pid_step(self.motor.get_speed().await.value).await;
self.current_direction.dir_from_f32(pid_output); self.current_direction.dir_from_f32(pid_output);
let motor_command = (pid_output * 65535.0) as u16; let motor_command = (pid_output * 65535.0) as u16;
self.motor self.motor
.set_speed_and_direction(motor_command, self.current_direction); .set_speed_and_direction(motor_command, self.current_direction)
.await;
} }
pub fn new(motor: T, max_speed: Speed, pid: pid::PID) -> Self { ///Retrieve the speed from the motor inside the controller.
/// This allows you to get a speed value from behind the move.
pub async fn retrieve(&self) -> AngularVelocity {
self.motor.get_speed().await
}
///Creates a new Controller with a motor (of type T), a max speed and a pid::Config
/// This then allows for you to use the controller with the provided types
pub fn new(motor: T, max_speed: AngularVelocity, config: pid::Config) -> Self {
Controller { Controller {
motor: motor, motor: motor,
max_speed: max_speed, max_speed: max_speed,
pid: pid, pid: pid::PID::new(config),
current_direction: Direction::CCW, current_direction: Direction::CCW,
} }
} }
-4
View File
@@ -1,4 +0,0 @@
pub mod drivetrain;
pub mod motor;
pub mod sensing;
pub mod wheel;
-1
View File
@@ -1 +0,0 @@
-1
View File
@@ -1 +0,0 @@
-1
View File
@@ -1 +0,0 @@
-3
View File
@@ -1,3 +0,0 @@
pub mod kinematics;
pub mod motor;
pub mod pid;
-9
View File
@@ -1,9 +0,0 @@
#[cfg(feature = "core_communication")]
pub mod communication;
#[cfg(feature = "core_logic")]
pub mod logic;
pub mod motor;
pub mod positional;
pub mod units;
-172
View File
@@ -1,172 +0,0 @@
use core::fmt::Display;
use serde::{Deserialize, Serialize};
use crate::core::{
motor::Direction::{CCW, CW},
units::{Angle, Current, Voltage},
};
///A simple enum for Counterclockwise or Clockwise direction semantics. Makes it easier much clear than a true/false bool
/// IF you use this to convert to a signed number note that CW is negative and CCW is positive
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub enum Direction {
///CounterClockWise
CCW,
///ClockWise
CW,
}
impl Direction {
///Inverts the direction currently stored in this.
/// Helps with a simple direction change without knowing the current direction.
pub fn inv_dir(&mut self) {
match *self {
Self::CCW => {
*self = Self::CW;
}
Self::CW => {
*self = Self::CCW;
}
}
}
///Changes the current direction based on the sign of the float.
///Recommended to use this over the "From" impl for directions that already exist, to prevent werid 0.0 case and NaN problems
/// This handles 0.0 and NaN by just doing nothing. The "From" impl defualts to CCW for both
pub fn dir_from_f32(&mut self, value: f32) {
if value == 0.0 || value.is_nan() {
return;
}
*self = value.into();
}
///Changes the current direction based on the sign of the int.
///Recommended to use this over the "From" impl for directions that already exist, to prevent weird 0 case problems
///This handles 0 by just doing nothing. The "From" impl defaults to CCW
pub fn dir_from_i32(&mut self, value: i32) {
if value == 0 {
return;
}
*self = value.into();
}
}
///Converts F32 to direction using the number's sign.
/// This defaults to CCW for 0.0 and NaN.
impl From<f32> for Direction {
fn from(value: f32) -> Self {
if value < 0.0 { CW } else { CCW }
}
}
/// Converts i32 to direction using the number's sign.
/// This defaults to CCW for 0.
impl From<i32> for Direction {
fn from(value: i32) -> Self {
if value < 0 { CW } else { CCW }
}
}
///A enum for containerizing speeds easily
/// Lets the backend take in a Rotations per minute value from a user Sensor implementation and convert it to a Radians per second value
///Pay attention to the units of each term
#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
pub enum Speed {
///Rotations per minute
RPM(f32),
///Radians per second
RADS(f32),
}
///Used to convert from Rotations per minute to radians per second
const RPM_TO_RADS: f32 = core::f32::consts::TAU / 60.0;
///Used to convert from Radians per second to Rotations per minute
const RADS_TO_RPM: f32 = 60.0 / core::f32::consts::TAU;
impl Speed {
///Returns the value as Radians Per Second regardless of what the enum contains
/// Uses no runtime division
#[inline]
pub fn rads(&self) -> f32 {
match *self {
Self::RPM(rpm) => rpm * RADS_TO_RPM,
Self::RADS(rps) => rps,
}
}
///Returns the value as Rotations Per minute regardles of what the enum contains
/// Uses no runtime division
#[inline]
pub fn rpm(&self) -> f32 {
match *self {
Self::RPM(rpm) => rpm,
Self::RADS(rps) => rps * RPM_TO_RADS,
}
}
}
impl Display for Speed {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "")
}
}
///This trait is implemented on a motor struct to implement the motor DRIVER (like an ESC) capabalities in how it should control the motor.
/// This will then let other systems use this generic trait and system to control your motor without needing to understand the hardware as much.
pub trait Driver {
///Spins in the provided direction
/// Properly map each direction to CounterClockWise and Clockwise when LOOKING AT THE MOTOR SHAFT. This is VITAL for the way the systems within core::logic will work.
///This is best not called manually, use set_speed_and_direction_raw instead
fn spin(&mut self, dir: Direction);
///Commands the motor to stop
/// This should stop the motor in what ever way you see fit.
/// Some hardware may have a proper "Stop" or "Off" Signal, some will not.
/// If there is no proper hardware stop, verify that 0 speed is actually a stopping command and you can easily just set speed to 0 via set_speed_raw in this method.
/// No default implementation (though this is easily something I could have done) because it SHOULD be something you notice and implement PROPERLY if applicable
fn stop(&mut self);
///This method uses a full u16 to set the motor speed. This does not change spin direction.
/// You need to map 0 to 65535 properly to your specific hardware range, just because PWM is commonly 0 to 65535 do not assume that ALL ways of controlling a motor cleanly takes a value of 0 to 65535,
/// you need to verify and map properly.
/// 65535 should be the max possible speed, while 0 should be stopped.
///This is best to not call manually, use set_speed_and_direction_raw instead
fn set_speed(&mut self, speed: u16);
///Commands the motors to use the speed and spin in the same command.
///Uses a number between 0 and 65535
///This should be used in most cases, unless the motor has the core::logic::motor::controller Trait, then the the methods from that should be used instead.
fn set_speed_and_direction(&mut self, speed: u16, dir: Direction) {
//Set direction before speed, so it won't start spinning in one direction, then snap to the other.
//Most MCUs should execute these two lines of code so fast, that it should be neglible regardless.
self.spin(dir);
self.set_speed(speed);
}
}
///This trait is implemented on motors that have some form of sensory feedback. Note that this does not require the motor ITSELF provide feedback, just that the setup the motor is in supports it. IE, a Current draw based ESC
/// Speed Feedback is REQUIRED, if your device does not provide speed feedback directly,
/// Implement the other conditions and use them to then implement the speed method.
///
/// Some motors/sensors might have a direct "Current Angle" being reported, the option is there in case yours can, so the communication system can sync it to the host for you.
/// Some sensors may also provide current and voltage feedback, if implemented the communication system can sync them to the host you for.
/// Can also be used for other custom logic. They are unused by RNavP, entirely optional.
pub trait Sensor {
///Returns the speed struct value from the motors sensor.
/// This should be non-blocking, there should be some form of cached value ready to go as soon as the method is called
///
/// IF properly returned in the correct Enum Data field, all other systems will use the value propely, being unit agnostic later.
fn get_speed(&self) -> Speed;
///Returns the current from the sensor, if it capable.
/// This should be non-blocking. Keep a cached value ready.
fn get_current(&self) -> Option<Current>;
///Returns the current voltage from the sensro, if it is capable.
/// This should be non-blocking. Keep a cached value ready.
fn get_voltage(&self) -> Option<Voltage>;
///Returns the current angle from the sensor if it is capable.
/// This should be non-blocking. Keep a cached value ready.
fn get_angle(&self) -> Option<Angle>;
}
-250
View File
@@ -1,250 +0,0 @@
use core::fmt::Display;
use serde::{Deserialize, Serialize};
///Generic Positional Data Struct, This can contain XYZ positions in meters or Radians
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug)]
pub struct XYZPos {
x: Option<f32>,
y: Option<f32>,
z: Option<f32>,
unit: Unit,
}
///Generic Velocity Data Struct, This can contain XYZ velocities in Meters Per Second or Radians Per Second
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug)]
pub struct XYZVel {
x: Option<f32>,
y: Option<f32>,
z: Option<f32>,
unit: Unit,
}
///Generic Acceleration Data Struct, This can contain XYZ accelerations in Meters Per Second Squared or Radians Per Second
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug)]
pub struct XYZAccel {
x: Option<f32>,
y: Option<f32>,
z: Option<f32>,
unit: Unit,
}
impl XYZData for XYZPos {
fn x(&self) -> Option<f32> {
self.x
}
fn y(&self) -> Option<f32> {
self.y
}
fn z(&self) -> Option<f32> {
self.z
}
fn unit(&self) -> Unit {
self.unit
}
fn is_pos(&self) -> bool {
true
}
}
impl XYZData for XYZVel {
fn x(&self) -> Option<f32> {
self.x
}
fn y(&self) -> Option<f32> {
self.y
}
fn z(&self) -> Option<f32> {
self.z
}
fn unit(&self) -> Unit {
self.unit
}
fn is_vel(&self) -> bool {
true
}
}
impl XYZData for XYZAccel {
fn x(&self) -> Option<f32> {
self.x
}
fn y(&self) -> Option<f32> {
self.y
}
fn z(&self) -> Option<f32> {
self.z
}
fn unit(&self) -> Unit {
self.unit
}
fn is_accel(&self) -> bool {
true
}
}
impl Position for XYZPos {}
impl Velocity for XYZVel {}
impl Acceleration for XYZAccel {}
impl Display for XYZPos {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let unit_str = match self.unit {
Unit::Meters => "m",
Unit::Radians => "rad",
Unit::Custom => "custom",
};
write!(
f,
"[X: {:?}{unit_str} | Y: {:?}{unit_str} | Z: {:?}{unit_str}]",
self.x, self.y, self.z
)
}
}
impl Display for XYZVel {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let unit_str = match self.unit {
Unit::Meters => "m",
Unit::Radians => "rad",
Unit::Custom => "custom",
};
write!(
f,
"[X: {:?}{unit_str}/s | Y: {:?}{unit_str}/s | Z: {:?}{unit_str}/s]",
self.x, self.y, self.z
)
}
}
impl Display for XYZAccel {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let unit_str = match self.unit {
Unit::Meters => "m",
Unit::Radians => "rad",
Unit::Custom => "custom",
};
write!(
f,
"[X: {:?}{unit_str}/s^2 | Y: {:?}{unit_str}/s^2 | Z: {:?}{unit_str}/s^2]",
self.x, self.y, self.z
)
}
}
///Structs that impl this trait, mean they are positions. Determine what type of position by reading the unit.
pub trait Position: XYZData {}
///Structs that impl this trait mean they are Velocities. Determine what type of velocity by reading the unit.
pub trait Velocity: XYZData {}
///Structs that impl this trait mean they are Accelerations. Determine what type of Acceleration by reading the unit.
pub trait Acceleration: XYZData {}
///This is the data backbone for the XYZ Position, Velocity, and Acceleration Data structs.
///They MUST implmenent this so it possible to easily and quickly get the data from the struct.
///Provides methods to check what type this is
pub trait XYZData {
fn x(&self) -> Option<f32>;
fn y(&self) -> Option<f32>;
fn z(&self) -> Option<f32>;
fn unit(&self) -> Unit;
///Returns an array of f32s that are the XYZ position, velocity or accel, based on the implemented traits.
///Any option field in the array that are None are returned as 0.0 here.
///Do not forget to check the unit, this may be in radians or meters.
fn xyz_array(&self) -> [f32; 3] {
[
self.x().unwrap_or(0.0),
self.y().unwrap_or(0.0),
self.z().unwrap_or(0.0),
]
}
fn is_pos(&self) -> bool {
false
}
fn is_vel(&self) -> bool {
false
}
fn is_accel(&self) -> bool {
false
}
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
pub enum XYZDataBucket {
Pos(XYZPos),
Vel(XYZVel),
Accel(XYZAccel),
}
impl XYZData for XYZDataBucket {
fn is_pos(&self) -> bool {
matches!(self, Self::Pos(_))
}
fn is_vel(&self) -> bool {
matches!(self, Self::Vel(_))
}
fn is_accel(&self) -> bool {
matches!(self, Self::Accel(_))
}
fn x(&self) -> Option<f32> {
match self {
Self::Pos(p) => p.x(),
Self::Vel(v) => v.x(),
Self::Accel(a) => a.x(),
}
}
fn y(&self) -> Option<f32> {
match self {
Self::Pos(p) => p.y(),
Self::Vel(v) => v.y(),
Self::Accel(a) => a.y(),
}
}
fn z(&self) -> Option<f32> {
match self {
Self::Pos(p) => p.z(),
Self::Vel(v) => v.z(),
Self::Accel(a) => a.z(),
}
}
fn unit(&self) -> Unit {
match self {
Self::Pos(p) => p.unit(),
Self::Vel(v) => v.unit(),
Self::Accel(a) => a.unit(),
}
}
}
///Represents the unit this position struct is carrying. Combining the Unit + Trait it impls lets you determine what this message contains
/// If you need to send a unit not listed here please use Unit::Custom
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug)]
pub enum Unit {
Meters,
Radians,
Custom,
}
-75
View File
@@ -1,75 +0,0 @@
use serde::{Deserialize, Serialize};
///Standard conversion constant to convert to micro from base unit
pub const TO_MICRO: f32 = 1_000_000.0;
///Standard conversion constant to convert from micro to base unit;
pub const FROM_MICRO: f32 = 1.0 / 1_000_000.0;
///Standard conversion constant to convert to milli from base unit;
pub const TO_MILLI: f32 = 1_000.0;
///Standard conversion constant to convert from milli to base unit;
pub const FROM_MILLI: f32 = 1.0 / 1_000.0;
///Standard way for the RNavP system to transfer around Current measurements.
/// This system by default uses Amps as f32.
/// Offers MilliAmps and MicroAmps for utilizing higher precision raw data for when needed.
/// Implements all needed conversions for handling f32 into and from this data type.
/// Uses Amps by default, please use MicroAmps and MilliVolts when needed for higher precision.
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Current {
Amps(f32),
MilliAmps(i32),
MicroAmps(i32),
}
impl From<f32> for Current {
fn from(value: f32) -> Self {
Self::Amps(value)
}
}
impl Into<f32> for Current {
fn into(self) -> f32 {
match self {
Self::MicroAmps(micro) => micro as f32 * FROM_MICRO,
Self::MilliAmps(milli) => milli as f32 * FROM_MILLI,
Self::Amps(amps) => amps,
}
}
}
///Standard way for the RNavP system to transfer around voltage measurements.
/// This system by default uses Volts as f32.
/// Offers MilliVolts and MicroVolts for utilizing higher precison raw data for when needed.
/// Implements all needed conversions for handling f32 into and from this dataType.
/// Uses Volts by default, please use MicroVolts and MilliVolts when needed for higher precision.
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Voltage {
Volts(f32),
MilliVolts(i32),
MicroVolts(i32),
}
impl From<f32> for Voltage {
fn from(value: f32) -> Self {
Self::Volts(value)
}
}
impl Into<f32> for Voltage {
fn into(self) -> f32 {
match self {
Self::MicroVolts(micro) => micro as f32 * FROM_MICRO,
Self::MilliVolts(milli) => milli as f32 * FROM_MILLI,
Self::Volts(volts) => volts,
}
}
}
///Standard way for the RnavP system for handling angles.
/// The system does use a f32, so no conversions needed.
/// Has methods for returning the wanted unit type regardless of what is stored.
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Angle {
Degrees(f32),
Radians(f32),
}
-7
View File
@@ -1,7 +0,0 @@
#[cfg(feature = "std")]
compile_error!(
"The 'std' feature is enabled, which is incompatible with 'embassy'. \n\
The 'host' feature (enabled by default) turns on 'std'. \n\
Please use '--no-default-features --features embassy' to build for MCU\n\
or verify that you have not included a different feature that requires'std'"
);
-1
View File
@@ -1 +0,0 @@
-13
View File
@@ -1,13 +0,0 @@
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "core")]
pub mod core;
#[cfg(feature = "embassy")]
pub mod embassy;
#[cfg(feature = "host")]
pub mod host;