From a642e4ca31d00d58ba349bede497dcfb52a4858c Mon Sep 17 00:00:00 2001 From: Jake Read <jake.read@cba.mit.edu> Date: Tue, 11 Jan 2022 15:37:52 -0500 Subject: [PATCH] checks for exceptional rates --- firmware/motion-head/src/smoothie/SmoothieRoll.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/firmware/motion-head/src/smoothie/SmoothieRoll.cpp b/firmware/motion-head/src/smoothie/SmoothieRoll.cpp index 127de94..ad22631 100644 --- a/firmware/motion-head/src/smoothie/SmoothieRoll.cpp +++ b/firmware/motion-head/src/smoothie/SmoothieRoll.cpp @@ -49,8 +49,13 @@ void SmoothieRoll::checkMaxRates(void){ // we also have per-axis steps per unit, and max rates, // if rate * spu exceeds the tick frequency, we are in trouble: for(uint8_t m = 0; m < SR_NUM_MOTORS; m ++){ - if(actuators[m]->get_max_rate() * actuators[m]->get_steps_per_mm() > SR_TICK_FREQ){ - sysError("motor " + String(m) + " exceeds max rate"); + float maxTick = actuators[m]->get_max_rate() * actuators[m]->get_steps_per_mm(); + if(maxTick > SR_TICK_FREQ){ + sysError("motor " + String(m) + " exceeds max tick, " + String(maxTick)); + // new rate should be old rate * rate / + float newMax = actuators[m]->get_max_rate() * (SR_TICK_FREQ / maxTick); + sysError("old max velocity: " + String(actuators[m]->get_max_rate()) + " new: " + String(newMax)); + actuators[m]->set_max_rate(newMax); } } } \ No newline at end of file -- GitLab