Search Unity

Phantom Omni with Unity

Discussion in 'Scripting' started by Aldebran, Oct 6, 2011.

  1. Aldebran

    Aldebran

    Joined:
    Oct 6, 2011
    Posts:
    3
    Hello everybody, i'm trying to develop some scripts in order to use the Phantom Omni haptic device (http://www.sensable.com/haptic-phantom-omni.htm) in Unity.
    So I have put the DLL of the API given with the Phantom Omni in the folder Assets/Plugins, and then i'm trying to call functions from this DLL with DllImport like this :

    Code (csharp):
    1. [DllImport("hd32")]
    2. public static extern int hdInitDevice(string pConfigName);
    I'm new in Unity so maybe there is something that i'm missing but actually this doesn't work : when I try to call the function hdInitDevice in my script, I always get a DllNotFoundException and I really don't understand why because my DLL seems to be in the good folder.

    Does someone know why I get this error ?

    I'm using Windows 7 64 bits.
     
    Last edited: Oct 6, 2011
  2. Indee3

    Indee3

    Joined:
    Feb 15, 2013
    Posts:
    2
    Hello..Were you able to call the Phantom Omni using the DLL available?
     
  3. brendiche

    brendiche

    Joined:
    Jun 21, 2013
    Posts:
    2
    Hello,i am a french engineering student and i am currently doing an internship in Tokyo. I also want to connect the Phantom to Unity with dll writing in C++ but my function are not correctly recognize by unity.
    i use this :

    sing UnityEngine;
    using System.Collections;
    using System;
    using System.Runtime.InteropServices;

    public class test : MonoBehaviour {

    public float x,y,z;
    public float magnitude;

    delegate void loopFunc();

    [DllImportAttribute(@"C:\Users\demo\Desktop\unitytest\Assets\plugins\simpleDLL", EntryPoint = "init")]
    public static extern void init();

    [DllImportAttribute(@"C:\Users\demo\Desktop\unitytest\Assets\plugins\simpleDLL", EntryPoint ="position")]
    public static extern IntPtr position();

    [DllImport(@"C:\Users\demo\Desktop\unitytest\Assets\plugins\simpleDLL")]
    public static extern void CallbackPosition(loopFunc hapticRendering);


    and i have a problem with the last import.
    If someone can help me?
    Thanks
     
  4. Mahdi-2

    Mahdi-2

    Joined:
    Jul 30, 2013
    Posts:
    3

    Hi
    I try to use Phantom device in Unity 3D. I would appreciate that if I know you could make this connection?
    Thank you in advance.
    Mahdi
     
  5. m-poyade

    m-poyade

    Joined:
    Jan 22, 2014
    Posts:
    18
    Last edited: Nov 5, 2014
    damayor11 likes this.
  6. inz_przemyslaw_wozniak

    inz_przemyslaw_wozniak

    Joined:
    Sep 12, 2014
    Posts:
    16
    Dr. Poyade,

    I'd like to use your plugin in my academic project. I've encountered two problems:

    1) I've installed Open Haptics Toolkit v 3.0 (Academic Edition) and I can't find the DLLs you mentioned in read-me PDF. Can you specify the exact location of these files?
    2) Regardless of the above, I've tried to run one of your scenes in my Unity project. Besides of the errors "can't find DLL file", there is "License error. This plugin is only supported in Unity Pro!". I'm using free edition of Unity 4.5.5f. Is this plugin only for Pro version (can't find that info in read-me or on Asset Store) or is this connected to the missing of the above mentioned DLLs?

    Thank you very much for your response!
     
    Last edited: Oct 20, 2014
  7. m-poyade

    m-poyade

    Joined:
    Jan 22, 2014
    Posts:
    18
    Hi,

    1. The openhaptics DLLs are not included in the project. You have to copy and paste them from your OpenHaptics 3.0 package into the indicated folder (See page 6 of the Manual). The only DLL file which is included is that of the Plugin.
    2. I have only tried the Plugin on Unity pro, which is the one I have on my professional PC. However, I do not see why it should not work on the academic version of Unity.

    I hope this will be helpful.

    Matt.
     
    Last edited: Oct 21, 2014
  8. adgomes6

    adgomes6

    Joined:
    Sep 12, 2014
    Posts:
    3
    Hi Matt,

    I've also tried to use the simple haptic plugin for a project we're working on, and it does not seem to be connecting to unity properly on Windows 7.
    I have Unity Pro on Windows 7 and XP computers, and while the plugin is working fine on our XP machine, connecting to Windows 7 throws the error "DllNotFoundException: ASimpleHapticPlugin" for all the examples that came with the haptic plugin.

    We put all the required DLL's in the root folder, for both XP and 7 machines, and we are sure the Phantom Omnis are working using the configuration tool provided by Geomagic.

    Would you have any idea why this problem exists/how to solve the problem?

    Thanks,

    Adam
     
  9. m-poyade

    m-poyade

    Joined:
    Jan 22, 2014
    Posts:
    18
    Hi Adam,

    Sorry for my late answer :-(

    I have developed the plugin on Window 7. if you have downloaded the plugin from the asset store, please ensure that you have copied the plugin folder (which includes the plugin) into your assets folder (not the root folder of your project). The rest of the haptic DLL will go in the root folder of your project. (Watch out this is a 32 bits development).

    Keep me up to date.

    BR

    Matt.
     
  10. m-poyade

    m-poyade

    Joined:
    Jan 22, 2014
    Posts:
    18
    Hi there,

    I would like to post a conversation I had about the possibility to add in real time haptic object.

    Please find the conversation below.


    From P.
    Hi,

    I'll take just a moment. When I'm instantiating a new object with haptic properities at a run-time (it works OK when called from Start()), I can't touch it (my touching object goes through it). I believe i need to somehow update the haptic workspace, but I quite don't get it.

    I'm using slightly modified GenericFunctionsClass (I've modified GetTouchedObject() for my needs, that is - creating & destroing FixedJoints instead of direct manipulation on transform - but there is UpdateHapticObjectMatrixTransform() still present). The other script for my dummy is SimpleShapeManipulationAndPhysics (unmodified).

    Which function and where should I call to enable touch for dynamically created objects (through Instantiate)? Thank you very much for your help.

    Regards,

    P.

    I have answered the following:

    Hi P.,

    There is the function SetHapticGeometry() in the script myGenericFunctionsClass, which traverses all the object tagged as “Touchable”. I have moved this function from the start to the update method of my main script (e.g. SimpleContact Script) and I was able to add dynamically a new object. It is working fine.

    So, when you want to assign a new haptic object, just tag this object as “Touchable” (and maybe for the sake of optimization, you can launch some kind of event to allow the execution of SetHapticGeometry() in your update method (for instance) only in that frame).

    I hope this is useful.

    BR

    Matt.
     
  11. adgomes6

    adgomes6

    Joined:
    Sep 12, 2014
    Posts:
    3
    \

    Thank you so much for the reply.

    So we've followed you're advice, and now the plugin is starting up on Unity. The scene loads fine on unity, and the pen is movable in the environment, however, when the pen is about to come into contact with a surface, unity either freezes or throws a runtime error. I've attached a screenshot of unity throwing the error.

    If let me know if you've encountered any errors like this before.
    Thanks again for your help,

    Adam
     

    Attached Files:

  12. m-poyade

    m-poyade

    Joined:
    Jan 22, 2014
    Posts:
    18

    hi Adam,

    I am afraid, I never had this error on Unity - To me and the people who test it here, it appeared to be quite stable. Some of our partners abroad tried it, they did not report any issues so far.

    what version of OpenHaptics do you have (I have compiled it using OH 3.0 - I cannot guarantee normal functioning with lower versions)? Does this happen with all the scenes? Did you modify any of the scripts - especially the GenericFunctionClass, or you are running the examples as they are? You told me you have also been able to run the examples on XP, do you have the same error in XP?



    Matt.
     
  13. adgomes6

    adgomes6

    Joined:
    Sep 12, 2014
    Posts:
    3
    Hi Matt,

    Sorry for the late response, we were getting new hardware for our lab. So we used another windows 7 computer and changed our FireWire PCI's, and now it works!

    You guys did awesome work on the plugin!

    Thanks so much for your help again.

    Adam
     
  14. inz_przemyslaw_wozniak

    inz_przemyslaw_wozniak

    Joined:
    Sep 12, 2014
    Posts:
    16
    For those who use free version of Unity and would like to use Matt's plug-in: all you have to do is follow the instructions in read-me, but additionally you should move the SimpleHapticsPlugin.dll from Plugin folder to the main folder of your project. Everything works great and you won't get license error.
     
  15. Deepschalappatta

    Deepschalappatta

    Joined:
    Jul 27, 2013
    Posts:
    8
    I am Working on unity3d and try to use Phantom device in Unity 3D for our surgical simulation projects.
    I have already downloaded the "Unity Haptic Plugin for Geomagic OpenHaptics" project from asset store.
    But it shows an error"NotFoundException: ASimpleHapticPlugin"
    I would appreciate that if I know how you could make this connection between Phantom device and Unity 3D?
    How to get this plugins like
    1. glu32.dll
    2. glut32.dll
    3. hd.dll
    4. hl.dll
    5. opengl32.dll
    6. PhantomLib42.dll
    Thank you in advance for your help.
     
  16. m-poyade

    m-poyade

    Joined:
    Jan 22, 2014
    Posts:
    18
    Hi,

    Sorry for my late answer.

    The mistake you have got is due to the fact that Unity does not find your plugin dll file. You must paste your plugin file in the correct folder as indicated in the documentation or above in this forum.

    You can find the dll files you mention in your openhaptic folders. I think the PhantomLib42.dll is not required so no worry if you cannot find it.

    Best Regards


    Matt.
     
  17. d_brick

    d_brick

    Joined:
    Mar 11, 2015
    Posts:
    3
    Hello,

    I have been working on a training simulation, and I have run into a problem. My program works just fine when I run it in the Unity editor, but when I build it and run the .exe file, the program has a tendency to freeze. This problem is exaggerated when I touch an object or run a program with a large number of objects. It happens even on the sample programs that came with the plugin, and I do not know what the problem is. I would greatly appreciate your help on this matter.
     
  18. m-poyade

    m-poyade

    Joined:
    Jan 22, 2014
    Posts:
    18
    Hi d_brick,

    I do not really understand why the simultation runs fine in editor mode but not when the project has been built.

    I just can give you the advice to have a look at the number of vertices your objects have. Try to simplify your objects, or render haptically a simplified version of your scene.

    This development is a relatively basic (and quick) implementation I have done for my students to be able to develop quicky some basic games on Unity.

    BR

    Matt.
     
  19. s_patel

    s_patel

    Joined:
    Jun 16, 2015
    Posts:
    2
    Hi Matt,

    I am a grad student and have found your plugin extremely helpful. Based on my present use of your plugin, it has been extremely useful and easy to use. I love how easily I can implement haptic properties to elements of the user interface for a realistic experience. But I am developing a game for my thesis research which requires the use of two haptic devices, therefore I was wondering if your plugin allows an easy modification to allow for this. Please let me know if you have any idea about my concern as I would like to continue to use your plugin and Unity to complete my research.

    Thanks in advance for all your assistance.
     
  20. m-poyade

    m-poyade

    Joined:
    Jan 22, 2014
    Posts:
    18
    Hi,

    Sorry for my late answer. It is actually not possible for the plugin to recognize two haptic devices because it is not designed to do so. I am currently working on my free time to make a plugin which would be able to recognize X devices.

    How every you eventually try to use two computers, each with an haptic device and pass to each other through network the modifications done by each device.

    Regards

    Matt.
     
  21. s_patel

    s_patel

    Joined:
    Jun 16, 2015
    Posts:
    2
    Thanks for the response. I actually do need both the omnis to work from one computer and connect to a single user interface. Your plugin seemed like the way to go but I will be looking forward to updates to the plugin. I did enjoy using your plugin as it made using Omni in Unity very easy.
     
  22. Jaafreh

    Jaafreh

    Joined:
    Jul 25, 2015
    Posts:
    1
    Hello Matt,
    I can only find glut32.dll, hd.dll, hl.dll from the openhaptic folder. In fact I am using openhaptics academic 3.2. Also I have copied the dll from the win32 folder. Please I needd your help
     
  23. m-poyade

    m-poyade

    Joined:
    Jan 22, 2014
    Posts:
    18
    Hi Jaafreh,

    At looking at your error, apparently the the plugin file (ASimpleHapticPlugin.dll) cannot be found. Did you move the plugin folder from the component folder to the Assets folder?



    Let me know if this is solving your problem.

    BR

    Matt.
     
  24. zamarron

    zamarron

    Joined:
    Mar 11, 2015
    Posts:
    1
    AsimpleHapticPlugin.dll it is compiled for 32 bits and it is not working in unity 64 .
    please let us know it there is an upgrade.
    Thank you in advance.
     
  25. m-poyade

    m-poyade

    Joined:
    Jan 22, 2014
    Posts:
    18
  26. Superrobot

    Superrobot

    Joined:
    Nov 26, 2015
    Posts:
    1
    Hi all, I am new with Unity. And I plan to use haptics omni with unity for surgical simulation,
    The plugin that m.poyade create is very user for me. I plan to use haptics omni with my project. How ever I'm really don't know how to apply your c# script to my work. The task is quite similar to your example that I will control the movement of needle by use haptic omni then insert into the model which has 2 layer consist of bone and tissue. Anyone tell me how to use c# script to control the needle by haptics omni and send force feedback when it touch the surface. I'm really appreciate your help in advance
     
  27. Tx_onda

    Tx_onda

    Joined:
    Jan 12, 2016
    Posts:
    2
    Hi Matt, I am working in a university project, I download your plugin, and it is very useful for my project, thank you.
    I try to use it with an oculus, but at the time of prove it, I only see a black screen, but the phantom works. Do you have any idea why this happen?
    I'm really appreciate your help, I'm new in unity.

    Thank you
     
  28. m-poyade

    m-poyade

    Joined:
    Jan 22, 2014
    Posts:
    18
    Hi,

    I think it might be something from Oculus configuration. does your oculus work fine without the haptics?

    Matt.
     
  29. d_brick

    d_brick

    Joined:
    Mar 11, 2015
    Posts:
    3
    Hello. Thank you for your previous reply. Has anyone run this plugin in Windows 10? If so, how does it run?
     
  30. yonghang

    yonghang

    Joined:
    Apr 1, 2016
    Posts:
    1
    Hi Brick:

    I tried it in Windows 10, it works good, no worried about that~
     
  31. m-obeid

    m-obeid

    Joined:
    Aug 7, 2012
    Posts:
    9
    Hi all,

    First, thank you Matt for the diligent work on this plug-in, I found your work very beneficial.
    Second, I would like to let everybody know that I have successfully used the plug-in to run Omni, Phantom Premium High Force, and Phantom 6 DOF haptic devices. I was also able to run it both on Windows 7 and 10.

    Lastly, I have a question for you Matt, as I work on the project in the Editor, everything works fine. However, when I build the scene, the haptic device is not initiated at all and nothing is moving. Everything in my scene functions normally but the haptic device isn't used at all. Again, this is only on Build mode.

    Am I supposed to do something special for the plug-in to work in Build mode?

    Thank you again.
    -MFO
     
  32. vigneshu

    vigneshu

    Joined:
    Jun 30, 2016
    Posts:
    1
    Hello All,
    I installed the plugin and when I run i get the error "DllNotFoundException: Assets/Plugins/ASimpleHapticPlugin.dll"
    . I have the plugins folder in the same folder which contains assets and the plugins folder contains ASimpleHapticPlugin.dll and the other required dlls(except PhantomLib42.dll). I am using windows 10 and unity 5.3.5 64bit
     
    Last edited: Jun 30, 2016
  33. dabrick

    dabrick

    Joined:
    Jul 1, 2016
    Posts:
    1
    Also, has anyone run into the "Pure virtual function call" error (R6025) in running force effects on this plugin? I am trying to run the Kinect with this on Unity 4, and this error comes up with too many force effects.
     
  34. m-poyade

    m-poyade

    Joined:
    Jan 22, 2014
    Posts:
    18

    Hi,

    I think you might have forgotten to copy the open haptic DLLs where you have your built exe file.

    BR

    Matt.
     
  35. Curious

    Curious

    Joined:
    Nov 19, 2009
    Posts:
    334
    Hi there,
    First I'd like to thank you for the nice plugin you published to the community :)

    I'm using Touch 3D Stylus and it works pretty good.

    I'm using Unity 5.4.0f3, your plugin and OpenHaptics 3.4.0 on Windows 10

    The plugin causes Unity to crash from time to time, almost randomly but I kind of think it is related to the amount of force being applied or the penetration value! But other than that the plugin is a time saver and does the job :)

    I would also like to vote for the two haptic device compatibility feature request, it would be really handy.

    I have a question as well.
    There's a free script on the store that demonstrates softbody physics with mass-spring mesh (MSM), I was wondering if it's possible to interact with soft-body meshes as well.
    https://www.assetstore.unity3d.com/en/#!/content/50767

    Well, I already know about SetHapticGeometry() and tried to hack a scene together and had little play with Script Execution Order too, but had no luck getting proper results :\

    Any thoughts?
     
  36. gKaranovich23

    gKaranovich23

    Joined:
    Aug 4, 2016
    Posts:
    1
    Hi Matt,
    I am currently working with a haptic device in unity. Your plugin works beautifully but I also need to record the forces being exerted by the device. Is there some quick easy code of doing this or will I have to write my own plugin involving hduRecord or get(HD_CURRENT_FORCE)?
    Thanks.
     
  37. d_brick

    d_brick

    Joined:
    Mar 11, 2015
    Posts:
    3
    I had a similar problem. I was able to trace it back to the calls to the ConverterClass.ConvertIntPtrToByteToString function inside of GetTouchedObject(). For some reason, Windows 10 resolves IntPtr addresses differently from Windows 7 or 8, so -- for me at least -- the program crashed when I held contact with an object for too long. If you can find another way to identify which objects are being touched (for instance, a trigger collider), that should prevent the program from crashing.

    Hope that helps.
     
  38. Curious

    Curious

    Joined:
    Nov 19, 2009
    Posts:
    334
  39. m-poyade

    m-poyade

    Joined:
    Jan 22, 2014
    Posts:
    18
    Hi,

    I am planning releasing a newer version of the plugin soon, I will attempt to embed this functionality in the newer version.

    BR

    Matt.
     
    Torigas likes this.
  40. Curious

    Curious

    Joined:
    Nov 19, 2009
    Posts:
    334
    Oh, great news.
    Are you going to include the second device feature as well? Would be really great.
     
  41. Torigas

    Torigas

    Joined:
    Jan 1, 2014
    Posts:
    63
    Hi Matt,

    I'm trying to figure out a way to set the proxy object manually with the goal of simulating different tools and not just a simple dimensionless point in space.
    However I couldn't access the hlDisable functions, since I can't figure out how to get the enum values that are expected as parameters from the dll.
    I was wondering if you could maybe open source your dll or maybe just give me a supportless version of the code so i can peek at and maybe extend your implementation a little.
    Thanks in advance,

    Paul
     
  42. ykaradayi

    ykaradayi

    Joined:
    Oct 25, 2015
    Posts:
    8
    Hi there everyone,

    Great job Matt on the plugin, real time saver for my project! I'm trying to get the device up and running with a Hololens which has an x86 architecture, so I'm just starting out trying to get an .exe app to render the haptic example with win32 dlls. I have tried all combinations of .dlls in the root .exe folder, and for some reason, it works perfectly with the x64 app build, but not the x86. Any ideas what I can do to get it working?

    EDIT: I figured out that the error is that ASimpleHapticPlugin.dll is written for a x64 bit architecture and not for x86. Is it possible for you to re-compile it into an 32 bit architecture for me please? Thanks!
     
    Last edited: Sep 30, 2016
  43. Torigas

    Torigas

    Joined:
    Jan 1, 2014
    Posts:
    63
    just check the asset store. The old version should be 32 bit?
     
  44. ykaradayi

    ykaradayi

    Joined:
    Oct 25, 2015
    Posts:
    8
    I had tried that and it had not worked for me. I did manage to get it running from another developer's project that used it , though, so that's strange but ... good

    It still does not work on the Hololens or the Hololens emulator though. Anyone who happens to have one to try with haptics...let me know!
     
  45. MLitvinov

    MLitvinov

    Joined:
    Jan 10, 2015
    Posts:
    7
    I was able to get the plugin working inside of Unity using the 32bit version of Unity and the 32bit plugin. The 64 bit plugin was not working and when I made a build with the 64 bit plugin it stated in the Unity log file: Failed to load ASimpleHapticPlugin.dll with error '%1 is not a valid Win32 application. I am also having major frame rate issues only in the editor with the 32bit plugin (I have attached an image of the Unity Profiler below). This frame rate issue only occurs in the editor and when I make a 32bit build there are no frame rate issues. Could anyone possibly point me in the right direction for either of these problems. It would be much appreciated.
     

    Attached Files:

  46. MLitvinov

    MLitvinov

    Joined:
    Jan 10, 2015
    Posts:
    7
    Did you ever have frame rate issues using the pluginin the editor ? Thank you
     
  47. Torigas

    Torigas

    Joined:
    Jan 1, 2014
    Posts:
    63
    Curious. I've used the 64 bit version without any problems (editor and build have to be 64 of course).
    "Failed to load ASimpleHapticPlugin.dll with error '%1 is not a valid Win32 application" This sounds weird. If its actually 64 Bit...
    I can't say I've used the 32 Bit version a lot though, unfortunately. The RenderHaptics taking this long is also very curious. Are you working with very elaborate geometry? Try using some basic cube or the included example scenes maybe. These don't cause any issues for us (64 Bit again).
     
  48. MLitvinov

    MLitvinov

    Joined:
    Jan 10, 2015
    Posts:
    7
    I was able to discover the cause of the frame rate issues. It had to do with the RAM on my temp laptop (I ended up switching machines). Though I still can't get the 64 bit version of the plugin to work, and the editor is 64 bit. What are your specs for your Windows version, Unity version, and hapticsPlugin version? Thank you for the response!
     
    Last edited: Jan 23, 2017
  49. Torigas

    Torigas

    Joined:
    Jan 1, 2014
    Posts:
    63
    Heya! Sorry for the late answer. Haven't visited this website in quite some time.
    This is the setup:
    Windows 10 X 64
    Unity 5.4.0 f3
    64 bit haptics plugin
    Phantom driver and tool 5.1.7
    Openhaptics 3.4
     
    itouhirohumi8255 likes this.
  50. itouhirohumi8255

    itouhirohumi8255

    Joined:
    Jul 20, 2018
    Posts:
    1
    Thank you Trigas.I can execute asset.