Implement stepper shaper

I’m thinking that stealth compensation (TMC StealthChop Rotor Positional Lag and Compensation) would be easier than the motor phase compensation, for me, and now at least.

Basic idea: the motor’s rotor lag is predictable, lag <90 degrees/fullstep.
This stepper in the kinematic, at any point in time, would be in the past position.

Basically, calc_position_cb should return to the itersolver the position at the T-motor_phase_lag (200us..2ms), in the past.

But do to that, I need to know the instant speed at the requested time, for the stepper.
To calculate the speed of the rotor.
(specifically, speed of the phase change, so precise time between steps is enough, but it would be available only at the output of the itersolver).

So, I’m trying to implement a kinematics wrapper: GitHub - nefelim4ag/klipper at stepper-shaper-20250503 - it is boilerplate, which only wraps.
There are a lot of caveats. For example, if I wrap IS kinematics → step compress error, but if IS wraps me, well, then I do not have access to speed/time relations.

Right now, I have a slightly different issue.
I simply want to determine the stepper speed at a given moment of time without IS:

inline double
move_get_speed(struct move *m, double move_time)
{
    return m->start_v + 2 * m->half_accel * move_time;
}

static double
shaper_calc_position(struct stepper_kinematics *sk, struct move *m, double move_time)
{
    struct stepper_shaper *ss = container_of(sk, struct stepper_shaper, sk);
    double cur = ss->orig_sk->calc_position_cb(ss->orig_sk, m, move_time);
    double next = ss->orig_sk->calc_position_cb(ss->orig_sk, m, move_time + 0.00001);
    double diff = next - cur;
    double speed = diff / 0.000001;
    double speed2 = move_get_speed(m, move_time);
    fprintf(stderr, "diff: %f, speed: %f, speed2: %f\n", diff, speed, speed2);

    if (ss->motor_constant == .0)
        return ss->orig_sk->calc_position_cb(ss->orig_sk, m, move_time);

}

The problem is, I’m not sure that it is a stepper speed here on a CoreXY.

// G0 X10 F120 ; expect 2 mm/s
diff: 0.000020, speed: 20.000000, speed2: 2.000000
diff: 0.000020, speed: 20.000000, speed2: 2.000000
diff: 0.000020, speed: 20.000000, speed2: 2.000000
diff: 0.000020, speed: 20.000000, speed2: 2.000000
INFO:root:Exiting (print time 105.015s)
diff: 0.000020, speed: 20.000000, speed2: 2.000000
diff: 0.000020, speed: 20.000000, speed2: 2.000000
diff: 0.000020, speed: 20.000000, speed2: 2.000000
diff: 0.000020, speed: 20.000000, speed2: 2.000000
diff: 0.000020, speed: 20.000000, speed2: 2.000000

// G0 X10 Y10 F120 ; expect 2 / 0.707 ~ 2.82 mm/s
diff: -0.000019, speed: -19.380281, speed2: 2.000000
diff: -0.000019, speed: -19.380280, speed2: 2.000000
diff: -0.000019, speed: -19.380280, speed2: 2.000000
diff: -0.000019, speed: -19.380280, speed2: 2.000000
INFO:root:Exiting (print time 295.606s)
diff: -0.000019, speed: -19.380280, speed2: 2.000000
diff: -0.000019, speed: -19.380281, speed2: 2.000000
diff: -0.000019, speed: -19.380281, speed2: 2.000000
diff: -0.000019, speed: -19.380280, speed2: 2.000000

Is there a good way to determine the instant speed of the stepper motor?

Thanks.