Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

OSCuMote - Wiimote support for the free version

Discussion in 'Made With Unity' started by sketchground, Apr 17, 2009.

  1. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    With no native plugin support with the indie license i decided to create a workaround.
    It basically consists of OSCulator sending OSC messages to unity over UDP and my little wrapper that parses these OSC messages.

    As OSCulator supports multiple wiimotes and Balance Boards so does my little wrapper.
    As of version 1.2, Nunchucks, Classic Controllers, Motion plus, vibration, LED and motion plus recalibration support has been added.



    Only problem is that with the unregistered version of OSCulator, sending is blocked while "nagging screen" is shown :S (happens around every 10 minutes).

    GlovePIE for windows might be a viable alternative for the ones not running OSX.

    Edit: The source is uploaded and can be found here: http://itu.dk/people/jzso/OSCuMote/oscumote.html
     
  2. ttt121

    ttt121

    Joined:
    Oct 20, 2008
    Posts:
    18
    good~this is my interesting~ Can you share your plugin files or scripts? I hope to enjoy it~ :p
     
  3. ron333

    ron333

    Joined:
    Jan 3, 2009
    Posts:
    47
    Yes, I am interested. Having the Wiimote work with Indie would be great.
     
  4. larsjessen

    larsjessen

    Joined:
    Mar 17, 2008
    Posts:
    44
    I would be very interested in seeing the code as well - I am trying to do something similar and don't have too much experience with the OSC protocol. Are you planning to make it public at some point?

    I am also using OSCulator - but you can use the DarwiinremoteOSC as well which doesn't have any popup windows
    http://code.google.com/p/darwiinosc/downloads/list

    However, I don't think it supports the balance boards
     
  5. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Oh my... Yeah I'm very interested! larzie is right, DarwiinremoteOSC would be a great replacement - there are some Processing examples that use it.

    I would definitely appreciate this as I've been working on some interactive music video prototypes and I've had the Wii remote in mind this whole time. I was afraid I'd have to wait until I had Unity Pro, but it'd be great to test this out before I can save up for it.
     
  6. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Why not simply build OSC into DarwinRemote, and make DarwinRemote run as a background process?
     
  7. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    Here's the source. I'm terribly sorry for the long response time. I failed to notice that people had replied to my post :)

    http://www.itu.dk/people/jzso/OSCuMote.zip

    I hope it's still of any use.
    Some of the code was inspired by another user from the forum which i unfortunately forgot his name. But thanks to him anyways if he sees this.
     
  8. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Thanks so much for this! Once I get something going using this, I'll make sure to post it in the showcase.

    And if I end up doing any enhancements to this, I'll post it here, too.
     
  9. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    @ bliprob : yes i do agree that it might be a better solution however it would require learning objective C :) I'm not sure if darwiin remote supports balance boards either.

    @God at play: Sounds great :)
    Regarding the DarwiinOSC if it sends the same OSC messages as OSCulator does then it should work out of the box.

    Again i really wanted balance board support so that's why i decided to use OSCulator.
     
  10. larsjessen

    larsjessen

    Joined:
    Mar 17, 2008
    Posts:
    44
  11. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    432
    Looks great ! Would love to test it too, but the links are no more functional...
     
  12. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    @Yann

    I have updated the links so they work now. I hope the code is still useful as i haven't looked at it for quite a while :)
     
  13. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    432
    @sketchground : this is very kind of you, thank you so much ! :D
     
  14. deepcgi

    deepcgi

    Joined:
    Aug 24, 2006
    Posts:
    57
    I haven't been able to download the link for some reason.

    Also, I noticed they are working on a beta version of the wiimote driver with the motion-plus add-on in Osculator.

    thanks.
     
  15. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    Sorry i had only remembered to update the url in the initial post. But it is all changed now. I just checked it and the updated one still works fine :)

    Yea i have noticed they are working on a beta for motion plus. Once that is done it should be really easy to extend the script to support it as well.

    Good luck with it.
     
  16. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    If any of you put it into cool use i would love to see the results :)

    And if you have any suggestions of improvements of the code please share.
     
  17. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    Many thanks for this. Im not going to use it with wii remotes, but rather other osc stuff such as the jazzmutant lemur, monomes, and max4live.

    I will post details when I have done something with it, I have a lot to learn about unity so it may take a while.

    By the way I think there is a new version of osculator on their website now.
     
  18. gavspav

    gavspav

    Joined:
    Dec 3, 2009
    Posts:
    1
    Thanks to the OP for these scripts,

    I needed to get data from the Nunchuk and accelerometer x/y/z data so I amended the scripts to display these.

    I culled the Balance board though sorry.

    The X/Y/Z acceleration for the Wiimote is at the bottom of the Nunchuk section - sorry couldnt be bothered to change all the text positions for a test app.

    I've attached the amended scripts and the Osculator project file.
     

    Attached Files:

  19. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    I have pulled up the project again and added support for a whole range of things. Some of it is listed in my initial post with a deeper explanation on my website linked to in the initial post as well.
     
  20. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    This is an awesome update! Thanks.

    I think I might prefer this over the plug-in; connecting seems to be a lot more reliable and it doesn't give me kernel panics. :p

    I'll try to get this integrated into my app and let you know how it goes.

    One suggestion: your documentation wasn't clear that in OSCulator you have to set every item to OSC Routing and localhost:8876. Might want to add that in there for those just starting out.
     
  21. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    Thanks God at play.
    I'll specify that a little more clear.

    I'd like to hear how it goes. :)
     
  22. menace

    menace

    Joined:
    Nov 12, 2008
    Posts:
    5
    Thank you very much for your hard work! This is exactly what i need right now.
    I am trying to make this work with GlovePie as i work under windows with Unity.
    I found out that Glovpie 0.30 works with osc so this should work but it doesnt.
    Unity doesnt react on the Wiimote Inputs being sent over OSC.

    I tried your 1.2_Beta too.

    I am thankfull for every clue.

    Update:

    Now I get console messages like:

    ,f
    ,f
    ,f
    ,i
    ,i

    ... and so on

    So OSCuMote does receive something from GlovePie I guess, but i have no GUI in Unity3d showing the values like in your screenshots. I go further investigating.

    Is there a OSC Message needed for this :

    Code (csharp):
    1. if(receiver.wiimotes.ContainsKey(1) )
    what is ContainsKey?
     
  23. MartyC

    MartyC

    Joined:
    Oct 30, 2009
    Posts:
    17
    @Menace

    Yep, basically what you do from glovepie is that you send out the following:
    (Cant guarantee the caps is correct :) but you'll see if it works when you e.g. copy paste it)

    SendOSC(ip,port,<address>, values)

    So for instance, this following code would send a message to the local pc, on port 6000 - and indicate what it is:

    SendOSC(127.0.0.1, 6000, "/wii/1/button/A", 1.0)

    Then in the Unity Oscumote part, you ensure that the port in the script is set to the same (in this case 6000) - what the code you posted yourself then does is check the "/1/" value - if its a 1 - then it has found wiimote 1 and will access the GUI parts and such to be displayed in Unity.

    In this case the data is sendt as a 1.0 - meaning it will always be true - we dont want that, so either directly link the button input through a Wiimote.A in glovepie, or store the data as a float in GlovePie using something like var.buttonA = wiimote.A .

    That way, whenever you hit button A it will return 1.0, and if you dont it will return 0.0.

    Anyway, to help ease things up a bit - if you havent figured it out by tomorrow :) i'll throw up my GlovePIE to Unity script which contains all that is needed for using all the buttons, pitch and roll and the XYZ (using sensor-bar) - so all you have to do is run it.

    Its on my work pc which i cant access right now, so you'll have to wait for tomorrow.


    EDIT: Remember (and this is important) to have the same port number in the GlovePIE script AND in the WiimoteReciever script in Unity! otherwise you wont get squab out of it.
     
  24. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    I think MartyC is right on.

    That printout of ,f or ,i is actually a mistake on my behalf. It is a debug print i have forgotten to delete :)
    I suggest you delete that line in WiimoteReceiver.cs (Line 105: MonoBehaviour.print(message.TypeTag); ) as it will slow down the script as a whole.

    To follow up on your question about:
    if(receiver.wiimotes.ContainsKey(1) )

    What it does is checking if there is a wiimote number 1 connected. And if there is, we can extract data from the Wiimote object stored in receiver.wiimotes.

    Again. I believe too that your problem is in the address you send as MartyC mentioned. If the "message address" is wrong, that might very well be why the GUI don't appear.

    Hope it helps :)
     
  25. menace

    menace

    Joined:
    Nov 12, 2008
    Posts:
    5
    Thank you very much you both! Just came home and saw your posts. It will be the first thing i try at work tomorrow. I left my Notebook at work. So i can´t test it here. If it still doesnt work i will certainly ask you for the GlovePie script.
     
  26. MartyC

    MartyC

    Joined:
    Oct 30, 2009
    Posts:
    17
    Right :) im at work now so i'll just attach what i have here atm.
    Its proberbly not that optimized and can most likely be done a bit better - however its been tested in several applications and turned out to work just fine :)

    Theres a few comments in the script to ease the understanding :) but feel free to ask if any problems arise.
     

    Attached Files:

  27. menace

    menace

    Joined:
    Nov 12, 2008
    Posts:
    5
    yep! it works now. Great stuff!
    Thx alot. First time using osc for something.
    Your script is great because now i have a template for glovepie and understand glovepie osc -> oscumote.

    Edit:

    GlovePie 0.43 works too! Just tested it.

    Greetings meNace
     
  28. MartyC

    MartyC

    Joined:
    Oct 30, 2009
    Posts:
    17
    Its sort of random if it works with the never versions :) if you read the documentation for 0.43 he actually mentions that the OSC part is broken from 0.40 onwards :D but hey, if it works for you thats great!
     
  29. menace

    menace

    Joined:
    Nov 12, 2008
    Posts:
    5
    Bugs in short form:

    1.Oscumote doesnt close after you press stop in the unity editor. CPU usage is still 50% for unity.

    2.Oscumote saves all data being sent to it. Never deleting old data. Footprint (taken RAM) is getting bigger and bigger by time.


    Hi i found a bug in Oscumote. If you press "play" in UnityEditor and use it. Then press "stop" it still listenes to osc data being sent over from GlovePie.
    That is no problem but the problem is that the RAM gets filled by time. So after using it for one hour it shows 600MB footbrint in the taskmanager and its using the cpu permanently.


    greetz meNace
     
  30. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    Thanks menace.

    I do see one bug. I don't know if it's the only one. I will fix it up asap.
    in short... When i turned WiimoteReceiver.cs into a singleton i forgot to clean up the code somewhat. e.g. the connect method should under no means create a new instance of WiimoteReceiver.

    I'll look deeper into it. Kinda embarresing :)
     
  31. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    I look forward to the update! It's working pretty well for me so far. I did have one instance right before a performance where I couldn't connect, and I couldn't figure out why. Of course, later it just worked. :p
     
  32. nib

    nib

    Joined:
    Jul 14, 2008
    Posts:
    6
    Hi
    Very nice patch!
    Do anyone out there happen to have a javascript version of this one?
     
  33. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    Hi nib.

    As this code is running on the .NET runtime engine, It should be possible to call C# code from within javascript in unity.

    Now i'm by no means good at javascript but try something like:

    Code (csharp):
    1.  
    2. var receiver = Wiiremote.Instance;
    3. receiver.connect(8876);
    4.  
    5. if(receiver.wiimotes.containskey(1))
    6. {
    7.      var wiimote = receiver.wiimotes[1];
    8.  
    9.     // Do something with wiimote.BUTTON_A ...
    10. }
    11.  
    Haven't tested it but it might work if my syntax is correct.

    Just A note. Don't mix up javascript and C# in the same file.
     
  34. nib

    nib

    Joined:
    Jul 14, 2008
    Posts:
    6
    Hi
    And thanks a lot for the answer.
    Unfortunately it doesn't seem to work ... It is probably me doing something really stupid.
    When I try to place in the above code in a new javascript file, inside the same library as the cs files containing the tuio-code and run the game, I get the following error "Unknown identifier: "Wiiremote".
    Could that be just because of wrong reference or that I need to place it somewhere else in order to see it or is it just wrong what I did?

    If there is anyone who has a specific unity files with the js code in that works with unity in order to both send and receive the osc data from oscuator I would be soooo happy


    Niels
     
  35. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    Hi Niels.

    I just checked the unity documentation.
    It seems if you put the C# code in a folder called Standard Assets, it will be compiled first and then can be found by javascript code placed outside the Standard Assets folder.

    Take a look at the attachment. I haven't tested with wiimote as i don't have one available at the moment.
    I cleaned up the project so it only contains what's essential.
    But it compiles and runs.

    Hope it's of any use.

    Jens.
     

    Attached Files:

  36. nib

    nib

    Joined:
    Jul 14, 2008
    Posts:
    6
    Yes! That works!
    Thanks a lot for that. That was extremely useful. Thank you very much for the extremely fast reply

    Niels
     
  37. nib

    nib

    Joined:
    Jul 14, 2008
    Posts:
    6
    He he ... now it's me again.
    It works perfectly for me when Im just trying to the float values from for instance the A and B buttons on the Wii controller. But as soon as I want to access the data coming from the accelerometer or similar I am getting this error:
    "Wiimote.m_motionVeloPitch' is inaccessible due to its protection level."

    Do you have any idea what this is and how to solve it?

    Niels
     
  38. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    That one is a quick fix :)

    first of all motion... is motion plus data, so that might not be what you're after.

    Inside the OSCuMote folder there is a file called Wiimote.cs. Here you can see all the data you can access.
    What you're interested in is all the public fields... the ones written in caps.

    If you are sending pitch,roll and yaw from OSCulator then you can use
    PRY_PITCH
    PRY_ROLL
    PRY_YAW
    For Raw Acceleration data you can use:
    ACC_X
    ACC_Y
    ACC_Z

    And if it is the motion plus you're after you would use either
    MOTION_ANGLE_PITCH
    MOTION_ANGLE_ROLL
    MOTION_ANGLE_YAW
    or
    MOTION_VELO_PITCH
    MOTION_VELO_ROLL
    MOTION_VELO_YAW

    Of cause you have to set OSCulator up so it actually forwards all these numbers :)

    Good luck.
    Jens.
     
  39. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Will that bug you mentioned to menace be rolled into a version 1.3, or is there already a newer build somewhere?

    Just checking since I'm about to use this for a production and am trying to make sure I'm up to date.
     
  40. nib

    nib

    Joined:
    Jul 14, 2008
    Posts:
    6
    Thank you so much once again. It was just me making a stupid mistake. It works now.
    Have you had any experiences with lacking? - And do you now anything about speeding the data transfer a bit up? - Im also connecting it with Max/MSP and it seems to be much faster in Max/MSP somehow?

    Niels
     
  41. sketchground

    sketchground

    Joined:
    Dec 18, 2008
    Posts:
    15
    God At Play:
    I have been looking into it and i think i was too quick with regards to the memory leak. After having it run for a while i haven't experienced any memory leaks. I have also tried to fix the issue with the thread not stopping in unity when you stop running the application. I did make a fix that worked when running the code from a normal C# program, however unity doesn't seem to want to stop the thread.
    Then again. It should only be an issue inside the unity editor and not when you have a standalone application (hopefully :) ).
    I'm getting really busy at school so i might not have so much time to look deeper into it the coming month.
    If you experience any memory leak and can track it down, please let me know :)


    Nib:

    I haven't had any issues with lagging as such.
    I do have some recommendations that might speed up things though.

    * Only send data that you need. E.g. don't send ir data if you're not using it etc...
    * In OSCulator you can "smooth" the data. This causes a delay effect... So here you might also be able to tweak things. (This is located in the "Wiimote drawer" in OSCulator)
    * Last thing could be an implementation issue from my part that i unfortunately don't have time at the moment to improve or look into it.
     
  42. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Thanks for the heads up. I'll keep an eye on the memory and let you know if I run across anything fishy.
     
  43. shmeck

    shmeck

    Joined:
    Apr 19, 2008
    Posts:
    25
    Hi Everyone,
    i'm a performing artist and OSCuMote is a wonderful solution to help me add a Wii to my media performances, but i'm having some trouble. hope you have a minute to help me troubleshoot:

    - GameOn.unity receives OSC data for Pitch, Roll Yaw, and these value changes appear in the in-game display. However, nothing happens in the demo when i move the wii -- the sphere just drops onto the plane and sits motionless.

    - no change appears in the in-game display for the buttons and joystick values when i press them. Osculator is responding to the buttons joystick, and i was able to get a different app to receive the button messages from Osculator using your settings.

    as you've probably guessed, i'm not a coder. i had a friend who knows some C# look at it. he hacked WiiMoteTest.cs a bit:
    http://www.shmeck.com/uploads/OSCuMoteHackedCube.zip
    when we deleted the WiiMoteTest.cs from the WiiMoteListener and instead attached our hacked version of WiiMoteTest.cs to a cube, we got it to wiggle around [see attachment].

    any idea what i'm doing wrong here? i'm using OSCuMote 1.2 and Unity 2.61

    best,
    Shane Mecklenburger
    http://www.shmeck.com
     
  44. swenson5559

    swenson5559

    Joined:
    Oct 11, 2010
    Posts:
    10
    Hi, first post here, also very limited in my abilities with CS. I'm just wondering, what is the syntax in the wii listener script that represents the values of the Pitch and Yaw?
     
  45. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    WOW, I've been looking for OSC input into Unity for some time now. I just found your awesome script, thank you for sharing!
     
  46. youtoo

    youtoo

    Joined:
    Oct 11, 2011
    Posts:
    1
    Thanks for your amazing plugin, made my life so much happier when I found it!

    I'm prototyping a few games in our games company and a thing I'm in need is to know the distance between the screen and the wimote(motionplus).

    Currently I'm using the ACC_Y but is not as great as I'd like. I was thinking of using the size of the IR leds, but the value is only 0 or 1...

    Is that I'm missing something? Have you guys achieved to get the the distance in any way?

    Thanks for your help!
     
  47. Helgosam

    Helgosam

    Joined:
    Feb 2, 2012
    Posts:
    12
    Hi Sketchground / all

    Sounds amazing! I've been using http://forum.unity3d.com/threads/16882-MIDI-or-OSC-for-Unity-Indie-users/page3 to successfully get the OSC messages into Unity

    Now though I'm trying something harder - getting the OSC messages into Android. Does this library work on android? Anyone have any thoughts/tips?

    *EDIT
    So I got the OSC messages through to my android device - pretty sweet really:


    This image shows how I got the Wiimote connected to darwiinRemoteOSC (via bluetooth) to send OSC messages straight to the android tablet (located at 10.0.2.12: 8080 on my home-grown MBP wifi network), and the Android unity app actually responds to the wiimote controls... pretty nice!
     
    Last edited: Jun 5, 2012