speed control and position control?

control and position control

  • Pid controller problem

    Votes: 2 40.0%
  • position with optical encoder

    Votes: 3 60.0%

  • Total voters
    5
good day all the automation engineers in the forum.
i am new to this forum and a plc beginner.

i have a project to work on, which i have to control the speed of 12volt DC motor and its position with an optical encoder with two channel. i have H-bridge.
component:-

1. wago 750-842 plc
2. aslong 12volt dc
3. optical encoder
4. H-bridge.

i know many instruction i have read on the internet said i have to use pid.
how do i calculate the integral and differentiation of the pid. is there any standard formula in plc to calculate all these function.

or if there is any other way of doing this, please i will love to know that.
 
There is no easy calculation for PID variables. Look up "ziegler nichols" for one that will *probably* work. That particular method is not popular in some industries as it has a tendency to do bad things to the process equipment. It relies on making the process unstable, which can result in a big boom if its say a chemical plant. For a 12V DC motor, its probably fine.

Wikipedia and google should get you a few different methods.

These threads are in my bookmarks folder, so are probably helpful to start
http://www.plctalk.net/qanda/showthread.php?t=11242
http://www.plctalk.net/qanda/showthread.php?s=&threadid=11969
 
thanks Chris for the link,

i will look them up.
what i really wanted to know how to input integral formula and differentiation is structure test. the below pid is what i have created before but i am not getting the require result. there is always error of maximum 10. but it does not do the ramping.

so i want to know how to input integra fomula into the sequential structure test.


(* IN is the error signal, used as the input for the PID function *)
(* OUT is the output of the PID controller *)
(* x_0, x_1, x_2, y_0 and y1 are variables to retain previous states *)
(* min_v and max_v are values used to limit the output *)
(* KP, KI and KD are the PID constants *)
(* Note that for proper operation it is essential to have the time *)
(* between two calculations fixed. *)
x_2 := x_1;
x_1 := x_0;
x_0 := IN;
y_1 := y_0;
y_0 := y_1 + (KP*(x_0 – x_1) + KI*x_0 + KD*(x_0 – 2*x_1 + x_2))/1000;
(* limit the PID controller between min_v and max_v *)
IF y_0 < min_v THEN
y_0 := min_v;
END_IF;
IF y_0 > max_v THEN
y_0 := max_v;
END_IF;
 
greatfa2013 said:
i have a project to work on, which i have to control the speed of 12volt DC motor and its position with an optical encoder with two channel. i have H-bridge.
component:-
How are you going to set the initial position. Usually encoders have a Z pulse that is used for "homing"

how do i calculate the integral and differentiation of the pid. is there any standard formula in plc to calculate all these function.
There is no standard way but there are formulas for calculating the PID gains provide you know the gain of the motor and load and its inertia.
I use a technique called pole placement. See page 1/30 in my example below.

y_0 := y_1 + (KP*(x_0 – x_1) + KI*x_0 + KD*(x_0 – 2*x_1 + x_2))/1000;
You haven't scaled the KI and KD gains to account for the scan time.

there is always error of maximum 10. but it does not do the ramping.
What is 10? 10 what? mm? m?
The target generator or motion profile generator is the hardest part of making a good motion controller.

Chris Hasler said:
Look up "ziegler nichols" for one that will *probably* work.
NOOOO!!!!! Not for motion control. Why do people think Z-N will work on any system? The mention of Z-N should be a crime. In motion control we usually don't want any over shoot and settling times must be as short as possible.

KalleOlsen said:
There's also at least one PID in there.
greatfa2013's PID is fine once he scales the KI and KD gains for the sample time.

http://ctms.engin.umich.edu/CTMS/index.php?example=MotorSpeed&section=SystemModeling
http://ctms.engin.umich.edu/CTMS/index.php?example=MotorPosition&section=ControlPID
This is how I would do the simulations above. My calculations are much more detailed and provide a much better understanding if you can wade through the math.
http://deltamotion.com/peter/Mathcad/Mathcad - DC Motor Velocity.pdf

Units are important.
Controlling a small motor with a PLC is difficult. Sample times are not even and not fast enough.
You should use floating point or 32 bit ints ( DINTs ).
Are you controlling the current directly using voltage like in the links? In this case you are controlling torque.

This must be a school project.
 
