Script which control tilt of car - crash, why?

Hi,
I am trying to write script which control tilt of my car. Tilt is depended from speed and difference between angle of car and front wheel.

Why my script makes blender crash and how fix it?

code:

  • import bpy
  • import math
  • def pochyl(klatka):
  • speedobj='Car_Rig'
    
  • fps=25
    
  • x=bpy.context.scene.objects[speedobj].matrix_world.to_translation().x
    
  • y=bpy.context.scene.objects[speedobj].matrix_world.to_translation().y
    
  • z=bpy.context.scene.objects[speedobj].matrix_world.to_translation().z
    
  • bpy.data.scenes['Scene'].frame_set(klatka+1)
    
  • x2=bpy.context.scene.objects[speedobj].matrix_world.to_translation().x
    
  • y2=bpy.context.scene.objects[speedobj].matrix_world.to_translation().y
    
  • z2=bpy.context.scene.objects[speedobj].matrix_world.to_translation().z
    
  • bpy.data.scenes['Scene'].frame_set(klatka)
    
  • odleglosc=math.sqrt( pow(x2-x,2) + pow(y2-y,2) + pow(z2-z,2))
    
  • predkosc=odleglosc*fps*3.6
    
  • kat=bpy.context.scene.objects['Felga'].matrix_world.to_euler().z - bpy.context.scene.objects[speedobj].matrix_world.to_euler().z
    
  • pochylenie=(predkosc*0.01)*kat
    
  • <b>print</b>(pochylenie)
    
  • <b>return</b> pochylenie
    
  • bpy.app.driver_namespace[‘pochyl’]=pochyl

driver:


crash:




blend file:
http://www.speedyshare.com/xAjNq/CGmasters-car-modeling-and-texturing2a.blend

Does it give any tracebacks in the terminal?

ok, I quess I found the issue. My function is infinity looped.