View Single Post
#1
03-13-2009, 09:05 AM
 durf 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

ball1.scale(1,1,1)

ball2.scale(1,1,1)

#controls distance in virtual world

#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