#define main historical_tests_main
#include "test_drill_smo.c"
#undef main
int main(void){
 historical_tests_main();unsigned cases=0;
 for(unsigned pp=1;pp<=4;pp*=2)for(unsigned k=0;k<4;++k)for(int dir=-1;dir<=1;dir+=2){
  const float rpms[]={5000,15000,35000,50000};
  drill_smo_config c=config();c.pole_pairs=(uint8_t)pp;c.max_dt_s=0.00005f;c.min_bemf_v=0.05f;
  drill_smo_state s;assert(drill_smo_init(&s,&c));drill_smo_output o={0};
  float theta=0.7f;const float dt=0.00005f,speed=(float)dir*rpms[k]*TWO_PI/60.0f*(float)pp;
  /* Fixed synthetic R,L,Ke across the sweep; low-amplitude observation
   * threshold here is a test parameter, not qualified hardware sensitivity. */
  const float ke=0.00030f, current_peak=0.05f;
  for(unsigned n=0;n<40000u;++n){
   const float ia=current_peak*cosf(theta),ib=current_peak*sinf(theta);
   drill_smo_input i={.voltage_alpha_v=c.phase_resistance_ohm*ia-(c.phase_inductance_h*current_peak+ke)*speed*sinf(theta),.voltage_beta_v=c.phase_resistance_ohm*ib+(c.phase_inductance_h*current_peak+ke)*speed*cosf(theta),.current_alpha_a=ia,.current_beta_a=ib,.dt_s=dt,.commanded_direction=(int8_t)dir};
   assert(drill_smo_step(&s,&i,&o));theta=wrap_pi_test(theta+speed*dt);
  }
  float err=wrap_pi_test(o.electrical_angle_rad-theta),rpmerr=fabsf(o.mechanical_speed_rpm-(float)dir*rpms[k]);
  printf("SWEEP pp=%u rpm=%.0f estimate=%.3f angle_error=%.6f locked=%d\n",pp,(float)dir*rpms[k],o.mechanical_speed_rpm,err,o.observer_locked);
  assert(o.observer_locked&&rpmerr<rpms[k]*0.02f&&fabsf(err)<0.20f);++cases;
 }
 drill_smo_config c=config();c.max_dt_s=0.00005f;c.pole_pairs=12;drill_smo_state s;assert(!drill_smo_init(&s,&c));
 c.pole_pairs=11;assert(drill_smo_init(&s,&c));
 printf("A97_SWEEP_PASS cases=%u; Nyquist boundary rejected; necessary condition only\n",cases);
 return 0;
}
