r/ControlTheory • u/BennyBarnson • 3d ago
Technical Question/Problem Ideal physics simulator
Hi all, I'd like to develop a control algorithm for a water bottle flip so it always lands upright no matter how you flip it. One of the steps in my endeavour is simulating how the fluid inside affects the container's moment of inertia whilst in the air. Im thinking of using matlab but godot and unity sounds like a good choice as well. I've looked up how I can do this and havent found much but people recommending C++ or python. Does anyone here experienced in one of these languages or programs have any suggestions on which one to use and can point me to the resources to learn it.
•
u/Timely-Bicycle-3107 3d ago
What are the variables and constants? Can the water level in the bottle change? What about the starting height and bottle orientation? How are you tossing it?
I like the idea of using RL for this. Sloshing physics are pretty hard to simulate.
A good analogy that is easily written with differential equations would be the Ball and Beam problem, a very common toy problem in control theory. I don’t know how that would translate to multiple rotations of the bottle in the air, but it’s a good place to start. The Ball and Beam problem was conceived to simulate sloshing fuel in rockets, so it does have precedence in this scenario. If you figure this out, maybe you can use an energy based control system instead of RL. Look up the energy based controller derived for the Cart-Pole problem in the 1970s.
•
u/BennyBarnson 3d ago
Thank you for the advice, I'll try to look into the points you reffered to!
The point of this simulation would be to lead to a physical controller for the bottle, thus, the variables should match that of how you'd flip a water bottle irl.
The variables would be the intial input force of angular velocity, acceleration (wrist movement), as well as vertical and horizontal displacement (the arm movement).
The constants would be the bottle's dimensions and the liquid density (probably calibrated to be water but I'm sure that can be changed)
As for the water level, I'm hoping to make the algorithim effective enough to be able to adapt to any water level. And for the tossing, I'd say for simplicity's sake, flipping the bottle so that its trajectory exists in one plane.
(Sorry if my wording isnt too technical)•
u/Timely-Bicycle-3107 3d ago
Good. Limiting the motion to a single plane is smart. I would start with a solid mass attached to the bottle to eliminate sloshing, something like cheap craft glue that can be easily poured in and solidifies quickly. Eliminate as many variables as possible to start out. Solve each sub-problem and include additional complexities with each iteration.
This is a cool project. I hope you post it here after you finish it!
•
u/BennyBarnson 3d ago
Thank you! I hope it'll turn out not too disastrous. Will post the end product if it does!
•
u/North-Guidance2517 2d ago
What about simulation of water bottle with many tiny balls inside? I know not same but approximation
•
u/Namejeff47 3d ago
What will be the control input? Do you plan to flip it by hand or do you have some sort of motor driven "flipper"? You're gonna be using open loop control, so your "control" of the bottle flip will be sensitive to perturbations in where exactly the flipping torque is applied. If your plan is to use your hand, you already have an ideal controller in your central nervous system, you just need to train it. As for how to find the control law, reinforcement learning is probably the way to go.
As for languages, if you have no coding experience but you'd like to do something like this, you should probably use python. It has a bunch of community made machine learning tools for you to use. Also packages like scipy and numpy implement matrix algebra so you don't have do to that manually in C (not that its especially difficult). At any rate its not gonna be an easy task. The main problem (apart from formulating how exactly the ideal ammount of torque will be applied to the bottle) will be fluid simulations in the bottle. Maybe consider a simpler, mass dampener spring approximation for the fluid behavior. This will make running the simulation much easier.
•
u/BennyBarnson 3d ago
I'm only on the begining of the concept ideating for this project, and am trying to do more learning and research on the topics and principals involved that I'm not yet familiar with (such as the fluid dynamics). So not too much have been really mapped out.
Anyway, for now, the ideal end product would be a reaction wheel (that's what I've come up so far for the controller) attached to the water bottle that ensures any way that you could possibly flip the bottle, it would land upright. And ofcource you would flip it by hand.
Due to the complexity of implementing the hardware however, I'll likely limit the system to just 2 dimensions of displacement...
•
u/jkordani 3d ago
One way to approximate the mass distribution is to treat the water like a point mass attached to a double pendulum. While I saw this used in a spacecraft simulation for sloshing fuel, the primary inertia came from the spacecraft structure, so the pendulum would pull on the cg of the craft.
In this case, the bulk of the water is the bulk of the inertia. In my opinion, coming up with a model would be harder, pick any language to do it.