Skip to content

Commit

Permalink
improv how sampleTime and motionCtrl work together
Browse files Browse the repository at this point in the history
  • Loading branch information
Strooom committed Aug 18, 2022
1 parent ac41b12 commit 4b10c3a
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 58 deletions.
6 changes: 4 additions & 2 deletions lib/motion/motionctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ step motionCtrl::calcNextStepperMotorSignals() {
while (true) {
if (theSampleTime.isBeyondEndOfMotion()) {
if (theMotionBuffer.getLevel() > 1) {
theSampleTime.initializeNextMotion();
theSampleTime.cleanupCurrentMotion();
theMotionBuffer.pop();
theSampleTime.initializeNextMotion(theMotionBuffer.getHead().speedProfile.duration, theMotionBuffer.getHead().speedProfile.tStop);
theEventBuffer.pushEvent(event::motionCompleted);
} else {
theMotionBuffer.pop();
Expand All @@ -263,4 +264,5 @@ step motionCtrl::calcNextStepperMotorSignals() {
return theStepSignals.output();
}
}
}
}

2 changes: 1 addition & 1 deletion lib/motion/motionctrl.drawio
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<mxfile host="Electron" modified="2022-08-18T12:37:11.428Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/20.2.3 Chrome/102.0.5005.167 Electron/19.0.11 Safari/537.36" version="20.2.3" etag="XwrTjXHAB2IYhabNhYSM" type="device" pages="3"><diagram id="pe0snOJMbtaNUKmXhN9i" name="class hierarchy">7VhNj5swEP01ObbCEAg5tiTZVm2lqjl0e1pZMAteAabGJKS/viYM35tsutvCRuopzPPM2PPm2ZjMDCfKbwRNgi/cg3Cma14+M1YzXTdM01Q/BXIoEZ1YRon4gnklRhpgy34BghqiGfMg7ThKzkPJki7o8jgGV3YwKgTfd93uedidNaE+DICtS8Mh+p15MkCUWMtm4AMwP8CpbX1RDkS0csZK0oB6fN+CjPXMcATnsnyKcgfCgr2KlzJuc2K0XpiAWF4SIO/eOezbkjjbT46+dsnPZHP3hmCaVB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dOp6QHK9kLvaDz/KzpZZijqSw+lKxeGsdg6n9+VwaWD9P30laalF+lqe6dHn4QXGxWtChL4tXmoD8xwGMP0lXmBHlC+DBBOnBqY+HDX46/iPDsAv9t+PX8LPHz4r843vzUcx/F4N+NxA0i4FW9Xc0UANusrGS8ngfbJH3WZjvR8bX7Skv/1l48WbM3K1AYKOrdwwh7VyVd7vBejA7kgcyr8L6mm0DOj9Gfsom70m6pndG6VyorXlMud603mIWeMiNiHy2RqxJq88M/4ZC+VCyf+MRZmsLQeOhpoUDT0Yimgox8JRiW01Do5ObI03l/N7svlvZbavLXqZSv08bYtelf49Fb1kAhJXvS49b5LsI+NnqdeNTbXBOIWUA2YF8sFbm8KdPJHFjUHyGGhdRRnEpU3QzqXlgRaVwmrVcBJN9JYBwSg7t0nWUUFratRwENg5ma1Nu2/wqOncQue4aVetpAignE671f7DpF2Z6eLwjygIcODIaXdSFVx17MNdINfCob2HwRb9if2OK4Rd6bBCBUHNeV2m12F4y6SqJuMmGqNtohn1BAjIHw0Js18ztFtjhwMRfhfWP6Tx1+bskb9mnJLtW7Lt16psqIJh7eT6uHi9rl6Y7c0KO7N8nzbG3qwG4xMRpnPip2oNJwYdE78Kv1xWv3M+3V1VhqB9lhTDty4MOMhAITTGiDOY3yI2cQpotfzcqLdap1y0IhHbRWya6a9KoBWlnfp6y3//mSLDyyHP6iXkvbjXbSgjyQMtKwMZXZ3I8Gb+m5Kke/7LHO3mXw==</diagram></mxfile>
<mxfile host="Electron" modified="2022-08-18T12:47:09.687Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/20.2.3 Chrome/102.0.5005.167 Electron/19.0.11 Safari/537.36" version="20.2.3" etag="AXQ3FgHLCC5Ru7KSU7_z" type="device" pages="3"><diagram id="pe0snOJMbtaNUKmXhN9i" name="class hierarchy">7VhNj5swEP01ObbCEAg5tiTZVm2lqjl0e1pZMAteAabGJKS/viYM35tsutvCRuopzPPM2PPm2Z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5+oQt5eAg5xlUwslm/HR9Dwicg43pY7lSbkk9N2MP0Fy1BByLIiqQyT7PFdC1DlSyDT2NCn+O5crg2VmzNOLhVW6Eu8e8jvrrVk4sZWu/gs4qfeLItI96EXI2LStg16hroSknPminaT4VUKERuIQumss7jnzmGM/XqFOemk4ohp8BZZeD0KiKJE4qnclAuKYXHQjcR+Bvn0fX6eW5fua7cJpIVdOp6QHK9kLvaDz/KzpZZijqSw+lKxeGsdg6n9+VwaWD9P30laalF+lqe6dHn4QXGxWtChL4tXmoD8xwGMP0lXmBHlC+DBBOnBqY+HDX46/iPDsAv9t+PX8LPHz4r843vzUcx/F4N+NxA0i4FW9Xc0UANusrGS8ngfbJH3WZjvR8bX7Skv/1l48WbM3K1AYKOrdwwh7VyVd7vBejA7kgcyr8L6mm0DOj9Gfsom70m6pndG6VyorXlMud603mIWeMiNiHy2RqxJq88M/4ZC+VCyf+MRZmsLQeOhpoUDT0Yimgox8JRiW01Do5ObI03l/N7svlvZbavLXqZSv08bYtelf49Fb1kAhJXvS49b5LsI+NnqdeNTbXBOIWUA2YF8sFbm8KdPJHFjUHyGGhdRRnEpU3QzqXlgRaVwmrVcBJN9JYBwSg7t0nWUUFratRwENg5ma1Nu2/wqOncQue4aVetpAignE671f7DpF2Z6eLwjygIcODIaXdSFVx17MNdINfCob2HwRb9if2OK4Rd6bBCBUHNeV2m12F4y6SqJuMmGqNtohn1BAjIHw0Js18ztFtjhwMRfhfWP6Tx1+bskb9mnJLtW7Lt16psqIJh7eT6uHi9rl6Y7c0KO7N8nzbG3qwG4xMRpnPip2oNJwYdE78Kv1xWv3M+3V1VhqB9lhTDty4MOMhAITTGiDOY3yI2cQpotfzcqLdap1y0IhHbRWya6a9KoBWlnfp6y3//mSLDyyHP6iXkvbjXbSgjyQMtKwMZXZ3I8Gb+m5Kke/7LHO3mXw==</diagram></mxfile>
16 changes: 7 additions & 9 deletions lib/motion/motionctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,17 @@ class motionCtrl {
#endif
motionState theMotionCtrlState = motionState::stopped; //
overrides theOverrides;
sampleTime theSampleTime = sampleTime(1); // TODO : set a correct sample interval
motionBuffer theMotionBuffer; //
stepSignals theStepSignals; //
sampleTime theSampleTime;
motionBuffer theMotionBuffer; //
stepSignals theStepSignals; //

point currentPosition;
point nextPosition;

float vJunction(uint32_t left, uint32_t right) const; //
// void positionInSteps(); //
// void positionInMm(uint32_t anAxis, float sNow, motionTrajectory& currentMotionTrajectory); //
bool needStepForward(uint32_t anAxis); //
bool needStepBackward(uint32_t anAxis); //
void optimizePair(int32_t junctionIndex); //
void move(); // from currentPosition to newPosition
bool needStepForward(uint32_t anAxis); //
bool needStepBackward(uint32_t anAxis); //
void optimizePair(int32_t junctionIndex); //
void move(); // from currentPosition to newPosition
bool isOptimal{false};
};
22 changes: 18 additions & 4 deletions lib/motion/sampletime.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include <limits>
#include "sampletime.h"

sampleTime::sampleTime(const float theMinStepPulseWidth) : minStepPulseWidth(theMinStepPulseWidth) {
sampleTime::sampleTime() {
}

// sampleTime::sampleTime(const float theMinStepPulseWidth) : minStepPulseWidth(theMinStepPulseWidth) {
// }

void sampleTime::next() {
sampleIndex++;
timeInMotion = (static_cast<float>(sampleIndex) * minStepPulseWidth) + sampleZeroOffset;
Expand All @@ -12,6 +16,7 @@ void sampleTime::initialize() {
sampleIndex = 0;
sampleZeroOffset = 0.0F;
timeInMotion = 0.0F;
motionTStop = std::numeric_limits<float>::infinity();
}

bool sampleTime::isBeyondEndOfMotion() const {
Expand All @@ -22,10 +27,15 @@ bool sampleTime::isBeyondStop() const {
return (timeInMotion > motionTStop);
}

void sampleTime::initializeNextMotion() {
sampleIndex = 0;
void sampleTime::cleanupCurrentMotion() {
sampleZeroOffset = timeInMotion - motionDuration;
timeInMotion = sampleZeroOffset;
}

void sampleTime::initializeNextMotion(float someMotionDuration, float someStopTime) {
sampleIndex = 0;
motionDuration = someMotionDuration;
motionTStop = someStopTime;
timeInMotion = sampleZeroOffset;
}

void sampleTime::setMotionTStop(float someStopTime) {
Expand All @@ -34,3 +44,7 @@ void sampleTime::setMotionTStop(float someStopTime) {
void sampleTime::setMotionDuration(float someMotionDuration) {
motionDuration = someMotionDuration;
}

void sampleTime::setminStepPulseWidth(const float theMinStepPulseWidth) {
minStepPulseWidth = theMinStepPulseWidth;
}
21 changes: 12 additions & 9 deletions lib/motion/sampletime.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@

class sampleTime {
public:
sampleTime(const float theMinStepPulseWidth); // constructor
void next(); // calculate the position of the next sampling point
void initialize(); //
bool isBeyondEndOfMotion() const; //
bool isBeyondStop() const; //
void initializeNextMotion(); //
void setMotionTStop(float someStopTime);
void setMotionDuration(float someMotionDuration);
sampleTime(); // constructor
// sampleTime(const float theMinStepPulseWidth); // constructor
void next(); // calculate the position of the next sampling point
void initialize(); //
bool isBeyondEndOfMotion() const; //
bool isBeyondStop() const; //
void cleanupCurrentMotion(); //
void initializeNextMotion(float someMotionDuration, float someStopTime); //
void setMotionTStop(float someStopTime); //
void setMotionDuration(float someMotionDuration); //
void setminStepPulseWidth(const float theMinStepPulseWidth); //

#ifndef unitTesting
private:
Expand All @@ -28,5 +31,5 @@ class sampleTime {
uint32_t sampleIndex{0}; // zero-based index of sampling points inside the current motion
float motionTStop{0.0F}; // time after which the motion comes to a stop [s]
float motionDuration{0.0F}; // duration [s] of the complete motion
const float minStepPulseWidth; // duration [s] of a single discrete timeTick, equals the time [s] between the sampling points
float minStepPulseWidth{1.0F}; // duration [s] of a single discrete timeTick, equals the time [s] between the sampling points
};
78 changes: 45 additions & 33 deletions test/native/test_motion_control/motioncontrol_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "machineproperties.h" // motionControl relies on an external dependency : there must be a global instance of machineProperties where it can read settings/properties
#include "eventbuffer.h" // motionControl relies on an external dependency : there must be a global instance of eventBuffer where it can notify/push events that occured
#include <math.h>
#include <limits>

// ----------------------------------
// --- to be tested API ---
Expand Down Expand Up @@ -42,6 +43,7 @@ void setUp(void) {
theMachineProperties.motors.dMax[2] = -1.0f;
theMachineProperties.motors.vMax[2] = 1.0f;
}

void tearDown(void) {} // after test

void initialize() {
Expand All @@ -57,6 +59,31 @@ void initialize() {
}
}

void nextStep_notRunning() {
step aStep;
motionCtrl theMotionCtrl;
theMotionCtrl.theStepSignals.setMaxTicksSinceLastOutput(maxTicksSinceLastOutput);

aStep = theMotionCtrl.calcNextStepperMotorSignals();
TEST_ASSERT_EQUAL(0U, aStep.signals); // we should get default stepSignals..
TEST_ASSERT_EQUAL(maxTicksSinceLastOutput, aStep.timeBefore); //
TEST_ASSERT_EQUAL(0U, theMotionCtrl.theSampleTime.sampleIndex); // and the sampleTime should not proceed
}

void nextStep_emptyMotionBuffer() {
step aStep;
motionCtrl theMotionCtrl;
theMotionCtrl.theStepSignals.setMaxTicksSinceLastOutput(maxTicksSinceLastOutput);

theMotionCtrl.theMotionCtrlState = motionState::running;

aStep = theMotionCtrl.calcNextStepperMotorSignals();
TEST_ASSERT_EQUAL(0U, aStep.signals); // we should get default stepSignals..
TEST_ASSERT_EQUAL(maxTicksSinceLastOutput, aStep.timeBefore); //
TEST_ASSERT_EQUAL(0U, theMotionCtrl.theSampleTime.sampleIndex); // and the sampleTime should be reset to zeroes
TEST_ASSERT_EQUAL(motionState::stopped, theMotionCtrl.getState());
}

void test_calcNextPositionInMm() {
motionCtrl theMotionCtrl;
simplifiedMotion aSimpleMotion;
Expand Down Expand Up @@ -98,46 +125,31 @@ void test_vJunction() {
TEST_FAIL_MESSAGE("missing test");
}

void test_calcNextPositionInSteps() {
TEST_FAIL_MESSAGE("missing test");
}

void nextStep_notRunning() {
step aStep;
motionCtrl theMotionCtrl;
theMotionCtrl.theStepSignals.setMaxTicksSinceLastOutput(maxTicksSinceLastOutput);

aStep = theMotionCtrl.calcNextStepperMotorSignals();
TEST_ASSERT_EQUAL(0U, aStep.signals); // we should get default stepSignals..
TEST_ASSERT_EQUAL(maxTicksSinceLastOutput, aStep.timeBefore); //
TEST_ASSERT_EQUAL(0U, theMotionCtrl.theSampleTime.sampleIndex); // and the sampleTime should not proceed
}
int main(int argc, char **argv) {
UNITY_BEGIN();
RUN_TEST(initialize);

void nextStep_emptyMotionBuffer() {
step aStep;
motionCtrl theMotionCtrl;
theMotionCtrl.theStepSignals.setMaxTicksSinceLastOutput(maxTicksSinceLastOutput);

theMotionCtrl.theMotionCtrlState = motionState::running;
// --- Testing generation of stepSignals ---

aStep = theMotionCtrl.calcNextStepperMotorSignals();
TEST_ASSERT_EQUAL(0U, aStep.signals); // we should get default stepSignals..
TEST_ASSERT_EQUAL(maxTicksSinceLastOutput, aStep.timeBefore); //
TEST_ASSERT_EQUAL(0U, theMotionCtrl.theSampleTime.sampleIndex); // and the sampleTime should be reset to zeroes
TEST_ASSERT_EQUAL(motionState::stopped, theMotionCtrl.getState());
RUN_TEST(nextStep_notRunning); // 1. output defaults when empty buffer
RUN_TEST(nextStep_emptyMotionBuffer); //

}
// 2. output defaults when non-empty buffer but stopped
// 3. output steps when running and motionItems in the buffer
// 4. proceed to next motionItem after completing the current one
// 5. go to Stopped after completing last motionItem
// 6. go to Stopped after passing tStop
// 7. time should proceed only when not stopped = running or stopping
// 8. stepsignals should always proceed

int main(int argc, char **argv) {
UNITY_BEGIN();
// RUN_TEST(initialize);
RUN_TEST(nextStep_notRunning);
RUN_TEST(nextStep_emptyMotionBuffer);
// RUN_TEST(test_calcNextPositionInMm);

// RUN_TEST(test_optimize);
// RUN_TEST(test_optimizePair);
// RUN_TEST(test_vJunction);
// RUN_TEST(test_calcNextPositionInSteps);
// --- Testing motionBuffer optimization ---

RUN_TEST(test_optimize);
RUN_TEST(test_optimizePair);
RUN_TEST(test_vJunction);
UNITY_END();
}

0 comments on commit 4b10c3a

Please sign in to comment.