psmoveservice / PSMoveService

A background service that communicates with the psmove and stores pose and button data.
Apache License 2.0
590 stars 148 forks source link

Create OpenVR plugin for psmoveservice #23

Closed HipsterSloth closed 8 years ago

HipsterSloth commented 8 years ago

In order to make the PSMoveService broadly usable I think it makes the most sense to create an OpenVR plugin. This will expose the psmove controllers and the ps3eye trackers to SteamVR. Fortunately Valve has already provided a reference driver for the Razer Hydra so it should be pretty straight forward to adapt a plugin that connects to PSMoveService instead.

HipsterSloth commented 8 years ago

The first revision of the the steam vr plugin is implemented and now in master, but it's still untested. I'm going to try and get it working by the end of the week.

zelmon64 commented 8 years ago

@HipsterSloth After seeing your video this morning I thought I'd have a go. After managing to register the driver with SteamVR it worked just like in your video. When I re-ran SteamVR both PSMoves were vibrating continuously. This vibration would not stop until I closed PSMoveServer.

So far I've been able to get them to work in SteamVR two more times without the vibration but I can't seem to do it reliably. This vibration seems random - sometimes it's both and other times it's just one.

The vibrating also happens when I run PSMoveConfigTool. I'm using VRidge as my HMD and if my phone is connected and the driver is registered then the PSMove will vibrate when I run PSMoveConfigTool. If either the phone isn't connected or the driver isn't registered then I get no vibration. PSMoveConfigTool can detect my HMD either will or without the psmoveservice driver being registered with SteamVR. If I launch SteamVR without the phone connected the PSMove will sometimes be okay and other times it will vibrate.

Obviously it may be something with VRidge interfering with PSMoveService but seing as it has worked a couple of times I'm not so sure.

I really like how I can see where the PSEyes are in SteamVR (only tested with two so far). It is also quite nice that as long as PSMoveService is running before SteamVR, the PSMoves can be turned on before or after launching SteamVR and they will connect (I had one connected and not vibrating so I turned another on and it was also fine).

If there's any thing you'd like me to try just say the word :)

HipsterSloth commented 8 years ago

@zelmon64 Thank you for testing this. After looking at the plugin I realized I had a few bugs with the rumble update. Some uninitialized variables as well as not resetting the rumble if no new rumble value has been sent after a timeout. I was also able to fix the SteamVR crash I was getting. Turns out I was accidentally saying that the tracker implemented the controller interface (which it doesn't). When Steam VR tried to send a controller rumble to the tracker it would crash. This is now all fixed in latest (c092b9e1d958d8261f67d0d14ccd59de8e0a923b).

Would you mind giving this a quick test. As a bonus, if it works for you you should now be able to play steamvr games :).

zelmon64 commented 8 years ago

@HipsterSloth That's great news. I'll test it in the morning as it's 1:20 am here and I'm about to go to sleep ;).

I just have a question about the wiki. You say to run InitialSetup.bat then ReinstallDriver.bat.To get it working I copied the contents of openvr_plugin to a similar folder structure as the Hydra driver then just registered the folder with SteamVR. Would it be better for me to do it your way? Those .bat files were a little complex for me to understand straightaway.

HipsterSloth commented 8 years ago

@zelmon64 Oh no rush! Sleep is certainly more important :).

Those batch files should be doing the same thing that you did manually. And if fact if they don't that's a bug in the scripts I'd love to hear about. In fact I'm trying to get the custom psmove and ps3eye render models to show up and am not having much luck so it's possible the scripts aren't doing the right thing.

zelmon64 commented 8 years ago

@HipsterSloth I got it working with two and three PSEyes. I did it my way as I don't have OpenVR. Is it needed? I didn't want to complicate things by installing it if it's not necessary.

I can launch and close games fine. The buttons seem to work fine (where is the config file for that?). The vibration is much better but there may still be some bugs. I tried the tutorial and the vibration got stuck a couple of times. In the end I had to close the tutorial to stop the vibration.

I finally managed to get driver_null to work. Do you know if there's a way to move about with a controller or keyboard and mouse? I seem to be stuck upside-down for some reason. [edit] It turns out that I was upside-down because I needed to run room scale. I still can't figure out how to move though.

HipsterSloth commented 8 years ago

@zelmon64 OpenVR doesn't appear to be needed. I have SteamVR at work and OpenVR at home. I think the script should work with either an OpenVR install or a SteamVR install. The batch file looks for the OpenVR folder first and if it doesn't find it then it looks for the SteamVR folder. The directory structure internally looks to be the same. To be completely honest I don't know how I got OpenVR instead of SteamVR at home.

For the moment the button mapping is hard coded. I need to expose that in the config settings. I'll let you know when I get that in. I'm working on fixing up a bunch of nasty bugs related to controller pairing today.

That's interesting the vibration still get's stuck. I'll try and take a look at that today if I have time.

As far as movement is concerned I don't know if there is any keyboard mapping for the null driver. My guess is that movement via gamepad or keyboard would be game specific. I take it the VRidge doesn't support head tracking?

EDIT: Thanks for testing all this btw!

zelmon64 commented 8 years ago

@HipsterSloth It was just that the batch file complained at me for not finding OpenVR so I wasn't sure if it just gave up or moved onto SteamVR like you said.

I only asked about the button mapping because I remembered it. There's absolutely no rush.

VRidge can do orientation and also position with the help of FreeTrack. It just could be more convenient not to have to keep fiddling with an HMD when testing. I thought you may have had some experience with driver_null since it's in the wiki but thinking about it I suppose it was just coppied from the Hydra driver then.

I have quite a bit of free time at the moment. I quite like coding, fiddling with computers and getting thing to work so by helping out with this I can feel useful :)

HipsterSloth commented 8 years ago

@zelmon64 I just checked in a ton of fixes into master. One of them should have fixed the rumble issue. When you have a spare moment I'd love to know if it fixes it for you. Also after you pull latest, make sure to git submodule update in the project root since I updated the ps3eyedriver submodule (some multithreading bug fixes).

zelmon64 commented 8 years ago

@HipsterSloth I managed to use your batch files to register the driver this time. I had to change the paths a little though because my PSMoveClient.dll and driver_psmoveservice.dll get built to PSMoveService\build\src\psmoveclient\Release\ and PSMoveService\build\src\openvr_plugin\Release\ respectfully. I build them by going to Build > Build Solution in VS2013.

Unfortunately the vibration still seems problematic. I don't know if it would have anything to do with the way the buttons get disabled in the tutorial perhaps? Do you know of a good (free) game to test the rumble in?

I like how the red LED on the PSEyes now turn off when I close the service but the window no longer closes itself. I don't know if it's getting stuck on something maybe.

Another problem is that the yaw drift seems to be worse than it was. Sometimes I can calibrate the magnetometers then by the time I launch SteamVR the controllers have rotated by 90 deg or more. I don't think there should be anything destabilising my local magnetic field.

Sorry for all the bad news.

[update] I tried The Lab but couldn't press the start button. The trigger works fine in the menu and when looking at the desktop I can click-and-drag just fine. I bought Cosmic Trip because that flying companion looks so darn cute but I can't select to start.

While in Cosmic Trip I noticed that sometime the rumble turned off fine and others it didn't. In the game if you turn over a controller it shows you how many crystal you've collected and it does a quick burst of vibration. This always turns off fine. On the other hand, if you activate the weapon it does a burst then a sustained low rumble. When the weapon is deactivated the rumble should turn off but it doesn't.

I've been thinking that maybe the games try to gradually stop the rumble rather than going from fully on to off. I remember from somewhere that a low rumble setting would not turn off the rumble. Could it be something like that? If the setting is 0 to 255 then perhaps anything below 70 should be set to 0 or something like that?

Back to the game, I was able to select things when I used the Hydra emulation method but I couldn't fling the weapons. I think this may be because the raw IMU data isn't transferred from the PSMove to the Hydra (only the position and orientation are). And of course I wasn't able to see if it works with your driver because I couldn't select start.

Since there is currently no trigger animation I was wondering if the scale is correct. When emulating the Hydra the trigger wanted a value from 0 to 1 but initially I was passing the total 0 to 255 so it would spin around madly. I tried changing what I thought was the correct setting (NewState.rAxis[0].x = clientView.GetTriggerValue();) but it didn't seem to have an affect.

HipsterSloth commented 8 years ago

@zelmon64 Oh yeah I forgot to mention after you build in VisualStudio you want to build the "INSTALL" target under "CMakePredefinedTargets". This copies all of the built binaries and scripts into a top level win32/bin folder. That's the folder the SteamVR install scripts are meant to copy the binaries from. I really need to write up some documentation for all this stuff tonight. Thanks for slogging through this process without any info.

I was able to repo the stuck rumble issue in TiltBrush (does a test rumble on each controller at start). I checked in another fix that appears to fix it (at least in that instance).

I also made another fix for occasional poor video feed performance that involved tweaks to the PS3EyeDriver. If you get latest make sure to do a git submodule update.

I still haven't figured out the wired controller orientation issue. Does it repro for you in the "Test Orientation" window too? Also what does the megnetometer calibration block in C:\Users\<username>\AppData\Roaming\PSMoveService\<controller bluetooth address>.json look like?

