add a simple control loop
This commit is contained in:
parent
41aa27f02f
commit
74455e887d
37
sndlock.cpp
37
sndlock.cpp
@ -261,10 +261,13 @@ static std::atomic<float> init_current_heating[SND_PCHAN];
|
|||||||
static std::atomic<float> init_temp[SND_PCHAN];
|
static std::atomic<float> init_temp[SND_PCHAN];
|
||||||
static std::atomic<float> leadin_current[SND_PCHAN];
|
static std::atomic<float> leadin_current[SND_PCHAN];
|
||||||
static std::atomic<float> leadin_thr[SND_PCHAN];
|
static std::atomic<float> leadin_thr[SND_PCHAN];
|
||||||
|
static std::atomic<float> loop_setpoint[SND_PCHAN];
|
||||||
|
static std::atomic<float> loop_bias[SND_PCHAN];
|
||||||
|
static std::atomic<float> loop_p[SND_PCHAN];
|
||||||
|
|
||||||
static void servo_thread(int channel)
|
static void servo_thread(int channel)
|
||||||
{
|
{
|
||||||
Clocker clocker = Clocker(std::chrono::milliseconds(100));
|
Clocker clocker = Clocker(std::chrono::milliseconds(30));
|
||||||
Kirdy kirdy = Kirdy(kirdies[channel][0], kirdies[channel][1]);
|
Kirdy kirdy = Kirdy(kirdies[channel][0], kirdies[channel][1]);
|
||||||
float temp;
|
float temp;
|
||||||
|
|
||||||
@ -310,6 +313,7 @@ static void servo_thread(int channel)
|
|||||||
|
|
||||||
servo_state[channel] = "LOCKING";
|
servo_state[channel] = "LOCKING";
|
||||||
while(servo_enable[channel]) {
|
while(servo_enable[channel]) {
|
||||||
|
kirdy.set_tec_current(loop_bias[channel] + loop_p[channel]*(li_principal[channel] - loop_setpoint[channel]));
|
||||||
clocker.tick();
|
clocker.tick();
|
||||||
laser_temp[channel] = temp = kirdy.get_laser_temp();
|
laser_temp[channel] = temp = kirdy.get_laser_temp();
|
||||||
}
|
}
|
||||||
@ -355,14 +359,17 @@ int main(int argc, char* argv[])
|
|||||||
frequency[i] = 441.0 + 202.0*i;
|
frequency[i] = 441.0 + 202.0*i;
|
||||||
amplitude[i] = 1.0;
|
amplitude[i] = 1.0;
|
||||||
multiplier[i] = 1;
|
multiplier[i] = 1;
|
||||||
lpf_bandwidth[i] = 10.0;
|
lpf_bandwidth[i] = 8.5;
|
||||||
principal_angle[i] = M_PI/4.0;
|
principal_angle[i] = M_PI/4.0;
|
||||||
servo_state[i] = "DISABLED";
|
servo_state[i] = "DISABLED";
|
||||||
init_current_cooling[i] = 270.0f;
|
init_current_cooling[i] = 310.0f;
|
||||||
init_current_heating[i] = -30.0f;
|
init_current_heating[i] = -30.0f;
|
||||||
init_temp[i] = 16.0f;
|
init_temp[i] = 16.0f;
|
||||||
leadin_current[i] = 230.0f;
|
leadin_current[i] = 280.0f;
|
||||||
leadin_thr[i] = 0.007f;
|
leadin_thr[i] = 0.01f;
|
||||||
|
loop_setpoint[i] = 0.01f;
|
||||||
|
loop_bias[i] = 280.0f;
|
||||||
|
loop_p[i] = 700.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::thread dsp_thread_h = std::thread(dsp_thread);
|
static std::thread dsp_thread_h = std::thread(dsp_thread);
|
||||||
@ -554,6 +561,26 @@ int main(int argc, char* argv[])
|
|||||||
ImGui::InputFloat(str, &leadin_thr_l, 0.0f, 0.001f, "%.6f");
|
ImGui::InputFloat(str, &leadin_thr_l, 0.0f, 0.001f, "%.6f");
|
||||||
leadin_thr[i] = leadin_thr_l;
|
leadin_thr[i] = leadin_thr_l;
|
||||||
ImGui::PopItemWidth();
|
ImGui::PopItemWidth();
|
||||||
|
|
||||||
|
ImGui::AlignTextToFramePadding();
|
||||||
|
ImGui::Text("loop: ");
|
||||||
|
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x / 6.0f);
|
||||||
|
ImGui::SameLine();
|
||||||
|
sprintf(str, "bias mA ##%d", i);
|
||||||
|
float loop_bias_l = loop_bias[i];
|
||||||
|
ImGui::InputFloat(str, &loop_bias_l, 1.0f, 500.0f, "%.3f");
|
||||||
|
loop_bias[i] = loop_bias_l;
|
||||||
|
ImGui::SameLine();
|
||||||
|
sprintf(str, "setpoint ##%d", i);
|
||||||
|
float loop_setpoint_l = loop_setpoint[i];
|
||||||
|
ImGui::InputFloat(str, &loop_setpoint_l, 0.0f, 0.001f, "%.6f");
|
||||||
|
loop_setpoint[i] = loop_setpoint_l;
|
||||||
|
ImGui::SameLine();
|
||||||
|
sprintf(str, "P ##%d", i);
|
||||||
|
float loop_p_l = loop_p[i];
|
||||||
|
ImGui::InputFloat(str, &loop_p_l, 0.0f, 50.0f, "%.2f");
|
||||||
|
loop_p[i] = loop_p_l;
|
||||||
|
ImGui::PopItemWidth();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user