Determining PID values for SM-42BYG011-25 Nema17 Stepper Motor.

426 views
Skip to first unread message

Mark Johnston

unread,
Aug 27, 2016, 7:32:20 PM8/27/16
to Mechaduino
I am using a SM-42BYG011-25 Nema17 stepper motor for my tests.    Values of note are 12V, 0.33A, 200 Steps, with step angle of 1.8 degrees 

Current limiting was adjusted in State.cpp by setting line 29.  (Not sure that this is the correct way to do this.)
set const float iMAX = 0.3; // Initially was set to 1.0

I've calibrated my Mechaduino by running the W command and copied the new values into Parameters.cpp lookup table.
Everything seems to work fine in open loop stepper mode.

When I run the closed loop mode I my motor is displaying the following buzzing non-movement behaviour shown in the following youtube video.

https://www.youtube.com/watch?v=mTR5psKU4t8&feature=youtu.be  


Open loop stepping works (d, s, w etc.)

Closed Loop Modes (y - enable interrupts) 

Position loop (x) -> buzzing no movement

Velocity loop (v) -> buzzing no movement

Torque loop (t) -> motor rotates

Set Point (r). some movement 


In summary in the Position Loop and Velocity loop the motor just seems to buzz.  In the Torque loop the motor rotates.

Not sure what might be causing this behaviour but one possibility is that the motor requires tuning with some relevant PID values? 


As I am new to tuning stepper motors I am wondering if anyone already have an idea of what PID values that I should be using here?

Or at least some way to determine what they might be?


Thoughts and suggestions welcome!


Mark


Additional questions

There is a formula that calculates the uMax in State.cpp.  

volatile int uMAX = (255/3.3)*(iMAX*10*rSense); 

How or where is this formula derived from?

Also rSense is defined as  const float rSense = 0.150;  
however the sense resistors R12 and R13 used in this build are are 0.250 ohms 
Wondering if rSense correctly defined in State.cpp?


State.cpp

tropica...@gmail.com

unread,
Aug 28, 2016, 12:51:58 PM8/28/16
to Mechaduino
Hi Mark,

Yes, that sounds like you need to tune your PID parameters.  These will vary depending on the motor you use and the load you are trying to drive.  You can tune these values by hand, or you can model your setup (on paper or in Matlab/Octave, etc) and determine the best values to meet your performance objectives. 

Some very general tuning advice:  I would start with your ki and kd gains at zero and then adjust kp until you get a feel for when the system goes unstable.  Then I'd back off on the kp a little and add in some ki to get rid of any steady state error.  At this point you can start adding some kd to improve performance.

There is a lot of information out there on how to hand tune PID systems.  For many applications, hand tuning is probably good enough, but if you are trying to get really high performance, I recommend using loop-shaping methods or other classical controls techniques. 

The control laws are all implemented in controller.cpp.  If you want to change the PID implementation, or implement a custom controller, you can do that there.
We have had success designing controllers using discrete time loop shaping techniques in Ocatve and then directly implementing the appropriate difference equations here.

To answer your other questions:

We changed rSense to .150 ohms from .250 ohms a while ago to allow higher peak currents.  .250 ohms will work fine, but you will be limited to 1.3A max current.

This equation,

"volatile int uMAX = (255/3.3)*(iMAX*10*rSense); "
calculates the Vref value needed to set the A4954 currents to iMAX.  "(iMAX*10*rSense)" is from the A4954 datasheet (i*rSense = vsense, the a4954 has a nominal internal current gain of 10).

Hope that helps!
Joe

Tarjei Knapstad

unread,
Aug 29, 2016, 4:27:13 AM8/29/16
to Mechaduino


On Sunday, August 28, 2016 at 6:51:58 PM UTC+2, tropica...@gmail.com wrote:

We changed rSense to .150 ohms from .250 ohms a while ago to allow higher peak currents.  .250 ohms will work fine, but you will be limited to 1.3A max current.


Please update the BOM :-)

--
Tarjei
 

Thor Zhou

unread,
Feb 12, 2023, 8:23:05 PM2/12/23
to Mechaduino
Hello, what does (255/3.3) mean in the formula: "volatile int uMAX=(255/3.3) * (iMAX * 10 * rSense);"?
Reply all
Reply to author
Forward
0 new messages