Page 1 of 1

Philips Hue integration with STK

PostPosted: 20 Sep 2015, 23:34
by kmangame0
I am working on a project for school that integrates Philips Hue smart light bulbs into STK. The objective of this project is to use audio-to-visual replacement to allow players whom have hearing disabilities an equal playing advantage. IE: if there is a audio warning for being targeted by a weapon there would also be a visual cue via the smart bulbs. Right now I am working on a way to measure the distance of one kart to another and align that value with the brightness of a bulb (the closer the opponent the brighter the bulb). For reference I have very little experience in game programming and even less in c++, but I am wondering if anyone who has experience with this code base can tell me if the code already exists in the project to measure the distance between the karts or if I will have to write this logic myself.

Re: Philips Hue integration with STK

PostPosted: 22 Sep 2015, 00:30
by hiker
Hi,

kmangame0 {l Wrote}:I am working on a project for school that integrates Philips Hue smart light bulbs into STK. The objective of this project is to use audio-to-visual replacement to allow players whom have hearing disabilities an equal playing advantage. IE: if there is a audio warning for being targeted by a weapon there would also be a visual cue via the smart bulbs. Right now I am working on a way to measure the distance of one kart to another and align that value with the brightness of a bulb (the closer the opponent the brighter the bulb).

Sounds interesting!

For reference I have very little experience in game programming and even less in c++, but I am wondering if anyone who has experience with this code base can tell me if the code already exists in the project to measure the distance between the karts or if I will have to write this logic myself.

Not ideal circumstances, but the actual code change should be pretty simple: look at src/karts/controller/player_controller.cpp, find update() (which is called once per frame for each player kart) and add something like (note I didn't check that the code compiles, there might be a typo, or declaration missing):
{l Code}: {l Select All Code}
  for(unsigned int i=0; i<World::getWorld()->getNumKarts(); i++)
{
    const AbstractKart* kart = m_world->getKart(j);
    if(kart==m_kart) continue;   // skip player's kart
   float distance = (m_kart->getXYZ() - kart->getXYZ() ).length();
}


Then you can do what you want - probably determine the minimum distance to set the light brightness.

Hope that helps!

Cheers,
Joerg

Re: Philips Hue integration with STK

PostPosted: 27 Sep 2015, 18:45
by kmangame0
Thanks so much for your help!

Re: Philips Hue integration with STK

PostPosted: 28 Sep 2015, 12:27
by ArDanWol
Cool project! Maybe we can integrate some kind of visual warning system into STK in the future!

Re: Philips Hue integration with STK

PostPosted: 29 Sep 2015, 01:09
by hiker
kmangame0 {l Wrote}:Thanks so much for your help!

Could you perhaps report back how it works? It's always interesting for us to see how stk is used!

Thanks!
Joerg

Re: Philips Hue integration with STK

PostPosted: 09 Oct 2015, 18:21
by kmangame0
Yes I absolutely will!

Re: Philips Hue integration with STK

PostPosted: 13 Oct 2015, 21:54
by kmangame0
Okay guys I have one more question. I am trying to use a python wrapper in order to scoop up the stdout of supertuxkart.app. To do this I have decided to use pythons popen but I am running into some weird behavior.

File "/var/root/Documents/dev/cmichDev/stk/stkReader.py", line 5, in <module>
stdin=subprocess.PIPE)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied

Have you guys ever tried to access the stdin or stdout of supertuxkart? If so, what was your method?

Re: Philips Hue integration with STK

PostPosted: 14 Oct 2015, 04:03
by hiker
kmangame0 {l Wrote}:Okay guys I have one more question. I am trying to use a python wrapper in order to scoop up the stdout of supertuxkart.app. To do this I have decided to use pythons popen but I am running into some weird behavior.

File "/var/root/Documents/dev/cmichDev/stk/stkReader.py", line 5, in <module>
stdin=subprocess.PIPE)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied

Have you guys ever tried to access the stdin or stdout of supertuxkart? If so, what was your method?


'Permission denied' would indicate that perhaps you are trying to start the wrong 'thing' (e.g. perhaps a directory instead of the binary?) Note that nearly all output of stk is also written to the log file in the user config directory. If you are adding output, just use the Log::verbose/warning/error/... functions, and you can see it there as well. Otherwise just copy&paste your code, and we can have a look. Also, on what platform are you on?

Cheers,
Joerg

Re: Philips Hue integration with STK

PostPosted: 14 Oct 2015, 18:54
by konstin
I tried

print(subprocess.Popen("SUPERTUXKART_DATADIR=/path/over/datapath /path/to/supertuxkart", shell=True, stdout=subprocess.PIPE).stdout.read())

on linux, and it worked, though the output formatting was wrong. I assume you have a permission problem (binary doesn't belong to you user, exutable bit not set, etc.). You can probably find a solution using google with "python OSError: [Errno 13] Permission denied ".

Re: Philips Hue integration with STK

PostPosted: 16 Oct 2015, 18:07
by kmangame0
hiker {l Wrote}:'Permission denied' would indicate that perhaps you are trying to start the wrong 'thing' (e.g. perhaps a directory instead of the binary?)


You were absolutely correct. For whatever reason the Python library thought that proc = subprocess.Popen(['supertuxkart.app'],stdout=subprocess.PIPE, shell=False) was a directory.

hiker {l Wrote}:Otherwise just copy&paste your code, and we can have a look.

import subprocess
proc = subprocess.Popen(['open supertuxkart.app'],stdout=subprocess.PIPE, shell=True)
while True:
line = proc.stdout.readline()
if line != '':
print "test:", line.rstrip()

hiker {l Wrote}:Also, on what platform are you on?

I am running Mac OS X 10.11

hiker {l Wrote}:Note that nearly all output of stk is also written to the log file in the user config directory. If you are adding output, just use the Log::verbose/warning/error/... functions, and you can see it there as well.

This is extremely helpful! I still need to figure out more information about this popen business. I was under the impression that because it opened a sibling process that there was a "standard" out. Meaning to the cmd, terminal, ect. But apparently that's not the case.