diff --git a/src/modules/motion.h b/src/modules/motion.h index 2cc67d8..98cc23b 100644 --- a/src/modules/motion.h +++ b/src/modules/motion.h @@ -151,6 +151,20 @@ public: axisData[axis].ctrl.SetAcceleration(accel); } + /// Get current jerk for the selected axis + /// @param axis axis affected + /// @returns jerk + steps_t Jerk(Axis axis) const { + return axisData[axis].ctrl.Jerk(); + } + + /// Set maximum jerk for the selected axis + /// @param axis axis affected + /// @param max_jerk maximum jerk + void SetJerk(Axis axis, steps_t max_jerk) { + return axisData[axis].ctrl.SetJerk(max_jerk); + } + /// State machine doing all the planning and stepping. Called by the stepping ISR. /// @returns the interval for the next tick st_timer_t Step(); diff --git a/src/modules/pulse_gen.h b/src/modules/pulse_gen.h index ecf9fbc..9c10a38 100644 --- a/src/modules/pulse_gen.h +++ b/src/modules/pulse_gen.h @@ -24,6 +24,12 @@ class PulseGen { public: PulseGen(steps_t max_jerk, steps_t acceleration); + /// @returns the jerk for the axis + steps_t Jerk() const { return max_jerk; }; + + /// Set maximum jerk for the axis + void SetJerk(steps_t max_jerk) { this->max_jerk = max_jerk; }; + /// @returns the acceleration for the axis steps_t Acceleration() const { return acceleration; }; diff --git a/tests/unit/modules/motion/test_motion.cpp b/tests/unit/modules/motion/test_motion.cpp index d241b83..f7d8d14 100644 --- a/tests/unit/modules/motion/test_motion.cpp +++ b/tests/unit/modules/motion/test_motion.cpp @@ -32,13 +32,13 @@ TEST_CASE("motion::basic", "[motion]") { } TEST_CASE("motion::dual_move_fwd", "[motion]") { - // check for configuration values that we cannot change but should match for this test - // to function as expected (maybe this should be a static_assert?) - REQUIRE(config::idler.jerk == config::selector.jerk); - // enqueue moves on two axes REQUIRE(motion.QueueEmpty()); + // ensure the same jerk is set on both + motion.SetJerk(Idler, motion.Jerk(Selector)); + REQUIRE(motion.Jerk(Idler) == motion.Jerk(Selector)); + // ensure the same acceleration is set on both motion.SetAcceleration(Idler, motion.Acceleration(Selector)); REQUIRE(motion.Acceleration(Idler) == motion.Acceleration(Selector)); @@ -57,13 +57,13 @@ TEST_CASE("motion::dual_move_fwd", "[motion]") { } TEST_CASE("motion::dual_move_inv", "[motion]") { - // check for configuration values that we cannot change but should match for this test - // to function as expected (maybe this should be a static_assert?) - REQUIRE(config::idler.jerk == config::selector.jerk); - // enqueue moves on two axes REQUIRE(motion.QueueEmpty()); + // ensure the same jerk is set on both + motion.SetJerk(Idler, motion.Jerk(Selector)); + REQUIRE(motion.Jerk(Idler) == motion.Jerk(Selector)); + // ensure the same acceleration is set on both motion.SetAcceleration(Idler, motion.Acceleration(Selector)); REQUIRE(motion.Acceleration(Idler) == motion.Acceleration(Selector));