Minetest as an experimental tool for neuroscience

Post Reply
eeMagic
Member
Posts: 12
Joined: Wed May 25, 2016 15:59

Minetest as an experimental tool for neuroscience

by eeMagic » Post

Hi everyone

I want to use Minetest for analyse memory. It looks like a perfect environment and it's quite easy design the maps. But I need some way to export precise information about the behaviour of the Player.

My principal goal is save in a file the player's coordinates with the system timestamp (aprox 60 per second, but I can work with less). Do you know if that is possible?

Could someone give me some tip?
Last edited by eeMagic on Fri May 27, 2016 23:13, edited 1 time in total.

User avatar
burli
Member
Posts: 1643
Joined: Fri Apr 10, 2015 13:18

Re: Minetest as an experimental tool for neuroscience

by burli » Post

Well, there is a function called register_globalstep. This function is called every few milliseconds from the engine

You can get the current player and his position, the system time with os.clock() and open a file to store the values

And by the way: welcome and this is an interesting project

eeMagic
Member
Posts: 12
Joined: Wed May 25, 2016 15:59

Re: Minetest as an experimental tool for neuroscience

by eeMagic » Post

Thanks!

Now I know it's possible I can keep working. I didn't check how to code it, but probably I will need a way to close the file (I can open it in init.lua). Do you remember some function called when the game is close?

User avatar
burli
Member
Posts: 1643
Joined: Fri Apr 10, 2015 13:18

Re: Minetest as an experimental tool for neuroscience

by burli » Post

I would close the file after writing to prevent file corruption an case of a crash. But if you really keep it open you can use this

http://dev.minetest.net/minetest.register_on_shutdown

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Minetest as an experimental tool for neuroscience

by rubenwardy » Post

The server doesn't update fast enough to be able to record at 60fps, by default it updates at 10fps.
To log at 60fps you'll need to set the server fps to 60 (dedicated_time_Step or something in minetest.conf) or edit the client source code. You'll probably end up needing to do the latter as I doubt that the server could work that fast, and that the client would even send their position that fast.
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

eeMagic
Member
Posts: 12
Joined: Wed May 25, 2016 15:59

Re: Minetest as an experimental tool for neuroscience

by eeMagic » Post

@burli: thanks. You are right, at least I will save in different files each stage.

@rubenwardy: thanks for the info. That isn't so bad, It could work fine with 10fps and a little of interpolation (without the fast privilege the movement is quite slow). In any case, I will check how to reduce the time_step.

User avatar
burli
Member
Posts: 1643
Joined: Fri Apr 10, 2015 13:18

Re: Minetest as an experimental tool for neuroscience

by burli » Post

I tinker a bit with register_globalstep.

