WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Omni Velocity information (https://forum.worldviz.com/showthread.php?t=5735)

M@rcello 05-30-2016 04:30 AM

Omni Velocity information
 
Hi, do you know if there is the chance to get the velocity information from the Omni.
The problem is that i have attacched a ball to the omni, and i am able to control the pose of the ball with it.
What i want to do is to use velocity like trigger to send forces from the device to the operator.

This is my code:
Code:

import viz
import hd
import vizinfo
import time
import math
import cmath
from datetime import datetime


viz.go()

ball=viz.add('white_ball.wrl')

viz.MainView.setPosition([0,-0.5,-5])

hd.marker(ball)

start_box=viz.add('box.wrl')
start_box.setPosition([2.5,-0.7,3])
start_box.color([0,256,0])
start_box.setScale([0.5,0.5,0.5])

start_box.collideBox()

finish_box=viz.add('box.wrl')
finish_box.setPosition([-2.5,-0.7,3])
finish_box.setScale([0.5,0.5,0.5])

finish_box.collideBox()
       
pos_goal=[2.35,-0.4,0]       

#print pos_new[0],pos_new[1],pos_new[2]       
       
vizinfo.add('To start reach the green zone and then reach the red one')

error=[0,0,0]
vel=[0,0,0]
Kp=([0.05,0,0],[0,0.05,0],[0,0,0.05])
pos_hidden=[0,0,0]

def print_pos():
        t1 = current_milli_time()
        delay=t1-t0
        print delay
        if (delay>3000):
                for i in range(0,3):
                        pos=hd.get(hd.POSITION)
                        error[i]=-pos_goal[i]+pos_hidden[i]
                        vel[i]=-Kp[i][i]*error[i]
                        pos_hidden[i]=pos_hidden[i]+vel[i]

                ce = hd.ConstantEffect(dir=[pos_hidden[0]-pos[0],pos_hidden[1]-pos[1],0],mag=0.2)
                ce.trigger(0.2)
       
        #        print pos_goal[0],pos_goal[1],pos_goal[2]
        #        print error[0],error[1],error[2]
        #        print vel[0],vel[1],vel[2]
        #        print pos_hidden[0],pos_hidden[1],pos_hidden[2]

current_milli_time = lambda: int(round(time.time() * 1000))

def start():
        global t0
        t0 = current_milli_time()
        vizact.ontimer(0.1,print_pos)
vizact.onkeydown(' ',start)

Thanks in advance!!

Jeff 05-30-2016 06:39 AM

Do you mean the velocity of the stylus as the operator moves it or something else?

M@rcello 05-30-2016 07:46 AM

I would like to have information about the phantom's velocity during the motion!
I want to use it as a trigger,like:

Before sending forces check if in the last 3 seconds the velocity(x,y,z) was zero->in that case send forces otherwise wait!

I would like to now if there is already something like the hd.POSITION but for the velocity!

Jeff 05-31-2016 05:00 AM

It does not look like there is a velocity command. The available commands can be found in the Sensable and standard sensor pages in the Vizard help. You could calculate the velocity between frames or some other time interval. For example:

Code:

import viz
import vizact
import vizmat

viz.go()
viz.addChild('piazza.osgb')
device = sensable.addHapticDevice()

lastPos = [0,0,0]
def calculateVelocity():
        global lastPos
        pos = device.getPosition()
        distance = vizmat.Distance(lastPos,pos)
        velocity = distance/viz.elapsed()
        lastPos = pos
       
vizact.ontimer(0.1,calculateVelocity)


M@rcello 05-31-2016 08:12 AM

First of all thanks for your interest.

I thougth about this solution and in this case it could work.
The problem is:what happens when i need velocity information in real time during a task?
What I am trying to say is that velocity computed in this way could be affected by rumors,it means that i have to filter the information obtained.

What do you think?

Jeff 06-02-2016 11:37 PM

You could calculate the velocity from one frame to the next using the following:

Code:

lastPos = [0,0,0]
def calculateVelocity():
        global lastPos
        pos = device.getPosition()
        distance = vizmat.Distance(lastPos,pos)
        velocity = distance/viz.getFrameElapsed()
        lastPos = pos
       
vizact.onupdate(0,calculateVelocity)


Robin 02-03-2018 02:59 AM

getVelocity Function
 
Hello @Jeff & @Marcello,

since this thread is a little bit older, I wanted to know, if there is a update regarding the velocity issue.

I'm am working on a Virtual Track in WorldViz with STOP-signs, where the user is instructed to stop. Whether he does so, I wanted to controll with the help of a proximity sensor. The requirements for a successful "stop" should be "reached sensor" and "velocity = 0".

Within the vizard help I found the command getVelocity(), which only works with . Is it somehow possible to get the velocity of the user (or rather the MainView)?

Best regards
Robin

Jeff 02-04-2018 10:48 PM

Here's an example that prints out the viewpoint velocity each frame:

Code:

import viz
viz.go()

viz.addChild('piazza.osgb')

lastPos = [0,0,0]
def calculateVelocity():
        global lastPos
        pos = viz.MainView.getPosition()
        distance = vizmat.Distance(lastPos,pos)
        velocity = distance/viz.getFrameElapsed()
        print velocity
        lastPos = pos
       
vizact.onupdate(0,calculateVelocity)



All times are GMT -7. The time now is 07:25 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC