See the docs about drivers, they're comprehensive.
Also see TextEditor -> Templates -> Python -> Driver Functions
Add a Driver
If your object is key-framed, you can evaluate the F-Curve using a frame number like
Add a Driver to a custom property of your object.
Make a python expression text block with something like the code below, and Run the code so the expression is added to the
from mathutils import Vector
# triggered by a frame change, any code inside here gets run.
p = bpy.data.objects['Plane']
current_xyz = p.location
fcurve = p.animation_data.action.fcurves
x = fcurve.evaluate(frame-1)
y = fcurve.evaluate(frame-1)
z = fcurve.evaluate(frame-1)
# may want to find the top speed first, and normalize
# this value using that information
delta = (current_xyz - Vector((x, y, z))).length
nodes = bpy.data.materials.node_tree.nodes
nodes.inputs.default_value = (delta, 0, 0, 1.0)
# the return value is of no relevance and can be static.
bpy.app.driver_namespace['driver_delta_to_RED'] = driver_delta_to_RED
Add the function call to the Driver
if it's a frame behind or ahead of what you want, then instead of the Driver, it might make sense to add an application_handler specifically the frame_change_pre or frame_change_post handlers.
The code for Drivers and frame_change handlers is slightly different, but the app handler docs will describe how to get the current frame from inside the handler function.