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
Attachments:
PID rev2.vi ‏1143 KB
PID rev1.vi ‏1158 KB

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.

Similar Messages

  • Mult-channel PID control using PID Toolkit

    I am controlling the light level in six locations (zones) using light sensors, dimmable ballasts (which respond to a 2 to 10 VDC signal) and the PID toolkit.  In my VI, I loop through 6 times (once for each zone) to control the light levels.  I use the simple PID.vi to determine the next setpoint for the dimmable ballast on the lights.  My problem is as follows, I think:
    The PID algorithm uses past response and the current difference between the measured variable and the setpoint to calculate the next setpoint.  If my understanding is correct, then I am confusing the PID algorithm by calling it with 6 different data sets.  It is almost as if I need 6 separate PID functions, one for each zone. 
    Perhaps I am wrong about the operation of the PID algorithm.  Can someone straighten me out?
    Attached is a snapshot of the VI.  The FOR loop goes from 1 to 6, that is, once for each sensor zone.
    Message Edited by rgentry on 04-29-2007 09:11 PM
    Attachments:
    temp.jpg ‏92 KB

    rgentry,
    The PID has two modes of operation: Single Channel and Muti-channel. The way you developed your algorithm, you are using single channel algorithm with multiple setpoint and variables. This will not work properly since LV will not keep the internal states correct for each channel.
    To fix this, it is pretty simple. Remove the For Loop and provide the whole 1D array to the PID.vi. This will enable the "multi-channel" mode and every time you call your VI, it will keep the internal states for each channel, as if you had 6 different PIDs in parallel. Notice that the interpolation also will work the same way, you just need to remove the build array primitive.
    Hope this helps!
    Barp - Control and Simulation Group - LabVIEW R&D - National Instruments

  • Throttle body PID control using pulse width modulation

    Hello all,
    I am trying to do a PID control for a throttle body (using pulse width modulation) for a set value of feedback voltage. The process variable is the pulse width duty cycle. The throttle body is expected to be fully open at a feedback voltage of 5V and pulse width duty cycle of 42.5%.  When I use the highlight execution using the attached file, I can see the throttle body fully open (the values observed are: PID output 42.5 %, feedback voltage approximately 4.7V). However, when the highlight execution is unclicked, the throttle body flutters in the closed condition (still PID output 42.5%, feedback voltage approximately 0.9 V). Can any one please help by suggesting any modification to this attached file to make this throttle body respond to the set value of feedback voltage.
    Many thanks 
    Ajith
    Attachments:
    Throttle body control using PWM technique - PID.vi ‏525 KB

    How did you determine your P, I, and D gains? If you have not tuned your controller, you'll get poor performance. Running with execution highlighting will slow down the execution, which will change the effect of the gains. I would start with pure proportional control (I and D = 0) with a small proportional gain, and see if it responds in approximately the way you want. If so, then your code is probably correct, and you just need to do a full tuning to get good performance. There are many resources available on the web, on this forum and elsewhere, for PID tuning. Note that since your code uses a simple PID example, and not the one from the PID toolkit, the gains do not have the units that are used in many tutorials so you'll have to correct the calculations to compensate.

  • PID control using LabView 6i

    Hallo,
    We use NI PCI 6024E Card in PC with Celeron 1,1 GHz, 256 MB SDRAM,
    The Card has 16 Analog input and 2 analog output. I plan to use this card as
    a PID controller.
    Our LabView contains the modules for motions and all the add ons to.
    The question is, whether the PCI 6024E is capable to do controling, since we
    have to
    control the velocity of 2 mm/s with scan rate 50 S/s.
    thanks

    I can tell you that using a PC of similar horsepower under XP Pro and a PCI-6071E I've successfully run PID loops with sample rates of 10KS/s in 100msec bursts. At first I was seeing a fairly high rate of input buffer overflows. But when I set LabVIEW's execution priority to "High" this problem all but disappeared. (At some time in the future we plan to migrate to LabVIEW RT, which I hope will cure this problem completely.) 50S/s should be a breeze. You might want to add memory. I've got 512Meg in my machine.

  • PID control of Inverted pendulum using arduino

    Hi everyone, first of all i would not class myself as a good programmer so my code is not the best to look and i have probably made loads of mistakes.i also dont have alot of experience with labview.
    Background:
    Im using the labview arduino interface and im trying to control the angle of an inverted pendulum using a PID algorithm. the project is part of my FYP and therefore i want to try writing my own PID algo instead of using a labview PID.vi. now the code for the PID algorithm still needs work but my main question is this.
    i want to be able to control the range of pendulum angle that the control algorithm will work on. so basically i want to constantly read the angle value, then once inside a specified range the PID algo would kick in. while its not in the range the program will still run and would still be checking the angle. i was thinking of placing a case statement before and outside the PID loop to check the angle, but i think this would only work once at the start of the program. so then i taught of inserting the PID loop and the case statement inside a bigger while loop. so would this be the way to think about this or is there a better way. please all comments are welcome.
    Attachments:
    PID rev1.vi ‏673 KB

    Hi. You can use the method you suggested and it will work so long as you place both the "read angle" function and the PID algorithm inside the same loop for every iteration of the control loop. Additionally I recommend you to put your VI algorithm in a sub vi to keep your code cleaner, especially if you'll place that in a case structure. You can do it easily by selecting all of the nodes (functions) you use in your algorithm and then going to Edit->Create SubVI.
    Regards.
    Aldo
    Aldo H
    Ingenieria de Aplicaciones
    Attachments:
    Demo.png ‏16 KB

  • I have problem running the inverted pendulum trainer using NI ELVIS.

    i have a problem running the inverted pendulum trainer using NI ELVIS. While loading the NI ELVIS bypass VI it is unable to find the "enable communications bypass.vi". could anybody please attach the VI.
    I am using NI ELVIS 2
    Thanks

    The Enable Communications Bypass VI sounds like a VI that is only included with Traditional or legacy ELVIS designed to work with the first generation ELVIS unit, not the ELVIS II/II+ or myDAQ. It sounds like the inverted pendulum trainer you have is for use with ELVIS I. In the LabVIEW Loading dialog, do you see the full path for where it's looking for the VI? Can you provide that full path? If the inverted pendulum trainer is designed to work with the older ELVIS unit, there may be a newer version that supports ELVIS II.
    Donovan

  • Using lab view to control an Arduino led cube

    Has anyone used lab view to control an Arduino led cube? It seems to me that you could make a pretty awesome project out of the two.

    Hi there, I haven't done it my self but, you may find a tread at the LabVIEW Interface for Arduino Group including links to download the LabVIEW Interface for Arduino Toolkit . I think this will make the task easier. Good luck!
    Alejandro | Academic Program Engineer | National Instruments

  • I need to maintain a temperatur​e profile for my process.Ca​n i use PID control for this applicatio​n?

    Hi all,
    I need to maintain a temperature for my process.Can i use PID control vi's for this application?
    I have NI-PCI 6023E DAQ board.Should I need any other hardware components???
    Any help in this regard is highly appreciated.
    Thanks,
    radhika

    Hi,
    Thanks for your reply.
    I do have a temperature sensor and it is read by the DAQ (NI 6023E) .
    Also i have a voltage input to the program which has to be controlled in order to control the temperature.
    So , I am using a PID , the output of the PID should control the Voltage input so that the temperature is controlled.
    Can I give the  voltage input and the temperature  to the PID through the DAQ and  just use one more channel in the DAQ to get the output from the PID.Will that work???
    I am not sure why you have mentioned SC2345,SCB68.
    Thanks,
    radhika

  • Pid control motor

    I am trying to build a PID control that will be controlling two motors for a small balancing robot.  I am using an accelerometer and am unsure how to build a vi that will be used with a the arduino mega.

    What did you make your servomotors do? (I suspect it would have at least involved Proportional control, which is the first part of PID control).
    I recommend you start by learning basic PID theory (http://www.ni.com/white-paper/3782/en , or Google some lecture notes). Apply that knowledge on a single motor, to control its position via PID. I assume you're using a servomotor, so use the Encoder signal as your PID feedback.
    Then, learn how to interpret your accelerometers (Google it).
    Then, combine those to use both your accelerometer and encoder as PID feedback, to control one motor's position.
    Then, combine two motors to build your balancing robot.
    These will probably take you a few weeks. Good luck!

  • Angle error in inverted pendulum (encoder_read_ni.vi)

    Hi,
    I'm using the quanser inverted pendulum, NI ELVIS and Labview for a control engineering task, the problem I am having is the angle arm and pendulum angle are not registering the correct angle, if I move the pendulum 180 degrees it give me an amplitude of 120,000 when it should be reading from -180 to 0 degrees, I think this could be to do with the encoder I have been supplied with (maybe?!), the required encoder is Encoder_Read_ni.vi but the only encoder available to me is Encoder_Read_MX.vi, the MX encoder allows me to run the programm but I'm not obtaining the correct angles.
    Anybodys help will be greatly appriciated. 

    Hi Craig,
    Where did you obtain these VI's from? Were these developed by you or did you get the VI's on purchase of  the Inverted Pendulum (IP). You should have obtained the correct VI's that work with your Quanser IP when you purchased it. 
    There are a few links here which may give you more information on using a quanset IP with NI Elvis 
    http://www.ni.com/white-paper/7340/en 
    http://zone.ni.com/devzone/cda/epd/p/id/6383
    Supreeth.K
    Applications Engineer
    NIUK

  • PID control of Counters (PWM)

    Hello everybody!!
    I work on a closed loop PID controlled problem (Labview 8.5) and I have a couple of questions in order to make some progress!
    Firstly, I have to declare that my loop is composed of 2 AI channels (2 accelerometers), 1 AO channel (excitation channel-shaker), and 2 CO (for pulse creation PWM-controllers). The idea is very simple. When the AI (channel 1) value surpass or underpass a predetermined threshold value, then the appropriate CO should be activated in order to apply the necessary control forces and simultaneously to copy my data values of both AI channels in binary style for CPU velocity reasons! BUT, with the PID controller I want to optimize the Duty Cycle value of the pulses!
    My questions are :
    1) Why when I put Kp=Ti=Td=0 ( = run WITHOUT control) I can copy ALL the AI samples and when I start to activate the PID controller (let’s say for only Kp=0.5) I CAN’T copy ALL the AI samples? Where is my fault?
    2) About the PID vi which I use, is it correct or I should use the PID vi for ARRAYS?
    3) And finally, about the Boolean statement just before the Case Structures and the Shift Register, is it ok/necessary?
    I attach two vis, the ReadBinar .vi is used to read my binary files generated in the end of running of the Control.vi.
    Best regards
    Grigorio
    Attachments:
    Control.vi ‏277 KB
    ReadBinar.vi ‏162 KB

    Hello Zach!
    First of all, I want to thank you for your kind interest on my problem!!
    I must describe you the desired process with the Control.vi. There are two AI channels writing down the acceleration of a structure in two different points (for velocity reasons I use Binary Type storage for my data). One AO channel for structure sinusoid excitation (shaker) and two CO channels for controlling two solenoid valves with which I want to control my structure acceleration (minimize it as well and fast as possible)!!
    In order to help the description, let’s ‘cut’ the block diagram of Control.vi into three pieces (Before While Loop – Inside While Loop – After While Loop).
    In Before While Loop section, the main question is about simultaneousness. The DAQmx Start inside the Flat Sequence Structure, do you think that is necessary, ok? I want to run my experiment for 30s and to collect 6000 samples with 200 samples/s. In addition, in the CO DAQmx timing, I have set 200 samples/channel in order to be able to change the duty cycle value because of the conditions inside the While Loop. Do you think that everything in this section works well? 
    Inside the While Loop, firstly in the DAQmx Read, I have set 200 samples per Input Channel, which is also equal to the AI and AO Sampling rate! Before some days I have put there -1 and unfortunately the total written samples were less than 6000!! My main problem is how I can check all the read data without losing run velocity and simultaneous if one sample is >0 then it goes further to the first PID.vi (left solenoid valve) or if that sample is <0 then it goes further to the second PID.vi (right solenoid valve)!! When a sample has gone to a PID.vi, then I want to tune the duty cycle of the controller (PWM control) as well as possible in order to achieve the Setpoint value for the second AI channel. Are all these possible? If not, what do you suggest me?
    In addition I compare the present duty cycle value with the previous one in order to be inside a tolerance value (let’s say 0.1). Moreover, is it correct the Case Structures where I want to share the positive and negative AI samples before going to the respective PID ?
    Finally, After the While Loop, I believe that everything is OK. I just finish all the tasks.
    I have to mention that I work on a PCI-6289 and Labview 8.5.
    With best regards!
     Grigorio
    Attachments:
    Control.vi ‏288 KB
    equal within tolerance.vi ‏9 KB
    ReadBinar.vi ‏163 KB

  • I am looking to control a 4-way hydraulic solenoid valve. Do I need a PID control toolset, or can i control the system through my 16E4 daq card and scxi chasis

    I am looking to control a 4-way hydraulic solenoid valve. Do I need a PID control toolset, or can i control the system through my 16E4 daq card and scxi chasis

    I think you're asking 2 different questions.
    The PID control toolset is for using PID loops for control; it's just software.
    The DAQ card and scxi chassis are hardware. If you have the appropriate signal conditioning cards in your chassis to control/monitor your solenoid valve, then you can run a PID loop.
    I believe the simple answer is: the PID control toolset is the best way to do control, but there are simple PID VI's (even on this website) that you can download and use for simple control.
    Mark

  • PID control in a windows CE Labview application

    Hi there,
    I want to build an application that will control the temperature in some ovens, using PID control. The application will be running in a controller (or a touch panel computer) with windows CE OS. I have Labview 8.6, PID control toolkit 8.6 and Touch panel module 8.6. The problem is that the PID vi's don't seem to work in touch panel module. 
    Is there any way to implement PID control in a windows CE Labview application?  
    Thanks in advance.
    Solved!
    Go to Solution.

    I think with a timed loop you can run reasonable good timing down to 1 mSecond. I think 1 mSecond is the lower limit for non realtime systems like Windows/windows CE. And if you have the PID toolkit this will supply you with the functions you need. You do not need an extra CE PID toolkit. This because  the touch panel module run under your standard Labview environment. But I do not know if all the functions in the PID tool like fuzzy logic are compatible with CE. Have you also considered Windows Embedded as OS for your module. With windows Embedded you can run standard Labview built exe files
    Both Windows Embedded, and XP Embedded can be trailed
    http://www.microsoft.com/windowsembedded/en-us/products/westandard/default.mspx
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)

  • Steps to create vi file for PID control in 8.0 pro without specific PID addons.

    Per my other posts, I am testing a friend's software to see if this is what we would like to use.  I would prefer to use their software for our initial work to help offset the cost of the software.  Problem is their software is 8.0 pro without the extra PID stuff.  I am curious how one gets started creating a custom PID algorithm to be used in series between an input and an output.  I have viewed several tutorials but all seem to simply point at the PID toolkit that is not availalbe to me right now.  I realize it might be more work to create one but probably the only option at this point. 
    To simply the process, lets just compare a single input and output where the software will control the output to obtain to desired input.  in  tutorial, I was following right along until the PID loop was added and that seems to be just a drop and go type of deal in which would rarely apply to a real work application. I am simply trying to learn how PID systems are written into the block diagrams.  
    Hopefully my question makes sense.  

    asdfs wrote:
    Per my other posts, I am testing a friend's software to see if this is what we would like to use.  I would prefer to use their software for our initial work to help offset the cost of the software.  Problem is their software is 8.0 pro without the extra PID stuff.  I am curious how one gets started creating a custom PID algorithm to be used in series between an input and an output.  I have viewed several tutorials but all seem to simply point at the PID toolkit that is not availalbe to me right now.  I realize it might be more work to create one but probably the only option at this point. 
    To simply the process, lets just compare a single input and output where the software will control the output to obtain to desired input.  in  tutorial, I was following right along until the PID loop was added and that seems to be just a drop and go type of deal in which would rarely apply to a real work application. I am simply trying to learn how PID systems are written into the block diagrams.  
    Hopefully my question makes sense.  
    Take a look at the PID Control Toolkit User Manual . It clearly defines the math used and there is absolutely nothing stoping you from writing that code yourself.
    What you will not get by doing it yourself is the auto-tuning as well as all of the supporting and helper sub-VI along with the polymorphic versions that will support arrays of PIDs.
    If you write it yourself and it work good please post up your version for others to review or use.
    Have fun,
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How to apply notch filter in the PID control

    Dear all,
    I am using PID control in my positioning stage but the output is every noisy with some fixed frequencies(30,50,150Hz). I want to add a notch filter to take off those noise. However, I do not know how to apply the notch filter to the PID module. Could anyone tell me how and show me example if you have?
    Thanks
    best
    Attachments:
    PID_notch filter.png ‏21 KB
    PID_notch filter.png ‏21 KB

    Hi LYnn,
    I am sorry for my late reply. My stage is driven by a voice coil actuator (VCA). The VCA as a resolution of 1 um and range of 6 mm. The NF of the stage does shift when the load is changing. Do you have any advice for controlling such kind of stage?
    BTW, as far as I see, the control frequency is determined in the DAQ Assistant settings and its value is equal to "Sampling rate"/"Samples to read", am I right?
    Thanks
    best
    Attachments:
    VCA stage.png ‏160 KB

