Compare commits

..

17 Commits

Author SHA1 Message Date
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
10 changed files with 273 additions and 36 deletions
Generated
+1 -1
View File
@@ -22,7 +22,7 @@ dependencies = [
[[package]]
name = "rnavp"
version = "0.2.0"
version = "0.3.0"
dependencies = [
"serde",
]
+2 -1
View File
@@ -1,8 +1,9 @@
[package]
name = "rnavp"
version = "0.2.0"
version = "0.3.0"
edition = "2024"
publish = ["gitea"]
license = "MIT OR Apache-2.0"
[features]
default= ["embassy"]
+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
+6 -7
View File
@@ -6,23 +6,22 @@ This is a crate designed to assit in development for the entire stack from the M
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!*
## Project Goals
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.
Be 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 Host 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.
BUT, you can easily just throw this entire system on core 1 (The 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
Licensed under either Apache License, Version 2.0 (LICENSE-APACHE) or MIT license (LICENSE-MIT).
+15 -6
View File
@@ -25,26 +25,35 @@ where
///Controller Impl for the adding the PID logic for handling the motor compiston
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
pub fn control(&mut self, set_speed: Speed) {
pub async fn control(&mut self, set_speed: Speed) {
let max_speed_rads = self.max_speed.rads();
let set_speed_rads = set_speed.rads().clamp(-max_speed_rads, max_speed_rads);
self.pid.set_point(set_speed_rads);
let pid_output = self.pid.pid_step(self.motor.get_speed().rads());
self.pid.set_point(set_speed_rads).await;
let pid_output = self.pid.pid_step(self.motor.get_speed().await.rads()).await;
self.current_direction.dir_from_f32(pid_output);
let motor_command = (pid_output * 65535.0) as u16;
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) -> motor::Speed {
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: Speed, config: pid::Config) -> Self {
Controller {
motor: motor,
max_speed: max_speed,
pid: pid,
pid: pid::PID::new(config),
current_direction: Direction::CCW,
}
}
+6 -6
View File
@@ -38,14 +38,14 @@ impl PID {
integral: 0.0,
prev_error: 0.0,
set_point: 0.0,
output: 0.0
output: 0.0,
}
}
}
impl Default for PID {
fn default() -> Self {
PID::new(Config{
PID::new(Config {
kp: 0.0,
ki: 0.0,
kd: 0.0,
@@ -61,7 +61,7 @@ impl PID {
///Will output a float between -1.0 and 1.0
///Current value is the current "position" of the system NOT the goal
/// 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
let error = self.set_point - current_value;
@@ -93,9 +93,9 @@ impl PID {
//Calculate and store the output
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 = change.clamp(-self.config.accel, self.config.accel);
@@ -117,7 +117,7 @@ impl PID {
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 {
//Update all internal fields
self.integral = 0.0;
+1
View File
@@ -4,6 +4,7 @@ pub mod communication;
#[cfg(feature = "core_logic")]
pub mod logic;
pub mod error;
pub mod motor;
pub mod positional;
pub mod units;
+19 -15
View File
@@ -111,62 +111,66 @@ impl Display for Speed {
}
}
///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.
/// # 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
fn spin(&mut self, dir: Direction);
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
fn stop(&mut self);
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
fn set_speed(&mut self, speed: u16);
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.
fn set_speed_and_direction(&mut self, speed: u16, dir: Direction) {
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);
self.set_speed(speed);
self.spin(dir).await;
self.set_speed(speed).await;
}
}
///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
/// # 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.
/// 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;
async 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>;
async 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>;
async 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>;
async fn get_angle(&self) -> Option<Angle>;
}