WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-30-2016, 04:30 AM
M@rcello M@rcello is offline
Member
 
Join Date: May 2016
Posts: 11
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!!
Reply With Quote
  #2  
Old 05-30-2016, 06:39 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,369
Do you mean the velocity of the stylus as the operator moves it or something else?
Reply With Quote
  #3  
Old 05-30-2016, 07:46 AM
M@rcello M@rcello is offline
Member
 
Join Date: May 2016
Posts: 11
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!
Reply With Quote
  #4  
Old 05-31-2016, 05:00 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,369
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)
Reply With Quote
  #5  
Old 05-31-2016, 08:12 AM
M@rcello M@rcello is offline
Member
 
Join Date: May 2016
Posts: 11
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?
Reply With Quote
  #6  
Old 06-02-2016, 11:37 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,369
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)
Reply With Quote
  #7  
Old 02-03-2018, 03:59 AM
Robin Robin is offline
Registered User
 
Join Date: Feb 2018
Posts: 1
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 <node3D>. Is it somehow possible to get the velocity of the user (or rather the MainView)?

Best regards
Robin
Reply With Quote
  #8  
Old 02-04-2018, 11:48 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,369
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)
Reply With Quote
Reply

Tags
omni, velocity

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Information associated with a model roobert Vizard 7 08-01-2014 09:34 AM
MainView velocity depending on joystick deflection 4711 Vizard 3 01-17-2014 01:50 PM
velocity shader subbu Vizard 0 11-24-2013 07:56 AM
how to remove velocity when mouse is disabled? jvacare1 Vizard 2 02-18-2010 11:25 AM
How Can I use two SensAble Omni at the same time junghungchien Vizard 0 09-03-2009 07:04 AM


All times are GMT -7. The time now is 02:05 PM.


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