|  | 
| 
			 
			#1  
			
			
			
			
			
		 | |||
| 
 | |||
| 
				
				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()Any suggestions are appreciated, Thanks, -miles | 
| 
 | 
 | 
|  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 |