Added setPosition() to StepperControl

Needs testing and debugging
This commit is contained in:
HomeSpan 2023-06-18 17:55:29 -05:00
parent 2eb70f1d1b
commit 480af6cf85
3 changed files with 20 additions and 4 deletions

View File

@ -97,6 +97,17 @@ int StepperControl::position(){
//////////////////////////
void StepperControl::setPosition(int pos){
if(!stepsRemaining()){
downLinkData.position=pos;
xQueueOverwrite(downLinkQueue,&downLinkData);
} else {
ESP_LOGE(STEPPER_TAG,"can't set Position while motor is running");
}
}
//////////////////////////
void StepperControl::brake(){
move(0,10,BRAKE);
while(stepsRemaining());

View File

@ -87,6 +87,7 @@ class StepperControl {
void move(int nSteps, uint32_t msDelay, endAction_t endAction=NONE);
void moveTo(int nPosition, uint32_t msDelay, endAction_t endAction=NONE);
int position();
void setPosition(int pos);
int stepsRemaining();
void enable();
void disable();

View File

@ -41,13 +41,17 @@ void setup() {
delay(1000);
Serial.printf("\nHomeSpan Steppers\n\n");
motor=new Stepper_TB6612(23,32,22,14,33,27);
// motor=new Stepper_TB6612(23,32,22,14);
// motor=new Stepper_TB6612(23,32,22,14,33,27);
motor=new Stepper_TB6612(23,32,22,14);
motor->setStepType(StepperControl::EIGHTH_STEP);
motor->setStepType(StepperControl::HALF_STEP);
motor->setAccel(10,100);
motor->move(1600,2);
motor->move(100,2);
motor->setPosition(200);
while(motor->stepsRemaining());
motor->setPosition(200);
delay(10);
Serial.printf("Position=%d\n",motor->position());
motor->moveTo(0,2,StepperControl::BRAKE);
}