Impulse From Spring

Activity Information

Learning Goals

  • Apply newton’s second law to model the force from a spring(HS-PS2-1)
  • Create a model to see that the momentum of a system is conserved when there is no net force (HS-PS2-2)

Prior Knowledge Required

  • Vectors
  • Newton’s 2nd Law
  • The Momentum Principle

Code Manipulation

  • Interpreting / Editing Existing code
  • Creating new code from mathematical equations
  • Using while loops

Activity

Handout – Impulse From Spring

Your team now works for Hamilton Toys. Time is running out for the holiday sales season and Hamilton is pushing to get their new toy on the market. They have jumped on the STEM band wagon and have developed a modular track concept for a new toy that allows children to create many configurations of a simulated amusement park ride. Different teams are creating different components for the system.

Your team has been given the task of creating a simulation for the spring rebound module. The 2 kg cart will enter this level section at 8 m/s, compress a spring mounted on the end of the track, and rebound with essentially the same speed.

Along with the animation, the folks in marketing would also like you to produce a graph showing the change in velocity of the cart and the force exerted on the cart during the rebound. You have some existing code that shows the cart moving along the track, but it doesn’t include the rebound element. Your team will have to select anappropriate spring that will serve to redirect the cart, but not be so abrupt as to damage the cart.

Code

Link

GlowScript 2.7 VPython

scene.fov = .03
box1=box(pos=vec(-.5,0,0), size=vec(2,.5,.5), color=color.green)
box2=box(pos=vec(0.7,0,0), size=vec(.4,.5,.5), color=color.cyan)
box3=box(pos=vec(1.2,.25,0), size=vec(.6,1,.5), color=color.cyan)
cart=box(pos=vec(-1.45,.45,0), size=vec(.1,.4,.5), color=color.red)

#Create the object to be in motion and set its velocity

vcart = vector(8,0,0)
cartm = 2
k = 5
Fs = vector(0,0,0)

#Set up timing data
dt = 0.001
t = 0
tf = 5

g1 = graph(width=600, height=350,title='<b>Cart Velocity (red) & Spring Force (blue)</b>',xtitle='<i>time (s)</i>', ytitle='<i>velocity (m/s) red, force (N) blue</i>',foreground=color.black, background=color.white,xmin=0, xmax=tf, ymin=-10, ymax=10)
      
f1 = gcurve(color=color.red) # a graphics curve
f2 = gcurve(color=color.blue)

while t<tf:
    rate(180)
    if cart.pos.x<1000:
        cart.pos = cart.pos + vcart*dt
        t = t + dt
        f1.plot(pos=(t,vcart.x))
        f2.plot(pos=(t,Fs.x))
        if cart.pos.x<=-1.45:
            break

    else:
        cart.pos = cart.pos + vcart*dt
        t = t + dt
        f1.plot(pos=(t,vcart.x))
        f2.plot(pos=(t,Fs.x))
        if cart.pos.x<=-1.45:
            break

Answer Key

Handout

There are two main ways to solve this problem, both require finding the force from the spring.

The force from a spring is given by Hooke’s law: F = -ks, where k is the spring constant (in N/m) and s is how far the spring has stretched from its relaxed length, L0. This can be represented in the code with:

s = cart.pos.x - L0  # The end of the spring is where the cart is
Fs = vec(-k*s,0,0)   # This force is only in the x-direction
Fs = Fnet            # The spring force is the only force acting on the cart

Now that we have the force of the spring, there are two ways to solve the rest of the problem:

Solution 1, Based on Newton’s 2nd law:

Fnet = ma, so to find the acceleration this can be re-written a = Fnet/m. The velocity update equation: vf = vi + at will also be needed. Setting this up in the second while loop looks like:

        Fnet = Fs           # The only force on the cart is the spring force
        acart = Fnet/cartm  # Calculate the acceleration each loop
        vcart = vcart + acart*dt  # update the velocity of the cart

Solution 2, based on the momentum principle:

First, the momentum of the cart has to be defined as p = mv. Then the momentum principle, Δp = FnetΔt, can be applied within the while loop. To get a velocity back out from the updated momentum, the momentum equation can be rearranged to v =p/m:

        Fnet = Fs
        pcart = pcart + Fnet*dt
        vcart = pcart/cartm

Both solutions are given below. They also both include a helix to represent the spring, though the graphical inclusion of the spring isn’t necessary to get the simulation to behave as expected.

