Help setting up spindle PID loop

More
23 Apr 2019 14:27 #131640 by F4br1c4t3D
I'm on the final leg of configuring my motor speed control and struggling with closing the loop. I've used trial and error and feedback from the error logs at launch to get a config together based on this example . LCNC will now launch error free but when I command a speed the motor lurches forward, spins up relatively fast then immediately grinds to a halt.

I'm guessing this has something to do with the PID terms, scale component, or polarity of input from my encoder/index sensor but I'm not sure how to remedy this. Most of my .hal code came from stepconf - the output of which is very hard to understand for a beginner to LinuxCNC and could be made so much more palatable if it was organsied more systematically with comments to explain what the code is doing. I'm thankful it exists though, as getting this far would have been much more of a struggle without it. At least I now have an excuse for the horrendous state of the .hal file though (nothing to do with my shortcomings as a programmer - honest :P )

What should I be looking at to remedy the aforementioned behaviour with the spindle speed feedback? I've attached my most up to date .hal and .ini files for perusal (apologies in advance if it's hard to follow)
Attachments:

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

More
23 Apr 2019 14:39 #131642 by pl7i92
i am realy sorry to hear you are up with errors
but to make it all user friendly stepconf its not easy everyone needs oter settings

DID you look here to get your PID spindle running

wiki.linuxcnc.org/cgi-bin/wiki.pl?Closed...pindle_Speed_Control
The following user(s) said Thank You: F4br1c4t3D

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

More
23 Apr 2019 14:52 #131649 by F4br1c4t3D
Yes, I've looked at that guide. If you check the link provided in my original post, it's to the exact same page. This is the guide I've used to get the pid feedback set up. I've done my best to splice in the code from the guide to my existing hal. and LCNC now launches without errors. The problem is the way the loop is causing the spindle to behave. It seems to be limiting the speed very aggressively. (As in its causing the spindle to stop entirely) can't figure out what I've done wrong though.

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

More
23 Apr 2019 15:23 #131655 by Glite
How is your spindle controlled? If control is done via VFD, possibly you don't need PID at all, because it's already present in VFD. Adding PID in linuxcnc will add unnecessary problems.

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

More
23 Apr 2019 17:32 #131673 by F4br1c4t3D
Nope, that's not it. The motor is a brushless DC motor controlled by an electronic speed controller (ESC) that's being controlled via PWM. I have a 100ppr quadrature encoder for the spindle A and B phases (set up in counter mode for just counting whole pulses on phase A) and a slotted disk that triggers a photosensor for the index. All the signals are going to the PC correctly it's just making the connections in hal that I'm struggling with. Well, actually I think I have the connections sorted and the PID is influencing the motor speed, just not how it should be. (It's causing it to grind to a halt almost immediately). Everything was working as expected prior to adding the pid loop, so the issue is definitely in my code. Will no doubt be glaringly obvious to the .hal experts out there.

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

More
23 Apr 2019 17:53 #131675 by PCW
Its helpful to initially setup the PID component so that
FF0 = 1.0 and all other terms are 0

This means the PID does nothing except pass the velocity command
to its output. This should behave identically to your open loop configuration.

At this point you can add some P term to see if the velocity feedback
improves the speed accuracy (it will go crazy at this point if the encoder
velocity is backwards)
The following user(s) said Thank You: F4br1c4t3D

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

More
23 Apr 2019 20:42 #131691 by F4br1c4t3D
Thanks, PCW.

So, at the moment I only have PI&D gains set up as per the example I linked. So I should set all these to 0 initially. I'm assuming I have to setp for the FF0 pin and give it a value of 1. Then see how that works. If the motor spins as before, I can then move on to tuning the PI&D terms.

At a friend's at the moment but I'll give it a try later. I'm assuming I do have an inversion problem with the encoder velocity too as the motor was basically stopping and starting erratically (cogging) when I first got things set up. At least I should be able to sort that out if it's my issue.

I'll let you know how I get on.

Cheers

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

Time to create page: 0.108 seconds
Powered by Kunena Forum