Work on projector: Still having issues with IteadDualStepperShield (addresses wrong motor, wrong number of steps).
This commit is contained in:
parent
141d27599f
commit
24fe1e8773
|
@ -61,7 +61,7 @@ void IteadDualStepperShield::_both () {
|
||||||
delayMicroseconds(_usStepA);
|
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;
|
uint8_t stepPin = motor == 0 ? _stepA : _stepB;
|
||||||
setDir(motor, dir);
|
setDir(motor, dir);
|
||||||
for (int i = 0; i < steps; i++) {
|
for (int i = 0; i < steps; i++) {
|
||||||
|
@ -74,7 +74,7 @@ void IteadDualStepperShield::onestep (uint8_t motor, uint8_t dir) {
|
||||||
_single(stepPin);
|
_single(stepPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IteadDualStepperShield::stepBoth (uint16_t steps) {
|
void IteadDualStepperShield::stepBoth (uint64_t steps) {
|
||||||
for (int i = 0; i < steps; i++) {
|
for (int i = 0; i < steps; i++) {
|
||||||
_both();
|
_both();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,8 @@ class IteadDualStepperShield {
|
||||||
void setSpeed(uint8_t motor, uint16_t speed);
|
void setSpeed(uint8_t motor, uint16_t speed);
|
||||||
|
|
||||||
//full
|
//full
|
||||||
void step(uint8_t motor, uint16_t steps, uint8_t dir);
|
void step(uint8_t motor, uint64_t steps, uint8_t dir);
|
||||||
void stepBoth(uint16_t steps);
|
void stepBoth(uint64_t steps);
|
||||||
void onestep(uint8_t motor, uint8_t dir);
|
void onestep(uint8_t motor, uint8_t dir);
|
||||||
|
|
||||||
void release();
|
void release();
|
||||||
|
|
|
@ -16,11 +16,11 @@ void McopyProjector::begin () {
|
||||||
void McopyProjector::setDirection (bool dir) {
|
void McopyProjector::setDirection (bool dir) {
|
||||||
_dir = dir;
|
_dir = dir;
|
||||||
if (_dir) {
|
if (_dir) {
|
||||||
steppers.setDir(0, 1);
|
steppers.setDir(0, FORWARD);
|
||||||
steppers.setDir(1, 1);
|
steppers.setDir(1, FORWARD);
|
||||||
} else {
|
} else {
|
||||||
steppers.setDir(0, 0);
|
steppers.setDir(0, BACKWARD);
|
||||||
steppers.setDir(1, 0);
|
steppers.setDir(1, BACKWARD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,34 +28,46 @@ void McopyProjector::frame (bool dir) {
|
||||||
if (dir != _dir) {
|
if (dir != _dir) {
|
||||||
setDirection(dir);
|
setDirection(dir);
|
||||||
}
|
}
|
||||||
steppers.stepBoth(_stepsPerFrame);
|
steppers.step(FEED, _stepsPerFrame, _dir ? FORWARD : BACKWARD);
|
||||||
_posTakeup += dir ? _stepsPerFrame : -_stepsPerFrame;
|
_posTakeup += dir ? _stepsPerFrame : -_stepsPerFrame;
|
||||||
_posFeed += 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) {
|
if (steps < 0) {
|
||||||
steppers.setDir(motor, 0);
|
steppers.setDir(motor, BACKWARD);
|
||||||
} else {
|
} else {
|
||||||
steppers.setDir(motor, 1);
|
steppers.setDir(motor, FORWARD);
|
||||||
}
|
}
|
||||||
steppers.step(motor, abs(steps));
|
steppers.step(motor, s, _dir ? FORWARD : BACKWARD);
|
||||||
if (motor == 0) {
|
if (motor == 0) {
|
||||||
_posTakeup += steps;
|
_posTakeup += steps;
|
||||||
} else if (motor == 1) {
|
} else if (motor == 1) {
|
||||||
_posFeed += steps;
|
_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) {
|
if (steps < 0) {
|
||||||
steppers.setDir(0, 0);
|
steppers.setDir(TAKEUP, BACKWARD);
|
||||||
steppers.setDir(1, 0);
|
steppers.setDir(FEED, BACKWARD);
|
||||||
} else {
|
} else {
|
||||||
steppers.setDir(0, 1);
|
steppers.setDir(TAKEUP, FORWARD);
|
||||||
steppers.setDir(1, 1);
|
steppers.setDir(FEED, FORWARD);
|
||||||
}
|
}
|
||||||
steppers.stepBoth(abs(steps));
|
steppers.stepBoth(s);
|
||||||
_posTakeup += steps;
|
_posTakeup += steps;
|
||||||
_posFeed += 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) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,18 @@ class McopyProjector {
|
||||||
|
|
||||||
uint8_t _motorSteps = 200;
|
uint8_t _motorSteps = 200;
|
||||||
uint8_t _frames = 8;
|
uint8_t _frames = 8;
|
||||||
uint8_t _stepsPerFrame = round(_motorSteps / _frames);
|
uint8_t _stepsPerFrame = 25; //round(_motorSteps / _frames);
|
||||||
uint16_t _speed = 500;
|
uint16_t _speed = 300;
|
||||||
|
|
||||||
int64_t _posTakeup = 0;
|
int64_t _posTakeup = 0;
|
||||||
int64_t _posFeed = 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;
|
bool _dir = true;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -25,11 +31,11 @@ class McopyProjector {
|
||||||
McopyProjector();
|
McopyProjector();
|
||||||
void begin();
|
void begin();
|
||||||
//0 = takeup, 1 = feed
|
//0 = takeup, 1 = feed
|
||||||
void adjust(uint8_t motor, int32_t steps);
|
void adjust(uint8_t motor, int64_t steps);
|
||||||
void adjustBoth(int32_t steps);
|
void adjustBoth(int64_t steps);
|
||||||
//true = forward, false = back
|
//true = forward, false = back
|
||||||
void frame(bool dir);
|
void frame(bool dir);
|
||||||
void frames(bool dir, uint32_t count);
|
void frames(bool dir, uint64_t count);
|
||||||
void setDirection(bool dir);
|
void setDirection(bool dir);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue