Dog and UPS Truck

Activity Information

Learning Goals

  • Model a projectile in one dimensional constant velocity motion
  • Model a projectile in one dimensional constant accelerated motion
  • Understand the relationship between velocity and acceleration

Prior Knowledge Required

  • Vectors
  • Kinematics in one dimension

Code Manipulation

  • Interpret existing code
  • Edit existing code
  • Synthesize new code from existing code

Activity

Handout – Dog and UPS Truck

Before doing any coding,  solve the following problem:

Your dog runs down a long driveway with an initial constant speed of 4 m/s for 6 seconds. He then uniformly accelerates to a speed of 10 m/s in 3 seconds upon seeing the UPS truck pull up to the end of your driveway. 

  1. How far did the dog run after the 6 seconds?
  1. What was the dog’s acceleration during the second part of his motion?
  1. How long is your driveway? (in other words, how far did your dog run?

Now time to start coding! Use the following trinket to duplicate this scenario on the computer.  Select copy or remix to save it to your trinkets.

Your ultimate goal is to build a model of this problem you just solved.

You should see a tan box (dog) and a black driveway

  1.  Look around line 27, the code reads        ev = scene.waitfor(‘click’)

What is this code telling the program to do?

  1. When you do click to run, you’ll notice your dog is moving very slowly.  We don’t want to change the dogs speed just yet, we want the computer to run through its calculations more quickly.  There are two ways to do this. a. Look around line 25.  dt=0.01

This code tells the computer that the change in time is 0.01 seconds.  Change the 0.01 to a different number.  Try again until you get the program to run through its iterations more quickly.  Return the code to d=0.01 when you are done experimenting.

b. Now look around line 37.  You will see the code rate(100).  This code is telling the computer to run 100 iterations per second.  How could you get it to run more iterations per second so that the dog appears to get his task done more quickly? 

Remember these options as you are working and get tired of waiting on the program

Here is the computational task:

1. Get the box(dog) to sit on the driveway – not in it or above it.  (Change their color if you like)

2.  Now change the code such that the dog moves at the stated constant speed for 6 seconds.  How far should the dog have gone down the driveway?  Is this what you get for a final position?

3.  At 6 seconds, the dog begins to accelerate.  Alter the program so that it models the second portion of the problem (as well as the first).  Do your graph and numbers match what you predicted? 

4.  Let’s say after the initial run of 6 seconds,  instead of accelerating, the dog starts to slow down.    Change the code such that he comes to rest in 4 seconds, what was his acceleration?  Model this in your program. 

5. Create a UPS truck to sit at the end of your driveway throughout the last problem. Place it such that the dog is right next to the truck, but not touching it, when he comes to rest.

Code

Link

GlowScript 2.9 VPython

#Window setup
scene.range=100
scene.width =600
scene.height = 300
scene.background = vector(0.8,0.8,0.8)
scene.center = vector(50,0,0)

#Objects
driveway = box(pos=vector(0,0,0), length=250, height=1, width=1, color=color.black)
dog = box(pos=vector(0,15,0), length=5, height=8, width=1, color=vector(1,1,0.3))

label(pos=vec(-10,-10,0), text='click to run', color=color.black )

#Parameters and Initial Conditions
#initial velocity
dogv = vector(05,0,0)
#acceleration
doga = vector(0,0,0)

#Time and time step
t=0
tf=10
dt = 0.01

ev = scene.waitfor('click')
#graph the motion
gd = graph(width=600, height=150, title='<b>velocity v time</b>',
    xtitle='<i>time</i>', ytitle='<i>velocity</i>', 
    foreground=color.black, background=color.white, 
    xmin=0, xmax=20, ymin=-20, ymax=20)
f1 = gcurve(data=[ [t,dogv.x] ],  color=color.green)

#Calculation Loop
while dogv.x>0 and t<tf: 
    rate(100)
 #dog runs down driveway
    dog.pos = dog.pos + dogv*dt

    f1.plot(data=[t,dogv.x])
   
    #dog starts to accelerate
    if t>5 :
   
      dogv = dogv + doga*dt

    f1.plot(data=[t,dogv.x])
 
    t = t + dt
    
     
print('final position = ' ,dog.pos.x)
print('time = ' ,t)
print('final velocity = ' ,dogv.x)
print('dog acceleration = ' ,doga.x)

Answer Key

Handout

Preliminary problem solution:

  1. Use the constant velocity equation: v = d/t => d = vt to get 24 m
  2. Use constant acceleration equation: a = Δv/Δt to get 2 m/s^2
  3. Use kinematic equation Δx = Vi*t + 1/2at^2 to find that the dog traveled 32 m in the last 4 seconds. Adding this to the 24 m from before yields a total distance of 56meters for the length of the driveway. That’s about 184 feet.

Initial coding questions:

  1. ev = scene.waitfor(‘click’) is telling the code not to run until a mouse click in the window of the program is detected.
  2. (b) The code can be made to run more iterations per second by increasing the value in rate(100).

Computational Task Solution:

  1. This can be done by changing the position object property of dog to pos=vector(0,5,0)
  2. Change the value of tf to 6 so the loop stops running at t =6
  3. This can be done by changing doga to vec(2,0,0) and by changing “if t>5 :” to “if t>6 :”
  4. Change doga = vector(2,0,0) to doga = vector(-1,0,0) to model this
  5. See line 13 in the code below

Code

Link

GlowScript 2.9 VPython

#Window setup
scene.range=100
scene.width =600
scene.height = 300
scene.background = vector(0.8,0.8,0.8)
scene.center = vector(50,0,0)

#Objects
driveway = box(pos=vector(0,0,0), length=250, height=1, width=1, color=color.black)
dog = box(pos=vector(0,5,0), length=5, height=8, width=1, color=vector(1,1,0.3))
truck = box(pos=vector(39.5,5,0),length=10, height=10, width = 1, color=vector(0.715, 0.506, 0.253))

label(pos=vec(-10,-10,0), text='click to run', color=color.black )

#Parameters and Initial Conditions
#initial velocity
dogv = vector(4,0,0)
#acceleration
doga = vector(-1,0,0)

#Time and time step
t=0
tf=10
dt = 0.01

ev = scene.waitfor('click')
#graph the motion
gd = graph(width=600, height=150, title='<b>velocity v time</b>',
    xtitle='<i>time</i>', ytitle='<i>velocity</i>', 
    foreground=color.black, background=color.white, 
    xmin=0, xmax=20, ymin=-20, ymax=20)
f1 = gcurve(data=[ [t,dogv.x] ],  color=color.green)

#Calculation Loop
while dogv.x>0 and t<tf: 
    rate(800)
 #dog runs down driveway
    dog.pos = dog.pos + dogv*dt

    f1.plot(data=[t,dogv.x])
   
    #dog starts to accelerate
    if t>6 :
   
      dogv = dogv + doga*dt

    f1.plot(data=[t,dogv.x])
 
    t = t + dt
    
     
print('final position = ' ,dog.pos.x)
print('time = ' ,t)
print('final velocity = ' ,dogv.x)
print('dog acceleration = ' ,doga.x)