// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: calc_osc_k_factors()
void calc_osc_k_factors()
{
double i_tc;
double f_tc;

   // This routine converts the user friendly input PID constants into the
   // "k" values used by the PID filter algorithm.  It is called whenever
   // a PID filter constant is changed by the user.
   //
   // OSC_P_GAIN        -> osc_k1   (PID gain)
   // OSC_D_TC          -> osc_k2   (derivative time constant)
   // OSC_FILTER_TC     -> osc_k3   (filter time constant)
   // OSC_I_TC          -> osc_k4   (integrator time constant)
   // OSC_FILTER_OFFSET             (osc setpoint offset)

   if(osc_rampup && OSC_I_TC && (osc_rampup < OSC_I_TC)) {
      i_tc = OSC_I_TC      * (osc_rampup / OSC_I_TC);
      f_tc = OSC_FILTER_TC * (osc_rampup / OSC_I_TC);
      osc_rampup += 1.0;
   }
   else {
      i_tc = OSC_I_TC;
      f_tc = OSC_FILTER_TC;
   }

   if(i_tc) osc_k4 = (1.0/i_tc) / OSC_PID_UPDATE_RATE * OSC_P_GAIN;
   else     osc_k4 = 0.0;

   if(f_tc > 0.0) {
      osc_k3 = 1.0 - (1.0/((f_tc*OSC_PID_UPDATE_RATE)+1.0));
      osc_k2 = (-1.0 * OSC_D_TC * OSC_P_GAIN) / (f_tc*OSC_PID_UPDATE_RATE+1.0) * (OSC_PID_UPDATE_RATE/OSC_SCALE_FACTOR);
   }
   else {
      osc_k3 = OSC_FILTER_TC;
      osc_k2 = (-1.0 * OSC_D_TC * OSC_P_GAIN) * (OSC_PID_UPDATE_RATE/OSC_SCALE_FACTOR);
   }

   osc_k1 = ((OSC_P_GAIN/OSC_SCALE_FACTOR) * (1.0-osc_k3)) - osc_k2;

   if(osc_pid_debug && (osc_rampup == 0.0)) {  // set a marker each time a PID value changes
      if(++test_marker >= MAX_MARKER) test_marker = 1;
      if(test_marker < 0) test_marker = 1;
      mark_q_entry[test_marker] = plot_q_in;
   }

   if(osc_pid_debug) {
      show_osc_pid_values();
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
leaq 0x2339a1(%rip), %rax    # 0x39e8c0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x16af33
jp 0x16af33
jmp 0x16afde
leaq 0x23395e(%rip), %rax    # 0x39e898
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x16af4e
jp 0x16af4e
jmp 0x16afde
leaq 0x23396b(%rip), %rax    # 0x39e8c0
movsd (%rax), %xmm1
leaq 0x233938(%rip), %rax    # 0x39e898
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x16afde
leaq 0x233927(%rip), %rax    # 0x39e898
movsd (%rax), %xmm0
leaq 0x233944(%rip), %rax    # 0x39e8c0
movsd (%rax), %xmm1
leaq 0x233911(%rip), %rax    # 0x39e898
divsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
leaq 0x2338f5(%rip), %rax    # 0x39e890
movsd (%rax), %xmm0
leaq 0x23391a(%rip), %rax    # 0x39e8c0
movsd (%rax), %xmm1
leaq 0x2338e7(%rip), %rax    # 0x39e898
divsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd 0x40a2(%rip), %xmm0     # 0x16f068
leaq 0x2338f3(%rip), %rax    # 0x39e8c0
addsd (%rax), %xmm0
leaq 0x2338e8(%rip), %rax    # 0x39e8c0
movsd %xmm0, (%rax)
jmp 0x16affe
leaq 0x2338b3(%rip), %rax    # 0x39e898
movsd (%rax), %xmm0
movsd %xmm0, -0x8(%rbp)
leaq 0x23389b(%rip), %rax    # 0x39e890
movsd (%rax), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x16b010
jp 0x16b010
jmp 0x16b03e
movsd 0x4050(%rip), %xmm0     # 0x16f068
divsd -0x8(%rbp), %xmm0
movsd 0x4043(%rip), %xmm1     # 0x16f068
divsd %xmm1, %xmm0
leaq 0x233850(%rip), %rax    # 0x39e880
mulsd (%rax), %xmm0
movsd %xmm0, 0x349e24(%rip)   # 0x4b4e60
jmp 0x16b049
xorps %xmm0, %xmm0
movsd %xmm0, 0x349e17(%rip)   # 0x4b4e60
movsd -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16b0d1
movsd -0x10(%rbp), %xmm0
movsd 0x4004(%rip), %xmm1     # 0x16f068
addsd %xmm1, %xmm0
movsd 0x3ff8(%rip), %xmm1     # 0x16f068
divsd %xmm0, %xmm1
movsd 0x3fec(%rip), %xmm0     # 0x16f068
subsd %xmm1, %xmm0
movsd %xmm0, 0x349dd0(%rip)   # 0x4b4e58
movsd 0x4088(%rip), %xmm0     # 0x16f118
leaq 0x2337f1(%rip), %rax    # 0x39e888
mulsd (%rax), %xmm0
leaq 0x2337de(%rip), %rax    # 0x39e880
mulsd (%rax), %xmm0
movsd -0x10(%rbp), %xmm1
movsd 0x3fb5(%rip), %xmm2     # 0x16f068
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd 0x3fa5(%rip), %xmm1     # 0x16f068
mulsd %xmm1, %xmm0
movsd %xmm0, 0x349d81(%rip)   # 0x4b4e50
jmp 0x16b116
leaq 0x2337b8(%rip), %rax    # 0x39e890
movsd (%rax), %xmm0
movsd %xmm0, 0x349d74(%rip)   # 0x4b4e58
movsd 0x402c(%rip), %xmm0     # 0x16f118
leaq 0x233795(%rip), %rax    # 0x39e888
mulsd (%rax), %xmm0
leaq 0x233782(%rip), %rax    # 0x39e880
mulsd (%rax), %xmm0
movsd 0x3f5e(%rip), %xmm1     # 0x16f068
mulsd %xmm1, %xmm0
movsd %xmm0, 0x349d3a(%rip)   # 0x4b4e50
leaq 0x233763(%rip), %rax    # 0x39e880
movsd (%rax), %xmm0
movsd 0x3f3f(%rip), %xmm1     # 0x16f068
divsd %xmm1, %xmm0
movsd 0x3f33(%rip), %xmm2     # 0x16f068
subsd 0x349d1b(%rip), %xmm2   # 0x4b4e58
movsd 0x349d0b(%rip), %xmm1   # 0x4b4e50
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x349cdc(%rip)   # 0x4b4e48
leaq 0x233705(%rip), %rax    # 0x39e878
cmpb $0x0, (%rax)
je 0x16b1ed
leaq 0x233741(%rip), %rax    # 0x39e8c0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x16b1ed
jp 0x16b1ed
leaq 0x233683(%rip), %rax    # 0x39e818
movl (%rax), %eax
addl $0x1, %eax
leaq 0x233677(%rip), %rcx    # 0x39e818
movl %eax, (%rcx)
cmpl $0xa, %eax
jl 0x16b1b5
leaq 0x233669(%rip), %rax    # 0x39e818
movl $0x1, (%rax)
leaq 0x23365c(%rip), %rax    # 0x39e818
cmpl $0x0, (%rax)
jge 0x16b1ce
leaq 0x233650(%rip), %rax    # 0x39e818
movl $0x1, (%rax)
leaq 0x10f333(%rip), %rax    # 0x27a508
movq (%rax), %rdx
leaq 0x233639(%rip), %rax    # 0x39e818
movslq (%rax), %rcx
leaq 0x10f2a7(%rip), %rax    # 0x27a490
movq %rdx, (%rax,%rcx,8)
leaq 0x233684(%rip), %rax    # 0x39e878
cmpb $0x0, (%rax)
je 0x16b1fe
callq 0x16b210
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)