1. dedicated_time_step has no effect (I guess it's the wrong parameter for this)
2. in idle register_globalstep is around 30 calls per second (cps)
3. if I move cps can go up??!!
4. if I have lots of mods installed cps can go below 10 or even to 0 (no calls for one or more seconds)

ptvirgo
Member
Posts: 55
Joined: Thu May 26, 2016 22:18
GitHub: ptvirgo
In-game: Mox Wos
Contact:

Re: Minetest as an experimental tool for neuroscience

by ptvirgo » Post

Depending on exactly how you want to interpret your data, it might be more efficient to log key-presses and mouse movements. Interesting sounding project, I hope you'll tell us more about it.
{-| Visiting Minetest worlds and making up stories: www.codeforyendor.xyz -}

eeMagic
Member
Posts: 12
Joined: Wed May 25, 2016 15:59

Re: Minetest as an experimental tool for neuroscience

by eeMagic » Post

@ptvirgo: That could be useful. But I need the coordinates because the environment should have walls... and they will break the relationship between key-press and position.

User avatar
burli
Member
Posts: 1643
Joined: Fri Apr 10, 2015 13:18

Re: Minetest as an experimental tool for neuroscience

by burli » Post

I don't think that you really need 60 positions per second. The human reaction time is around 0.2 seconds. It you record 20 positions per second it's enough I think

ptvirgo
Member
Posts: 55
Joined: Thu May 26, 2016 22:18
GitHub: ptvirgo
In-game: Mox Wos
Contact:

Re: Minetest as an experimental tool for neuroscience

by ptvirgo » Post

@eeMagic: Yeah, I wasn't thinking about that; no good being efficient if you cant' actually use the results..!
So are you finding what you need? How's the project coming?
{-| Visiting Minetest worlds and making up stories: www.codeforyendor.xyz -}

eeMagic
Member
Posts: 12
Joined: Wed May 25, 2016 15:59

Re: Minetest as an experimental tool for neuroscience

by eeMagic » Post

@ptvirgo: I have a lot to learn (specially about lua), but I think that minetest has all the features I need. The project is going quite slowly, first I have to show that the idea is really possible (and that requires a lot of code and time) .

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Minetest as an experimental tool for neuroscience

by sofar » Post

eemagic:

The code below will do what you need, click on the link to see the full source:

https://gist.github.com/sofar/e5da2a6ce ... 9b367bd7ac

Put this in worlds/<worldname>/worldmods/track/init.lua and start your world, and this will output CSV formatted time+position files for each player.

Output files are overwritten if the player reconnects.

eeMagic
Member
Posts: 12
Joined: Wed May 25, 2016 15:59

Re: Minetest as an experimental tool for neuroscience

by eeMagic » Post

@sofar: Thank you very much!! It works perfectly! Now I can start with the crazy stuff.

Sorry for the stupid question but... what is the difference between a worldmod and a mod?

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Minetest as an experimental tool for neuroscience

by rubenwardy » Post

There are three places a mod can be.

In a subgame like minetest game (games/minetest_game/mods/) - the mod is automatically enabled and specific to that subgame, so any world using that subgame will have that mod.
The main mods dir (mods/)- disabled by default, and world can enable amd use it.
The worldmods mod dir (worlds/worldname/worldmods/) - always enabled, mods are specific to that world.
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
burli
Member
Posts: 1643
Joined: Fri Apr 10, 2015 13:18

Re: Minetest as an experimental tool for neuroscience

by burli » Post

rubenwardy wrote: The worldmods mod dir (worlds/worldname/worldmods/) - always enabled, mods are specific to that world.
Didn't know that

eeMagic
Member
Posts: 12
Joined: Wed May 25, 2016 15:59

Re: Minetest as an experimental tool for neuroscience

by eeMagic » Post

Hi again,
I keep working in this project. My biggest problem now is how to add/remove a few blocks before load, I'm using
minetest.after() but I don't want to show the previous arrange of blocks.

eeMagic
Member
Posts: 12
Joined: Wed May 25, 2016 15:59

Re: Minetest as an experimental tool for neuroscience

by eeMagic » Post

Is it possible use a fixed camera? or at least change the max distance of set_eye_offset() in third person?

User avatar
srifqi
Member
Posts: 570
Joined: Sat Jun 28, 2014 04:31
GitHub: srifqi
IRC: srifqi
In-game: srifqi
Location: Indonesia

Re: Minetest as an experimental tool for neuroscience

by srifqi » Post

eeMagic wrote:Is it possible use a fixed camera? or at least change the max distance of set_eye_offset() in third person?
I'm not sure about fixed camera. Also, if you mean "max distance" is viewing range, you can set it by pressing Numpad - or Numpad + or add this line into minetest.conf:

Code: Select all

viewing_range = (insert your viewing range here, in block)
Saya dari Indonesia! · Terjemahkan Minetest! · my mods · My nickname in IPA: /es.rif.qi/

eeMagic
Member
Posts: 12
Joined: Wed May 25, 2016 15:59

Re: Minetest as an experimental tool for neuroscience

by eeMagic » Post

I mean the relative position of the camera. In set_eye_offset(offset_first, offset_third), I found that after y=15, offset_third doesn't change any more.

User avatar
srifqi
Member
Posts: 570
Joined: Sat Jun 28, 2014 04:31
GitHub: srifqi
IRC: srifqi
In-game: srifqi
Location: Indonesia

Re: Minetest as an experimental tool for neuroscience

by srifqi » Post

eeMagic wrote:I mean the relative position of the camera. In set_eye_offset(offset_first, offset_third), I found that after y=15, offset_third doesn't change any more.
Yes, it does. As stated in docs/lua_api.txt:

Code: Select all

* `set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})`: defines offset value for camera per player
    * in first person view
    * in third person view (max. values `{x=-10/10,y=-10,15,z=-5/5}`)
Saya dari Indonesia! · Terjemahkan Minetest! · my mods · My nickname in IPA: /es.rif.qi/

eeMagic
Member
Posts: 12
Joined: Wed May 25, 2016 15:59

Re: Minetest as an experimental tool for neuroscience

by eeMagic » Post

Is there a way to change that maximum values?

User avatar
srifqi
Member
Posts: 570
Joined: Sat Jun 28, 2014 04:31
GitHub: srifqi
IRC: srifqi
In-game: srifqi
Location: Indonesia

Re: Minetest as an experimental tool for neuroscience

by srifqi » Post

eeMagic wrote:Is there a way to change that maximum values?
You can, but you need to change engine codes. It's already hard-coded in the engine code (src/script/lua_api/l_object.cpp) to "Prevent abuse of offset values (keep player always visible)":

Code: Select all

	// Prevent abuse of offset values (keep player always visible)
	offset_third.X = rangelim(offset_third.X,-10,10);
	offset_third.Z = rangelim(offset_third.Z,-5,5);
	/* TODO: if possible: improve the camera colision detetion to allow Y <= -1.5) */
	offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS
Remove those lines above in source code and compile.
Saya dari Indonesia! · Terjemahkan Minetest! · my mods · My nickname in IPA: /es.rif.qi/

eeMagic
Member
Posts: 12
Joined: Wed May 25, 2016 15:59

Re: Minetest as an experimental tool for neuroscience

by eeMagic » Post

thanks :)

I have a big problem now. I have to use an external C library to communicate with hardware. I made a dll wrapper in C for lua and it works (I tested it using luaforwindows) . But minetest crash when I try to use: require(wrappername) in the init.lua of a mod.

I'm using Minetest portable 32 bits, Visual Studio for compiling and I tested the code with luaforwindows.

am I totally confused?
is it there another way to use dlls in minetest?

eeMagic
Member
Posts: 12
Joined: Wed May 25, 2016 15:59

Re: Minetest as an experimental tool for neuroscience

by eeMagic » Post

I suppose I should tell the end of this

I couldn't compile minetest in part because I wasn't able to find an easy way to add all the codes and libraries we need to send signals to the hardware. But I worked around this issue...
Using Windows, Python and pyHook, I synchronised the game and the external hardware when I press 'return' after input a command in minetest that start the navigation experiment.
I'm quite sure that it has a lot of timing error, but it works fine enough for a lot of tests.

Probably we will move to Blender, the level/game design is more complex but It hasn't the limitations of Minetest. It was fun, I learned a lot, and I will try to use Minetest to test/design others experiments. Thanks to those who helped me with all this

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests