pootle / tripipy

Simple python driver for Trinamic tmc5130 connected to Raspberry Pi
The Unlicense
36 stars 14 forks source link

Fix soft stops and add option for hard stops #7

Closed gautamjain closed 4 years ago

gautamjain commented 4 years ago

Calling stop() did not work as expected for me. It caused the motor to:


It seems like waitStop() was not polling frequently enough to catch the moment at which the motor velocity reached zero. When the velocity reached zero, the driver would notice the difference between XACTUAL and XTARGET and drive backwards to compensate.

One way to fix this would be to poll more frequently, i.e. reduce the ticktime. It must be reduced to less than TZEROWAIT, so we can catch the moment when velocity is zero. However, TZEROWAIT cannot be always initialized to a safe value. (It is derived from the driver's clock frequency and would vary for different circuits).

I've changed stop() to use one of the other methods described in the datasheet (see 'Early Ramp Termination'). It no longer depends on TZEROWAIT or even directly on ticktime.


I've also added the option to perform a hard_stop() which will cause the motor to halt without ramping down (per the same section in the datasheet).

Let me know what you think. Thanks!

pootle commented 4 years ago

hard stop: definitely OK as a separate call

smooth stop: stop as soon as you can but don't reverse - the entry in early ramp termination (Switch to velocity mode, set VMAX=0 and AMAX to the desired deceleration value. This will stop the motor using a linear ramp.) Looks like the best option for what you want, Or the b) option (at least in the 5130 datasheet): "For a stop in positioning mode, set VSTART=0 and VMAX=0. VSTOP is not used in this case. The driver will use AMAX and A1 (as determined by V1) for going to zero velocity."

As any given app is likely to want to use 1 or other mode of smooth stop, the simple option I think is to have different stop methods and let the app use the one it prefers.

stop here: the current version.

gautamjain commented 4 years ago

Got it thanks. I didn't realize the current stop method was intentionally driving backwards.

I'll update the PR to so all three methods are available for use.

hard_stop(), smooth_stop(), and stop()

gautamjain commented 4 years ago

Alright, done. Names are slightly different: