4
$\begingroup$

I'm new to blender and python I need to control armature in blender game engine via a serial data comes from arduino. I'm useing this code but it does not work.

import GameLogic arm = GameLogic.getCurrentController().owner print(arm.channels['Upperleg.L'].rotation_euler) arm.channels['Upperleg.L'].rotation_euler = [5, 5, 5] arm.update() print(arm.channels['Upperleg.L'].rotation_euler) 

I'm using blender 2.71 and used a always sensor with the python controller(script). I Can't find whats wrong in this code. Does any one know how to change the euler angles of the armature in blender game engine mode?

$\endgroup$

2 Answers 2

1
$\begingroup$

I've built MotioSuit, an active open-source imu based mocap suit based on arduino and blender.

All the info needed is here: https://hackaday.io/project/9266-motiosuit

And files are available in github: https://github.com/bqlabs/MotioSuit

Take a look around the game engine logic and python script in the blender file, I hope this helps!

$\endgroup$
0
3
$\begingroup$

You need to invoke your script from an actuator otherwise the scene will not be updated see image at the bottom of this post. I searched my old sources and found this very messy one that still works in BGE (today tested with Blender (2.68.5):

enter image description here

import sys import time import os import random import select from math import * import mathutils import bge import bpy import math from mathutils import Vector from mathutils import Quaternion def applyKinect(rot,name): scene = bge.logic.getCurrentScene() source = scene.objects main_arm = source.get('Armature') #q = Quaternion((rot.w,-rot.x,-rot.z,rot.y)) q = Quaternion((rot.w,rot.x,rot.y,rot.z)) main_arm.channels[ name ].rotation_quaternion = q.normalized() main_arm.update() v = rot.to_euler("XYZ") if name.startswith('head'): print("%s X:%r Y:%r Z:%r" % (name,math.degrees(v.x),math.degrees(v.y),math.degrees(v.z))) def map(): #print("map") for i in range(1, 11): user = bpy.nui.get_user(i) if not user: continue #print("Map Kinect Found User=" + str(i)) # rot = user.hip_center[1] # applyKinect( rot, 'hip_center' ) # print("hip_center %r" % rot ) #rot = user.neck[2] #applyKinect( rot, 'neck' ) rot = user.head[2] arm = applyKinect( rot, 'head' ) rot = user.r_shoulder[2] applyKinect( rot, 'shoulder_R' ) rot = user.r_elbow[2] applyKinect( rot, 'elbow_R' ) rot = user.r_wrist[2] applyKinect( rot, 'wrist_R' ) rot = user.r_hand[2] applyKinect( rot, 'hand_R' ) rot = user.l_shoulder[1] applyKinect( rot, 'shoulder_L' ) rot = user.l_elbow[1] applyKinect( rot, 'elbow_L' ) rot = user.l_wrist[1] applyKinect( rot, 'wrist_L' ) rot = user.l_hand[1] applyKinect( rot, 'hand_L' ) def dump(ctx, obj, level=0): for attr in dir(obj): print( "%s.%s = %s" % (ctx, attr, getattr(obj, attr))) map() #test() 

I used quaternions (note that you can convert your euler angles to a quaternion using the methods from mathutils).

The data is provided by an addon (and polled by bpy.nui.get_user(i)), the script is executed with a logic block like this:

enter image description here

$\endgroup$
2
  • $\begingroup$ Your code is working fine and there is no problem with other code also.I tried it on blender 2.5 which was install on other machine and it works fine.The problem occurs on my laptop.I'm using blender 2.71 and it generates black lines on the middle of the screen while moving the mouse.Same thing happens for blender 2.68.Does this happens for graphic card problem? $\endgroup$ Commented Sep 25, 2014 at 5:18
  • $\begingroup$ @RandikaPathirana Display errors are usually caused by graphics drivers, you should try to update. When this works for you could consider accepting the answer. $\endgroup$ Commented Sep 25, 2014 at 6:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.