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

moveToPositionInSteps() in constant speed option #32

Open
christophepersoz opened this issue Jun 10, 2023 · 5 comments
Open

moveToPositionInSteps() in constant speed option #32

christophepersoz opened this issue Jun 10, 2023 · 5 comments

Comments

@christophepersoz
Copy link

Hi,

You did a really good job with this library, thanks a lot for that.
I'm looking a way to adapt your lib to add a moveToPositionInSteps() in constant speed skipping the calculation of acceleration en deceleration. Unfortunately, I'm maybe doing something wrong as my change do not work and result in a non moving motor.

Is there a way to get that really quickly? Maybe I missed something somewhere in your code that would allows me to do so.

Thanks in advance!
Cheers,

@pkerspe
Copy link
Owner

pkerspe commented Jun 10, 2023

Hi Christophe,
Can you post your code so I can have a look at it?

Kind regards
Paul

@pkerspe
Copy link
Owner

pkerspe commented Jun 10, 2023

Btw you could also just try to set the acceleration values to some realy high numbers which would effectively result in a almost instant speed change.
But keep in mind that your motor will need enough torque for you specific use case (desired max speed and load on motor and inertia of motor itself or if it is a geared motor also to overcome the inertia of the gears) to perform such instant acceleration to prevent stalling.

So bedside the software you might also have pure physics boundaries.

One thing you can try to increase torque / reduce loss of steps is to disable microstepping in you stepper driver, you will lose precision but only perfoming full steps MIGHT increase torque. Also you need to make sure you provide enough current to match the motor specs.

@christophepersoz
Copy link
Author

Hello Paul,

thanks a lot for your reply!

I’m using you lib in a really specific use which isn’t the primary use of it I have to admit - sorry 🤩
I’m feeding the core1 with speed and position values and assign them on core 0 which is in charge of the motor moves only.
The acc/dec is managed by the speed ramp values provided so it will prevent brutal acc/dec and skipping steps.
I noticed that removing all the unnecessary part in you lib that implies test and CPU cycles like brakes, limits etc speed up and improve the movement when I’m feeding the core with new speed/pos values each 10 to 20ms. On that way I thought that skipping the calculation of the acc/dec will make sense and will contribute to a better responsiveness of the system; also the overall movement will be much constant as it won’t be acc/dec at each new position to move on.

I do not know if that’s really clear but to be shorter, that’s why I intend to stick to the minimum calculation and get a faster response of the whole.

For the moment I was concentrated on the part in charge of the step calculation.

Thanks a lot!
Christophe

@pkerspe
Copy link
Owner

pkerspe commented Jun 10, 2023

well, it is a bit difficult for me to decide which functions you want to keep from the library in your use case.
The thing is: if you only need to generate a specific amount of step signals and a specific frequency, you might be much better offer simply creating your own logic to simply generate a Squarewave signal for your stepper motor.
Easiest would be to simply write a while loop to set a pin low and high with delays. Obviously not very elegant though
More advanced: use a time and interrupts to generate the signal and count the steps
best: use a hardware module of the ESP32 to generate the signals, I wrote a long text about the different options in one of Issue #4 #4 (comment)

Of course you could still create your own fork of the library and adapt the processMovement function and DeterminePeriodOfNextStep function to your needs, I think that is all that needs to be modified and where most CPU cycles are spent.

e.g. you can throw out all the emergency break stuff if you do not need it, also you can remove the break logic, if you do not need it and you can remove limit switch checks etc. The thing is: I do not know what you need of these features, so I cannot provide a solution.

It would be best if you post your code you have so far so we can check

@aaryanmurgunde
Copy link

Hi, @pkerspe

I have a similar case scenario, what I want to achieve is to do a trajectory execution for a robotic arm. In that case what I receive on the esp32 end is individual point by point for all the joints, having values (position, velocity, acceleration).
I tried using your lib but since the acceleration and deceleration both happen for a particular target, I get a discontinued motion between points.

The velocity profile and the acceleration are manged by the higher level controller when generating the trajectory, Ideally what I would like to achieve is that I set these values and the motor runs with them and after position is achieved the motor comes to a sudden stop. What this does is as I have a profile build and a next point queued, The execution wont be discontinued.

If you can tell me what the necessary changes would be for the same that would be Great!

Thank You.

gosnik pushed a commit to gosnik/Stepper that referenced this issue May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants