Adaptive PID controller Microcontroller-based  - Page 1
Forum section: electronics / projects

author: XaviPacheco
author_rank: Regular Contributor
timestamp: October 20, 2018, 09:47:23 pm
content: I would like to build an adaptive PID controller for DC motor speed control. This controller should adjust the PWM duty cycle. The idea is that the program identifies the DC motor transfer function and adjust the PID parameters automatically for that motor. I've seen this using MATLAB, i.e, some data is recorded and given to MATLAB so it does all the job. But this time, let's say, I don't want to use MATLAB everytime I have to do PID tuning. I mean, let's say I have different DC motors, it means the transfer function changes, so PID parameter should change for that specific motor. Now, I have couple of doubts:1- I'm measuring speed and current of the motor. Is this information enough?2- The motor nameplate usually indicates the voltage, amps, and RPM. Can I extract useful information from it for the controller?3- Is this achievable with a 32-bit ARM microcontroller?Basically, I'm asking for help to write and understand the C algorithm, and implementation. I have been researching in Google about this, but I don't find much. if you have any document, book, or papers references which explain how to implement the C code, I will appreciate it.

author: IanB
author_rank: Super Contributor
timestamp: October 20, 2018, 09:57:27 pm
content: Your controller has a measured variable (the motor speed) and a manipulated variable (the PWM signal or motor voltage).Your "process" has an input (the PWM value or voltage) and an "output" the motor speed.What you need to do is to identify a model of your process (e.g. second order transfer function) by changing the process input in some way (maybe a step change) and recording the process response. Once you have this model of your process you can calculate by regression, or otherwise, an optimal set of PID parameters. Your PID tuning may depend on whether you need regulatory control (keeping the speed the same), or servo control (changing the speed on demand).This is the most basic approach. Other more sophisticated approaches are possible, but they require more theory to understand.There is not enough space in a forum post to explain how to do all of this in detail. There are quite a few things to learn along the way.

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 20, 2018, 11:04:38 pm
content: Not sure why you'd need an adaptive PID. A simple PID should do the trick.I have implemented rotation speed control through PWM on a DC motor years ago and didn't even implement a full PID. It was on an 8-bit PIC with very limited processing power. It was essentially just a PD controller (no integral term) and that worked fairly well with no need to extensively tweak the parameters. Rotation speed sensing was done with a slotted disc mounted on the axis of the reduction gearbox (4 slots, so 4 pulses per turn) and an optical sensor. It was additionally counting the number of turns and stopping exactly after a programmable number of turns (formed the basis of some kind of coil winder in which you could program the rotation speed, with a progressive start and stop to avoid wire breakage, and the number of turns). The 4 pulses per turn helped getting a more accurate speed rotation speed estimation (and a more accurate number of turns so I'd get better than a 1/2 turn error max.)Using the measured current is not essential but could be an interesting plus as it would allow you to detect any failure or excessive mechanical resistance and maybe help getting a smoother movement if you use it wisely.You may find some ideas in this:https://docplayer.net/48427382-Design-of-controllers-pd-pi-pid-for-speed-control-of-dc-motor-using-igbt-based-chopper.html

author: XaviPacheco
author_rank: Regular Contributor
timestamp: October 21, 2018, 01:25:34 am
content: Quote from: SiliconWizard on October 20, 2018, 11:04:38 pmWell, this is the true:For a college project, I'm designing a DC motor controller, and it works fine in hardware. I have some previous posts about it. I'm now dealing with the software where I have the control over the PWM. So far, the system is open-loop. With the speed readings, I'm going to close the loop and design a PID. What I plan to do is take some speed measurements, and process these values in MATLAB to get my motor transfer function and PID values. Then, I'm going to use these values to set the discrete PID in the microcontroller.I plan to use different DC motors, so I think every motor has different characteristics. The board supports DC motors up to 4 HP. My professor told me that if the motor is replaced by another one, my microcontroller should be able to identify the new motor and calculate itself the system transfer function and PID parameters without having connection with MATLAB. I think he's demanding more than what I can do.I can design a discrete PID controller, but I would need Kp, Ki, Kd previously calculated by another software. Normally, you find the motor transfer function and PID values using MATLAB.

author: IconicPCB
author_rank: Super Contributor
timestamp: October 21, 2018, 02:59:25 am
content: Forget PID... include Feed forward and only then think of PID .

author: Rerouter
author_rank: Super Contributor
timestamp: October 21, 2018, 08:58:52 am
content: More likely it would be a PI controller with trimming.Most speed sources are too noisy for a derivative term.As for how you would go about trimming it. Even an 8 bit micro has enough free cpu time to be calculating the parameters from step response during the original spin up of the motor. You can do a stair step startup if you want more data points.The other way can be the free oscillating way of deriving it. With your step response values if it reaches a steady oscillation. The amplitude and frequency can furthur refine itFor single element control loops like this the transfer function is generally quite simple. You have a voltage * current * pwm% this gives you power. Which is rotational torque. You have the motors drag which increases with rpmAnd your regulating that tourque to balance the drag and loading for that given motor.I can garentee this can be solved without matlab. Heck the procedures for determining the P and I parameters dont even need more than 5th grade algebra.

author: bson
author_rank: Unknown
timestamp: October 21, 2018, 11:31:20 am
content: Quote from: XaviPacheco on October 21, 2018, 01:25:34 amSounds like you should make a serious attempt to understand what the MATLAB software actually does.

author: max_torque
author_rank: Super Contributor
timestamp: October 21, 2018, 01:04:16 pm
content: The elephant in the room is "what is the load"??For a motor, it's rotational speed is directly and linearly proportional to it's supply voltage for a fixed torque!If you are using voltage control, then you already have a feedback loop integral in the physics, that will increase torque to try to restore motor speed when the load increases. (load increases, backemf falls, so if supply voltage stays the same, then there is more voltage (Vfwd minus Vbemf) to drive more current through the motor and hence make more torque)If your load is variable and unknown, then your control gains will need to be modified, perhaps in real time (in-extremis) but it really depends on the load and NOT on the motor (as that's a fixed system, with fixed Kt and Ke etc)