LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Inverted pendulum PID control using Arduino

Hi everyone, I still have a ongoing problem trying to control the inverted pendulum using a self built PID algorithm. The problem is not with the algorithm itself but the program around the algorithm. Anyway this is what IM trying to do.

 

 I want to be able to constantly read the angle of the pendulum, which will be done using the arduino read analog vi. Now the pendulum angle will be represented as a voltage. This is all fine. Now:

 

1. If the angle(voltage) is inside a specified correction range I want the PID algorithm to turn on  and let the algorithm work on the error as it would normally (while updating the angle(voltage) reading after each PID loop.

2. Also when this angle(voltage) goes back outside the specific correction range I would like the PID algorithm to STOP, however at this stage I would like the overall program to continue running and keep checking the angle(voltage) to see if its value comes back into range and if it does switch back again to the PID algorithm.

 

I don't have great knowledge of labview and IM still learning about it. I have included my program so far below. rev2 is the higher layer and the PID algorithm itself is rev1. 

 

I have tested my program with the arduino but what happens is this:

 

the checking of the angle range works but once the value is true i.e. Angle is inside correction range , the angle value moves into the PID algorithm however is never updated at this stage and I can not get back out of the PID while loop.

 

Sorry if what I have been saying does not make sense and was hard to follow, however I have include my code below for help. And I would really appreciate help on this and what I could look at in order to get it working all comments are very welcome.

Thanks

Fran

Download All
0 Kudos
Message 1 of 6
(6,725 Views)

ladysman217f wrote:

the checking of the angle range works but once the value is true i.e. Angle is inside correction range , the angle value moves into the PID algorithm however is never updated at this stage and I can not get back out of the PID while loop.


That's a very accurate description of the problem with your code - enough so that I think you could figure out how to solve it.  You might find it helpful to run your code with execution highlighting enabled.  Remember that values at loop tunnels never change.  At the moment you take one measurement of the angle, feed it into the PID loop, and then the PID continues to run in its own loop without ever measuring the angle again.  You either need to put the measurement and the PID algorithm in the same loop; you could do this by making the PID run only once per call, or by moving the angle measurement into the loop that implements the algorithm.

0 Kudos
Message 2 of 6
(6,717 Views)

Hi nathand, thanks very much for the reply. Oh well IM not that great at programming anyway but your after putting me on the right track and I think I have something to try now. So I will try it and post back to this post if I still need help. Yes that execution highlighting is a great help I use it all the time. Also is there any guides as to how I can make my code easier to follow and neater like some basic rules or something because at the moment as u probably have seen my PID algorithm is all over the place. Even using the clean up diagram function does not do a great job!. No disrespect ni.

 

Thanks very much again for the help.

Regards

Fran

0 Kudos
Message 3 of 6
(6,713 Views)

Look for the Style Guidelines and Style Checklist in the LabVIEW help, there are good suggestions there.  Some of it comes from experience.  Keep your wires as straight as possible; I rearrange code regularly in order to keep it neat.

0 Kudos
Message 4 of 6
(6,711 Views)

Thanks, ill have a look at that too.

 

Regards

0 Kudos
Message 5 of 6
(6,707 Views)

HI i someone can help me because i have problems in implemente PID for to control DC motor via arduino, i make my ow algorithm in labview (pid) but with arduino 

i don't find any document thank you lotof

0 Kudos
Message 6 of 6
(5,998 Views)