WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-13-2011, 07:31 AM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
Driving simulation

Hello all,

I have been tasked with creating a driving simulation to use with our existing code. I am fairly new to interfacing with devices, so I am having difficultly understanding what I need to do to make our hardware work with our existing virtual environment.

Our virtual environment can currently be navigated using mouse & keyboard or by using our Intersense system. We have a steering wheel (USB) and foot pedals (Serial with USB adapter), both from ECCI.

Here is the existing code to connect to either the Intersense or the mouse & keyboard. INTERSENSE and DRIVING are both flags set earlier in the program.
Code:
link = 0

# If we're using InterSense, attempt to connect to the tracker, then add a link to it
if INTERSENSE:
	print 'Checking for intersense attached to system'
	#Turn mouse control off
	viz.mouse(viz.OFF)
	
	tracker = viz.add('intersense.dls')
	if tracker:
		link = viz.link(tracker, viz.MainView)
		print 'Successful link to Intersense.'
	else:
		print 'Intersense tracker not found. Switching to mouse control.'
		link = 0
else:
	print 'Not using intersense'
	viz.mouse(viz.ON)
	viz.mouse.setTrap(viz.ON)
	
# If we don't find the tracker or have not loaded InterSense, we should be using the mouse and keyboard to control movement

# If we haven't found a link, we must use the initial link between the keyboard and mainView that is created
#	when we initialize a Vizard program.  Travis found this deep in the code, it wasn't well documented
if link == 0:
	import viztracker
	tracker = viztracker.KeyboardMouse6DOF()
	
	fixedTracker = viz.addGroup()
	link = viz.link(fixedTracker, viz.MainView)
	print 'Using keyboard link'
	
	# So instead of getting data from the InterSense to apply to the mainView, we use data from the keyboard and mouse
	#	Like in a video game.  Arrow keys move, not WASD
	
	def updateView():
		x,y,z = tracker.getPosition()
		fixedTracker.setPosition(x, 1.2, z)
		fixedTracker.setEuler(tracker.getEuler())
		
	vizact.ontimer(0, updateView)
	
	# If both InterSense and the keyboard aren't working, shut down the program
	if link == 0:
		print 'Could not load a tracker. Exiting.'
		sys.exit()
Do I need to write a plugin for the driving hardware? I've also looked into the built in joystick library, vizjoy, but I couldn't seem to find what I was looking for.

Any suggestions are appreciated,
Thanks,
-miles
Reply With Quote
  #2  
Old 04-13-2011, 01:09 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
Run the joystick.py example in the examples -> input folder of the Vizard installation to see if Vizard reads the controls of your steering wheel. If your steering wheel is seen by Windows as a standard gamepad device it will work with Vizard.

The Viewpoint Control tutorial shows how to move the body and head of the viewpoint independently. Move the body of the viewpoint around with steering wheel data and link the car to the viewpoint. Move the head orientation of the view with the Intersense data.
Reply With Quote
  #3  
Old 04-18-2011, 11:16 AM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
Jeff - Thank you for the tips. I looked into joystick.py and the viewpoint control tutorial and I have much of it working. The steering wheel was picked up by vizjoy and I can get readings from both joy.getPosition()[0] and joy.getAngle().

The pedals are still not working; with Windows 7 it appears as "USB HS SERIAL CONVERTER", which is the device we used to adapt the serial device to a USB port. Is there any way to communicate with this serial device?

Thanks again,
-miles
Reply With Quote
  #4  
Old 04-18-2011, 01:29 PM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
It appears we have the pedals working now too, thanks Jeff for your help.
-miles
Reply With Quote
  #5  
Old 04-18-2011, 05:37 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
What did you do to get the pedals working?
Reply With Quote
  #6  
Old 04-27-2011, 08:16 AM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
We had the hardware connected incorrectly, once it was connected I was able to poll <joy>.getSlider().
-miles
Reply With Quote
  #7  
Old 04-27-2011, 08:47 AM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
I've run into another issue, I'm not sure if it is appropriate to open a new thread. I got the car demo working with the steering hardware, but when I try to import this code into our project, I run into issues. It appears viz.MainView.move() does nothing after we create a link. Is there a way to apply car movement which could be recorded independently of head movement?
Reply With Quote
  #8  
Old 04-27-2011, 12:13 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
If the view is linked to the car then you will not be able to use the move command.

The tutorial I mentioned earlier uses viewpoint data to position the car. Maybe you want to set it up the other way around. The following thread explains how to link the view to a car's movement and apply tracking data relative to the car's orientation:

http://forum.worldviz.com/showthread.php?t=3656
Reply With Quote
  #9  
Old 04-27-2011, 02:51 PM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
We don't have an actual car object in our virtual environment like there is in the demo, I am just trying to move the subject. If you see in the code excerpt I have in the first post, we are linking which ever hardware device we are using to the MainView. Reading through the thread you've linked, I'm not sure how exactly this would tie in.

We need to record both the "car" position and the subject's position in the "car". One suggestion that has come up in the lab is to move the environment rather than the viewpoint. The thought is that we can record the environment's position for "car" position, and the MainView would be the position within the car.

