diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3a1b750 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +## [0.1.7] - XXXXXX +### Added +- no_std support + +## [0.1.6] - 2021-05-01 +### Changed +- Improved algorithm to calculate the maximum possible acceleration +## [0.1.0] - 2020-10-9 +Initial Release \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 2e8ccf5..23d7bd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,16 @@ path = "src/lib.rs" name = "plot" path = "examples/plot.rs" -[dependencies] +[dependencies.num-traits] +# todo https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies +version = "0.2" +default-features = false +features = ["libm"] + [dev-dependencies] -gnuplot = "0.0.37" \ No newline at end of file +gnuplot = "0.0.37" + + +[features] +default = ["std"] +std = [] \ No newline at end of file diff --git a/README.md b/README.md index b4cdab3..e700ea4 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,8 @@ 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 @@ -39,11 +40,17 @@ An S-Curve consists of 7 phases: 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.)); } ``` +## no-std support + +To use scurve in an environment without the standard library you can set ```default_features = false``` for the crate. +Then you have to use the eval_{position,velocity,acceleration,jerk} directly. + + #### License Copyright (c) 2020 Marco Boneberger Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or [MIT license](LICENSE-MIT) at your option. diff --git a/src/lib.rs b/src/lib.rs index 3debe04..068b1ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,8 @@ * 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 @@ -23,7 +24,7 @@ * 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.)); * } @@ -31,6 +32,9 @@ * */ +#[cfg(not(feature = "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 @@ -333,7 +337,8 @@ impl SCurveInput { } } -fn eval_position(p: &SCurveParameters, t: f64) -> f64 { +/// calculates the current position of the trajectory given the SCurve parameters and a time t in seconds. +pub fn eval_position(p: &SCurveParameters, t: f64) -> f64 { let times = &p.time_intervals; if t < 0. { return p.conditions.q0; @@ -369,8 +374,8 @@ fn eval_position(p: &SCurveParameters, t: f64) -> f64 { p.conditions.q1 } } - -fn eval_velocity(p: &SCurveParameters, t: f64) -> f64 { +/// calculates the current velocity of the trajectory given the SCurve parameters and a time t in seconds. +pub fn eval_velocity(p: &SCurveParameters, t: f64) -> f64 { let times = &p.time_intervals; if t < 0. { return p.conditions.v0; @@ -394,7 +399,8 @@ fn eval_velocity(p: &SCurveParameters, t: f64) -> f64 { } } -fn eval_acceleration(p: &SCurveParameters, t: f64) -> f64 { +/// calculates the current acceleration of the trajectory given the SCurve parameters and a time t in seconds. +pub fn eval_acceleration(p: &SCurveParameters, t: f64) -> f64 { let times = &p.time_intervals; if t < 0. { 0. @@ -416,8 +422,8 @@ fn eval_acceleration(p: &SCurveParameters, t: f64) -> f64 { 0. } } - -fn eval_jerk(p: &SCurveParameters, t: f64) -> f64 { +/// calculates the current jerk of the trajectory given the SCurve parameters and a time t in seconds. +pub fn eval_jerk(p: &SCurveParameters, t: f64) -> f64 { let times = &p.time_intervals; if t < times.t_j1 { p.j_max @@ -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(feature = "std")] pub fn s_curve_generator( input_parameters: &SCurveInput, derivative: Derivative, @@ -466,9 +473,9 @@ pub fn s_curve_generator( #[cfg(test)] mod tests { - use crate::{ - s_curve_generator, Derivative, SCurveConstraints, SCurveInput, SCurveStartConditions, - }; + #[cfg(feature = "std")] + use crate::{s_curve_generator, Derivative}; + use crate::{SCurveConstraints, SCurveInput, SCurveStartConditions}; #[test] fn timings_3_9() { @@ -575,6 +582,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn simple_curve() { let constraints = SCurveConstraints { max_jerk: 30.,