thanks
How are you going to set the initial position. Usually encoders have a Z pulse that is used for "homing"
First thanks for the break done of your question, your assistance and your time. when you say initial position did you mean the distance position or just the speed setpoint. for the position control, i have not be able to figure that out? but if you mean the speed, i have a set point which is from the input and this setpoint-motorspeedis my error. the IN of the PID is equal to error

There is no standard way but there are formulas for calculating the PID gains provide you know the gain of the motor and load and its inertia.
I use a technique called pole placement. See page 1/30 in my example below.
Okay, i will check that up to see how the formulas work, but the bad part of it is that, how will i know the motor gain and its inertia when there is not datasheet for the motor. i have try to find the datasheet of aslong 12v dc motor online, but could not see anyone.


You haven't scaled the KI and KD gains to account for the scan time.
nope, i have done that, i only scaled the setpoint and the output of the pid. how will i scale the KD and KI?


What is 10? 10 what? mm? m?
i am not sure of the 10 you mean.

The target generator or motion profile generator is the hardest part of making a good motion controller.


NOOOO!!!!! Not for motion control. Why do people think Z-N will work on any system? The mention of Z-N should be a crime. In motion control we usually don't want any over shoot and settling times must be as short as possible.


greatfa2013's PID is fine once he scales the KI and KD gains for the sample time.

http://ctms.engin.umich.edu/CTMS/index.php?example=MotorSpeed&section=SystemModeling
http://ctms.engin.umich.edu/CTMS/index.php?example=MotorPosition&section=ControlPID
This is how I would do the simulations above. My calculations are much more detailed and provide a much better understanding if you can wade through the math.
http://deltamotion.com/peter/Mathcad/Mathcad - DC Motor Velocity.pdf

Units are important.
Controlling a small motor with a PLC is difficult. Sample times are not even and not fast enough.
You should use floating point or 32 bit ints ( DINTs ).
Are you controlling the current directly using voltage like in the links? In this case you are controlling torque.

This must be a school project.
yes it is a school project and i use DINT as my data type.

also i have to control position

o_O just checked through your calculation on the pdf link, that will be hard for me to follow:teacher:
 
Homing and the z pulse is used to set the initial position for position control. The motion controller must know where it is before it can know where to go. The only other solution is to run the motor into a hard stop and then set the position. This works if you know the equipment won't break.

If you estimate the gain and time constant or bandwidth for the motor and load that is enough. The time constant is usually in the fraction of a second range. The gain is speed/control output.
The formulas for calculating the PID gains for position control is on page 1/10. The trick is estimating the gain and time constant or bandwidth.

http://deltamotion.com/peter/Mathcad/Mathcad - t1p1 pid mrplc.pdf
This is a simpler example and I am doing the PID just like your example above but notice that I multiplied KI by the sample time and divide KD by the sample time, T. This keeps the units consistent. It also means KI and KD don't need to be adjusted if the scan time changes. Your equation above is fine if you multiply KI by the scan time and divide KD by the scan time.

You mentioned an error of 10 in your second post. You didn't make it clear whether you are doing speed or position control. 10 what? Millimeters ? Millimeters/second?

Position control is harder than velocity control.
Who chose this project?
You have an uphill battle. I will help though.

You do understand Laplace transforms don't you?
What PLC are you using? I am assuming a Siemens. If so use floats instead of DINTS for most of the calculations if you can.
 
What PLC are you using? I am assuming a Siemens. If so use floats instead of DINTS for most of the calculations if you can.

If you are using a Siemens PID, just let the PLC do all the calculations for the PID. There is a link on youtube to handle PID.

But for motor control there are technology blocks that do all that stuff for you, no PID involved assuming you just want to move to a position at a certain speed.

Finally there are load of sample projects on the Siemens website for motor control.
 
If you are using a Siemens PID, just let the PLC do all the calculations for the PID. There is a link on youtube to handle PID.
No,
Code:
y_0 := y_1 + (KP*(x_0 – x_1) + KI*T*x_0 + (KD/T)*(x_0 – 2*x_1 + x_2))/1000;
[/code]
Is a good PID for motion control. This equation needs some refinements but it is a good start. The PIDs that come with PLCs are often lame. Then have round of issues, output saturation issues and definitely integrator windup issues.

