8000 Add a new function for linear motion scenes · Issue #126 · laurb9/StepperDriver · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Add a new function for linear motion scenes #126
Open
@XingYunFei580

Description

@XingYunFei580

For the linear reciprocating motion of the lead screw nut driven by the motor, according to the expected linear displacement (s) and the known screw lead (d), we can add a public function "goback(double s, int d)" in the head file to achieve the goal more simply and intuitively. Of course, other necessary data, such as the motor speed and pulse number, have been completed through other settings.
in the file "BasicStepperDriver.h", add:
class BasicStepperDriver {

Public

void goback(double s, int d);
long calcStepsForGoBack(double s, int d) {
return s/d * motor_steps * microsteps;
}
};

in the file"BasicStepperDriver.cpp",add:

void BasicStepperDriver::goback(double s, int d){
move(calcStepsForGoBack(s,d));
}

An example program as below:

#define MOTOR_STEPS 300
#define RPM 200
#define DIR_PIN 7
#define STEP_PIN 8
#define SLEEP 9
#define MICROSTEPS 1
BasicStepperDriver stepper(MOTOR_STEPS, DIR_PIN, STEP_PIN, SLEEP)

int d=5; //screw lead 5mm
double s=30.4; //nut moving distance 30.4mm

void setup( ) {
stepper.begin(RPM, MICROSTEPS);
}

void loop( ){

stepper.goback(s, d);
delay(100);
stepper.goback(-s, d);
delay(100);
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0