#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 |
#2
|
|||
|
|||
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. |
#3
|
|||
|
|||
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 |
#4
|
|||
|
|||
It appears we have the pedals working now too, thanks Jeff for your help.
-miles |
#5
|
|||
|
|||
What did you do to get the pedals working?
|
#6
|
|||
|
|||
We had the hardware connected incorrectly, once it was connected I was able to poll <joy>.getSlider().
-miles |
#7
|
|||
|
|||
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?
|
#8
|
|||
|
|||
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 |
#9
|
|||
|
|||
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 |
#10
|
|||
|
|||
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) Last edited by miles; 04-27-2011 at 06:07 PM. Reason: Sample inaccurate |
#11
|
|||
|
|||
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) |
#12
|
|||
|
|||
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 |
#13
|
|||
|
|||
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) |
#14
|
|||
|
|||
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?
|
#15
|
|||
|
|||
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.
|
#16
|
|||
|
|||
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?
|
#17
|
|||
|
|||
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. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to create mini car driving by wiimote | superantTTY | Vizard | 7 | 05-18-2010 06:18 AM |
How to pause the Vizard simulation? | 4711 | Vizard | 4 | 03-18-2010 05:45 PM |
Particle simulation | imperialkat | Vizard | 0 | 01-29-2010 01:01 PM |
driving simulator | paulpars | Vizard | 1 | 05-12-2006 12:46 PM |