Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   PID Loops (http://www.chiefdelphi.com/forums/showthread.php?t=93498)

Ether 13-03-2011 17:43

Re: PID Loops
 
Quote:

Originally Posted by PriyankP (Post 1038699)
So (m*currentPotValue+b) doesn't have to be within -1 to +1?

"m" and "b" are constants which you need to calculate and set so that the operating range of the process variable corresponds to the desired operating range of the joystick, be it -1 to +1 or 0 to +1 or whatever.


Quote:

And what exactly does it, the process variable, do?
Read this post, then ask if it's not clear.



PriyankP 13-03-2011 17:59

Re: PID Loops
 
Quote:

Originally Posted by Ether (Post 1038703)
"m" and "b" are constants which you need to calculate and set so that the operating range of the process variable corresponds to the desired operating range of the joystick, be it -1 to +1 or 0 to +1 or whatever.




Read this post, then ask if it's not clear.


Am I correct about this:

JoyStickYaxis is +1 (operator input)
currentPotValue is 550 (min is 300 and max is 600)

(m*(currentPotValue+b)) = ( (1/150)*(550-450) )
m is 1/150 and b is -450 so that the number is always between -1 and 1
error = 1 - 0.6666;
MotorOutput = k * 0.3333 and say k is 0.75 then the output becomes 0.25
of course, k needs to be adjusted so the error is as close to 0 as possible and/or the arm doesn't oscillate
Good so far? Or did I make a mistake somewhere?

EDIT: I have a feeling I did something wrong

Ether 13-03-2011 18:41

Re: PID Loops
 
Quote:

Originally Posted by PriyankP (Post 1038713)
JoyStickYaxis is +1 (operator input)
currentPotValue is 550 (min is 300 and max is 600)

(m*(currentPotValue+b)) = ( (1/150)*(550-450) )

m is 1/150 and b is -450 so that the number is always between -1 and 1

That should work, although it's a little different from the standard slope/intercept form that I posted.





PriyankP 13-03-2011 18:55

Re: PID Loops
 
Quote:

Originally Posted by Ether (Post 1038727)
That should work, although it's a little different from the standard slope/intercept form that I posted.




I think there is something wrong with that pseudo code because if the Yaxis is not touched, a value of 0 is being outputted, the arm will still move. How can I fix that? Do I need to do something like 'if the Yaxis is between -0.05 and +0.05, stop the arm, else run the code' ?

Ether 13-03-2011 19:04

Re: PID Loops
 
Quote:

Originally Posted by PriyankP (Post 1038734)
I think there is something wrong with that pseudo code because if the Yaxis is not touched, a value of 0 is being outputted, the arm will still move. How can I fix that? Do I need to do something like 'if the Yaxis is between -0.05 and +0.05, stop the arm, else run the code' ?

The code is correct. Perhaps you misunderstand what a closed-loop position controller does.

What you have implemented is a closed-loop position controller. The arm will move to a position commanded by the joystick, and stay there as long as the joystick continues to command that position. If you let go of the joystick, the joystick will return to its rest position and will be commanding "go to position zero", which corresponds to a reading of 450 on your pot. So that is where the arm will go.

If that is not the behavior you want, then you need to articulate more clearly what you are trying to accomplish.

For example, if you want the controller to hold the arm in a given position once you have moved it to where you want it to be with the joystick, then you could do something like the following: change the code so that it uses the joystick value for the setpoint only if Button1 is pressed. When Button1 is released, the joystick is ignored and the last joystick value continues to be used for the setpoint. So the driver holds Button1 pressed while he is moving the joystick to put the arm in position, and once the arm is where he wants it, he releases Button1, and the controller will hold the arm at that position, and he can let go of the joystick. When he wants to change the arm position, he holds Button1 pressed and uses the joystick to move the arm to the new position, and then releases Button1.

Or perhaps there is a small set of pre-defined positions from among which you would like to be able to select. For example: floor, level1, level2, level3. You could program 4 buttons so that each button changes the setpoint to the necessary value. The closed-loop controller then moves the arm to that setpoint. In this case, you could dispense with the "m" and "b" constants, and just assign a pot-value setpoint to each of the buttons.





PriyankP 13-03-2011 19:52

Re: PID Loops
 
Quote:

Originally Posted by Ether (Post 1038739)
The code is correct. Perhaps you misunderstand what a closed-loop position controller does.

What you have implemented is a closed-loop position controller. The arm will move to a position commanded by the joystick, and stay there as long as the joystick continues to command that position. If you let go of the joystick, the joystick will return to its rest position and will be commanding "go to position zero", which corresponds to a reading of 450 on your pot. So that is where the arm will go.

If that is not the behavior you want, then you need to articulate more clearly what you are trying to accomplish.

For example, if you want the controller to hold the arm in a given position once you have moved it to where you want it to be with the joystick, then you could do something like the following: change the code so that it uses the joystick value for the setpoint only if Button1 is pressed. When Button1 is released, the joystick is ignored and the last joystick value continues to be used for the setpoint. So the driver holds Button1 pressed while he is moving the joystick to put the arm in position, and once the arm is where he wants it, he releases Button1, and the controller will hold the arm at that position, and he can let go of the joystick. When he wants to change the arm position, he holds Button1 pressed and uses the joystick to move the arm to the new position, and then releases Button1.

Or perhaps there is a small set of pre-defined positions from among which you would like to be able to select. For example: floor, level1, level2, level3. You could program 4 buttons so that each button changes the setpoint to the necessary value. The closed-loop controller then moves the arm to that setpoint. In this case, you could dispense with the "m" and "b" constants, and just assign a pot-value setpoint to each of the buttons.




Oh I see, regardless of the practical usefulness on the robot, it was worth learning something new. :)

I already have the four presets that the operator can use, but the only difference is that I'm only using a P loop to reach that target. It works beautifully and doesn't oscillate. The only drawback is that its only accurate to +-5 pot values. But I compensate by increasing the desired value by 5 pot increments that way it gets as close to the target as possible going one way... I didn't really implement I and D because for one, I didn't really know how to use them and secondly, I didn't really have enough time to learn and implement it on the robot to yield some positive results.

Thank you!

Alan Anderson 13-03-2011 20:01

Re: PID Loops
 
Quote:

Originally Posted by Greg McKaskle (Post 1038460)
By the way, we are considering including both forms and a number of additional control tools in the future. Any feedback or requests?

Useful additions might be output limits and perhaps rate change limits.

Joe Ross 14-03-2011 15:01

Re: PID Loops
 
Quote:

Originally Posted by Alan Anderson (Post 1038778)
Useful additions might be output limits and perhaps rate change limits.

The advanced PID VI has output limits. There is also a rate limiter VI in the PID library.


All times are GMT -5. The time now is 23:40.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi