spring model....i want to get the program to return the value of the period of the motion of the pendulum

i have tried putting this outside the loop

oldVelocity = vector(0,0,0)

and this inside the loop before v:

oldVelocity = m.v

with print statement:

if oldVelocity.y/m.v <0:
   print ("time = ",t)

but i get this error:

oldVelocity = m.v
AttributeError: 'int' object has no attribute 'v'

i have also tried:

oldVeloctiy = v

inside loop and changing the
if statement to

if oldVelocity.y/v <0:
   print ("time = ",t)

here is my code:

from visual import*
from visual.graph import*
scene.background = color.white

L_o = 0.17



rod = cylinder(pos=(-.5,-.5,0),axis=(0,1,0),radius=.005,color=(166/255,172/255,182/255))
bar = cylinder(pos=(-.5,.4,0),axis=(.5,0,0), radius=.005,color=(166/255,172/255,182/255))
weight = cylinder (pos= (.5, -.6, 0), length=.05, radius=.02, color=(181/255,166/255,66/255))
spring = helix(pos=bar.pos+(.25,0,0), axis=(0,L_o,0), radius=.0093, length=.3, coils= 20)
platform = box(pos = ( -.1, -.5 , 0), axis = (0,1,0),height = .9, length = .001, width = .01, color = color.black)

m = 1
g = vector(0, -9.8, 0 )
Fg = m * g
d = .04
v = vector(0, 0 , 0)
p = m * v
k = 203
t = 0
dt = .01
r = vector(-0.25, 0.25, 0)
oldVelocity = vector (0,0,0)

while 1:
    rate(1/dt)
    Fd  = -d * mag(v) * norm(v)
    L = r - spring.pos
    Lo = L_o * norm(L)
    s = L - Lo
    Fsp = -k * s
    Fnet = Fd + Fg + Fsp
    p = p + Fnet * dt
    oldVelocity = m.v
    v = p / m
    r = r + v * dt
    weight.pos = r
    weight.axis = norm(L) * 0.05
    spring.axis = L

    t = t + dt
if oldVelocity.y/m.v <0:
    print ("time = ",t)

You set m as integer at line 15. Do you mean m*v? But that is just same as v as m is allways 1. Same way line 37 means only that v = p. Also you never exit the while loop.

Edited 4 Years Ago by pyTony

>>> m = 1
>>> oldVelocity = m.v
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
AttributeError: 'int' object has no attribute 'v'

As it say int object has no attibute 'v'
The dot "." is the member access operator.
Generally an object of a class has attributes/methods.
So as an example i do this.

>>> class Foo:
        v = 100

>>> m = Foo()
>>> m.v
100

Or.

>>> class Foo:
        @property        
        def v(self):
            return 5000

>>> m = Foo()
>>> m.v
5000

Here you see a class Foo that has attribute and method v.
So int class has no attribute/methods that is called v and give and error.

That was the long explanation of the error,maybe it was just and type error as pyTony metion.

Edited 4 Years Ago by snippsat

This question has already been answered. Start a new discussion instead.