add servo state, init params

This commit is contained in:
Sébastien Bourdeauducq 2025-01-20 11:58:27 +08:00
parent 8dc3b45f63
commit 3e94b0f0d8

View File

@ -251,16 +251,29 @@ static const char *kirdies[SND_PCHAN][2] = {
{"192.168.1.126", "1337"},
};
static std::atomic<double> laser_temp[SND_PCHAN];
static std::atomic<bool> servo_enable[SND_PCHAN];
static std::atomic<const char *> servo_state[SND_PCHAN];
static std::atomic<float> laser_temp[SND_PCHAN];
static std::atomic<float> init_current_cooling[SND_PCHAN];
static std::atomic<float> init_current_heating[SND_PCHAN];
static std::atomic<float> init_temp[SND_PCHAN];
static void servo_thread(int channel)
{
Clocker clocker = Clocker(std::chrono::milliseconds(100));
Kirdy kirdy = Kirdy(kirdies[channel][0], kirdies[channel][1]);
while(!shutdown_threads) {
clocker.tick();
laser_temp[channel] = kirdy.get_laser_temp();
kirdy.set_tec_current(0.01);
float temp;
while(true) {
servo_state[channel] = "DISABLED";
while(!servo_enable[channel]) {
clocker.tick();
if(shutdown_threads)
return;
laser_temp[channel] = temp = kirdy.get_laser_temp();
}
servo_state[channel] = "INIT";
}
}
@ -304,6 +317,10 @@ int main(int argc, char* argv[])
amplitude[i] = 1.0;
multiplier[i] = 1;
lpf_bandwidth[i] = 10.0;
servo_state[i] = "DISABLED";
init_current_cooling[i] = 100.0f;
init_current_heating[i] = 30.0f;
init_temp[i] = 25.0f;
}
static std::thread dsp_thread_h = std::thread(dsp_thread);
@ -433,7 +450,32 @@ int main(int argc, char* argv[])
char str[64];
sprintf(str, "Channel %d", i);
ImGui::SeparatorText(str);
ImGui::Text("laser temperature: %.4f", (float)laser_temp[i]);
bool servo_enable_l = servo_enable[i];
sprintf(str, "enable##%d", i);
ImGui::Checkbox(str, &servo_enable_l);
servo_enable[i] = servo_enable_l;
ImGui::Text("servo state: %s", (const char *)servo_state[i]);
ImGui::Text("laser temperature: %.4f °C", (float)laser_temp[i]);
ImGui::AlignTextToFramePadding();
ImGui::Text("init:");
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x / 6.0f);
ImGui::SameLine();
sprintf(str, "cooling mA##%d", i);
float init_current_cooling_l = init_current_cooling[i];
ImGui::InputFloat(str, &init_current_cooling_l, 1.0f, 500.0f, "%.3f");
init_current_cooling[i] = init_current_cooling_l;
ImGui::SameLine();
sprintf(str, "heating mA##%d", i);
float init_current_heating_l = init_current_heating[i];
ImGui::InputFloat(str, &init_current_heating_l, 1.0f, 500.0f, "%.3f");
init_current_heating[i] = init_current_heating_l;
ImGui::SameLine();
sprintf(str, "temp °C##%d", i);
float init_temp_l = init_temp[i];
ImGui::InputFloat(str, &init_temp_l, 1.0f, 500.0f, "%.4f");
init_temp[i] = init_temp_l;
ImGui::PopItemWidth();
}
}