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


arm.channels['Upperleg.L'].rotation_euler = [5, 5, 5]


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?


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!


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()
    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():
    for i in range(1, 11):
        user = bpy.nui.get_user(i)
        if not user:
        #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)))


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

  • $\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$ – Randika Pathirana Sep 25 '14 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$ – stacker Sep 25 '14 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.