Skip to content

newMoveTo does not work correctly with toStep less than current position #18

@drp0

Description

@drp0

If toStep is less than stepN the move to is incorrect. This also affects newMoveToDegree.

My solution:

void CheapStepper::newMoveTo (bool clockwise, int toStep){

	// keep toStep in 0-(totalSteps-1) range
	if (toStep >= totalSteps) toStep %= totalSteps;
	else if (toStep < 0) {
		toStep %= totalSteps; // returns negative if toStep not multiple of totalSteps
		if (toStep < 0) toStep += totalSteps; // shift into 0-(totalSteps-1) range

	lastStepTime = micros();

	}

	if (clockwise) { // drp correction for moveto < current position
		if (toStep < stepN) toStep = toStep + totalSteps;
	stepsLeft = toStep - stepN;
	//stepsLeft = abs(toStep - stepN);
	}
	else {
		if (toStep < stepN) { // drp correction for moveto < current position

		stepsLeft= toStep - stepN;
		}else{
		//stepsLeft = -1*(totalSteps - abs(toStep - stepN));
		stepsLeft = -1*(totalSteps - (toStep - stepN));
		}
	}
	
lastStepTime = micros();
}

As a bonus, abs no longer needed

David

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions