WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Driving simulation (https://forum.worldviz.com/showthread.php?t=3710)

miles 04-13-2011 07:31 AM

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

Jeff 04-13-2011 01:09 PM

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.

miles 04-18-2011 11:16 AM

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

miles 04-18-2011 01:29 PM

It appears we have the pedals working now too, thanks Jeff for your help.
-miles

Jeff 04-18-2011 05:37 PM

What did you do to get the pedals working?

miles 04-27-2011 08:16 AM

We had the hardware connected incorrectly, once it was connected I was able to poll .getSlider().
-miles

miles 04-27-2011 08:47 AM

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?

Jeff 04-27-2011 12:13 PM

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

miles 04-27-2011 02:51 PM

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

miles 04-27-2011 05:06 PM

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.

Jeff 04-29-2011 11:51 AM

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)


miles 05-23-2011 11:15 AM

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

kevin 06-07-2011 07:45 AM

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?

Jeff 06-10-2011 03:14 PM

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?

kevin 06-14-2011 07:31 AM

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.

Jeff 06-14-2011 11:43 AM

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?

kevin 06-14-2011 12:53 PM

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.


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

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