Motion: test low-level enable changes via GPIO stub
This fixes the driver's enable/disable incorrectly setting the direction bit instead.pull/96/head
parent
8e24d1e084
commit
0548c17078
|
|
@ -74,7 +74,7 @@ void TMC2130::SetCurrents(const MotorParams ¶ms, const MotorCurrents ¤
|
||||||
}
|
}
|
||||||
|
|
||||||
void TMC2130::SetEnabled(const MotorParams ¶ms, bool enabled) {
|
void TMC2130::SetEnabled(const MotorParams ¶ms, bool enabled) {
|
||||||
hal::shr16::shr16.SetTMCDir(params.idx, enabled);
|
hal::shr16::shr16.SetTMCEnabled(params.idx, enabled);
|
||||||
if (this->enabled != enabled)
|
if (this->enabled != enabled)
|
||||||
ClearStallguard(params);
|
ClearStallguard(params);
|
||||||
this->enabled = enabled;
|
this->enabled = enabled;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,17 @@
|
||||||
|
|
||||||
using namespace modules::motion;
|
using namespace modules::motion;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace shr16 {
|
||||||
|
extern uint8_t shr16_tmc_ena;
|
||||||
|
} // namespace shr16
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
// Conveniently read the enable state set into the lower-level shift register
|
||||||
|
bool getTMCEnabled(const MotorParams &mp) {
|
||||||
|
return (hal::shr16::shr16_tmc_ena & (1 << mp.idx));
|
||||||
|
}
|
||||||
|
|
||||||
// Perform Step() until all moves are completed, returning the number of steps performed.
|
// Perform Step() until all moves are completed, returning the number of steps performed.
|
||||||
// Ensure the move doesn't run forever, making the test fail reliably.
|
// Ensure the move doesn't run forever, making the test fail reliably.
|
||||||
ssize_t stepUntilDone(size_t maxSteps = 100000) {
|
ssize_t stepUntilDone(size_t maxSteps = 100000) {
|
||||||
|
|
@ -34,19 +45,23 @@ TEST_CASE("motion::basic", "[motion]") {
|
||||||
TEST_CASE("motion::auto_axis_enable", "[motion]") {
|
TEST_CASE("motion::auto_axis_enable", "[motion]") {
|
||||||
// by default the axis should start disabled
|
// by default the axis should start disabled
|
||||||
REQUIRE(motion.Enabled(Pulley) == false);
|
REQUIRE(motion.Enabled(Pulley) == false);
|
||||||
|
REQUIRE(getTMCEnabled(axisParams[Pulley].params) == false);
|
||||||
|
|
||||||
// enable manually the axis
|
// enable manually the axis
|
||||||
motion.SetEnabled(Pulley, true);
|
motion.SetEnabled(Pulley, true);
|
||||||
REQUIRE(motion.Enabled(Pulley) == true);
|
REQUIRE(motion.Enabled(Pulley) == true);
|
||||||
|
REQUIRE(getTMCEnabled(axisParams[Pulley].params) == true);
|
||||||
|
|
||||||
// now disable
|
// now disable
|
||||||
motion.SetEnabled(Pulley, false);
|
motion.SetEnabled(Pulley, false);
|
||||||
REQUIRE(motion.Enabled(Pulley) == false);
|
REQUIRE(motion.Enabled(Pulley) == false);
|
||||||
|
REQUIRE(getTMCEnabled(axisParams[Pulley].params) == false);
|
||||||
|
|
||||||
// planning a move should enable the axis automatically
|
// planning a move should enable the axis automatically
|
||||||
REQUIRE(motion.QueueEmpty());
|
REQUIRE(motion.QueueEmpty());
|
||||||
motion.PlanMove<Pulley>(1.0_mm, 100.0_mm_s);
|
motion.PlanMove<Pulley>(1.0_mm, 100.0_mm_s);
|
||||||
REQUIRE(motion.Enabled(Pulley) == true);
|
REQUIRE(motion.Enabled(Pulley) == true);
|
||||||
|
REQUIRE(getTMCEnabled(axisParams[Pulley].params) == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("motion::unit", "[motion]") {
|
TEST_CASE("motion::unit", "[motion]") {
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,12 @@ SHR16 shr16;
|
||||||
|
|
||||||
uint16_t shr16_v_copy;
|
uint16_t shr16_v_copy;
|
||||||
uint8_t shr16_tmc_dir;
|
uint8_t shr16_tmc_dir;
|
||||||
|
uint8_t shr16_tmc_ena;
|
||||||
|
|
||||||
void SHR16::Init() {
|
void SHR16::Init() {
|
||||||
shr16_v_copy = 0;
|
shr16_v_copy = 0;
|
||||||
shr16_tmc_dir = 0;
|
shr16_tmc_dir = 0;
|
||||||
|
shr16_tmc_ena = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHR16::SetLED(uint16_t led) {
|
void SHR16::SetLED(uint16_t led) {
|
||||||
|
|
@ -18,7 +20,11 @@ void SHR16::SetLED(uint16_t led) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHR16::SetTMCEnabled(uint8_t index, bool ena) {
|
void SHR16::SetTMCEnabled(uint8_t index, bool ena) {
|
||||||
// do nothing right now
|
// this is using another array for testing convenience
|
||||||
|
if (ena)
|
||||||
|
shr16_tmc_ena |= (1 << index);
|
||||||
|
else
|
||||||
|
shr16_tmc_ena &= ~(1 << index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHR16::SetTMCDir(uint8_t index, bool dir) {
|
void SHR16::SetTMCDir(uint8_t index, bool dir) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue