PID need someone to look it over.

I have PID programed in but I’m not sure if its going to work and I cannot test it right now. What its doing is when a button is pressed (and held) it will turn one motor until it hits the setpoint then run another motor until it hits its setpoint. then stop. I don’t know if it will work at all even in theory.

Whoa, that’s complicated. Some notations in the code might help people to understand what it’s doing. I can’t follow it easily, so I can’t give any helpful advice.

I’m sure there’s an easier way to choose among constants than using those deeply nested case blocks, though.

It makes me sad that you cant understand it. I annotated it to make it easier to understand. My build adviser got a laugh out of it. (43.5 KB) (43.5 KB)

If Alan can’t understand it - *the guy understands Klingon for goodness’ sake *- then it can’t be good.

I think I have a basic understanding of what it’s doing, although the details are beyond me. I think the code can be cleaned up a little, if nothing else.

Near the end, you are using case structures to decide which wire to use. Take a look at this block, it might be more suited for this.

Also the giant case structure in the middle… I’d be tempted to put the buttons into a boolean array, then convert that array to a number, then put that number into a single case structure which can select the constant. This was used pretty elegantly in the example line following code.

Also it seems a little messy to run the process value into the setpoint as a method of making it not move. I’m not sure I understand the goal, but perhaps removing the first case and instead making one around that PID would be better.

Hope this helps… My confidence is a little shot by Alan’s reply…

Using the automatic diagram cleanup tool made some of it a lot clearer. You put input and output tunnels on the same edge of the case, and it wasn’t at all obvious which way the data was flowing until they were rearranged to put things in a more traditional left-to-right order.

I am confused by your use of the dt input to the PID blocks. Can you explain what you intend it to do?

that part may be wrong because i do not know what that input does exactly but i was hoping that it would give me an exact time value instead of the vi calculating its own runtime

If you want a few pointers on more readable diagrams – so that you can read your code more easily and others can too, I’ll throw some out there.

When you have a choice between a case structure and the ternary assignment, also called the Select node, use the Select.

When you have a positive and negative constant that you are just selecting between, consider using one constant and multiply by either one or negative one. When you need to change the constant, you are far less likely to wind up with a partial update.

Whenever possible, combine the Booleans into a number and switch on that to minimize duplication of constants and code.

My monitor is 1920x1200 and I still need to scroll quite a bit to see your diagram. White space is cool, but if you need to scroll, limit the scrolling to one dimension. Even better, use subVIs to avoid scrolling altogether.

I can’t follow the logic enough to be able to answer your question about the PID.

Greg McKaskle

I think my problem is not knowing what i can use to simplify things more (also i find it easier to use stacked cases than use arrays). And what are ternary assignments?

Ternary assignment in C/C++ looks like

y= a<0.3 ? 0 : a;

which is equivalent to

if(a < 0.3)
y= 0;
y= a;

In LV it looks like the attached image.

Greg McKaskle

Clipboard 1.png

Clipboard 1.png