From 9a93ebecfc79770b15afb64c0e47bf0fd996009e Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 24 Aug 2021 17:01:45 +0200 Subject: [PATCH] Motion: add tests for the axis autoenable Add Motion::Enabled() to get the current axis enablement status. --- src/modules/motion.h | 3 +++ tests/unit/modules/motion/test_motion.cpp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/modules/motion.h b/src/modules/motion.h index e79636a..c7ec569 100644 --- a/src/modules/motion.h +++ b/src/modules/motion.h @@ -77,6 +77,9 @@ public: /// @returns true if the init was successful (TMC2130 responded ok) bool InitAxis(Axis axis); + /// Return the axis power status. + bool Enabled(Axis axis) const { return axisData[axis].enabled; } + /// Set axis power status. One must manually ensure no moves are currently being /// performed by calling QueueEmpty(). void SetEnabled(Axis axis, bool enabled); diff --git a/tests/unit/modules/motion/test_motion.cpp b/tests/unit/modules/motion/test_motion.cpp index ece685f..788644c 100644 --- a/tests/unit/modules/motion/test_motion.cpp +++ b/tests/unit/modules/motion/test_motion.cpp @@ -31,6 +31,24 @@ TEST_CASE("motion::basic", "[motion]") { REQUIRE(motion.Position(Idler) == 10); } +TEST_CASE("motion::auto_axis_enable", "[motion]") { + // by default the axis should start disabled + REQUIRE(motion.Enabled(Pulley) == false); + + // enable manually the axis + motion.SetEnabled(Pulley, true); + REQUIRE(motion.Enabled(Pulley) == true); + + // now disable + motion.SetEnabled(Pulley, false); + REQUIRE(motion.Enabled(Pulley) == false); + + // planning a move should enable the axis automatically + REQUIRE(motion.QueueEmpty()); + motion.PlanMove(1.0_mm, 100.0_mm_s); + REQUIRE(motion.Enabled(Pulley) == true); +} + TEST_CASE("motion::unit", "[motion]") { // test AxisUnit conversion in the PlanMove and PlanMoveTo. REQUIRE(motion.QueueEmpty());