Mechanics Lab 6. Planetoids with a Spring


Please take this pre-survey before beginning this exercise!

Think back to the momentum exercise. The little ship can collide with a "blob" and stick to it. Now imagine that this blob is attached to a spring. Wouldn't it be interesting if the ship could collide with the blob and then the spring would push and pull both around? This is what we will do in this exercise.

This spring will be attached to the blob and do the left-hand side of the screen as shown below.

Step 0. Read/think about spring forces.

Thus far the only force we have considered is $F_{\rm thrust}$ which is a constant force in whatever direction the ship is pointing. (We also considered gravity in the lunar descent exercise, but for simplicity this was treated as a constant acceleration instead of a constant force.) The force from a spring is a very different kind of force. The more the spring is compressed, the more it pushes back and the more the spring is stretched out the larger the force to try and pull it back into the rest position. The formula that corresponds to this is given here:

$$F_{\rm spring} = -k (x - L_{\rm relaxed})$$

The idea is that if $x = L_{\rm relaxed}$ then the force is zero. When $x < L_{\rm relaxed}$ then the spring force is positive so that it pushes the object to a larger $x$ value. And if $x > L_{\rm relaxed}$ then the spring force is negative and the object is pulled to a lower $x$ value.

In the code you will soon develop, you should use Lrelaxed to represent $L_{\rm relaxed}$ and Fspring for $F_{\rm spring}$ and use x_blob for $x$ because it's the blob that is attached to the spring, not the rocket (which has a position x in the code).

Step 1. Open a modified version of the momentum code.

This version will have a spring drawn on it and other minor tweaks. Click here to open the code in an editor

Please note that this exercise will remain 1-Dimensional for simplicity! Sorry!

Step 2. Get the blob and ship to oscillate after the ship collides with the blob

Our first goal will be to get the ship and the blob to oscillate together. Later we can think about letting the blob oscillate correctly without the ship.

Press up arrow to fly the ship into the blob. You will notice that the ship and the blob move to the left and eventually leave the screen.

There are three things we need to do to get this part to work:

1. Add a line to the code that translates $F_{\rm spring} = -k (x - L_{\rm relaxed})$ into code

2. Add a line of code to the update velocity section to make sure we are updating vx_blob with deltaVx_blob the same way that we are updating vx with deltaVx

3. Add a line to the code that uses Fspring to calculate the change in velocity of the blob (deltaVx_blob)

Advice #1 Remember that the BLOB is attached to the spring, not the ship! Also, it matters whether you are using the position of the blob or the position of the ship when you are calculating the spring force.

Advice #2 Remember that each timestep the change in velocity of the blob (deltaVx_blob) is the acceleration of the blob times the timestep (dt)

Advice #3 The acceleration of the blob is just Fspring divided by the mass. Because the blob and ship are attached, make sure to divide by the SUM of the mass of the blob and the mass of the ship.

If you make these changes your code should behave like this

Step 3. Get the blob to oscillate WITHOUT the ship attached

Step 3a. Give the blob an initial velocity

There is an easy way to get the blob to oscillate WITHOUT the ship colliding with it. Go to the beginning of the code and set vx_blob to some value, for example:

vx_blob = -10;

If you make this change you should see the blob oscillate back and forth. Hopefully you see something like this example

Step 3b. Make sure deltaVx_blob is correct for ONLY the blob oscillating

