View Single Post
  #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