I searched a lot about blender's Inverse Kinematics API, but I'm really confused right now. So the goal of my project is to control a robot arm that has 4 degrees of freedom. So far, I managed to model a rig in blender, that has the same characteristics as the arm I'd like to control (see example below). I also successfully added Inverse Kinematics constraints to make it easier to draw shapes in the air (as you can guess by the screenshot). A blender 3D viewport with a robot arm-like rig

Now the goal here is, in order to control this arm, I need to export the animation data as a CSV file, where each line contains data from one frame; and each column contains the angles of the joint in local space.

This is the code I have so far, since as a start I wanted to try some debugging of the values I might export later.

import bpy
from math import degrees

class SimpleBoneAnglesPanel(bpy.types.Panel):
    bl_label = "Bone Angles"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'

def draw(self, context):
    arm = context.scene.objects['Armature']
    self.drawInfo(arm,"Wrist vertical")
def drawInfo(self,armature,boneName):
    bone = armature.pose.bones[boneName]

    mat = bone.matrix.to_euler()
    box = self.layout.box()
    box.label(text=f'X: {degrees(mat.x):.3f}')
    box.label(text=f'Y: {degrees(mat.y):.3f}')
    box.label(text=f'Z: {degrees(mat.z):.3f}')

Thanks to this code snippet for the inspiration, it really helped !

So far so good, you might think. As shown in the screenshot and in the above code, I can access the individual rotations of each bone on the x, y and z axis.

The problem is that each joint of my robot can only rotate on one axis. And even though the IK constraint seems to work perfectly fine visually, the numbers I get (see Bone Angles panel on the right of the screenshot), they change on Y and Z as the arm is moving. I need the rotation on Z axis for each of the joints (except for the base it's Y).

So my question is, how can I get the local rotation of each pose bone? It looks like the API has changed, and matrix_local doesn't exist anymore. Thank you for taking the time to read and maybe help me out, I hope I was clear and concise enough.


Your Answer

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

Browse other questions tagged or ask your own question.