Multiaxis stepper motors using RMT

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Marius
Posts: 21
Joined: Fri Nov 30, 2018 2:08 pm

Re: Multiaxis stepper motors using RMT

Post by Marius » Fri Feb 07, 2020 6:15 pm

What about using some Trinamic 5160 drivers over spi/uart? Instead of step/dir.

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: Multiaxis stepper motors using RMT

Post by OlivierLenoir » Fri Feb 07, 2020 8:25 pm

Marius wrote:
Fri Feb 07, 2020 6:15 pm
What about using some Trinamic 5160 drivers over spi/uart? Instead of step/dir.
TMC5160-EVAL seem to be an excellent product. Thanks for this information. I'll keep this in mind for another project.

For this project, it's out of budget. One TMC5160-EVAL costs 100 € where a lot of five DRV8825 cost 15 €. But agreed with you TMC5160-EVAL and DRV8825 are totally different in term of functions and power.

Marius
Posts: 21
Joined: Fri Nov 30, 2018 2:08 pm

Re: Multiaxis stepper motors using RMT

Post by Marius » Sat Feb 08, 2020 12:18 am

How high voltage do you wnt to run? Check out the 5160 stepstick. Super cheap. And there is also the 5160 bob. If you dont have super high power check out trinamic 5161. 5161 have fets included.

random-builder
Posts: 3
Joined: Mon Oct 04, 2021 4:34 am

Re: Multiaxis stepper motors using RMT

Post by random-builder » Mon Oct 04, 2021 4:39 am

Hi, Guys.

Do you think this would actually work:

https://github.com/micropython/micropyt ... -933131381

Code: Select all

to accelerate/decelerate a stepper motor, RMT.write_pulses() would re-use same static pulse pattern,
by making this pattern fractal/self-similar, up to a clock frequency scale factor
and then update clock scale between RMT.write_pulses() invocations
by using rmt_set_clk_div()

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: Multiaxis stepper motors using RMT

Post by OlivierLenoir » Mon Oct 04, 2021 6:55 pm

On one axis, this seem to be doable, but this will depend on the number of acceleration and deceleration steps, because we are limited in memory.

Regarding multi-axis method, this will not work as it has been wrote today.

I plan to create g01() without acceleration / deceleration and an other one g01a() managing acceleration / deceleration.

random-builder
Posts: 3
Joined: Mon Oct 04, 2021 4:34 am

Re: Multiaxis stepper motors using RMT

Post by random-builder » Fri Apr 15, 2022 3:07 pm

Here is a working experimental implementation:
https://gist.github.com/Andrei-Pozoloti ... 4de9c67267

Basic approach is:
* use piecewise interpolation for stepper motor pulse profile
* persist interpolation segments once, inside esp32.RMT.items store
* start sending pulses from items store with rmt.h | rmt_set_clk_div() and rmt.h | rmt_write_items()
* continue sending by switching between pulse patterns with rmt.h | rmt_register_tx_end_callback() system ISR

boognevatz
Posts: 3
Joined: Sun Jul 03, 2022 11:37 am

Re: Multiaxis stepper motors using RMT

Post by boognevatz » Sun Jul 03, 2022 12:01 pm

OlivierLenoir wrote:
Mon Oct 04, 2021 6:55 pm
other one g01a() managing acceleration / deceleration.
Hi OlivierLenoir,

I tested your library with a stepper motor, and it seems to have some software bottleneck. Namely this line:
https://gitlab.com/olivierlenoir/microp ... xis.py#L71

Code: Select all

    def steps(self, steps, period=4, p_size=100):
        """Many 'steps' with position increment"""
        self.set_dir(steps)
        _d, _m = divmod(abs(steps), p_size)
        pulse = (DRV8825_MP, max(DRV8825_MP, min(32767, period - DRV8825_MP)))
        _wp = self._wp
        loops = range(_d)
        for _ in loops: # <-- here
            _wp(pulse * p_size)
        if _m:
            _wp(pulse * _m)
        self.pos += steps

Here, the "for _ in loops" method does not have any strict timings. So when you concatenate two "RMT. write_pulses" the timing can not be guaranteed.
I rotated a motor for 515.6 turns, and its quite audible when some of the loop begins (it is an audible glitch)
here is my testcode:

Code: Select all

rmt_step_pin = RMT(4, pin=Pin(4), clock_div=80)

# microstepping! 200/16, (4,40) @ clockdiv=80 is the minimum!
a = (4,500)*20 + (4,200)*20 + (4,100)*20 + (4,80)*20 + (4,60)*20 + (4,50)*20 + (4,40)*20 + (4,35)*20 + (4,34)*20 + (4,33)*20
v = (4,33)*200

def test(acceleration, velocity):

    rmt_step_pin.write_pulses(acceleration)
    loops = range(8250-1) # 16*515.6 - 1 , 515.6 turns (reduction gear ratio: 1:515.6)
    for _ in loops:
        rmt_step_pin.write_pulses(velocity)

test(a,v)
I wanted to try random-builder's solution, but it is above my paygrade.
A clear step by step tutorial is required for me, I have never recompiled micropython itself.

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: Multiaxis stepper motors using RMT

Post by OlivierLenoir » Mon Jul 04, 2022 5:10 am

Thanks for sharing your test.

As I mention in the README,
- RMT, MutliAxis.g01(), manage start period (µs) (start frequency), target
period (µs) (target frequency) and acceleration / deceleration rate (µs per step)
/!\ still working on Axis.steps() acceleration / deceleration.
In branch bresenham, I'm implementing Bresenham's Algorithm to improve step frequency.
I will also improve acceleration / deceleration management using this document by implementing Taylor series approximation, because, currently acceleration / deceleration used in Multiaxis.g01() is not linear.

Until I finalize a new release, you can adjust the following Multiaxis attributes, Multiaxis.start_period, Multiaxis.period and Multiaxis.acceleration_rate.

Post Reply