PID Loop for stepper motors

More
10 Feb 2020 10:16 #156941 by Ameone
PID Loop for stepper motors was created by Ameone
Dear all,
I'm currently working on implementing a PID position control with LinuxCNC for a rotary axis. The set-up includes a stepper motor with a rotary encoder. I'm attaching the HAL configuration file, I'm not really sure if everything is set-up correctly or not. Can you please check it?
Thanks,

Amedeo

File Attachment:

File Name: pid_conf.hal
File Size:2 KB
Attachments:

Please Log in or Create an account to join the conversation.

  • tommylight
  • tommylight's Avatar
  • Away
  • Moderator
  • Moderator
More
10 Feb 2020 10:30 #156942 by tommylight
Replied by tommylight on topic PID Loop for stepper motors
First delete or omit the following line:
setp pid.x.maxerror .0005

Please Log in or Create an account to join the conversation.

More
10 Feb 2020 10:40 #156943 by Ameone
Replied by Ameone on topic PID Loop for stepper motors
Ok done! Any other corrections?

Please Log in or Create an account to join the conversation.

  • tommylight
  • tommylight's Avatar
  • Away
  • Moderator
  • Moderator
More
10 Feb 2020 11:57 #156944 by tommylight
Replied by tommylight on topic PID Loop for stepper motors
Not that i noticed at first glance.
As you provided about 1/5 of the info, you get that same amount of help.
Attach the full files, hal and ini.
Either way, we can spot some glaring errors, but not all as i do not have the same hardware to test with.

Please Log in or Create an account to join the conversation.

More
10 Feb 2020 12:01 #156945 by Ameone
Replied by Ameone on topic PID Loop for stepper motors
Ok, I'm attaching the whole hal as well as the ini. Consider that the configuration is for a 5 axis robot, and only the first axis (axis 0) has the encoder configured. Hope it helps!

File Attachment:

File Name: moveo_step_5.hal
File Size:12 KB

File Attachment:

File Name: moveo.ini
File Size:10 KB
Attachments:

Please Log in or Create an account to join the conversation.

  • tommylight
  • tommylight's Avatar
  • Away
  • Moderator
  • Moderator
More
10 Feb 2020 12:07 #156946 by tommylight
Replied by tommylight on topic PID Loop for stepper motors
Looks good.
Start testing and report back if you get any errors.

Please Log in or Create an account to join the conversation.

More
10 Feb 2020 13:40 #156949 by Ameone
Replied by Ameone on topic PID Loop for stepper motors
Ok so I've tried moving the axis by jogging it of 10 degrees in both directions. The axis start oscillating vigorously, until a following error. The settings used are:

P = 60
I = 0.01
D = 0
BIAS = 0
FF0 = 0
FF1 = 0.5
FF2 = 0.5
DEADBAND = 0.001
MAX_OUTPUT = 0

I then tried to lower the P value until the axis stopped oscillating, while setting I, FF1, FF2 to 0 (to simplify the configuration). A value of P = 10 did the trick. When I look at the axis.0.f-error in the HAL oscilloscope I get a sawtooth wave when moving (img_1.jpeg) and a train of recangular pulses when stopped (img_2.jpeg). Is it correct?
Also, if i jog of 10 degrees the final reached position is never exactly 10 but something like 10.080.
Hope this helps, thank you very much for your help!

Attachments:

Please Log in or Create an account to join the conversation.

More
10 Feb 2020 14:01 #156953 by Hakan
Replied by Hakan on topic PID Loop for stepper motors
I see you have FF1= 0.5 and FF2=0.5. At the same time you seem to run stepgen i position control mode. Then I don't think these combinations are the best.

When you run stepgen in position control mode you are better off with FF0=1 and FF1=FF2=0. There is no scaling when using stepgen so the commanded output position from motion should go directly to stepgen via the pid FF0 parameter set to 1.

Actually it is better to run stepgen in velocity mode even when using steppers. If you switch to velocity mode you should set the pid parameters to FF0=0, FF1=1, FF2=0.

When that is fixed, start with small P values until it oscillates and then back off. Well normal servo tuning methodology.

Please Log in or Create an account to join the conversation.

More
10 Feb 2020 15:38 #156963 by Ameone
Replied by Ameone on topic PID Loop for stepper motors
I should be running in velocity mode (?). I've set the stepgen for that specific axis to control-type = 1.
Ok I've found a value of P at which the axis doesn't oscillate. Do i have to change some other parameter?
Also a quick note: now the axis is moving really slow and it doesn't change speed even if I change the jog speed itself.
Thank you again for the quick response!

Please Log in or Create an account to join the conversation.

More
10 Feb 2020 16:08 #156967 by PCW
Replied by PCW on topic PID Loop for stepper motors
As Hakan mentioned tuning should be

FF0=0
FF1=1.000
FF2=0
P maximum stable value
D = 0
I = 0

Proper operation also depends on having commensurate stepscale and encoder scales

Please Log in or Create an account to join the conversation.

Time to create page: 0.097 seconds
Powered by Kunena Forum