Driving a Linear Stage With the TMC4671 – Controller Tuning
Welcome back to my blog post series! I previously described how I set everything up in the post: Driving a Linear Stage With the TMC4671 – Setup. Today I will show you how I tuned my controller gains for torque/flux-, velocity- and position-mode.
I set a target voltage of 1000 and monitor the step response. The red line displays my voltage reference while the blue line shows the current rising with lowpass behavior. The algorithm estimates the inductance and resistance of the motor from the step response. The green line displays the fitting result for a first order lowpass with estimated parameters. Basically, the green line should fit well to the noisy blue line. If I see a bad fitting result, I can either perform the measurement again or modify the data range.
In the first picture, we see the step response for the default values. The second picture shows a bad fitting result because I reduced the data range. When I increase the data range again I get good values as seen in the third picture.
My controller parameters are automatically calculated and displayed in the bottom right. I can set them directly with the button “Set Parameters”.
I can check my controller performance with the step response tool by setting a small but good visible flux target. I chose 1000 here and measurement time of 1000 samples. Current controllers are pretty dynamic and will reach their target value after a few PWM cycles if the voltage limitation is not tripped. Here are two different step responses for different controller parameters.
I can now proceed with my velocity controller tuning. For this, I need to change my settings in the step response tool to velocity target and velocity actual. My reference value is now a little lower at 100 rpm. Since I selected PHI_M_ABN for velocity selection, the real mechanical velocity is displayed. I set PID_VELOCITY_P to 100 as a starting value and increase the value until I end up at 50% of the step response. After that, I increase the I-parameter concluding with P = 3000 and I = 2200.
With that tuning result, I start tuning my position control loop. I set a small P parameter (e.g. 10) while velocity mode is still active. Then I open the position mode dialog to reset the actual position with the “Clear” button. In order to not drive into the end stop, I do this in the middle of my traveling distance.
Now I use the step response tool to tune my position controller. Before applying a higher gain, I check my velocity limit in PID_VELOCITY_LIMIT. This should be a value the drive should actually be capable of driving. For this setup, it is 200 rpm as I chose mechanical angle PHI_M_ABN for velocity selection.
Now I can set up the step response tool for position control loop. I set POSITION_SELECTION in the selectors-section to phi_m_abn and choose a target value that represents one full revolution of my motor: 65536.
I open the step response tool again and evaluate the result of P = 10. As I’m not satisfied with the result, I increase P to 30. As seen below, the result already looks better but there is room for improvement since the target value is not yet reached. Thus, I set the gain to 60. This yields very good results as we reach our target value of one revolution and do not overshoot the target position.
If I increase the gain too much (e.g. P = 30,000 as seen above), the cascade gets unstable and the drive gets noisy. This resulted in the slide not reaching the actual target position as the feedback of the controller is too strong. This is not acceptable. Think about a CNC-mill for example. What you absolutely do not want is a cut where none should exist. This is why I stick to my previous results of P = 60.
Now I can do some tests with the position mode dialog driving back and forth. I can monitor the position in the position graph.
With these results, I can start developing some C-code for my firmware using the Trinamic API. I will see you in the next blog post, where I will show you my code and talk a little bit about the functions I used. See you there!
February 26, 2020 / Klemens Konhäuser / 7
Tags: code, code snippet, drive, eval kit, evaluation kit, Field Oriented Control, FOC, GUI, guide, How-To, IC, linear stage, programming, rtmi, servo, servo controller IC, setup, TMC4671, TMCL-IDE, tuning