Maybe you are looking for

  • I need help with a backup file that was deleted and now undeleted from my hard drive

    Last month (May 6, 2011), I was updating my iPod Touch 4G with the new software that came out. I always make a backup of my iPod's data before I update it. While my iPod was updating I left my iPod and computer alone and was doing things around the h

  • Binding To a Propery - Inside an ArrayCollection Problem

    I'm trying to make an editor where users can select an editable item from a list (each item in the list might be a different type of editable object). When the user selects an item from the list its editable properties show up in a panel with a suita

  • DB13 error for checkdatabase job

    Hi all, Our system has been working fine for db13 autoscheduled jobs , but suddenly from last 4 weeks checkdb and other jobs are failing , though our backups through DB13 is working fine , but other jobs are failing . below are logs for your referenc

  • My Apple ID password will not work for downloads + pop-up issues

    I have an Apple ID and password, yet it will not work to log into ICloud or for updates on my Mac. My computer is only 1.5 years old. Also, I continually get a pop-up that I need to create a password for Safari, but if I do not hit "cancel" I will ha

  • Inporting Flash Objects

    Hi, I've imported a flash file into dreamweaver, got it working great no problems. The Problem i am having though is that the flash object (550 x 550px) doesnt position flush to the edge of the browser window, theres a white border to the left and at