However, greatfa2013 will need to modify his PID to get it closer to perfect starting with the removal of the /1000 before adding on to y_1. y_0 should be scaled later just before output so resolution isn't lost.
What happens if result for
Code:
 (KP*(x_0 – x_1) + KI*T*x_0 + (KD/T)*(x_0 – 2*x_1 + x_2))
is 999? or 499? The control output will not windup correctly.
Also, if greatfa2013 is using a Siemens PLC he should use shift left and shift rights. Shift rights are much faster than divides when using DINTs.

Diameter157, I agree there are tools that would make this project much easier. Why not insert a motion control card in the PLC and be 99% done? We don't know why greatfa2013 is doing this project. Is a a project for a PLC class or is it a project for a motion control class.
 
How are you going to set the initial position. Usually encoders have a Z pulse that is used for "homing"
We are going to make use of a 5volt optical encoder with no name and datasheet which was giving to us by the school.


There is no standard way but there are formulas for calculating the PID gains provide you know the gain of the motor and load and its inertia.
That is the problem, i dont know the gain of the motor because there is no datasheet for it, all i know about the motor is that it is a 12 volt DC and its name is Aslong. i have try to find the datasheet but could not find one.
I use a technique called pole placement. See page 1/30 in my example below.


You haven't scaled the KI and KD gains to account for the scan time.
That is what i dont know, how do i scale the KI and KD? i only assume the KI and KD.


What is 10? 10 what? mm? m?
The target generator or motion profile generator is the hardest part of making a good motion controller.
i mean 10rpm which is for the speed error




Are you controlling the current directly using voltage like in the links? In this case you are controlling torque.
i dont understand this question,



Homing and the z pulse is used to set the initial position for position control. The motion controller must know where it is before it can know where to go. The only other solution is to run the motor into a hard stop and then set the position. This works if you know the equipment won't break. {/QUOTE] i am sure it wont break and secondly it just for presentation and demonstration for one day. if the hard stop will be be easy to work with, i will suggest to go with that. during the project defend, i can tell why i used the method and give the setback of the method and possible recommendation.

If you estimate the gain and time constant or bandwidth for the motor and load that is enough. The time constant is usually in the fraction of a second range. The gain is speed/control output.
The formulas for calculating the PID gains for position control is on page 1/10. The trick is estimating the gain and time constant or bandwidth.
i assume the KP since the higher the KP the lower the oscillation, you will see a graphic of the pid in FBD attached to this post

http://deltamotion.com/peter/Mathcad/Mathcad - t1p1 pid mrplc.pdf
This is a simpler example and I am doing the PID just like your example above but notice that I multiplied KI by the sample time and divide KD by the sample time, T. This keeps the units consistent. It also means KI and KD don't need to be adjusted if the scan time changes. Your equation above is fine if you multiply KI by the scan time and divide KD by the scan time.
i will try this formula out now and give you a feedback my teacher.

You mentioned an error of 10 in your second post. You didn't make it clear whether you are doing speed or position control. 10 what? Millimeters ? Millimeters/second?
it is for the speed control which is 10rpm.

Position control is harder than velocity control.
Who chose this project?
You have an uphill battle. I will help though.
it is my second year project which is 9 credit

You do understand Laplace transforms don't you?
What PLC are you using? I am assuming a Siemens. If so use floats instead of DINTS for most of the calculations if you can.
i am using codesys and wago plc. For the laplace transformation, i am not too good at that. but i am ready to learn

thanks for the time and your patient so far in doing what you know how to do best, i am learning and beginning to understand stuff which i didnt know before.

pid.PNG out.PNG input.PNG
 
If you are using a Siemens PID, just let the PLC do all the calculations for the PID. There is a link on youtube to handle PID.
No,
Code:
y_0 := y_1 + (KP*(x_0 – x_1) + KI*T*x_0 + (KD/T)*(x_0 – 2*x_1 + x_2))/1000;
[/code]

should the T be a a constant DINT or TIME data type just like the kp?

Is a good PID for motion control. This equation needs some refinements but it is a good start. The PIDs that come with PLCs are often lame. Then have round of issues, output saturation issues and definitely integrator windup issues.

