6 ms·
PID Control Challenges
- 01100011 3y agoSome sort of 'high score' would be nice so I can understand how close my solution is to the ideal. Pretty neat website overall. Seems like I'll be wasting some time on it.
- kavouras 3y agoThe ideal solution, given that there is not input limit, depends on the simulation accuracy. Theoretically, you could achieve 0 time solutions.
- whatever1 3y agoThis is great!
- edge17 3y agovery cool!
- fisherjeff 3y agoUgh, nerd sniped on a Sunday. Great.
- RhysU 3y agoPossibly useful: A header-only proportional-integral-derivative (PID) controller. https://github.com/RhysU/helm https://github.com/RhysU/helm
- stefan_ 3y agoIt's a nice theoretical implementation but few practical examples would be found using floating-point math, running as they are on systems that don't support it.
- cellularmitosis 3y agoI find this hard to believe. Even a humble arduino can do 34,000 software float divides per second. https://gist.github.com/cellularmitosis/506c878631f806cfe6f8c76d43b21c11 https://gist.github.com/cellularmitosis/506c878631f806cfe6f8...
- distract8901 3y agoIt can but that doesn't mean it's a great idea. Unless your chip has a hardware floating point unit, you're stuck using software float operations. They're slower, though not extraordinarily so. But the main drawback is the floating point library can massively inflate your code size to the point that it no longer fits in available memory. If you can get away with it, it's fine, but when you can't it's a huge problem.
- Philpax 3y agoNot all PID controllers are destined for embedded. They’re quite useful in gamedev, for example.
- ghotli 3y agoIf you're willing to expand on this, color me interested.
- sho_hn 3y agoI encountered an example recently in a Star Citizen changelog entry about the PID controller governing the interaction of an NPC character pushing a trolley, and tuning the constants for it. My reaction was a similar "Huh - makes sense".
- waste_monk 3y agoI'm not a gamedev myself but have played a few games (Stormworks, Garry's mod with Wiremod, From The Depths, at least one or two more which I can't think of the name right now) that allow PIDs to be used in player-designed contraptions. Quite useful for building stabilised gun platforms and things. I would be sure there's plenty of applications for PIDs in a game engine itself - a quick search turns up things like self-balancing physics objects, making game entities turn to follow a mouse pointer, and so on.
- Aeolun 3y agoYay, a new elevator saga!
- Faaak 3y agoFor those who don't know it: https://play.elevatorsaga.com/ https://play.elevatorsaga.com/ Beware: time flies past
- deleted 3y ago[deleted]
- nebster 3y agoThe "Ball on Platform: Edge Balance" one seems super interesting to me. Is the sample solution just hardcoded or is there some maths behind it to make it work from any location/initial speed?
- hddqsb 3y agoIt's robust. I hamstrung the model solution by forcing pistonAcceleration to be 0, and forcing hingeAcceleration to be 0 during the first second, but it still "caught" and balanced the ball.
- lqr 3y agoIf the author is here: I would really enjoy leaderboards!
- NooneAtAll3 3y agobest solutions will be "Insane value to instantly teleport to the point. Insane anti-value to instantly stop."
- v9v 3y agoI think what you are suggesting is similar to the "dead-beat controller" in discrete-time control literature. While a controller designed with this method can get the position error measured at the sampling times to zero very quickly, it gives no guarantees that the error stays zero between the samples. This means the block could be wildly oscillating around the arrow in reality, but oscillating in such a way that it's exactly under the arrow at the times your digital controller measures it. This would probably not be a concern in this digital simulator, but such an error can pop up when trying the same thing out in real life. See slide 17 here for a plot: https://www.slideserve.com/sibyl/finite-settling-time-design https://www.slideserve.com/sibyl/finite-settling-time-design
- kavouras 3y agoIt's actually a concern due to simulation error.
- NooneAtAll3 3y agowhat I'm suggesting is "abuse of total reproducibility of the system" or "premonition" nothing about real-life controllers
- nullc 3y agoThere appears to be a hidden limit on acceleration forces.
- deleted 3y ago[deleted]
- bandrami 3y agoMy control systems prof said every engineer has done an inverted pendulum problem in school and nobody in their career has ever been asked to balance an inverted pendulum. So our final was a thermostat instead.
- nullc 3y ago> nobody in their career has ever been asked to balance an inverted pendulum Thats what all those self-balancing scooters are.
- e-_pusher 3y agoSome engineers do balance inverted pendulums in their careers! https://space.stackexchange.com/questions/15486/how-does-the-spacex-falcon-9-first-stage-straighten-for-landing https://space.stackexchange.com/questions/15486/how-does-the...
- goku12 3y agoAn unstable rocket (almost all of the big ones) is an inverted pendulum of sorts. The combined center of thrust and aerodynamic forces is usually below the C.G, and the rocket tends to tip over if not actively stabilized. To add a little, a slight margin of tipping is allowed, but the rocket tends to break up if the angle of attack crosses certain limit at high speeds.
- 3y ago
- SkyMarshal 3y agoRelated: Sabine Hossenfelder made a video back in December on use of AI/ML in Chaos Control which is pretty interesting. TLDR: scientists have known it’s possible to control or steer chaotic systems since the 1990s at least, but AI/ML have recently given them new tools for doing so. One interesting use case example is using ML to control in real-time the plasma in a tokomak reactor. More: https://backreaction.blogspot.com/2022/12/how-chaos-control-is-changing-world.html https://backreaction.blogspot.com/2022/12/how-chaos-control-...
- goku12 3y agoThis is really nice! Does anybody know if the source is available? Or something similar with source?
- nullc 3y agoWhat's people's record on the first puzzle? My current is 0.42 seconds. (I haven't bothered even loading any of the other puzzles yet)
- pqdbr 3y agoShow code or it didn't happen :)
- nullc 3y agoit's pretty trivial! erghea -400oybpx.k-40oybpx.qk; (not that rot13 really obscures anything here!) The rest of the puzzles get pretty interesting, I shouldn't have just stopped on the first and spent all the time optimizing it. If the author sees this thread it would be fun if you could disturb the dynamics with the mouse after completing one. I wanna watch the ball catching piston right the ball if I poke it.
- ranting-moth 3y agoIf you're one of the lucky 10,000* echo "V fzvyrq gbb jura V yrnearq nobhg ebg13" | tr 'A-Za-z' 'N-ZA-Mn-za-m' *: https://xkcd.com/1053/ https://xkcd.com/1053/
- kavouras 3y agoI just spent too much time messing around with this, so here's the results. The simulation has a limit on the maximum magnitude of the force of your controller, which in this example is 50. The system is described by x'' = -1.00204*x + u (by experimenting with console.log). The theoretical solution to minimize time to the origin on a system like this is a bang-bang strategy: go full actuation and at some point slam the breaks to stop exactly at the origin. Using this strategy you can calculate that you should hit the brakes(-50) starting at x= − 0.867, with the system arriving at the origin at t=0.403. But the timestep of the simulation is dt =0.02, so the system goes from x=-0.874060101875918 to x = -0.6686069466721608 in one timestep, missing the critical switching point. If you try to switch at -0.6686069466721608 it overshoots and at -0.874060101875918 its almost there when t = 0.4 but not good enough for the simulation to decide you finished the challenge. So 0.42 has to be the best you can do. What you controller actually does, due to the actuation limits, is almost the strategy described above, staying either at 50 or -50, except for 3 time points, which make the dynamics just right to land on the origin.
- cedws 3y agoTerry Davis did a nice introduction to PID controllers in his own physics engine SimStructure: https://www.youtube.com/watch?v=25hLohVZdME https://www.youtube.com/watch?v=25hLohVZdME
- benreesman 3y agoAn “obvious in hindsight” (I missed it) application of control theory in general and PID controllers in particular is exploring more of a corpus when the fleet is less loaded in an IR setting. @ajtulloch might be the world’s leading expert in making 100 billion bucks in 2 months with a device that can be built out of mechanical parts.
- srean 3y agoCould you elaborate please.
- benreesman 3y agoSure! So in many, if not most, contemporary Information Retrieval (IR) problems, there is a total document set larger than could be explored on an interactive basis and so the data structures get laid out in such a way that with some probability north of a coin, you’ll find “better” documents in the “front” half. This is hand-waving a lot of detail away, so if you’d like me to go into some detail about multi-stage ranking, and compact posting lists and stuff I’m happy to do that in subsequent comment. But it’s a useful fiction as a model and the key part is that there’s still “good” stuff in the “back” half: you’d like to consider everything if you had time. A PID controller (again oversimplifying a bit) is charged with one primary task: given some observed quantity (temperature in a room) and some controlled quantity (how hard to run the AC), maintain the observed quantity as close to a target as possible via manipulating the controlled quantity. If you hook one of these things up to an IR/search system (web search, friend search, eligible ads, you name it) where the observer quantity is e.g. the p95 or p99.9 latency of the retrieval, and the controlled quantity is how “deep” to go into the candidate set something magical happens: you always do something close to your best even as the macro load on the system varies. That’s again a pretty oversimplified (to the point of minor technical inaccuracies) TLDR, but I think it makes the important point. If you’d like more depth feel free to indicate that in a comment and I’ll do my best.
- srean 3y agoAh thanks, now I have the context.Thanks again for replying.
- bagels 3y agoI put in large constant forces, but the acceleration doesn't seem to depend on the force.
- bagels 3y agoI put in large constant forces, but the acceleration doesn't seem to depend on the force (on the inclined car level)
- ilyt 3y agoMaybe it's just throttle pedal position ?
- forgotusername6 3y agoAfter a course on balancing PID controllers in university, our professor said that something like 90% of PIDs would be on out of the box factory settings..
- pidtuner 3y ago[dead]
- juangburgos 3y ago[dead]
- jstanley 3y agoThis is brilliant, what a good idea. On the "Cruise Control Intro" challenge it's not made clear what the output of the controlFunction is. Am I returning a throttle position? A delta to the throttle position? Something else? I didn't have any trouble until I got to "Ball on Platform: Balance" which seems to be multiple steps more difficult than the previous ones.
- bArray 3y agoI think the variable limits are not always made clear. The objective is only really accessible on that first menu, otherwise you cannot re-check it. Errors in the console are mostly squashed and don't give important details like line numbers. Don't get me wrong, I think this is really awesome! We are only talking about a few UI improvements to what is already an excellent resource.
- dominicdoty 3y agoThis is very cool, I like the increasing complexity levels. I actually made a similar thing based on writing your own autopilot for a Lunar Lander [1]. It's hard to make the difficulty increase linearly though. I like the use of different scenarios in this one. [1] https://lunar.unnecessarymodification.com/ https://lunar.unnecessarymodification.com/
- ivolimmen 3y agoI cheated on level one and entered: function controlFunction(block) { let x = 5; if (block.dx > 0) { x = block.dx; } if (block.T > 1.75) { return 0; } return 2 * x; }
- danbruc 3y agoWhy is that cheating? But it is still very slow, I got it down to 0.42 seconds. function controlFunction(block) { const t = Math.round(block.T / 0.02); return (t <= 10) ? +50 : (t <= 18) ? -50 : (t == 19) ? -22.4538198550841 : (t == 20) ? -27.5461801449159 : 0; } Misses the target by 6.1E-16 at an velocity of 6.3E-15. But yes, this should probably randomize the initial conditions or parameters like friction and gravity a bit so that you actually have to control the system.
- ssl232 3y agoIt's cheating because real world PID controllers only apply linear feedback, i.e. feedback expressed by a linear function. Ifs/elses etc. are not linear.
- danbruc 3y agoPID controller only appears in the Hacker News title, the URL just says control challenge. Also, why would you allow people to write arbitrary code if you just wanted a PID controller, then you should just allow them tuning the parameters and not write the complete thing themselves.
- ssl232 3y agoTrue. I'd still argue it's not realistic to use arbitrary code though, as most control problems need linear or at least invertible control laws, and the analysis techniques that provide you with control solutions usually assume so too.
- 3y ago
- kavouras 3y agoShouldn't this have some thrust limits? I'm not sure if they are added later(I've only seen the first example), but it would make the problems more realistic, interesting and related to control theory.
- i_am_a_peasant 3y agoWish using C was an option, I don't know enough about javascript to start approaching these problems :/
- function_seven 3y agoI'm still on the first level playing with various 'P's and 'D's (no 'I's yet), but I think I have a novel scheme! function controlFunction(block) { let L = Math.floor; let x = block.x; // Use Collatz. L(x+½) is the closest integer. return -(L(x+0.5) % 2 === 0 ? x/2 // Even, we chop it : 3*x + 1 // Odd, we triple-plus-one it. ); } It's not very good, but it does beat or tie some of my earnest attempts to get below 8 seconds.
- deleted 3y ago[deleted]
- pbazarnik 3y agoCan't get better than 0.88sec? function controlFunction(block) { const max_force=1000000000; const margin=0.01; const friction_comp=0.2; if(block.x<-1-(margin/2)) return max_force*(1+friction_comp); else if(block.x<-1.15*margin) return -max_force; else return -block.x; }
- kavouras 3y agoThe best you can do is 0.42, see a subcomment I made below. max force is limited to +-50
- iNic 3y agoI got 0.4 sec with this: function controlFunction(block) { const maxforce = 100.; if (block.x < -1.01) return maxforce; else if (block.x < -0.01) return -maxforce; else return -block.x - 2 * block.dx; }
- iNic 3y agoInterestingly enough this does not work in every browser. (It worked in Orion, but not in Brave.)
- Asymo 3y agoTutorial #3 0.72s function controlFunction(block) { return -500 * block.x -60 * block.dx; }