6 ms·
Show HN: 2D PID controller simulation
- ambrop7 11y agoI'm curious, is there any configuration of the PID parameters that would achieve optimal control for this simple physical system? I suppose the optimum looks like 100% thrust and switching to -100% thrust at just the right time to stop at the target position.
- agoetz 11y agoYes. Reformulate the systems transfer function into a state space representation, and then solve the algebraic ricatti equation to find an optimal gain matrix. This is know and the LQR problem. http://en.m.wikipedia.org/wiki/Linear-quadratic_regulator http://en.m.wikipedia.org/wiki/Linear-quadratic_regulator Switching the output from 100% to -100% is another viable approach, known as bang-bang control, but it is not necessarily optimal
- Matumio 11y agoFor some definition of "optimal". I expect you can reach the "5% deviation from target" region much faster if you allow a bit of overshoot.
- niccl 11y agoslightly relevant: I've just built a lighting desk that uses motorised faders for some of the control input. To get the PID values for the faders I built a genetic algorithm tool that would evolve the right numbers. Worked a treat but the first half hour of running had the fader slamming about like nobody's business: I burnt one out during testing... But the really interesting thing I found was that you really need a genetic algorithm tool to evolve the correct set of parameters for the goodness function: different goodness functions produced different results in different timeframes.
- danielvf 11y agoI've used desks with motorized faders! (and spent a couple days a week in high school running, maintaining, and programming a small half million dollar lighting setup for a big theater. ) Recently I've done some firmware programming on for theatrical/stage LEDs. All this to say, did you ever consider writing a test sequence of various position and rate changes, and then analyze the actual vs commanded data offline to get an equation for the response? I've had some success doing that for a similar control problem.
- deleted 11y ago[deleted]
- rounak 11y agoCan anyone explain what is this?
- sjtrny 11y agoProportional-integral-derivative (PID) controller is a feedback loop algorithm for control. You give some desired goal (in this case is to reach a position) and it moves to that goal by iteratively attempting to minimise the error (in this case distance). A real life example is the stabilisation of quadcopters ("drones" eugh I hate that word). Where instead of attempting to reach a location the target is to maintain a specific angle relative to the ground. As always wikipedia is your friend http://en.wikipedia.org/wiki/PID_controller http://en.wikipedia.org/wiki/PID_controller.
- watmough 11y agoThe article links the Wikipedia page: https://en.wikipedia.org/wiki/PID_controller https://en.wikipedia.org/wiki/PID_controller If the goal is to teach about PID controllers, then the demo could use a graph showing the parameters through time.
- sz4kerto 11y agoIn short, you're pushing the ball around, and the force you use depends on three things: - how far the ball is from the target (P, proportional) - how far the ball has been from the target over time (I, integrator), so if you are very far even after a long time you try to push harder - how quickly is the ball approaching the target (D, derivator), i.e. if you're approaching quickly then you decrease the force, if you're approaching too slow then you increase the force
- ingenter 11y ago- Brown ball is physically simulated (has inertia) - A program controls the ball only via two thrusters (x/y), force represented as orange bars - Program's goal is to deliver the ball to a given point (last click position) There is a link in the footer: https://en.wikipedia.org/wiki/PID_controller https://en.wikipedia.org/wiki/PID_controller which explains what's a PID controller in this case.
- mrpsrinkles 11y agoLooking at the source this is actually a PD controller, which makes sense for a simple simulation like this.
- antoinealb 11y agoOne way to make the integral term useful would be to add some static friction to the simulation, that would be interesting.
- sjtrny 11y agoIt's a shame that the PID values aren't exposed directly in text boxes but you can affect how the ball behaves (react faster/slower or cause under or overshoot) by adjusting the kp, ki and kd values.
- nikital 11y agoThat's a good idea, I'll add them. Edit: Done.
- icegreentea 11y agoYou should consider resetting your integral error when you accept new set points.
- nikital 11y agoI agree, I pushed a new update. Also, I adjusted the defaults for a snappier response with a bit of satisfying overshoot
- phkahler 11y agoThis is a special case. If there were gravity acting on the ball the integrator would be required to maintain altitude.
- icegreentea 11y agoYa, but then you would also probably use a separate controller for each dimension.
- fnordfnordfnord 11y agoNice demo. Thanks. FYI http://nikital.github.io/ http://nikital.github.io/ is 404.
- nikital 11y agoYeah, I didn't put anything there yet, but thanks for the heads-up.
- xnzakg 11y agoWould be pretty nice to have some external force (like gravity), otherwise the i value is pretty much useless. Also, some friction would be nice.
- nikital 11y agoYour comment regarding the gravity was really insightful for me (I didn't learn PID formally). When I put large values for i, the ball just oscillated and I couldn't see how i is useful. After I added gravity (in my local build, not published), I began to see how the integral affects the control. That's awesome!
- phonyphonecall 11y agoChallenge HN: Make it travel in a perfect circle. Comment with your strats.
- mrpsrinkles 11y agoMake it neutrally stable, e.g. Kp = 1, Kd = 0, Ki = 0; Click x to the right of its standstill position. When it is halfway there click x below its current position.
- pjkundert 11y agoFor a complete Python PID loop implementation and (console) demo: git clone https://github.com/pjkundert/ownercredit.git PYTHONPATH=$PWD python ./ownercredit/pid.py
- adiko 11y agoVery nice simulation!
- bobmoretti 11y agoThis would be a really cool illustration if you could solve the closed loop transfer function, and display the locations of the closed loop zeros and poles.