Author Topic: Adaptive PID controller Microcontroller-based  (Read 1400 times)

0 Members and 1 Guest are viewing this topic.

Offline XaviPachecoTopic starter

  • Regular Contributor
  • *
  • Posts: 243
  • Country: do
Adaptive PID controller Microcontroller-based
« on: October 20, 2018, 09:47:23 pm »
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.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11859
  • Country: us
Re: Adaptive PID controller Microcontroller-based
« Reply #1 on: October 20, 2018, 09:57:27 pm »
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.
« Last Edit: October 21, 2018, 01:04:23 am by IanB »
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14445
  • Country: fr
Re: Adaptive PID controller Microcontroller-based
« Reply #2 on: October 20, 2018, 11:04:38 pm »
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
« Last Edit: October 20, 2018, 11:19:02 pm by SiliconWizard »
 

Offline XaviPachecoTopic starter

  • Regular Contributor
  • *
  • Posts: 243
  • Country: do
Re: Adaptive PID controller Microcontroller-based
« Reply #3 on: October 21, 2018, 01:25:34 am »
Not sure why you'd need an adaptive PID. A simple PID should do the trick.

Well, 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.

 
 

Offline IconicPCB

  • Super Contributor
  • ***
  • Posts: 1534
  • Country: au
Re: Adaptive PID controller Microcontroller-based
« Reply #4 on: October 21, 2018, 02:59:25 am »
Forget PID... include Feed forward and only then think of PID .
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: Adaptive PID controller Microcontroller-based
« Reply #5 on: October 21, 2018, 08:58:52 am »
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 it

For 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 rpm
 And 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.
 

Offline bson

  • Supporter
  • ****
  • Posts: 2269
  • Country: us
Re: Adaptive PID controller Microcontroller-based
« Reply #6 on: October 21, 2018, 11:31:20 am »
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.
Sounds like you should make a serious attempt to understand what the MATLAB software actually does.
 

Offline max_torque

  • Super Contributor
  • ***
  • Posts: 1275
  • Country: gb
    • bitdynamics
Re: Adaptive PID controller Microcontroller-based
« Reply #7 on: October 21, 2018, 01:04:16 pm »
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)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf