Stepper motor motion planning

C_D
Wed Sep 26, 2018 1:30 am
Has anyone tried doing any advanced stepper motor control with an F1 or F4? I presume someone must have looked at this as there was talk of porting Marlin and/or making a 3D printer controller. Skimming the forums I can find a few people who tried the AccelStepper library http://www.airspayce.com/mikem/arduino/AccelStepper/ but its no where near fast enough for what I am hoping to do : ideally I would like to control 8 or so stepper motors at 50kHz step rates.

I have done a little optimisation of the stepping code in AccelStepper (eg. getting rid of digitalWrite() and delay()) but on an F1 the acceleration calculations are sssllloooowww because they use floating point math. Some rough bench marking indicated about 30uS of math per step per motor. So that nets me at best 30kHz step rate on a single motor, and no time left to do anything else while stepping.

Ive been playing with an F407 board and got the FPU working (thanks Pito and ag123 viewtopic.php?f=39&t=2001) but haven’t yet benchmarked AccelStepper using it. Ive probably got to do some hacking of the library first to make sure its all single precision float etc.

What i’m really after is an existing library that mostly meets my needs without needing a ton of further work. I’m sure this has been done many times before and I’d rather not spend weeks writing code to calculate acceleration profiles when someone has probably already done it!

Anyone else here doing something similar?

EDIT:
Actually this looks quite promising: https://github.com/luni64/TeensyStep. The Teensy 3.2 looks similar to an F103 and the Teensy 3.6 looks like its even more powerful than an F4.


ag123
Wed Sep 26, 2018 6:44 am
i’ve been wanting to play with the steppers for a while. however, i noted that when say one is considering say assembling a 3d printer
it is often more convenient and lower costs to go with the generic stepper modules
https://www.ebay.com/sch/i.html?_nkw=a4988&_sacat=0
https://www.ebay.com/sch/i.html?_nkw=drv8825&_sacat=0
rather often most existing codes are written to use the a4988, drv8825 stepper modules
while it is pretty possible to make stm32 (say f103) do just that, it often costs somewhat more per device, e.g. more components, more work to assemble the motor controllers
to save work, once could basically emulate those same features of a4988, drv8825 or to rewrite the drivers to use new custom drivers for a stm32 motor control, this is much harder and could involve changing much of the base codes

nevertheless there are various benefits of controlling the steppers directly from a stm32, including software calibration of currents control, micro-stepping, closed loop current control and and ideally to make a motor control engine that could run a stepper using high level commands rather than low level direction and step ticks control
i think there are a number of project out in the net that does just that e.g.
https://hackaday.com/2016/06/01/mechadu … -everyone/
https://github.com/Misfittech/nano_stepper
https://reprap.org/wiki/Motor_control_loop
http://www.ustepper.com/index/
https://github.com/jcchurch13/Mechaduino-Firmware
http://tropical-labs.com


C_D
Wed Sep 26, 2018 9:04 am
[ag123 – Wed Sep 26, 2018 6:44 am] –
it is often more convenient and lower costs to go with the generic stepper modules

Sorry I should have been more clear, that is exactly what I will be doing. I have an array of DRV8825 driver modules on my desk for testing. The role of the STM32 will be to generate the required step and direction signals for the drivers. Obviously generating fast pulses is easy, its the acceleration profiles and synchronisation of multiple motors moving at the same time that gets tricky.


Phono
Wed Nov 21, 2018 8:17 pm
I have some experience with this topic, but can you please clarify your needs : you mention 50 kHz step rate. I do not think you speak of physical steps, since on the classical motors with 200 steps/rev, this would mean a shaft speed of 250 rev/s, or 15 000 rev/min!
Can you specify the shaft speed do you need?
I have spent a part of my carrier to design stepper motor drives, so I might be able to help you.

C_D
Sun Nov 25, 2018 9:55 pm
Phono, it would be great to discuss my project with you, you sound like you have much more experience in this field than me.

I am building a programmable motor controller which can run several (up to 16) stepper motors simultaneously. The STM32 will be generating step and direction signals for external drivers. The high step rates are required for microstepping drivers which are sometimes set to 32, 64 or 128 microsteps so you need to send up to 25k steps per revolution of the motor, though I don’t think I will actually need to use 128 micrstepping in practice.