Here's mine:

        "Magnetometer": {
            "Center": {
                "X": "61",
                "Y": "-131.5",
                "Z": "58"
            },
            "BasisX": {
                "X": "1",
                "Y": "0",
                "Z": "0"
            },
            "BasisY": {
                "X": "0",
                "Y": "1",
                "Z": "0"
            },
            "BasisZ": {
                "X": "0",
                "Y": "0",
                "Z": "1"
            },
            "Extents": {
                "X": "146",
                "Y": "148.5",
                "Z": "146"
            },
            "Identity": {
                "X": "-0.346990079",
                "Y": "0.92931366",
                "Z": "0.126388475"
            },
            "Error": "16.8810806"
        }

As for the physics, yeah I need to pass the velocity etc. There was a bug with the data I was getting from the service so I disabled it for now. I'll try and look into that soon.

I'll try to take a look at the trigger thing too.

Finally I make a proper release. I'd be curious if the binaries and scripts work for you. https://github.com/cboulay/PSMoveService/releases/tag/v0.9-alpha

zelmon64 commented 8 years ago

@HipsterSloth The INSTALL build and your alpha don't have the CLEyeMulticam.dll file (so I just copied it across). The vibration definitely seems better now. I'd have to compare it to a Vive controller to be sure but it seems okay to me.

Looking at the SteamVR_UninstallDriver.bat file it appears not to remove the driver with vrpathreg after deleting the files so it may be nice to add that in. Do you know where vrpathreg stores the paths? Mine will probably be quite a mess and I'd like to clean it up. The SteamVR_InitialSetup.bat file also complains on first run because there is no SteamVR_SetDriverVars.bat file to delete but this does not seem to be a real problem.

Here's one of my calibration files:

{
    "is_valid": "true",
    "version": "2",
    "prediction_time": "0",
    "max_poll_failure_count": "100",
    "Calibration": {
        "Accel": {
            "X": {
                "k": "0.000233562998",
                "b": "0.0507999659"
            },
            "Y": {
                "k": "0.000230282094",
                "b": "0.0609096289"
            },
            "Z": {
                "k": "0.00022893773",
                "b": "0.0570055246"
            }
        },
        "Gyro": {
            "X": {
                "k": "0.00155140378",
                "b": "0"
            },
            "Y": {
                "k": "0.00190097129",
                "b": "0"
            },
            "Z": {
                "k": "0.00157769886",
                "b": "0"
            }
        },
        "Magnetometer": {
            "Center": {
                "X": "56.5",
                "Y": "-56",
                "Z": "-109"
            },
            "BasisX": {
                "X": "1",
                "Y": "0",
                "Z": "0"
            },
            "BasisY": {
                "X": "0",
                "Y": "1",
                "Z": "0"
            },
            "BasisZ": {
                "X": "0",
                "Y": "0",
                "Z": "1"
            },
            "Extents": {
                "X": "167.5",
                "Y": "169",
                "Z": "161"
            },
            "Identity": {
                "X": "0.267718643",
                "Y": "0.933811128",
                "Z": "-0.237325698"
            },
            "Error": "13.150588"
        }
    }
}

I gave the PSMove quite a vigorous shake while watching it with the test orientation. This appears to jar it such that it becomes misaligned in the yaw direction of the room's reference frame (rather than the PSMove's reference frame). If I'm more gentle with it there's no problem. I've actually seemed to have shaken loose something in one of my PSMoves but this doesn't appear to affect it. I'll have to open it up and remove the offending piece.

Just to let you know, I'll be going on a family holiday this Saturday so I won't be able to help while I'm away. Sorry for the inconvenience. Keep up the good work. I really appreciate the work you and cboulay are doing!

HipsterSloth commented 8 years ago

@zelmon64 Good catch with the CLEye dll. I updated the cmake script to copy the dll into the win32/bin folder when the "install" project is built. I also updated the steamvr uninstall script to make the remove driver call to steamvr. I'm not sure the the registered paths are stored. I would assume in C:\Program Files (x86)\Steam\config but the steamvr.vrsettings file doesn't appear to have any entries in there. The complaint about SteamVR_SetDriverVars.bat is not a problem. It's just me not knowing how to make a batch file that doesn't complain when there is no file to delete.

As for the drift issue, your magnetometer settings look totally fine. This makes me think I need to adjust the orientation filter to better detect when the Magnetometer/Accelerometer derived orientation deviates too far from the integrated Gyroscope orientation I need to crank up the blending weight to compensate for the drift. This probably gets aggravated by sharp controller movements since the accelerometer is used to tell where gravity is pointed, but under other accelerations it throws this movement off. Ideally I should detect when the accelerometer is getting spiked and only use gyros in that case.

And please don't feel obligated to any time commitments :). I appreciate all the time you've given so far to this. Enjoy your weekend!

zelmon64 commented 8 years ago

