{"id":881,"date":"2017-12-01T17:21:28","date_gmt":"2017-12-01T16:21:28","guid":{"rendered":"http:\/\/jmladeno.net\/?p=881"},"modified":"2018-05-07T15:56:43","modified_gmt":"2018-05-07T13:56:43","slug":"sync-data-from-unity-vr-and-physiology","status":"publish","type":"post","link":"https:\/\/jmladeno.net\/index.php\/2017\/12\/01\/sync-data-from-unity-vr-and-physiology\/","title":{"rendered":"Sync Unity and physiology"},"content":{"rendered":"<p style=\"text-align: left;\">Let&#8217;s say you want to record the position of a ball or whatever gameObject you use in Unity.<br \/>\nOr if you are using VR &#8212; you wish to stream the position\/rotation of the head and controllers while in VR.<br \/>\nAlso, at the same time you are measuring some physiology, e.g., the galvanic skin response (GSR) or EEG.<br \/>\nDuring the experiment, you have certain triggers\/events, also called Markers, that you also want to keep track of&#8230;<\/p>\n<p style=\"text-align: left;\">You wish to sync everything together? Well, my advice is use <a href=\"https:\/\/github.com\/sccn\/labstreaminglayer\" target=\"_blank\" rel=\"noopener noreferrer\">Lab Streaming Layer (LSL)<\/a><\/p>\n<h4 style=\"color: #660033;\">Why LSL?<\/h4>\n<p>It is <strong style=\"color: #cd5c5c;\">easy<\/strong> to implement in many languages and easy to use.<br \/>\nIt can <strong style=\"color: #cd5c5c;\">sync<\/strong> many data automatically, meant for physiological recording.<br \/>\nIt handles <strong style=\"color: #cd5c5c;\">multiple machines<\/strong> at the same time with high <strong style=\"color: #cd5c5c;\">precision<\/strong>, so one could sync even ERPs.<br \/>\nAnd <strong style=\"color: #cd5c5c;\">no need for ip<\/strong> addresses anymore when communicating between machines.<br \/>\nIt works on Local Network as well as WAN<br \/>\n(I advise you use a local router or hub to avoid interference)<\/p>\n<p>Most importantly, when using LSL, make sure you have <strong>DEACTIVATED FIREWALL<\/strong> for Unity and Openvibe and other apps in use!!!<\/p>\n<h4 style=\"color: #660033;\">1. For offline analysis :<\/h4>\n<p>One can record all data in an .xdf file with the <a href=\"ftp:\/\/sccn.ucsd.edu\/pub\/software\/LSL\/Apps\/\" target=\"_blank\" rel=\"noopener noreferrer\">Lab Recorder<\/a>,<br \/>\nand analyze offilne in Matlab for example, with <a href=\"https:\/\/sccn.ucsd.edu\/eeglab\/index.php\" target=\"_blank\" rel=\"noopener noreferrer\">eeglab<\/a> or other toolboxes.<\/p>\n<h5 style=\"color: #660033;\">2. Online processing:<\/h5>\n<p>You can use <a href=\"http:\/\/openvibe.inria.fr\/\" target=\"_blank\" rel=\"noopener noreferrer\">openvibe<\/a> which has LSL already integrated,<br \/>\nor <a href=\"https:\/\/fr.mathworks.com\/products\/simulink.html\" target=\"_blank\" rel=\"noopener noreferrer\">Simulink<\/a> (working on it)! tutorial soon&#8230;<\/p>\n<p>&nbsp;<\/p>\n<h5 style=\"color: #660033;\">How To:<\/h5>\n<p>1. download <a href=\"https:\/\/github.com\/jelenaLis\/LSL4Unity\" target=\"_blank\" rel=\"noopener noreferrer\">LSL4Unity<\/a> (this is a modified version from the original <a href=\"https:\/\/github.com\/xfleckx\/LSL4Unity\" target=\"_blank\" rel=\"noopener noreferrer\">xfleckx<\/a> )<br \/>\n2. download latest <a href=\"ftp:\/\/sccn.ucsd.edu\/pub\/software\/LSL\/Apps\/\" target=\"_blank\" rel=\"noopener noreferrer\">Lab Recorder<\/a><br \/>\n3. download <a href=\"https:\/\/unity3d.com\/get-unity\/download\" target=\"_blank\" rel=\"noopener noreferrer\">Unity<\/a>,<br \/>\nyou would need to have a game already made:<br \/>\ne.g., <a href=\"https:\/\/www.youtube.com\/watch?v=W_fAidYRGzs\" target=\"_blank\" rel=\"noopener noreferrer\">Rolling A Ball<\/a> &#8212; from the Unity tutorial,<br \/>\nor if you do VR, you would need an environment ready to use,<br \/>\nfor HTC Vive for example: from <a href=\"https:\/\/www.raywenderlich.com\/149239\/htc-vive-tutorial-unity\" target=\"_blank\" rel=\"noopener noreferrer\">htc-vive-tutorial-unity<\/a><br \/>\n4. For this tutorial Windows 7+ is needed (I tested on windows 10)<\/p>\n<p>Once you have downloaded and unzipped all the folders,<br \/>\nI advice you to follow the nice tutorials for Unity before using LSL.<\/p>\n<p>Make a copy of the Unity project you intend to use and rename it<br \/>\ne.g., Roll_a_Ball-LSL (to keep your original project without lsl).<br \/>\nThen copy the LSL4Unity folder in the Assets folder from your Unity project.<br \/>\nSo when you enter your project in Unity it looks like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-large wp-image-1057\" src=\"http:\/\/jmladeno.net\/wp-content\/uploads\/2017\/12\/assets-1024x368.png\" alt=\"\" width=\"1024\" height=\"368\" srcset=\"https:\/\/jmladeno.net\/wp-content\/uploads\/2017\/12\/assets-1024x368.png 1024w, https:\/\/jmladeno.net\/wp-content\/uploads\/2017\/12\/assets-300x108.png 300w, https:\/\/jmladeno.net\/wp-content\/uploads\/2017\/12\/assets-768x276.png 768w, https:\/\/jmladeno.net\/wp-content\/uploads\/2017\/12\/assets-1440x518.png 1440w, https:\/\/jmladeno.net\/wp-content\/uploads\/2017\/12\/assets.png 1521w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<h3 style=\"color: #660033;\">Send data streams from Unity :<\/h3>\n<p style=\"color: #660033;\">(Send data streams to Unity &#8211; bellow.)<\/p>\n<h5>Send streams from Unity<\/h5>\n<p><em>such as position, rotation of the gameObject or of head and controllers<\/em>,<\/p>\n<ul>\n<li><a href=\"http:\/\/jmladeno.net\/index.php\/2017\/12\/01\/tutorial-for-streaming-continuous-data\/\" target=\"_blank\" rel=\"noopener noreferrer\">FOLLOW THESE INSTRUCTIONS for Roll a Ball example<\/a> or an example for VR &#8211; HTC Vive<\/li>\n<\/ul>\n<h5>Send Marker streams from Unity<\/h5>\n<p><em>such as collision between game objects etc<\/em>.<\/p>\n<ul>\n<li><a href=\"http:\/\/jmladeno.net\/index.php\/2017\/12\/01\/tutorial-for-streaming-markers\/\" target=\"_blank\" rel=\"noopener noreferrer\">FOLLOW THESE INSTRUCTIONS for Roll a Ball example<\/a> or an example for VR &#8211; HTC Vive<\/li>\n<\/ul>\n<h3 style=\"color: #660033;\">Receive data in Unity :<\/h3>\n<h5>Receive streams in Unity<\/h5>\n<p><em> physiological stream which can influence your gameObjects&#8217; positions for instance<\/em>,<\/p>\n<ul>\n<li><a href=\"http:\/\/jmladeno.net\/index.php\/2018\/02\/13\/receive-streams-in-unity-e-g-from-openvibe\/\" target=\"_blank\" rel=\"noopener noreferrer\">FOLLOW THESE INSTRUCTIONS for Roll a Ball example<\/a><\/li>\n<\/ul>\n<h5>Receive Marker\/ events in Unity<\/h5>\n<p><em>such as openvibe stimuli <\/em>.<\/p>\n<p>&nbsp;<\/p>\n<p>==============================================================<\/p>\n<h5 style=\"color: #660033;\">Offline recording and syncing data with LabRecorder<\/h5>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>once you followed the instructions above, start game in Unity (press play)<\/li>\n<li>open Lab Recorder<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-952\" src=\"http:\/\/jmladeno.net\/wp-content\/uploads\/2017\/12\/Capture15-300x195.png\" alt=\"\" width=\"300\" height=\"195\" srcset=\"https:\/\/jmladeno.net\/wp-content\/uploads\/2017\/12\/Capture15-300x195.png 300w, https:\/\/jmladeno.net\/wp-content\/uploads\/2017\/12\/Capture15-768x500.png 768w, https:\/\/jmladeno.net\/wp-content\/uploads\/2017\/12\/Capture15.png 965w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><br \/>\n(Save the .xfd file in the desired destination and click on Update to see active streams)<\/p>\n<ol>\n<li>check all the streams you are interested in recording (Marker streams with continuous streams)<br \/>\nand press Start to Record!<\/li>\n<li>Once you are done recording press stop! And it is all synced and recorded in one .xdf file.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>To analyze data from this .xdf file you need to have dedicated toolboxes like <a href=\"https:\/\/github.com\/sccn\/labstreaminglayer\/tree\/master\/LSL\">liblsl<\/a> and <a href=\"https:\/\/github.com\/sccn\/xdf\">xdf-master<\/a> toolboxes available for Matlab and Python.<br \/>\nI used eeglab and xdf toolboxes to extract and analyze data in Matlab, but I am switching to Python \ud83d\ude42<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s say you want to record the position of a ball or whatever gameObject you use in Unity. &hellip;<\/p>\n","protected":false},"author":2,"featured_media":1014,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-881","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/jmladeno.net\/index.php\/wp-json\/wp\/v2\/posts\/881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jmladeno.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jmladeno.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jmladeno.net\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jmladeno.net\/index.php\/wp-json\/wp\/v2\/comments?post=881"}],"version-history":[{"count":119,"href":"https:\/\/jmladeno.net\/index.php\/wp-json\/wp\/v2\/posts\/881\/revisions"}],"predecessor-version":[{"id":1246,"href":"https:\/\/jmladeno.net\/index.php\/wp-json\/wp\/v2\/posts\/881\/revisions\/1246"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jmladeno.net\/index.php\/wp-json\/wp\/v2\/media\/1014"}],"wp:attachment":[{"href":"https:\/\/jmladeno.net\/index.php\/wp-json\/wp\/v2\/media?parent=881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jmladeno.net\/index.php\/wp-json\/wp\/v2\/categories?post=881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jmladeno.net\/index.php\/wp-json\/wp\/v2\/tags?post=881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}