03-24-2019 02:24 PM
Hello,
My name is Mike, and today I'm reaching here for some help with my own project.
Shortly, it's a small buggy car with 4 engines with encoder.(But right now I'm trying to make a program just for one engine ) and I'm dealing with the PID regulator. And here I would ask you for advice. I made vi with PWM signal for controlling speed (duty cycle) and one switch for changing direction. Everything works with H-bridge just fine. But I wanted to move my project to higher level and implement the PID. After few days of trying I have to admit, I need help. I tried few options, Google- YouTube it, some pdf sheets etc, I burned one H-bridge (my stupid mistake).. But the real problem is the "program" - instructions/output after the PID. (On picture "mycarvi" -> painted square 1). My plan was to take RPM, put it into the PID and in the end it will decide if, let's say terrain will change, hill, or another change (you will try stop wheel by your hand) the PID will register this change and automatically rise power and try to have the same RPM like it is on input. If output RPM = input RPM nothing will change, car is moving normally. I'm including H-bridge picture what I'm using. There is ENA(to open motor1), IN1 and IN2. I think bc of this, i need program which i can implement with this bridge and inputs. I tried something on my own (maybe all wrong) pic "mycarvi2" i but in the end I´m not able to make it work. At least I´m trying.I found some PID with graph, but i cannot connect outuput and the PWM to make it all work.
Maybe it sound like easy math problem with comparison..but somehow I'm not able to make it run. I'll be glad if someone can help me with the output from the PID to make sure program is fine and after that I can play with running 2-4 engines. And of course, if somebody is able to fix my vi, please be kind and explain that to me in short message. I wanna know how it works. I like myrio and I´am excited about it.
Maybe it will help I´m using these Dcmotors: Dcmotor
Thank you for any answer.
Solved! Go to Solution.
03-24-2019 04:13 PM
Hi Mike,
are you sure about using default PID gains and output range?
Will there ever be negative PWM values? (And how should it look like?)
I would just output the PWM value from PID and use the myRIO function you used in your first image.
03-24-2019 05:16 PM
Hello GerdW, as first, thank you for looking at this and for your answer.
-i just read few tutorials and it should work with this values, right? (gains) ,at least somehow and after that i can either calculate them or just try and try and improve them, true? And output range, well, I´m not, it was default, i read that AO cannot give more than +/-10V , so it should be lets say -10 to 10 right? (or 0-10). But i did not know what output i should use so i was hoping it will work with these values.
- Well, in the beginning i had duty cycle and PWM in scale -100 (back) to 100 (forward) , 0 was "engines off". But i wanted to have simple switch and 0-100 scale (or another values, RPM are never more than 75 so i had this scale) for moving. It does´t matter for me if duty cycle gonna have -100 to 100 scale or i´ll have switch. Whatever is easier to do and implement.
-I´m sorry, but I´m not sure what do you mean.Use what function exactly? ..Because i tried that pic1 (mycarVI) program (directly connect PID output to PMW function) and it did not work and it does not work right now like I´m trying. 😉
Mike
03-25-2019 04:33 AM - edited 03-25-2019 04:37 AM
Hi Mike,
Well, in the beginning i had duty cycle and PWM in scale -100 (back) to 100 (forward)
PWM is only defined between 0% and 100%. It's senseless to set an output range starting at -100…
Because i tried that pic1 (mycarVI) program (directly connect PID output to PMW function) and it did not work and it does not work right now like I´m trying.
In "skuskaencodera" you didn't connect the PID output with your PWM function. Instead you just compare the PID output with your RPM value - why? You also use that (-100, +100) output range for your PID, even though I never heard of negative PWM duty values…
In "skuskaencodera2" you connected the PID output correctly. What "does not work" here?
From your "H bridge" image you need to provide a PWM signal (for speed) and a Direction signal (forward/backward). The PWM is generated in your VI, the direction should be fixed as I guess your car is only going forward as you only implement a speed control…
03-25-2019 02:26 PM
-Right,my little mistake :). Yea, bc i did PrtSc from "skuskaencodera" -> pic1(mycarVI), and after that i used that file and tried to do some compare functions, probably i uploaded file after i tried something, so it´s not connected in vi. So let´s be clear one more time, are you sure that this purple "oval" should be just wire from output directly to PWM? (next picture). Hm, then i connected something wrong between myrio and h-bridge or something. Because engine is running, but PID is not working = when i´ll press by my hand against wheel, it will not rise power to maintain RPM.
-Well, i want that my car will go forward and backwards. I was thinking that i don´t necessarily need regulator (PID) for backwards movement (bc car will go backwards just few times for short time) but I´m not sure if it possible to make PID regulator just for going forward and some another way to control backwards movement. Probably not. So in the end i wanted to have functional PID for forward movement and than i´ll concern about movement backwards.
Thank you, Mike.
03-25-2019 03:03 PM
03-26-2019 12:41 PM - edited 03-26-2019 12:43 PM
Ok, thank you. But with this configuration, i have trouble to stop engine. After I will raise speed lets say from 0-50RPM, and i´ll put 0 again, engine is still running (on about 30RPM) Any idea what can cause that and how to fix this? I tried experiment to put scale on setpoint -50-100 and engine will stop on -50.
(if you still have a mood to help me 😄 )
thank you GerdW.
03-26-2019 03:33 PM
edit:
I did something like this. I connected two programs, for making Chart and for PID and for now, it seems like it´s working. PID and chart. I can even see how pid is trying to hold set value. Thank you for your time! You helped me a lot.
//Maybe if i could, i wanted to ask you if you know how to transfer encoder counting into RPM. I found some complicated ways, and i wanted to ask if you dont know some easier one.(you can send me a message and this topic will be marked like "solved" .
03-26-2019 03:39 PM
Hi Mike,
the encoder gives you pulses. You count them. To calculate speed you need to know the number of pulses per time unit: you already calc the difference/delta of the pulse count. Now you just need to divide by the time unit of your loop...