Using a POT to cont...
 
Notifications
Clear all

Using a POT to control PID values

7 Posts
4 Users
1 Likes
2,174 Views
(@helidoctor)
Member
Joined: 4 years ago
Posts: 4
Topic starter  

   
Quote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1112
 

@helidoctor

I remember seeing that video and thinking it was a nice demo of PID.  So this is just a quick of the top of my head response.   Whilst I don't doubt you could get potentiometers to work I think it would be much easier with encoders where you just count the pulses and interpret them to whatever scale you want.  So the KD could be from 0 to 8000 and set to an initial mid point of 4000, and the KI you could have a range of 2.0 to -1.0 etc.  You would decide on how many pulses would be used to increment each, so, for example, you could increment the KD to go from 4000 to 8000 with a complete turn to the right and from 4000 to 0 with a complete turn to the left. (or half a turn or 2 turns whatever is best for you.)  

As it happens there is a nice DronbotWorkshop video on the use of encoders if you peruse the back catalogue, with example code that you should the be able to incorporate in the code you present above.   I would also think of have a cheap LCD display that shows the current values of kp, ki and kd as the nobs get twiddled.

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@helidoctor

Posted by: @helidoctor

I know how to attach the pots as analogue inputs, what I don't know is how to tell the board to read the values of the pots and convert them to PID constants.

Arduino provides a map function, however you would be working with integers, and the resolution wouldn't be that good, as the analog to digital converter is only 10 bit, giving you a maximum of 0 - 1023 integer values.  There is an example with the following reference page if you wish to give it a go:

Arduino map function

Posted by: @helidoctor

Or does anyone have any other suggestions that allows me to alter each of the P.I and D values from 0 to max, individually without the need to flash the board for each new set of values.

Although not the ideal solution, you could pass the values you want in dynamically, and directly via the serial interface, as long as your Arduino is connected to your computer.  You could for example, pass in a string such as:

kp=8

Then within the main code, parse out the string and apply the value to the appropriate variable identified.

I think this can work, and may be worth a try.

Cheers!


   
triform reacted
ReplyQuote
triform
(@triform)
Member
Joined: 5 years ago
Posts: 324
 

@byron

I think a pot would be a better choice here.  Less stuff to do in the code.   Just a map and constrain pair with the analog value. 


   
ReplyQuote
(@helidoctor)
Member
Joined: 4 years ago
Posts: 4
Topic starter  

Thanks for the advice guys. 

I like the idea of an lcd display, probably outside my ability level right now but I like the challenge.

I did see about mapping. I think it could work for my needs. I

Once I have the PID dialled in, my thought was to have each pot some where near the middle range for each. I dont need it to be super accurate. The idea is mainly to be able to turn each or a combination of P,I and D on and off so the students get to visualise the effects. (Teaching  differentiation and integration without calculus lol)

The biggest problem I have is that the IT guys won't put IDE on the works computers and im not taking my laptop in to work each time I teach (I ride a bike and its a big laptop) so I'm trying to get a standalone unit that can work without being connected to IT....


   
ReplyQuote
(@helidoctor)
Member
Joined: 4 years ago
Posts: 4
Topic starter  
Posted by: @triform

@byron

I think a pot would be a better choice here.  Less stuff to do in the code.   Just a map and constrain pair with the analog value. 

Sounds like exactly what I need given my skillset.

In my head I have an LCD and maybe a keypad to view and enter the values (although rotary encoders would look almost as good on the final project)

 

The problem is the ideas are in my head, the ability to execute, not so much. But I'm in no real rush so I have time to learn (famous last words)


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1112
 

@helidoctor

The following youtube video just poped into my inbox, doing PID control for a self balancing robot, and like you he did not want to keep changing the PID values and used potentiometers to change the values. So I thought of you and hope this helps 

As said I would rather use encoders as its easy to make each encoder 'click' (assuming you get clickable ones 😎 ) increment or decrement by a chosen value.  So for kd you could increment in steps of 10 and for ki you could move in precise 0.01 steps etc.  And each click would increment the same value.  You will not be able to get such precise setting with a potentiometer.  Well you can look at the code for the potentiometer as per above and then look at the code in the DroneBot video to see which keeps you on the level 😀. (note that the DroneBot article also covers encoders for motors, but the bit of code for his knob is the bit to look at, oo err missus 😍 )   


   
ReplyQuote