However, greatfa2013 will need to modify his PID to get it closer to perfect starting with the removal of the /1000 before adding on to y_1. y_0 should be scaled later just before output so resolution isn't lost.
What happens if result for
Code:
 (KP*(x_0 – x_1) + KI*T*x_0 + (KD/T)*(x_0 – 2*x_1 + x_2))
is 999? or 499? The control output will not windup correctly.
Also, if greatfa2013 is using a Siemens PLC he should use shift left and shift rights. Shift rights are much faster than divides when using DINTs.

Diameter157, I agree there are tools that would make this project much easier. Why not insert a motion control card in the PLC and be 99% done? We don't know why greatfa2013 is doing this project. Is a a project for a PLC class or is it a project for a motion control class.

atually the project is for my second year which i have to demonstrate, only what was giving to us was a aslong 12v motor with optical encoder, wago 750-842 plc, H-Bridge. the plc rogram is codesys. it worth 9 credit


what do you mean 9999 or 499?
 
I see from the pictures you already have a PID motion block. Does the motion block use the PID formula you previously posted?
It is not good to filter the inputs. They cause phase lag and make closed loop control difficult.
What is your update rate? The smaller the better. 10 milliseconds is too long for position control.
How many counts do you get per revolution?
Think in terms of revolutions per second for now.
The T in the modified PID is the time between updates. This is usually a number like 0.001 seconds but it may be .010 seconds in your case. Like I said, use floats or you will spend more time scaling numbers than getting actual work done.
Does the Wago have timed interrupts? Can you put the closed loop code in an interrupt?
If not then how can you have constant time intervals between updates?

about the 499 or 999. What if the output is 999. If you divided it by 1000 to you get 0?
Please use floats.

I see in the pictures an actual speed. Where does that come from?
 
NOOOO!!!!! Not for motion control. Why do people think Z-N will work on any system? The mention of Z-N should be a crime. In motion control we usually don't want any over shoot and settling times must be as short as possible.

Because its obviously a school project, and having something that kind of works is better than nothing? I did mention that it can do bad things, depending on what the process is.

As long as the equipment won't break, and no one is in line to get injured, it often best to let people see things go horribly wrong and/or not quite work properly :)



I like Z-N, it works really well for a specific PID doing a specific process that requires something very like a Z-N tuned PID. Add in its easy, and well option no 2 for PID tuning. Option no 1 is TIA Portal auto tuning. :whistle: I lucked out and have a process it works on, and won't blow up when you try to tune it.
 
I see from the pictures you already have a PID motion block. Does the motion block use the PID formula you previously posted?
Yes
It is not good to filter the inputs. They cause phase lag and make closed loop control difficult.
okay i will make my datatype now to become float.

What is your update rate? The smaller the better. 10 milliseconds is too long for position control.
i thing i make use of 200miliseconds
How many counts do you get per revolution?
Think in terms of revolutions per second for now.
i dont understand how to check on that or maybe i dont understand your question.
The T in the modified PID is the time between updates. This is usually a number like 0.001 seconds but it may be .010 seconds in your case. Like I said, use floats or you will spend more time scaling numbers than getting actual work done.
i try your modified pid, it does not work for me or maybe i am not doing the right thing. i made the T to be a DINT type and try it out with 5 as a number, it does not regulate anything, only output the maximum number of the scaling.

Does the Wago have timed interrupts? Can you put the closed loop code in an interrupt?
If not then how can you have constant time intervals between updates?
What did you mean by interrupt?


about the 499 or 999. What if the output is 999. If you divided it by 1000 to you get 0?
Please use floats.

I see in the pictures an actual speed. Where does that come from?
the actual speed should be the econder feedback from the motor which measure the actual speed of the motor
 

Similar Topics

I have a application where a servo move left and right and in between there are 4 station at each station having sensor. When servo move form one...
5
Replies
1,744
Views
Does anybody have a sample program of a Centrifuge Scroll speed control? I only have a normal PID function block but I have zero experience with...
1
Replies
381
Views
Hello, I’m working on a speed control application with an Altivar 312HU30N4 drive. My goal is: Send a speed reference to the drive using a...
1
Replies
479
Views
I am looking at a servo motor controlling slack in a web-handling application. It looks like only one move for the drive exists in the program, a...
7
Replies
739
Views
I'm experiencing a real head-scratcher here. Over the last several years I have successfully integrated the control of several ABB VFDs with our...
0
Replies
713
Views
Top