// Look up a moving reference: the angle the rod is asked to be at, as a table of rows in time.
#include <cstdio>

#include "NMPC/Reference.h"

int main() {
    // One column, a row every 0.25 s: hang, swing out to 0.2 rad, then on to 0.5 rad.
    static const double angles[] = {0.0, 0.2, 0.5};
    NMPC::PathTable<double, 1> reference;
    reference.hold(angles, 3, 0.25);  // the table borrows these rows; keep them alive

    for (double time : {0.0, 0.125, 0.375, 0.5, 0.8}) {
        const auto span = reference.span(time);  // the rows either side of this time
        const double angle = span.r0(0) + span.a * (span.r1(0) - span.r0(0));
        std::printf("t %.3f s: %.0f%% of the way from %.1f to %.1f rad -> %.3f rad\n",
                    time, 100.0 * span.a, span.r0(0), span.r1(0), angle);
    }

    // A single-precision clock that keeps what each addition rounds off.
    NMPC::Clock<float> clock;
    float plain = 0.0f;
    clock.reset();
    for (int tick = 0; tick < 30000; tick++) {  // 30 s of 1 ms ticks
        clock.advance(0.001f);
        plain += 0.001f;
    }
    std::printf("after 30000 ticks of 1 ms: compensated %.4f s, plain sum %.4f s\n",
                double(clock.value), double(plain));
    return 0;
}
