WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1  
Old 01-05-2009, 04:38 AM
Saz Saz is offline
Member
 
Join Date: Nov 2008
Posts: 36
updating positional data

Hi,

hope you all had a good Christmas and New Year. I am trying to get the joystick position to update on the screen, however instead of updating it merely writes over the previous value resulting in a huge jumbled mess. Would I need to define this process as a separate function?

Code:
file = open( 'speed_.txt' + str(subject),'w' )
#Open file in path
#file = open( path + 'speed.txt', 'w' )

def mytimer (num):
	joy_pos = str(joy.getPosition())
	#speed = joy_pos*[0.0,5.0,0.0]
	out = str(joy_pos + '\n')
	file.write(out)
	file.flush()
	print out
	
#Add text to the screen.
	speed = viz.addText(joy_pos, viz.SCREEN)
	speed.setPosition(.05, .9 ) 
	speed.fontSize (30)
	
	speed.message(str(joy_pos))
	
viz.callback( viz.TIMER_EVENT, mytimer )
viz.starttimer( 0, 0.25, viz.FOREVER )
Also as its the joystick position it comes up as an [x, y, z] co-ordinate system whereas I'm only really interested in the y-axis, is there a way around this? Its coded as follows:

Code:
def UpdateJoystick():
    #Get the joystick position
    x,y,z = joy.getPosition()
    #Get the twist of the joystick
    twist = joy.getTwist()
    #Move the viewpoint forward/backward based on y-axis value
    if abs(y) > 0.001: #Make sure value is above a certain threshold
        viz.MainView.move(0,0,-y*MOVE_SPEED,viz.BODY_ORI)
    #Move the viewpoint left/right based on x-axis value
    if abs(x) > 0.001: #Make sure value is above a certain threshold
        viz.MainView.move(x*0.1,0,0,viz.BODY_ORI)
    #Turn the viewpoint left/right based on twist value
    if abs(twist) > 0.001: #Make sure value is above a certain threshold
        viz.MainView.rotate(0,1,0,twist,viz.BODY_ORI,viz.RELATIVE_WORLD)
The y position would also need to be multiplied by a value in order to make sense but I'm guessing that's a simple math function?
Any help - as usual will be greatly appreciated!!!
Reply With Quote
  #2  
Old 01-05-2009, 10:02 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
for your first question you could just add a textbox to your screen instead of text
Code:
speed = viz.addTextbox(parent = viz.SCREEN)
add the textbox and set its position outside of your timer function and then change the message in the timer function.

I not sure if I understand your second question. If you only want to move in the y direction then you could just remove the code that updates the x position and turns the viewpoint from UpdateJoystick()

Code:
def UpdateJoystick():
    #Get the joystick position
    x,y,z = joy.getPosition()

    #Move the viewpoint forward/backward based on y-axis value
    if abs(y) > 0.2: #Make sure value is above a certain threshold
        viz.MainView.move(0,0,-y*0.1,viz.BODY_ORI)
you can multiply the y value by something else if you want it to update by a different amount.
Reply With Quote
  #3  
Old 01-08-2009, 02:44 AM
Saz Saz is offline
Member
 
Join Date: Nov 2008
Posts: 36
Hi Jeff,

thanks for that, the joystick position is updating fine now once I took the textbox out of the timer loop. No, for the second part the code for the joystick position is working fine but what I am getting up on the screen at the moment is obviously the raw data of the joystick output - which is pretty meaningless to the observer, additionally it appears in the co ordinate system format of [0.0 0.0 0.0], wheareas I'm only really interested in the y co ordinate.

Therefore I'm trying to multiply the raw data of the joystick that's already acquired so that it appears in a meaningful context on the screen, say as mph or kph - which is what I'm having difficulty with
Reply With Quote
  #4  
Old 01-08-2009, 11:00 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
this should update the speed in just the y direction every time the timer function is called

Code:
#add textbox and set position on screen
text_speed = viz.addTextbox(parent = viz.SCREEN)
text_speed.setPosition(.15, .9 ) 
text_speed.fontSize (30)

old_posY = 0
def showSpeed():
	
	global old_posY
	
	current_pos = viz.MainView.getPosition()
	current_posY = current_pos[1]
	distance = abs(current_posY - old_posY)
	
	#get speed in meters/sec
	speed = distance/viz.elapsed()
	#get speed in km/hour
	speed = speed/1000*3600
	
	old_posY = current_posY
	
	#enter speed in textbox rounded to 1 digit after decimal
	text_speed.message(str(round(speed,1)) + 'km/hour')
	
vizact.ontimer(.25, showSpeed)
Reply With Quote
  #5  
Old 01-09-2009, 04:59 AM
Saz Saz is offline
Member
 
Join Date: Nov 2008
Posts: 36
Hi Jeff,

thanks for that - unfortunately it doesn't update and I constantly get 0.0km/hr on the screen - even though its moving along the road. I tried inserting joy.getPosition() in place of viz.MainView.getPosition() to see whether the code in principle functions and whilst that does produce a change in km/hr when either accelerating or deccelerating, because this piece of code is looking at a difference between outputs - when the joystick is held constant; there is no difference and so 0.0km/hr appears on the screen
Reply With Quote
  #6  
Old 01-09-2009, 10:17 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
That code should give you 0 km/hour if you are not moving along the y-axis which is the height. I think you may be wanting to get the speed along the z-axis. If that's the case then just dind the difference in z coordinates rather than the y coordinates.
Reply With Quote
  #7  
Old 01-09-2009, 10:29 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
just to clarify, in the joystick navigation code, when you move the joystick on its y-axis that moves Vizard's viewpoint forward or backward which is Vizard's z axis. So to get the current z position just do

Code:
current_posZ = current_pos[2]
Reply With Quote
  #8  
Old 01-12-2009, 03:20 AM
Saz Saz is offline
Member
 
Join Date: Nov 2008
Posts: 36
you're a star Jeff - thank you!! Is there any reason that I'm getting a continual drift of the viewpoint to the right though, even if I'm not using the joystick?
Reply With Quote
  #9  
Old 01-12-2009, 05:23 AM
Saz Saz is offline
Member
 
Join Date: Nov 2008
Posts: 36
Don't worry Jeff - its sorted! Cheers for your help!
Reply With Quote
Reply


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
output data to screen Saz Vizard 1 12-19-2008 05:59 PM
Flagging the Data Elittdogg Vizard 5 04-11-2008 12:40 PM
Data Files betancourtb82 Vizard 6 05-04-2006 03:43 PM
Obtaining Positional Data Plasma Vizard 40 04-04-2006 12:31 PM
tracking using quaternarion data jfreeman Vizard 2 06-01-2005 09:48 AM


All times are GMT -7. The time now is 03:36 PM.


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