Real-Time Control of a Cube with EMG signals. Possible?

An open space where people who use Blender in an academic environment can share progress and the typical problems and needs of academic environments.

Moderators: jesterKing, stiv

eduardoconto
Posts: 5
Joined: Tue Jan 11, 2011 7:54 pm
Location: Brazil

Real-Time Control of a Cube with EMG signals. Possible?

Postby eduardoconto » Wed Jan 12, 2011 7:10 pm

Hello from Brazil and Federal University of Rio Grande do Sul(UFRGS)!

In a project we are currently developing here, we are trying to develop a system to control a wheelchair based on electromyography(EMG). We have already have developed some techniques to process the signals and decide which movement has done. By now, we are trying to control a virtual object(like a cube) in real-time with the EMG signals we process. The objective of this is to compare and test the techniques we use to process the signals without using the physical chair.

We are thinking that maybe we can do this with Blender and its GameEngine. We would need a way to control this cube a mentioned with these decisions we do. We use NI LabVIEW here to process the signals, so we are trying to figure out a way to have an interface between Blender and LabVIEW, e.g, generate some file or data that Blender can read and use to control the cube, through its Python API.

Is it possible? Anyone have an idea of how we can do it?

Thanks in advance!
Eduardo de Conto

SirDude
Posts: 941
Joined: Sun Oct 13, 2002 7:37 pm
Location: University of Minnesota (USA)
Contact:

Postby SirDude » Thu Jan 13, 2011 5:24 pm

Yes there are a number of people that have written small interfaces to blender using python's socket's to comunicate with other things.

Just do a google search for blender python socket
and you'll be on your way.

eduardoconto
Posts: 5
Joined: Tue Jan 11, 2011 7:54 pm
Location: Brazil

Postby eduardoconto » Tue Jan 18, 2011 3:03 pm

hum... I've never worked with sockets before. Do you know somewhere I can look for good introductory material?
Thanks
Eduardo de Conto

eduardoconto
Posts: 5
Joined: Tue Jan 11, 2011 7:54 pm
Location: Brazil

Postby eduardoconto » Tue Feb 15, 2011 8:01 pm

Just do a google search for blender python socket
and you'll be on your way.


Were you talking about the Blender Command Port? I've been trying to build this to a Blender sw, but I couldn't. With this sw would I be able to call Blender through a TCP interface?
Eduardo de Conto

prof.t.adamson
Posts: 4
Joined: Tue Apr 19, 2011 2:57 am
Location: New Hampshire, USA

Postby prof.t.adamson » Tue Apr 19, 2011 3:33 am

Can you use your EMG device to create a small text file? If you can, then you can use Python to read the text and then act on the cube as a result. We have had some success in using a web-site to create a text file (using PHP) and then using Python to read the contents of that text file which in turn cause the cube to rotate in different directions.
We have demonstrated this at Southern New Hampshire University in our GAM-471 Special Topics course offered this semester.
If this seems like a possible solution for you, let me know and I can just give to you the source code I developed for this.
Hope this is of some help.
Best,
Tom A.
Visiting Assistant Professor,
Computer Game Design and Development.
SNHU.edu
I am interested in using Blender as a teaching tool in a beginning course in Computer Game Design and Development.

eduardoconto
Posts: 5
Joined: Tue Jan 11, 2011 7:54 pm
Location: Brazil

Postby eduardoconto » Tue Apr 19, 2011 6:00 pm

prof.t.adamson wrote:Can you use your EMG device to create a small text file? If you can, then you can use Python to read the text and then act on the cube as a result. We have had some success in using a web-site to create a text file (using PHP) and then using Python to read the contents of that text file which in turn cause the cube to rotate in different directions.
We have demonstrated this at Southern New Hampshire University in our GAM-471 Special Topics course offered this semester.
If this seems like a possible solution for you, let me know and I can just give to you the source code I developed for this.
Hope this is of some help.
Best,
Tom A.
Visiting Assistant Professor,
Computer Game Design and Development.
SNHU.edu


Well, actually, I have succeced in creating a interface between LabVIEW and Blender using UDP Sockets and the Blender GE, what, in turn, make it possible to me to control my blender object in real-time.
Eduardo de Conto

prof.t.adamson
Posts: 4
Joined: Tue Apr 19, 2011 2:57 am
Location: New Hampshire, USA

Postby prof.t.adamson » Tue Apr 19, 2011 11:02 pm

#What follows is the Python code we used with Blender. It reads this every 30 seconds:

from http.client import *
from GameLogic import *

conn = http.client.HTTPConnection("www.YourWebSite.org")
conn.request("GET", "/Python/Test.txt")
r1 = conn.getresponse()
print(r1.status, r1.reason)
data = r1.read()
data = data.strip()
print(data)

newText = data.decode()

print(newText)

matchText = newText.find('right')

cont = getCurrentController()

actList = cont.actuators
senList = cont.sensors

act1 = actList["right"]
act2 = actList["left"]

s1 = "right'"
s2 = "left'"

if newText.find('right') > -1:
print("Found right.")
cont.deactivate(act2)
cont.activate(act1)

if newText.find('left') > -1:
print("Found left.")
cont.deactivate(act1)
cont.activate(act2)

if newText.find('stop') > -1:
print("Found left.")
cont.deactivate(act1)
cont.deactivate(act2)

=============================================

This is the PHP code we used on the server which was activated by the following HTML document:

<?php
$txtID = $_GET["ID"];
$file = fopen("Test.txt","w");

switch ($txtID)
{
case 1:
$Instruction = "right";
break;
case 2:
$Instruction = "left";
break;
case 3:
$Instruction = "stop";
break;
}


fclose($file);
?>

============================================

This is the HTML code we used to control the text in the above php file:

<html>
<head>
<title>Link Page</title>
<script>
Start = "<iframe src='MyFrame.php?ID=";
End = "' />";
function DoIt(Value)
{
document.getElementById('Mine').innerHTML = Start + Value + End;
}
</script>
</head>
<body>
<h2>This is the link page.</h2>
You can control a Blender 3-D module from this page.
<span id="Mine"></span>
<input type="button" value="Right" OnClick="DoIt(1)" /><br />
<input type="button" value="Left" OnClick="DoIt(2)" /><br />
<input type="button" value="Stop" OnClick="DoIt(3)" /><br />
<input type="button" value="Four" OnClick="DoIt(1)" /><br /
</body>
</html>

=============================================

The result of this was that an HTML document on a remote computer could control a Blender object on another remote computer.

Hope this is of some use to you folks. Please let me know.
I am interested in using Blender as a teaching tool in a beginning course in Computer Game Design and Development.

Migerty
Posts: 1
Joined: Fri Jul 12, 2013 10:31 am

Postby Migerty » Fri Jul 12, 2013 10:46 am

Well, actually, I have succeced in creating a interface between LabVIEW and Blender using UDP Sockets and the Blender GE, what, in turn, make it possible to me to control my blender object in real-time.[/quote]


.........

Hi Eduardo, your research from 2011 sounds super interesting. I am just wondering if you still have access to your code which allowed LabVIEW to control a blender object? I am currently doing a summer project where I'd like to use IMUs to control an on screen avatar and controlling a box would be a great start. If you have anything that could help I would be so grateful! Also do you have any video of your EMG project, I have done projects with EMG before and would love to see yours in action.


Return to “Academic & Research”

Who is online

Users browsing this forum: No registered users and 4 guests