@HipsterSloth Looking back at my previous comment I realise that I didn't say that the holiday is for a week. That's the main reason I mentioned it. I didn't want you to get the the wrong impression if I suddenly stopped replying ;). I know it can get a little annoying if you're waiting for someone to give feedback on something.

Thanks. Hope you have a good weekend too =) .

(ps. Thanks also for the information on marshalling, I didn't even know that's what it's called)

cboulay commented 8 years ago

BTW, we can make CMake post-build or install commands do most of the work in SteamVR_InitialSetup.bat and SteamVR_ReinstallDriver.bat, possibly in a cross-platform way.

HipsterSloth commented 8 years ago

Yeah I've been meaning to make the cmake install script do the work that SteamVR_ReinstallDriver.bat does. We could probably replace the SteamVR_InitialSetup.bat with a FindSTEAM.cmake script. We would still need to generate the SteamVR_ReinstallDriver.bat file in the win32.bin folder though for people that are downloading a binary release (not building from source). That or make a proper installer like the Leap Motion SteamVR plugin does.

toto5100 commented 8 years ago

For me, the OpenVR implementation does not work. The controllers do not show, and it seems that the PSMove Service is not able to send data to OpenVR. When i do vrcmd, it returns :

Driver psmove : 0 displays Driver null : 0 displays [ERROR] ClientNetworkManager::stop - Problem shutting down the socket : a sending or receiving data request could not be authorized because the socket is not connected (when sending a socket datagram using a sendto call) and no adress has been provided.

On the psmove service windows it shows :

[2016-06-10 17:44:32.747088]: ClientConnection::send_connection_info - Sending connection id to client 0 [2016-06-10 17:44:32.860198]: ClientConnection::handle_tcp_read_request_header - failed to read header on connection 0: An existing connection was forcibly closed by the remote host. [2016-06-10 17:44:32.860198]: ClientConnection::stop - Stopping client connection id 0

HipsterSloth commented 8 years ago

Do you have SteamVR running when you call the vrcmd? If I don't have SteamVR started and I run vrcmd I get the same output you do. If I then start SteamVR my controllers light up and when I run the vrcmd I get the following output:

Driver psmove : 4 displays PSMove (Serial number psmove_controller0) PSMove (Serial number psmove_controller1) PSMove (Serial number psmove_tracker0) PSMove (Serial number psmove_tracker1) Driver psmove : 4 displays PSMove (Serial number psmove_controller0) PSMove (Serial number psmove_controller1) PSMove (Serial number psmove_tracker0) PSMove (Serial number psmove_tracker1)

Also do your controllers show in the "Controller Settings" menu when you run the PSMoveConfig tool?

toto5100 commented 8 years ago

Yes, the controllers are showing, and they are correctly tracked. I tried vrcmd with steamVR open, and now i get the same output as you. But SteamVR do not detect them, in the steamVR panel, the icon is still grey.

HipsterSloth commented 8 years ago

My next guess is that your tracking color calibration is off. I'm writing instructions for how to set that up today, but it the mean time you can see this video of me running though the process myself:

https://www.youtube.com/watch?v=1eKVqyo52IA

One thing that's new since this video was shot is that you can right click on the tracking bulb in the video and it will sample the hue, saturation, and value to use for the filter. You typically have to adjust the saturation range a bit after that too,

zelmon64 commented 8 years ago

@toto5100 Do you have the following in your steamvr.vrsettings file?

"steamvr" : {
      "activateMultipleDrivers" : true,
toto5100 commented 8 years ago

I already calibrated the color by right clicking, and in the masked view it looks great. My problem is that SteamVR do not detect them : http://i.imgur.com/uju9Sfh.jpg

Also, nothing to do with psmove, but i have now a new dumb problem : i went in oculus setting, and naively tried to reset dk2 position, and now, i'm stuck in the oculus setup screen, saying that i must press "A" to continue... but i don't have a xbox controller !

EDIT : fortunately dk2 problem resolved :)

toto5100 commented 8 years ago

@zelmon64 yes, i have I installed razer hydra steamvr drivers, and now they are detected. It's strange.

cboulay commented 8 years ago

@toto5100 Can you clarify? Do you mean that the PSMove controllers are now detected after installing the Hydra drivers?

toto5100 commented 8 years ago

They were detected by the PSMove Service and PSMove Config (i was able to calibrate magnometer), but not by SteamVR. Then, i installed steamvr hydra drivers (https://github.com/betavr/steamvr_driver_hydra/releases/tag/v1.0.1.9) and retried, and it worked. I don't know if it was really useful, but i did not do anything other than that.

cboulay commented 8 years ago

The plugin is in master. Though it's not perfect, it's there and it's working. Closing this issue. Great job @HipsterSloth