use sinara thermostat, minor gui improvements

This commit is contained in:
Sebastien Bourdeauducq 2023-09-12 10:11:46 +08:00
parent 57d41479b3
commit 9e842ddad5
1 changed files with 20 additions and 8 deletions

View File

@ -37,6 +37,7 @@ static std::atomic<float> freq_setpoint;
static std::atomic<float> freq_peak; static std::atomic<float> freq_peak;
static std::atomic<float> tec_bias; static std::atomic<float> tec_bias;
static std::atomic<float> tec_p; static std::atomic<float> tec_p;
static std::atomic<float> tec_current;
static std::atomic<int> fps; static std::atomic<int> fps;
@ -45,7 +46,7 @@ static void dsp_thread() {
net::io_context io_context; net::io_context io_context;
net::ip::tcp::socket tec_socket(io_context); net::ip::tcp::socket tec_socket(io_context);
tec_socket.connect(net::ip::tcp::endpoint(net::ip::make_address("192.168.1.91"), 5555)); tec_socket.connect(net::ip::tcp::endpoint(net::ip::make_address("192.168.1.27"), 23));
size_t len = 16384; size_t len = 16384;
std::vector<std::complex<int16_t>> frames(len); std::vector<std::complex<int16_t>> frames(len);
@ -84,10 +85,20 @@ static void dsp_thread() {
float freq_peak_local; float freq_peak_local;
freq_peak_local = 40.0f*float(distance(frames_mag.begin(), max_element(frames_mag.begin(), frames_mag.end())))/float(len); freq_peak_local = 40.0f*float(distance(frames_mag.begin(), max_element(frames_mag.begin(), frames_mag.end())))/float(len);
freq_peak = freq_peak_local; freq_peak = freq_peak_local;
// FIXME: net::write seems unimplemented as of libstdc++ 13
float freq_error = freq_peak_local - freq_setpoint; float freq_error = freq_peak_local - freq_setpoint;
tec_socket.write_some(net::buffer(std::format(":SOUR2:VOLT {:.3f}\n", float tec_current_local = std::max(tec_bias+tec_p*freq_error, 0.0f);
std::max(tec_bias+tec_p*freq_error, 0.0f)))); tec_current = tec_current_local;
// FIXME: net::write seems unimplemented as of libstdc++ 13
tec_socket.write_some(net::buffer(std::format("pwm 0 i_set {:.6f}\n", tec_current_local)));
std::string reply;
net::read(tec_socket, net::dynamic_buffer(reply),
[&reply](auto ec, auto n) -> std::size_t
{
if(ec || (reply.size() > 0 && reply.compare(reply.size()-1, 1, "\n") == 0))
return 0;
else
return 1;
});
last_tec += 100ms; last_tec += 100ms;
tick = true; tick = true;
} }
@ -243,14 +254,15 @@ int main(int argc, char* argv[])
ImGui::TableSetupColumn("", 0, 280.0f); ImGui::TableSetupColumn("", 0, 280.0f);
ImGui::TableSetupColumn("", 0, 1000.0f); ImGui::TableSetupColumn("", 0, 1000.0f);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Checkbox("Update", &update); ImGui::Checkbox("Update waterfall", &update);
ImGui::Text("Peak: %.3f", (float)freq_peak); ImGui::Text("Baseband peak: %.3f MHz", (float)freq_peak);
ImGui::Text("TEC current: %.6f mA", (float)tec_current);
ImGui::SliderFloat("Setpoint", &freq_setpoint_local, 0.0f, 40.0f); ImGui::SliderFloat("Setpoint", &freq_setpoint_local, 0.0f, 40.0f);
ImGui::SliderFloat("TEC bias", &tec_bias_local, 0.0f, 0.5f); ImGui::SliderFloat("TEC bias", &tec_bias_local, 0.0f, 0.5f);
ImGui::SliderFloat("TEC P", &tec_p_local, -0.05f, 0.05f); ImGui::SliderFloat("TEC P", &tec_p_local, -1.0f, 1.0f);
freq_setpoint = freq_setpoint_local; freq_setpoint = freq_setpoint_local;
tec_bias = tec_bias_local; tec_bias = tec_bias_local;
tec_p = tec_p_local; tec_p = 0.05f*tec_p_local;
if(ImGui::Button("Exit")) if(ImGui::Button("Exit"))
exit = true; exit = true;
ImGui::Text("FPS: %d", (int)fps); ImGui::Text("FPS: %d", (int)fps);