The spring force has been artificially scaled down when it is graphed, so that it fits on the graph. Alternatively, a longer spring with a lower k value could be used.

Code

Solution 1 code:

Link

GlowScript 2.7 VPython

scene.fov = .03
box1=box(pos=vec(-.5,0,0), size=vec(2,.5,.5), color=color.green)
box2=box(pos=vec(0.7,0,0), size=vec(.4,.5,.5), color=color.cyan)
box3=box(pos=vec(1.2,.25,0), size=vec(.6,1,.5), color=color.cyan)
cart=box(pos=vec(-1.45,.45,0), size=vec(.1,.4,.5), color=color.red)
spring = helix(pos=vec(1,0.5,0), axis=vec(-0.5,0,0), coils=(7), radius=(0.15))
#Create the object to be in motion and set its velocity

vcart = vector(8,0,0)
cartm = 2
k = 1200
Fs = vector(0,0,0)
L0 = 0.5

#Set up timing data
dt = 0.001
t = 0
tf = 0.5

g1 = graph(width=600, height=350,title='<b>Cart Velocity (red) & Spring Force (blue)</b>',xtitle='<i>time (s)</i>', ytitle='<i>velocity (m/s) red, force (N) blue</i>',foreground=color.black, background=color.white,xmin=0, xmax=tf, ymin=-10, ymax=10)
      
f1 = gcurve(color=color.red) # a graphics curve
f2 = gcurve(color=color.blue)

while t<tf:
    rate(180)
    if cart.pos.x<0.5:
        cart.pos = cart.pos + vcart*dt
        t = t + dt
        f1.plot(pos=(t,vcart.x))
        f2.plot(pos=(t,Fs.x))
        if cart.pos.x<=-1.45:
            break

    else:
      
        s = cart.pos.x - L0
        Fs = vec(-k*s,0,0)
        Fnet = Fs
        
        acart = Fnet/cartm
        
        vcart = vcart + acart*dt
    
        cart.pos = cart.pos + vcart*dt
        
        spring.axis = spring.axis + vcart*dt

        t = t + dt
        f1.plot(pos=(t,vcart.x))
        f2.plot(pos=(t,0.02*Fs.x))
        if cart.pos.x<=-1.45:
            break

Solution 2 code:

Link

GlowScript 2.7 VPython

scene.fov = .03
box1=box(pos=vec(-.5,0,0), size=vec(2,.5,.5), color=color.green)
box2=box(pos=vec(0.7,0,0), size=vec(.4,.5,.5), color=color.cyan)
box3=box(pos=vec(1.2,.25,0), size=vec(.6,1,.5), color=color.cyan)
cart=box(pos=vec(-1.45,.45,0), size=vec(.1,.4,.5), color=color.red)
spring = helix(pos=vec(1,0.5,0), axis=vec(-0.5,0,0), coils=(7), radius=(0.15))

#Create the object to be in motion and set its velocity

vcart = vector(8,0,0)
cartm = 2
pcart = cartm*vcart
k = 1200
Fs = vector(0,0,0)
L0 = 0.5

#Set up timing data
dt = 0.001
t = 0
tf = 0.5

g1 = graph(width=600, height=350,title='<b>Cart Velocity (red) & Spring Force (blue)</b>',xtitle='<i>time (s)</i>', ytitle='<i>velocity (m/s) red, force (N) blue</i>',foreground=color.black, background=color.white,xmin=0, xmax=tf, ymin=-10, ymax=10)
      
f1 = gcurve(color=color.red) # a graphics curve
f2 = gcurve(color=color.blue)

ev = scene.waitfor('click')

while t<tf:
    rate(180)
    if cart.pos.x<0.5:
        cart.pos = cart.pos + vcart*dt
        t = t + dt
        f1.plot(pos=(t,vcart.x))
        f2.plot(pos=(t,Fs.x))
        if cart.pos.x<=-1.45:
            break

    else:
      
        s = cart.pos.x - L0
        Fs = vec(-k*s,0,0)
        Fnet = Fs
        
        pcart = pcart + Fnet*dt
        
        vcart = pcart/cartm
    
        cart.pos = cart.pos + vcart*dt
        
        spring.axis = spring.axis + vcart*dt
        
        t = t + dt
        f1.plot(pos=(t,vcart.x))
        f2.plot(pos=(t,0.02*Fs.x))
        if cart.pos.x<=-1.45:
            break