Work on projector: Still having issues with IteadDualStepperShield (addresses wrong motor, wrong number of steps).

This commit is contained in:
Matt McWilliams 2023-08-25 16:44:28 -04:00
parent 141d27599f
commit 24fe1e8773
4 changed files with 42 additions and 24 deletions

View File

@ -61,7 +61,7 @@ void IteadDualStepperShield::_both () {
delayMicroseconds(_usStepA);
}
}
void IteadDualStepperShield::step (uint8_t motor, uint16_t steps, uint8_t dir) {
void IteadDualStepperShield::step (uint8_t motor, uint64_t steps, uint8_t dir) {
uint8_t stepPin = motor == 0 ? _stepA : _stepB;
setDir(motor, dir);
for (int i = 0; i < steps; i++) {
@ -74,7 +74,7 @@ void IteadDualStepperShield::onestep (uint8_t motor, uint8_t dir) {
_single(stepPin);
}
void IteadDualStepperShield::stepBoth (uint16_t steps) {
void IteadDualStepperShield::stepBoth (uint64_t steps) {
for (int i = 0; i < steps; i++) {
_both();
}

View File

@ -31,8 +31,8 @@ class IteadDualStepperShield {
void setSpeed(uint8_t motor, uint16_t speed);
//full
void step(uint8_t motor, uint16_t steps, uint8_t dir);
void stepBoth(uint16_t steps);
void step(uint8_t motor, uint64_t steps, uint8_t dir);
void stepBoth(uint64_t steps);
void onestep(uint8_t motor, uint8_t dir);
void release();

View File

@ -16,11 +16,11 @@ void McopyProjector::begin () {
void McopyProjector::setDirection (bool dir) {
_dir = dir;
if (_dir) {
steppers.setDir(0, 1);
steppers.setDir(1, 1);
steppers.setDir(0, FORWARD);
steppers.setDir(1, FORWARD);
} else {
steppers.setDir(0, 0);
steppers.setDir(1, 0);
steppers.setDir(0, BACKWARD);
steppers.setDir(1, BACKWARD);
}
}
@ -28,34 +28,46 @@ void McopyProjector::frame (bool dir) {
if (dir != _dir) {
setDirection(dir);
}
steppers.stepBoth(_stepsPerFrame);
steppers.step(FEED, _stepsPerFrame, _dir ? FORWARD : BACKWARD);
_posTakeup += dir ? _stepsPerFrame : -_stepsPerFrame;
_posFeed += dir ? _stepsPerFrame : -_stepsPerFrame;
}
void McopyProjector::adjust(uint8_t motor, int32_t steps) {
void McopyProjector::adjust(uint8_t motor, int64_t steps) {
uint64_t s = abs(steps);
if (steps < 0) {
steppers.setDir(motor, 0);
steppers.setDir(motor, BACKWARD);
} else {
steppers.setDir(motor, 1);
steppers.setDir(motor, FORWARD);
}
steppers.step(motor, abs(steps));
steppers.step(motor, s, _dir ? FORWARD : BACKWARD);
if (motor == 0) {
_posTakeup += steps;
} else if (motor == 1) {
_posFeed += steps;
}
//restore set direction after adjustment
steppers.setDir(motor, _dir ? FORWARD : BACKWARD);
}
void McopyProjector::adjustBoth(int32_t steps) {
void McopyProjector::adjustBoth(int64_t steps) {
uint64_t s = abs(steps);
if (steps < 0) {
steppers.setDir(0, 0);
steppers.setDir(1, 0);
steppers.setDir(TAKEUP, BACKWARD);
steppers.setDir(FEED, BACKWARD);
} else {
steppers.setDir(0, 1);
steppers.setDir(1, 1);
steppers.setDir(TAKEUP, FORWARD);
steppers.setDir(FEED, FORWARD);
}
steppers.stepBoth(abs(steps));
steppers.stepBoth(s);
_posTakeup += steps;
_posFeed += steps;
//restore set direction after adjustment
steppers.setDir(TAKEUP, _dir ? FORWARD : BACKWARD);
steppers.setDir(FEED, _dir ? FORWARD : BACKWARD);
}
void McopyProjector::frames(bool dir, uint64_t count) {
}

View File

@ -12,12 +12,18 @@ class McopyProjector {
uint8_t _motorSteps = 200;
uint8_t _frames = 8;
uint8_t _stepsPerFrame = round(_motorSteps / _frames);
uint16_t _speed = 500;
uint8_t _stepsPerFrame = 25; //round(_motorSteps / _frames);
uint16_t _speed = 300;
int64_t _posTakeup = 0;
int64_t _posFeed = 0;
const uint8_t FORWARD = 1; //CW
const uint8_t BACKWARD = 0; //CCW
const uint8_t TAKEUP = 0;
const uint8_t FEED = 0;
bool _dir = true;
public:
@ -25,11 +31,11 @@ class McopyProjector {
McopyProjector();
void begin();
//0 = takeup, 1 = feed
void adjust(uint8_t motor, int32_t steps);
void adjustBoth(int32_t steps);
void adjust(uint8_t motor, int64_t steps);
void adjustBoth(int64_t steps);
//true = forward, false = back
void frame(bool dir);
void frames(bool dir, uint32_t count);
void frames(bool dir, uint64_t count);
void setDirection(bool dir);
};