View Single Post
  #1  
Old 03-13-2009, 09:05 AM
durf durf is offline
Member
 
Join Date: Feb 2009
Posts: 61
Calculating Speed with sensor

Hello,

Right now I am trying to figure out how to calculate speed with a sensor. I know that speed is the rate of change with respect to time. So change of position / time.

I know I need to get the position(pos) of the sensor first. Then i have to have a def: that will check for its new pos then do the calculation - (new pos - old pos) / time. Then after that I need to start over and set the new pos to old pos.

The problem im having is trying to establish a pos before the def: starts running. Whenever I test for the old position i keep getting 0.0, 0.0, 0.0.

So its going to look something like this:
Code:
import viz
viz.go()

PORT_PPT = 6

for x in range(1):
     #Create sensors
     ppt1 = viz.add('vizppt.dls')
     ppt2 = viz.add('vizppt.dls')

     ball1 = viz.add('white_vall.wrl')
     ball1.scale(1,1,1)
     ballLink1 = viz.link(ppt1, ball1)

     ball2 = viz.add('white_vall.wrl')
     ball2.scale(1,1,1)
     ballLink2 = viz.link(ppt2, ball2)
 
     #controls distance in virtual world
     ballLink1.postScale([8,1,13],target = viz.LINK_FULL_OP)
     ballLink2.postScale([8,1,13],target = viz.LINK_FULL_OP)

#I need to check for ball1 pos before here
def speed():
      #need to check for new pos for ball1 here
      #need to somehow get old pos of ball1 so i can do the equation 
      #new pos - old pos /2(=1/2 second)
      if speed > 1:
           #some reaction happens in here
      #need to set old pos = new pos

vizact.ontimer(.5, speed)
Ive been trying to write this to work without errors but i keep getting them. I still new to vizard and python so any explanation would help also.

Thanks
Reply With Quote