The code you used to get the blob to oscillate correctly when the ship was attached, may not work in this step when you are trying to get the blob to oscillate correctly by itself. It may not work because when the ship is attached to the blob the acceleration is Fspring divided by the total mass of the blob and the ship combined. But if it is just the blob oscillating then only the mass of the blob matters (because the ship isn't even attached).

Think about this advice regarding the mass of the blob and the mass of the ship in this case. Modify your code and try to get a checkmark where it says ``Make sure the blob oscillates correctly WITHOUT the ship attached"

Step 4. Put it all together!

Now that you can get the blob to oscillate correctly by itself or with the ship attached, modify the code so that the oscillation is correct whether or not the ship is or is not attached.

Set vx_blob = 0; like this:

vx_blob = 0;

Then press up arrow to fly the ship into the blob so it starts oscillating. Then rotate the ship and fly away so the blob oscillates without the ship. Can you modify the code in such a way to get both check marks?

Here is how the program should behave

Note: You will probably not be able to see the difference between the correct and the incorrect behavior just by eye!

If you can't figure it out, you can still go on to the next few sections where we will measure the oscillations to see if it matches what we expect. You may find that working through the next few sections is helpful for ultimately getting everything to work like this.

Step 5. Think about the motion!

When is the velocity the largest? When is the force the largest? When is the acceleration the largest?

Step 6. Analyze the motion!

Let's modify the code in order to measure how long it takes for the blob to go from the relaxed position to either the fully stretched or fully compressed position and back. The easiest way to do this is to measure the amount of time it takes for the blob to return to $x = L_{\rm relaxed}$. This turns out to be trickier than it sounds. Follow the directions below. If you can think of a different way to do this, please feel free to try it out!

Step 6.a. Somehere after display(); add this:

tcounter += dt; 
drawText('counter time = ',0.7*width,0.8*height);

// if the position of the blob is near the relaxed position
if ((abs(x_blob - Lrelaxed) < abs(vx_blob)*dt) & (tcounter > dt)) {
tlasttime = tcounter;
tcounter = 0; //Reset the clock

drawText('half cycle time = ',0.7*width,0.65*height);

When x_blob is close to the value of Lrelaxed and tcounter is much larger than a timestep, then the value of tcounter gets copied to tlasttime. Then the "clock" gets reset to zero with tcounter = 0.

If you add this to your code your program should behave like this.

Step 6.b. Measure the "half cycle time" when the ship is attached to the blob

Fly the ship into the blob and then without firing the thrusters, watch the ship move back and forth a few times from the force of the spring. Write down what the typical "half cycle time" is.

Step 6.c. Measure the "half cycle time" when the ship is NOT attached to the blob

Set vx_blob = -10; at the beginning and let the blob oscillate WITHOUT the ship attached. What do you get for the "half cycle time"?

Does the half-cycle time depend on whether the ship is attached or not? Should it?

Step 7. Calculate the expected "half cycle time" from what you know about oscillating springs.

What is the "half cycle time" equivalent to? The angular speed? frequency? period? Use what you know about the period of an object attached to a frictionless spring to calculate what you would expect the "half cycle time" to be based on the mass of the objects and the spring constant. You should be able to estimate this quite accurately. (Hint: the angular speed of a frictionless spring is $\omega = \sqrt{k/m}$.)

Compare the numbers that you get to what you measured in Step 6.

Step 8. Increase the amplitude of the oscillations! See what happens to the half-cycle time!

There are two ways to increase the amplitude of the oscillations: (1) you can fire the thrusters while the ship is attached, or (2) you can give the ship different initial speeds before it slams into the blob (ex.  vx = -10, vx = -20, vx = -30...) Is the half cycle time the same or different? Make sure you watch the oscillations for a few cycles before you decide. Does the answer surprise you?

(Challenge part 1) Step 9a. Add damping to the spring system!

Add a drag (a.k.a. damping) force to the spring system. There is more than one kind of damping force you could use, but the simplest is $F_{\rm drag} = - b v$ where $b$ is a constant.

Test it out! Roughly how many cycles does it take for the motion to slow to a stop? Underdamped systems go through multiple oscillations before they slow to a stop. Make b much larger until the damping is so large that the system slows to a stop without oscillating. Overdamped systems slow to a stop without going through multiple oscillations. What value of b should you use to simulate a critically damped system?

(Challenge part 2) Step 9b. Calculate and Measure the half-cycle time for the damped system

Use the default values for the mass of the ship, the mass of the blob and the spring constant and set the damping constant b = 2.0. What do you measure for the half-cycle time now? You should be able to do a calculation that explains why you get the number that you get. (Hint: the angular frequency of a damped spring system is $\omega = \sqrt{k/m - (b/2 m)^2}$).

Please take this post-survey after completing the exercise!

Things you need to do to get full credit for this programming lab:

1. Submit your spring.js file after making all the changes asked for in steps 1-4 and (if you decide to) the challenge steps 7a and 7b

2. Measuring and calculating the half-cycle time

In carmen there is a comment box when you submit the code. Make sure to write the half-cycle time you measured in part 4, and describe the calculation you did in part 5 to explain why the half-cycle time turned out to be the number that it did. The number you calculate and the number you measure should be very similar. If the numbers are way off then you probably won't get full credit.

3. State whether the half-cycle time depends on the amplitude

Fly into the blob and then use your thrusters to make the amplitude of motion larger. Then stop firing the thrusters and measure the half-cycle time. Does it change or not?

3. The challenge is optional but if you take the time to do it you will get a few points of extra credit.