Ideally I would like to stick with the F103 for cost reasons, so I am hoping that simple constant acceleration control will be sufficient for my needs. I don’t think jerk controlled motion will be possible without an FPU and it seems overly complex for what I need at this point. Its definitely something I want to look into in the future though.

I’ve been busy designing the hardware for the past few weeks but I’m back onto the software side again now. I’m going to have a good look at TeensyStep this week and see if I can get it running on an STM32. The template code confused me a bit when I first tried to read it but I think I have it under control now :lol:

I have also just found TinyG which does 3rd order jerk controlled motion in 6 axes simultaneously on an Xmega that doesn’t seem to have hardware floating point. I will look into that a bit further too.


flyboy74
Mon Nov 26, 2018 6:59 am
Please keep posting what your up to and problems encounter and solutions found as I am also quite interested in learning about this topic.

I have built my own CNC mill but used off the shelf hardware and software.

I am cuurrently builting a robot to solve a 5x5x5 Rubik’s Cube. I am using robot servos to open/close the grippers but will be using steppers for the linear acuator and to rotate the grippers to turn the faces. See my project so far https://www.youtube.com/watch?v=tYFdmJEJuE8


paulvdh
Thu Dec 13, 2018 10:04 pm
Does Grbl fit your list?
Grbl has also been ported to the STM32F103.
There are a bunch of forks on github:
https://github.com/search?q=grbl+stm32
One of th most recent forks seems to be:
https://github.com/usbcnc/grbl

And stm32 is also mentioned on gnea/grbl which seems to be the official repository for grbl.

If the relative movement of your axis is fixed, as with most CNC machines, then you can easily extend the movements of all motors by extrapolating from the Bresenham line algorithm.
Just take the motor with the biggest number of steps and use that axis as a reference for a move.
All other motors are slaved to the fastest motor.
Of the shelf Grbl only does 3 axis Bresenham, but it does not matter much because of the above.


C_D
Wed Dec 19, 2018 2:19 am
[paulvdh – Thu Dec 13, 2018 10:04 pm] –
Just take the motor with the biggest number of steps and use that axis as a reference for a move.
All other motors are slaved to the fastest motor.

This is what TeensyStep implements, but with as many motors as you like (or have memory and cpu capacity for). Still working on porting it to STM32, havent had much time lately but I’m hoping to get back into it soon.

I was steering away from GRBL because it has a lot of features I don’t need like gcode parsing and motion planning. This thread is not well named as I don’t really need a motion planner, just acceleration and synchronised movements.


flyboy74
Wed Dec 19, 2018 11:21 am
I did see this video the other day https://www.youtube.com/watch?v=fHAO7SW-SZI

It seem to work very well to smoothly coordinate 6 stepper motors on a 16Mhz 8 bit Ardunio so the same concept shouldn’t have any problem on a STM32.


paulvdh
Thu Dec 27, 2018 6:04 pm
Flyboy mentions a youtube vid, which mentions an Atmel application note for stepper motor accelleration calculations.
That Atmel application note is based on an excellent article written by David Austin, and published in…
https://duckduckgo.com/html?q=david+aus … +algorithm
https://www.embedded.com/design/mcus-pr … -real-time

His algorithm only implement constant acceleration and no smooth S-curves.
The “real time” aspect is that it only needs a single division and a few additions / subtractions to calculate the next step delay.

In some future project I am planning to do at least 6 motor coordinated moves for a 6-axis industrial robot look alike, but I’d probably want to plan ahead for some auxilary axis too. At this moment my thought is to build upon Grbl, because extending the number of axis is easy and it’s already ported to STM32.
I haven’t looked into Teensy step, Marlin or other coordinated stepper motor stuff yet.


flyboy74
Thu Dec 27, 2018 9:51 pm
Thank you a lot :)
The second link was great and help to much better explain this solution.

For my more simplex robotics needs atm this will work great and is a perfect starter point for a beginner like me :)


Leave a Reply

Your email address will not be published. Required fields are marked *