I'm not sure how I'd move the environment as a whole, if that would mess up any of the existing code for recording data, or if this is even the right way to go. Thanks again for your thoughts and suggestions.
-miles
Reply With Quote
  #10  
Old 04-27-2011, 05:06 PM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
Update: I tried again to follow the thread you've linked. I created a blank node to represent the position of the car, and linked it to the MainView. It seems I can get one device working or the other, not both. Here is some relevant code:
Code:
tracker = viztracker.KeyboardMouse6DOF()
self.car = viz.addGroup()
self.link = viz.link( self.car, viz.MainView )
self.link.preMultLinkable(tracker)
With this code, only the vehicle controls work, not the keyboard/mouse. If I instead link the tracker directly with viz.link( tracker, viz.MainView ), the keyboard/mouse controls work, but not the vehicle controls.

Last edited by miles; 04-27-2011 at 05:07 PM. Reason: Sample inaccurate
Reply With Quote
  #11  
Old 04-29-2011, 11:51 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
Here's some code that moves a car forward/back with the joystick and links the view to the car. The viewpoint can be moved around with a keyboard tracker relative to the car. The viewpoint and car positions are printed out in a timer function. Does this help with your question?
Code:
import viz
import vizact
import vizjoy
import viztracker
viz.go()

keyTracker = viztracker.Keyboard6DOF()

viz.addChild('tut_ground.wrl')
viz.clearcolor(viz.SKYBLUE)

car = viz.addChild('mini.osgx')
ViewCarLink = viz.link(car,viz.MainView)
ViewCarLink.preTrans([-0.2,1.1,-0.3])
ViewCarLink.preMultLinkable(keyTracker)

joy = vizjoy.add()

def updateCar():
	#Use y position of joystick to compute forward car movement
	forwardMovementAmount = viz.elapsed() * 10 * -joy.getPosition()[1]
	car.setPosition( [ 0, 0, forwardMovementAmount], viz.REL_LOCAL )
	
vizact.ontimer(0,updateCar)

def recordData():
	print 'Car position',car.getPosition()
	print 'View position',viz.MainView.getPosition()

vizact.ontimer(1,recordData)
Reply With Quote
  #12  
Old 05-23-2011, 11:15 AM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
Apologies for delay in response. I found that the issue was link.reset(viz.RESET_OPERATORS), which apparently undoes preMultLinkable. Our research is just about done for the season. Thank you Jeff for all your help.

Regards,
miles
Reply With Quote
  #13  
Old 06-07-2011, 07:45 AM
kevin kevin is offline
Member
 
Join Date: Jun 2011
Posts: 18
Hi Jeff,

I've taken over the project from miles for this summer. Thanks for your help so far. We've almost got the entire rig working, but another problem has presented itself.

The code you provided in your last post was exactly what we needed. However, the car isn't turning properly. It's more or less drifting; when the steering wheel is turned, the car will turn in the right direction, but it will move both forward and to the side. Our code for moving the car is as follows:

Code:
self.car.setPosition([0,0,self.speed*viz.elapsed()],viz.REL_LOCAL)
self.car.setEuler([rot*self.speed*self.turn_speed*viz.elapsed(),0,0],viz.REL_LOCAL)
The head-tracking orientation data seems to be interfering with the local Z-axis of the car, though the local rotation is unaffected. I'm not sure whether to address the problem by making changes to the link or by making changes to the car movement. Any suggestions?
Reply With Quote
  #14  
Old 06-10-2011, 03:14 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
If you use the code I posted above and just add the line for turning to the updateCar function does the car appear to drift or does that work fine?
Reply With Quote
  #15  
Old 06-14-2011, 07:31 AM
kevin kevin is offline
Member
 
Join Date: Jun 2011
Posts: 18
The drift still happens. I've actually found that the car itself still navigates properly (we had switched to using an empty node). It's only the MainView which 'drifts.' The preMultLinkable operator seems to be the cause.
Reply With Quote
  #16  
Old 06-14-2011, 11:43 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
If I run the code I posted which uses a keyboard tracker to move the view I don't notice any drift. Is that what you are testing with or are you modifying the code at all or using a different type of tracker?
Reply With Quote
  #17  
Old 06-14-2011, 12:53 PM
kevin kevin is offline
Member
 
Join Date: Jun 2011
Posts: 18
We're using an Intersense tracker. Perhaps the drift is occurring because the tracker is not centered to begin with?

I've managed to get things working properly by establishing a link between the tracker and the MainView and then using setPos and setEuler operators, directly calculating where the MainView should be given the car's position and heading, and the data from the Intersense tracker.
Reply With Quote
Reply

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
How to create mini car driving by wiimote superantTTY Vizard 7 05-18-2010 05:18 AM
How to pause the Vizard simulation? 4711 Vizard 4 03-18-2010 04:45 PM
Particle simulation imperialkat Vizard 0 01-29-2010 12:01 PM
driving simulator paulpars Vizard 1 05-12-2006 11:46 AM


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


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