get rotation of parented object / get angle between bones

hi,

i want to run a servo from within blender via arduino.

the “pin 23” is an empty i have parented to a bone with inverse kinematic (screenshot).

now i want to extract the rotation of the empty and send it to the servo:

servoAngle23 = degrees(bpy.data.objects[‘Pin 23’].rotation_euler.z)

the problem is that the rotation of the empty always stays 0.
how do i get the angle of the transformation?

another possibility would be to extract the angle between the connected bone and the bone with ik.
is ther a possibility to get this done in python?

thanks very much in advance.

kind regards,
chris

Attachments


The Empty’s rotation is always 0 because it is parented to the bone. The Empty does not move or rotate, it appears to rotate because the bone is moving. You have a couple of options for getting the rotation data.

Most people that do these kinds of Arduino experiments access the bone data directly. The data you are looking for is stored in the ‘PoseBone’ data for your armature. If memory serves, you can access the data something like this:



import bpy

# Assumes that your armature is the active object in the current view
armObj = bpy.context.active_object
pose = armObj.pose


for pBone in pose.bones:
    print(pBone.rotation_euler)

Also note that Blender defaults to using quaternion’s for bone rotations, you will have to change your rotations to euler rotations, which are better for servo robotics experiments.

hi kastoria,
thank you very much for your reply.
i have just seen your post now.
allready solved the problem,
but your solution works much better.
kind regards,
chris