Odometer Problem

Hello i am making a car simulation game and i need to make an odometer to simulate tire damage and wear and so on so on
so the method to make the odometer i went with works like this
first i attach the odometer script to a tire (i chose the front drivers wheel).
now for the script the idea was this:
first i get the measurements of the tire on the y axis (the dimensions read 0.647 in BUs or 2.123ft in imperial units)
next i calculated the circumference of the tire (2.123ft*3.14) which equaled 6.66622ft
next i would get the current rotation of the x axis of the tire in degrees
then i would divide the current rotation by 360 and then check if that is a whole number
if it is a whole number then i would add 6.66622ft to a variable and then divide that variable by 5280
(my dad came up with the formula and the basis for the odometer)
then i would dump that to a game property or a text plane.
so my problem is that i don’t know how to get the current rotation of the tire period.
so how do i do that?
and i have to get the rotation of the x axis only and it has to be in degrees not radians or blender units
and also in python how would i check if a number was whole or not?
sorry for the long winded explanation
here’s the script to get the rotation
i already know how to do the math to get the amount of miles its traveled but i did up this script and it just wont work
when i debug the properties it dosen’t even show the odo property(i figured that out i need to add a .x to TireRot but now it just shows 0.000000 no matter how much the tire rotates) what am i doing wrong?

import bge
from bge import logic
import bpy
cont = bge.logic.getCurrentController()
own = cont.owner
set = own[‘odo’]

def main ():

Tire =  bpy.data.objects["TireFD"]
TireRot = Tire.rotation_euler
own['odo'] = TireRot.x

thanks in advance
by the way i am using blender 2.68



if 'start' not in own:
    own['start']=True
    own[Pos']=own.worldPosition
if own['Pos']!=own.worldPosition:
  D=own['Pos']-own.worldPosition
  own['Dt']+=D.magnitude 


own['Pos']=own.worldPosition

Dt=Distance Traveled


def init(cont):
    own = cont.owner
    own['rotation'] = own.worldOrientation.to_euler().x
    own['total_angle'] = 0.0

def update(cont):
    own = cont.owner
    current_angle = own.worldOrientation.to_euler().x
    last_angle, own['rotation'] = own['rotation'], current_angle
    rotation_difference = current_angle - last_angle
    own['total_angle'] += rotation_difference

def get_miles(cont):
    own = cont.owner

    radius = 1.0
    displacement = math.pi * radius * own['total_angle'] #Metric meters

blue print thank you for the help but when i start the script in bge it gives me an error in the console that says:

Traceback (most recent last call)
file “new odometer.py”, line 10, in <module>
AttributeError: Vector sunctraction: (str - Vector) invalid type for this operation

so whats wrong?
and also does this script mesure in miles or blender units?

and also how does this script work?

thank you @agoose7777 i put your loaded up your script and i didnt really know which module to call so i called the update module and it worked but it had 2 things wrong:

  1. it had an error in the console saying:

Traceback (most recent last call)
file “new odometer.py”, line 15, in update
TypeError: unsupported operand type(s) for -: ‘float’ and ‘str’

and
2. in the rotation property it starts out at 0.1 then goes all the way to 3.0 then starts counting backwards to -3.0 then starts count up agian and repeats this so its not mesuring the angle whats wrong?

thank you both very much for your input

import bge
cont=bge.logic.getCurrentController()
own=cont.owner
if 'start' not in own:
    own['start']=True
    own[Pos']=own.worldPosition
else:
    if own['Pos']!=own.worldPosition:
      D=own['Pos']-own.worldPosition
      own['Dt']+=D.magnitude 


own['Pos']=own.worldPosition

Attachments

exampleDT.blend (429 KB)

My mistake. I’d forgotten about the flipping point.
rotation.blend (432 KB)

Thank you both for your help
i have a question about your script blueprint
the final Dt game property what units is it using?
BUs feet inches meters miles what?
and agoose when i used your script with my cars wheel it showed nothing for the rotation why is that?
here is the script i am using to drive the car:

hmm i cant seem to post the script but you can get a working blend with the car in it at http://www.youtube.com/blender3dmaster
just look for his car setup v3 video(note this is not my work i am only modifing it)
thanks agian for all of your help

bu blender units

for all you blenders out there heres the soultion i worked up using blue prints script:


import bge
cont=bge.logic.getCurrentController()
own=cont.owner
Meter=0
Ft=0.0
Mi=0.0
if 'start' not in own:
    own['start']=True
    own['Pos']=own.worldPosition.copy
else:
    if own['Pos']!=own.worldPosition:
        D=own['Pos']-own.worldPosition
        own['Meter']+=D.magnitude
        Ft = own['Meter']*3.28
        own['Ft']=Ft
        print(Ft)
        Mi = Ft/5280
        own['Mi'] = Mi




own['Pos']=own.worldPosition.copy()

to set up first add these game properites to an object:
Meter
Ft
Pos
Mi
(All Of these Should Be Floats)
then attach this script to a game object via an always sensor with true pulse trigering enabled then your done and vola you have a working odometer calculated in real miles!
a huge thanks goes to BluePrintRandom for his help and to agoose77