Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/notebooks/chap25.ipynb
Views: 531
Modeling and Simulation in Python
Chapter 25
Copyright 2017 Allen Downey
Teapots and Turntables
Tables in Chinese restaurants often have a rotating tray or turntable that makes it easy for customers to share dishes. These turntables are supported by low-friction bearings that allow them to turn easily and glide. However, they can be heavy, especially when they are loaded with food, so they have a high moment of inertia.
Suppose I am sitting at a table with a pot of tea on the turntable directly in front of me, and the person sitting directly opposite asks me to pass the tea. I push on the edge of the turntable with 1 Newton of force until it has turned 0.5 radians, then let go. The turntable glides until it comes to a stop 1.5 radians from the starting position. How much force should I apply for a second push so the teapot glides to a stop directly opposite me?
The following figure shows the scenario, where F
is the force I apply to the turntable at the perimeter, perpendicular to the moment arm, r
, and tau
is the resulting torque. The blue circle near the bottom is the teapot.
We'll answer this question in these steps:
We'll use the results from the first push to estimate the coefficient of friction for the turntable.
We'll use that coefficient of friction to estimate the force needed to rotate the turntable through the remaining angle.
Our simulation will use the following parameters:
The radius of the turntable is 0.5 meters, and its weight is 7 kg.
The teapot weights 0.3 kg, and it sits 0.4 meters from the center of the turntable.
As usual, I'll get units from Pint.
And store the parameters in a Params
object.
make_system
creates the initial state, init
, and computes the total moment of inertia for the turntable and the teapot.
Here's the System
object we'll use for the first phase of the simulation, while I am pushing the turntable.
Simulation
When I stop pushing on the turntable, the angular acceleration changes abruptly. We could implement the slope function with an if
statement that checks the value of theta
and sets force
accordingly. And for a coarse model like this one, that might be fine. But we will get more accurate results if we simulate the system in two phases:
During the first phase, force is constant, and we run until
theta
is 0.5 radians.During the second phase, force is 0, and we run until
omega
is 0.
Then we can combine the results of the two phases into a single TimeFrame
.
Here's the slope function we'll use:
As always, we'll test the slope function before running the simulation.
Here's an event function that stops the simulation when theta
reaches theta_end
.
Now we can run the first phase.
And look at the results.
Phase 2
Before we run the second phase, we have to extract the final time and state of the first phase.
And make an initial State
object for Phase 2.
And a new System
object with zero force.
Here's an event function that stops when angular velocity is 0.
Now we can run the second phase.
And check the results.
Pandas provides combine_first
, which combines results1
and results2
.
Now we can plot theta
for both phases.
And omega
.
Estimating friction
Let's take the code from the previous section and wrap it in a function.
Let's test it with the same parameters.
And check the results.
Here's the error function we'll use with root_bisect
.
It takes a hypothetical value for torque_friction
and returns the difference between theta_final
and the observed duration of the first push, 1.5 radian.
Testing the error function.
And running root_scalar
.
The result is the coefficient of friction that yields a total rotation of 1.5 radian.
Here's a test run with the estimated value.
Looks good.
Animation
Here's a draw function we can use to animate the results.
Exercises
Now finish off the example by estimating the force that delivers the teapot to the desired position.
Write an error function that takes force
and params
and returns the offset from the desired angle.
Test the error function with force=1
And run root_bisect
to find the desired force.
Exercise: Now suppose my friend pours 0.1 kg of tea and puts the teapot back on the turntable at distance 0.3 meters from the center. If I ask for the tea back, how much force should they apply, over an arc of 0.5 radians, to make the teapot glide to a stop back in front of me? You can assume that torque due to friction is proportional to the total mass of the teapot and the turntable.