Added setPosition() to StepperControl
Needs testing and debugging
This commit is contained in:
parent
2eb70f1d1b
commit
480af6cf85
|
|
@ -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(){
|
void StepperControl::brake(){
|
||||||
move(0,10,BRAKE);
|
move(0,10,BRAKE);
|
||||||
while(stepsRemaining());
|
while(stepsRemaining());
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,7 @@ class StepperControl {
|
||||||
void move(int nSteps, uint32_t msDelay, endAction_t endAction=NONE);
|
void move(int nSteps, uint32_t msDelay, endAction_t endAction=NONE);
|
||||||
void moveTo(int nPosition, uint32_t msDelay, endAction_t endAction=NONE);
|
void moveTo(int nPosition, uint32_t msDelay, endAction_t endAction=NONE);
|
||||||
int position();
|
int position();
|
||||||
|
void setPosition(int pos);
|
||||||
int stepsRemaining();
|
int stepsRemaining();
|
||||||
void enable();
|
void enable();
|
||||||
void disable();
|
void disable();
|
||||||
|
|
|
||||||
|
|
@ -41,13 +41,17 @@ void setup() {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
Serial.printf("\nHomeSpan Steppers\n\n");
|
Serial.printf("\nHomeSpan Steppers\n\n");
|
||||||
|
|
||||||
motor=new Stepper_TB6612(23,32,22,14,33,27);
|
// 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);
|
||||||
|
|
||||||
motor->setStepType(StepperControl::EIGHTH_STEP);
|
motor->setStepType(StepperControl::HALF_STEP);
|
||||||
motor->setAccel(10,100);
|
motor->setAccel(10,100);
|
||||||
motor->move(1600,2);
|
motor->move(100,2);
|
||||||
|
motor->setPosition(200);
|
||||||
while(motor->stepsRemaining());
|
while(motor->stepsRemaining());
|
||||||
|
motor->setPosition(200);
|
||||||
|
delay(10);
|
||||||
|
Serial.printf("Position=%d\n",motor->position());
|
||||||
motor->moveTo(0,2,StepperControl::BRAKE);
|
motor->moveTo(0,2,StepperControl::BRAKE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue