The purpose of this lab is to explore a mass-spring system as it is set to oscillate in a plane. Though this scenario could be set up in a physical experiment, the periodicity of the mass spring system would be difficult to study due to dampening effects and potential radical motion from the spring and mass oscillating. This program will allow for more careful observations that are repeatable.
The following is the code provided at the start of the lab:
from __future__ import division
from visual import *
scene.width=600
scene.height = 760
## constants and data
g = 9.8
mball = 1 ## change this to the appropriate mass (in kg) from your mass-spring experiment.
L0 = 0.26 ## this is an approximate relaxed length of your spring in meters measured in lab.
ks = 1 ## change this to the spring stiffness you measured (in N/m)
deltat = .01
t = 0 ## start counting time at zero
## objects
ceiling = box(pos=(0,0,0), size = (0.2, 0.01, 0.2)) ## origin is at ceiling
ball = sphere(pos=(0,-0.3,0), radius=0.025, color=color.orange) ## note: spring compressed
spring = helix(pos=ceiling.pos,axis=ball.pos-ceiling.pos,color=color.cyan, thickness=.003 , coils=40, radius=0.015) ## change the color to be your spring color
trail = curve(color=ball.color) ## for leaving a trail behind the ball
## initial values
pball = mball*vector(0,0,0)
Fgrav = mball*g*vector(0,-1,0)
## improve the display
scene.autoscale = False ## don't let camera zoom in and out as ball moves
scene.center = vector(0,-L0,0) ## move camera down to improve display visibility
scene.mouse.getclick() ## Animation doesn't start when you Run Program.
## calculation loop
while t < 30:
rate(100)
Fnet = Fgrav
pball = pball + Fnet*deltat
ball.pos = ball.pos + pball/mball*deltat
spring.axis = ball.pos - ceiling.pos
trail.append(pos=ball.pos) ## this adds the new position of the ball to the trail
t = t + deltat
This code is broken and does not model a system that is oscillating. There is no spring force in this program. The program just models a ball in free fall with a helix attached to it. The following is a working version of the program and a video of the program running with the corresponding position graph.
#April 12th 2012
#Chris Cosio
#This is the first part to a Spring-Mass system model.
from __future__ import division
from visual import*
from visual.graph import*
from visual.graph import*
scene.width = 600
scene.height = 760
scene.y = 400
#Constants and Data
g = 9.8
mball = 0.24 #Hanging mass
L_0 = 0.26 #Relaxed length of a hanging spring
ks = 40 #Spring COnstant
deltat = 0.01
t = 0
#Objects
ceiling = box(pos=(0,0,0), size = (0.2,0.01,0.2))#Orgin is at the ceiling
ball = sphere(pos=(-0.10,-0.3,0), radius=0.025, color=color.orange)# note: spring compressed
spring = helix(pos=ceiling.pos,axis=ball.pos-ceiling.pos,collor=color.cyan,
thickness=0.003, coils=40, radius=0.015)
trail = curve(color=color.yellow)
ygraph = gcurve(color=color.yellow)
#Initial Values
pball = mball*vector(0,0,0)
Fgrav = mball*g*vector(0,-1,0)
#improve the display
scene.autoscale = False
scene.center = vector(0,-L_0,0)
scene.mouse.getclick()
#calculation loop
while t < 30:
rate(100)
L = ball.pos-ceiling.pos
F_spring = -ks*(mag(L)-L_0)*norm(L)
Fnet = F_spring+Fgrav
pball = pball + Fnet*deltat
ball.pos = ball.pos + pball/mball*deltat
spring.axis = ball.pos - ceiling.pos
trail.append(pos=ball.pos)
ygraph.plot(pos=(t,ball.pos.y))
t = t + deltat
The position graph depicts a wave envelope where a smaller oscillation is occurring within a larger oscillation. This is due to the spring oscillating up and down as the mass oscillates back and forth. graph never crosses zero in this program because of how the ball position is defined. The periodicity of the envelope can be found by taking the time interval from large peak to large peak. The period can be changed in the program by changing different variables. The spring constant, hanging mass, and initial velocity all can be changed to change the period of the larger oscillation; furthermore, the amplitude can be adjusted by changing the mass or spring constant.
No comments:
Post a Comment