Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial no_std support #4

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ path = "src/lib.rs"
name = "plot"
path = "examples/plot.rs"

[dependencies]
[dependencies.num-traits]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need this dependency? What is it doing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its for mathematical operations on floats. no_std dont have it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK num_trait is for division/multiplication, and libm is for sqrt

# todo https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies
version = "*"
default-features = false
features = ["libm"]

[dev-dependencies]
gnuplot = "0.0.37"
gnuplot = "0.0.37"


[features]
default = []
no_std = []
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ An S-Curve consists of 7 phases:
let constraints = SCurveConstraints {
max_jerk: 3.,
max_acceleration: 2.0,
max_velocity: 3.};
max_velocity: 3.
};
let start_conditions = SCurveStartConditions {
q0: 0., // start position
q1: 10., // end position
v0: 0., // start velocity
v1: 0. // end velocity
};
let input = SCurveInput{constraints, start_conditions};
let (params,s_curve) = s_curve_generator( & input,Derivative::Velocity);
let (params, s_curve) = s_curve_generator( &input,Derivative::Velocity);
for i in 0..101 {
println!("{}", s_curve(i as f64 * params.time_intervals.total_duration() / 100.));
}
Expand Down
26 changes: 17 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,28 @@
* let constraints = SCurveConstraints {
* max_jerk: 3.,
* max_acceleration: 2.0,
* max_velocity: 3.};
* max_velocity: 3.
* };
* let start_conditions = SCurveStartConditions {
* q0: 0., // start position
* q1: 10., // end position
* v0: 0., // start velocity
* v1: 0. // end velocity
* };
* let input = SCurveInput{constraints, start_conditions};
* let (params,s_curve) = s_curve_generator(&input,Derivative::Velocity);
* let (params, s_curve) = s_curve_generator(&input,Derivative::Velocity);
* for i in 0..101 {
* println!("{}", s_curve(i as f64 * params.time_intervals.total_duration() / 100.));
* }
* ```
*
*/

#![cfg_attr(feature = "no_std", no_std)]

#[cfg(feature = "no_std")]
use num_traits::float::Float;

/**
* Struct which contains the desired limits for jerk, acceleration and velocity in SI units.
* These are only the limits. It can happen that the acceleration or Velocity will be actually lower
Expand Down Expand Up @@ -333,7 +339,7 @@ impl SCurveInput {
}
}

fn eval_position(p: &SCurveParameters, t: f64) -> f64 {
pub fn eval_position(p: &SCurveParameters, t: f64) -> f64 {
let times = &p.time_intervals;
if t < 0. {
return p.conditions.q0;
Expand Down Expand Up @@ -370,7 +376,7 @@ fn eval_position(p: &SCurveParameters, t: f64) -> f64 {
}
}

fn eval_velocity(p: &SCurveParameters, t: f64) -> f64 {
pub fn eval_velocity(p: &SCurveParameters, t: f64) -> f64 {
let times = &p.time_intervals;
if t < 0. {
return p.conditions.v0;
Expand All @@ -394,7 +400,7 @@ fn eval_velocity(p: &SCurveParameters, t: f64) -> f64 {
}
}

fn eval_acceleration(p: &SCurveParameters, t: f64) -> f64 {
pub fn eval_acceleration(p: &SCurveParameters, t: f64) -> f64 {
let times = &p.time_intervals;
if t < 0. {
0.
Expand All @@ -417,7 +423,7 @@ fn eval_acceleration(p: &SCurveParameters, t: f64) -> f64 {
}
}

fn eval_jerk(p: &SCurveParameters, t: f64) -> f64 {
pub fn eval_jerk(p: &SCurveParameters, t: f64) -> f64 {
let times = &p.time_intervals;
if t < times.t_j1 {
p.j_max
Expand All @@ -439,6 +445,7 @@ fn eval_jerk(p: &SCurveParameters, t: f64) -> f64 {
/// returns the S-Curve parameters and a function which maps time [0,t] to Position, Velocity,
/// Acceleration or Jerk, depending on what you set as Derivative. Note that the acceleration
/// and velocity could be decreased if it is not possible to achieve them.
#[cfg(not(feature = "no_std"))]
pub fn s_curve_generator(
input_parameters: &SCurveInput,
derivative: Derivative,
Expand Down Expand Up @@ -466,9 +473,9 @@ pub fn s_curve_generator(

#[cfg(test)]
mod tests {
use crate::{
s_curve_generator, Derivative, SCurveConstraints, SCurveInput, SCurveStartConditions,
};
#[cfg(not(feature = "no_std"))]
use crate::{s_curve_generator, Derivative};
use crate::{SCurveConstraints, SCurveInput, SCurveStartConditions};

#[test]
fn timings_3_9() {
Expand Down Expand Up @@ -575,6 +582,7 @@ mod tests {
}

#[test]
#[cfg(not(feature = "no_std"))]
fn simple_curve() {
let constraints = SCurveConstraints {
max_jerk: 30.,
Expand Down