Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new function for linear motion scenes #126

Open
XingYunFei580 opened this issue Jul 18, 2024 · 1 comment
Open

Add a new function for linear motion scenes #126

XingYunFei580 opened this issue Jul 18, 2024 · 1 comment

Comments

@XingYunFei580
Copy link

XingYunFei580 commented Jul 18, 2024

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);
}

@laurb9
Copy link
Owner

laurb9 commented Aug 19, 2024

Thanks for the suggestion. Linear motion I find is a subset of geared drives, where the move amount is multiplied by some factor. I had been considering adding the geared motor functionality separate from the rest but I am still unconvinced just to avoid a multiplication with move().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants