From bffbea0637015f9b3edd8f9565bd67f96911bd1d Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Sat, 2 Mar 2024 13:18:47 +0100 Subject: [PATCH] adding calibration debuging information --- configuration.h | 4 ++ detect.h | 12 ++++ gui.h | 1 + posctl.cc | 121 ++++++++++++++++++++++++++++++++++---- simpleskycam.ui | 151 ++++++++++++++++++++++++++++++++++++++++++++++++ video.cc | 38 ++++++++++++ 6 files changed, 317 insertions(+), 10 deletions(-) diff --git a/configuration.h b/configuration.h index 9ac7793..c3b041d 100644 --- a/configuration.h +++ b/configuration.h @@ -18,6 +18,7 @@ class Configuration { private: int histogram_log = 1; // logarithmic or linear scale + int calibration_showdata = 0; // needed for debugging calibration JSONParse config; std::string GetDefaultFileName(); @@ -41,6 +42,9 @@ public: void SetHistogramLog(int trueorfalse); int GetHistogramLog() { return histogram_log; }; + void SetCalibrationShowData(int enabled) { calibration_showdata = enabled; }; + int GetCalibrationShowData() { return calibration_showdata; }; + void SetPresetButton (int btn, list *parameters); list GetPresetButton (int btn); }; diff --git a/detect.h b/detect.h index fa48f99..05ca733 100644 --- a/detect.h +++ b/detect.h @@ -69,6 +69,15 @@ enum { }; + +struct PosCtl_ThreadData { + position_2d c[2]; + position_2d a1[2]; + position_2d a2[2]; + int mode; +}; + + class PosCtl { private: GMutex mutex; @@ -85,6 +94,9 @@ class PosCtl { int calib_mode; position_2d calib_pos; + struct PosCtl_ThreadData threaddata; // will be copied to gtk thread + void NotifyGtk(); + void CalibModeStart(int x, int y); void CalibModeDelta(int x, int y); void CalibModeAxis(int x, int y); diff --git a/gui.h b/gui.h index d46d4d7..a4fc215 100644 --- a/gui.h +++ b/gui.h @@ -205,6 +205,7 @@ G_MODULE_EXPORT void cb_posctl_track_draw(GtkWidget *area, cairo_t *cr, int w, i // menu elements G_MODULE_EXPORT void cb_menu_set_rgbenc (GtkCheckMenuItem *checkmenuitem, gpointer user_data); G_MODULE_EXPORT void cb_menu_set_histlog (GtkCheckMenuItem *checkmenuitem, gpointer user_data); +G_MODULE_EXPORT void cb_menu_set_displaycalibdata(GtkCheckMenuItem *checkmenuitem, gpointer user_data); // // error handling diff --git a/posctl.cc b/posctl.cc index 4c20a62..1423e5b 100644 --- a/posctl.cc +++ b/posctl.cc @@ -46,6 +46,8 @@ struct AxisHistory { struct AxisHistory axis_history[2][AXIS_HISTORY_CNT]; int axis_history_pos[2] = { 0, 0 }; +struct PosCtl_ThreadData posctl_calib_debug; + void axis_history_add(int axis, double diff, double out) { if (axis > 1 || axis < 0) return; @@ -99,8 +101,16 @@ void cb_posctl_btncontrol (GtkWidget *widget, gpointer data) { posctl_gui_update(); } + +void cb_menu_set_displaycalibdata(GtkCheckMenuItem *checkmenuitem, gpointer user_data) { + if (gtk_check_menu_item_get_active(checkmenuitem) == TRUE) config.SetCalibrationShowData(true); + else config.SetCalibrationShowData(false); +} + + void cb_posctl_show (GtkWidget *widget, gpointer data) { printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); + posctl_calib_debug.mode = -1; posctl_gui_update(); } @@ -569,6 +579,7 @@ void posctl_gui_update() { gboolean cb_thread_posctl (gpointer data) { GtkWidget *da1 = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_da_axis1")); GtkWidget *da2 = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_da_axis2")); + GtkWidget *tg = NULL; posctl_gui_update(); @@ -579,6 +590,47 @@ gboolean cb_thread_posctl (gpointer data) { posctl_rot_da = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_da_rotation")); gdk_window_invalidate_rect(gtk_widget_get_window(posctl_rot_da), NULL, true); + if (data != NULL) { + posctl_calib_debug = *(struct PosCtl_ThreadData*) data; + free (data); + + switch (posctl_calib_debug.mode) { + case (POSCTL_CALIB_MODE_OFF): + tg = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cal_mode_off")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tg), true); + break; + case (POSCTL_CALIB_MODE_STOP1): + tg = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cal_mode_rs")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tg), true); + break; + case (POSCTL_CALIB_MODE_DELTAM): + tg = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cal_mode_r")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tg), true); + break; + case (POSCTL_CALIB_MODE_AXIS1START): + tg = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cal_mode_a1s")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tg), true); + break; + case (POSCTL_CALIB_MODE_AXIS1M): + tg = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cal_mode_a1")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tg), true); + break; + case (POSCTL_CALIB_MODE_AXIS2START): + tg = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cal_mode_a2s")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tg), true); + break; + case (POSCTL_CALIB_MODE_AXIS2M): + tg = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cal_mode_a2")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tg), true); + break; + case (POSCTL_CALIB_MODE_FINISH): + tg = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cal_mode_f")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tg), true); + break; + default: + break; + } + } return false; }; @@ -607,7 +659,51 @@ PosCtl::PosCtl() { void PosCtl::Stop() { printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); mode = POSCTL_MODE_OFF; - gdk_threads_add_idle(cb_thread_posctl, NULL); + NotifyGtk(); +} + + +void PosCtl::NotifyGtk() { + int i; + struct PosCtl_ThreadData *data = (struct PosCtl_ThreadData*) malloc(sizeof(struct PosCtl_ThreadData)); + threaddata.mode = calib_mode; + switch (calib_mode) { + case(POSCTL_CALIB_MODE_STOP1): + for (i = 0; i < 2; i++) { + threaddata.c[i].x = threaddata.c[i].y = -1; + threaddata.a1[1].x = threaddata.a1[i].y = -1; + threaddata.a2[1].x = threaddata.a2[i].y = -1; + } + break; + case(POSCTL_CALIB_MODE_DELTAM): + threaddata.c[0].x = calib_pos.x; + threaddata.c[0].y = calib_pos.y; + break; + case(POSCTL_CALIB_MODE_AXIS1START): + threaddata.c[1].x = calib_pos.x; + threaddata.c[1].y = calib_pos.y; + break; + case(POSCTL_CALIB_MODE_AXIS1M): + threaddata.a1[0].x = calib_pos.x; + threaddata.a1[0].y = calib_pos.y; + break; + case(POSCTL_CALIB_MODE_AXIS2START): + threaddata.a1[1].x = calib_pos.x; + threaddata.a1[1].y = calib_pos.y; + break; + case(POSCTL_CALIB_MODE_AXIS2M): + threaddata.a2[0].x = calib_pos.x; + threaddata.a2[0].y = calib_pos.y; + break; + case(POSCTL_CALIB_MODE_FINISH): + threaddata.a2[1].x = calib_pos.x; + threaddata.a2[1].y = calib_pos.y; + break; + default: + break; + } + *(struct PosCtl_ThreadData*)data = threaddata; + gdk_threads_add_idle(cb_thread_posctl, data); } @@ -623,7 +719,7 @@ void PosCtl::StartCalibration() { mode = POSCTL_MODE_CALIB; calib_mode = POSCTL_CALIB_MODE_STOP1; gettimeofday (&calib_timestamp, NULL); - gdk_threads_add_idle(cb_thread_posctl, NULL); + NotifyGtk(); } void PosCtl::StartControl() { @@ -637,7 +733,7 @@ void PosCtl::StartControl() { pid_axis[0].Start(); pid_axis[1].Start(); mode = POSCTL_MODE_CONTROL; - gdk_threads_add_idle(cb_thread_posctl, NULL); + NotifyGtk(); } @@ -673,7 +769,7 @@ void PosCtl::CalibModeStart(int x, int y) { calib_mode = POSCTL_CALIB_MODE_STOP1; if (OutputWriteStop()) mode = POSCTL_MODE_OFF; gettimeofday (&calib_timestamp, NULL); - gdk_threads_add_idle(cb_thread_posctl, NULL); + NotifyGtk(); }; @@ -692,7 +788,7 @@ void PosCtl::CalibModeWait(int x, int y) { calib_pos.y = y; gettimeofday (&calib_timestamp, NULL); - gdk_threads_add_idle(cb_thread_posctl, NULL); + NotifyGtk(); } } @@ -727,7 +823,9 @@ void PosCtl::CalibModeDelta(int x, int y) { if (OutputWriteValue(0, pid_axis[0].GetMax())) mode = POSCTL_MODE_OFF; gettimeofday (&calib_timestamp, NULL); - gdk_threads_add_idle(cb_thread_posctl, NULL); + calib_pos.x = x; + calib_pos.y = y; + NotifyGtk(); } }; @@ -762,7 +860,10 @@ void PosCtl::CalibModeAxis(int x, int y) { if (calib_mode != POSCTL_CALIB_MODE_OFF) calib_mode++; gettimeofday (&calib_timestamp, NULL); - gdk_threads_add_idle(cb_thread_posctl, NULL); + + calib_pos.x = x; + calib_pos.y = y; + NotifyGtk(); } }; @@ -776,7 +877,7 @@ void PosCtl::CalibModeFinish() { if (OutputWriteValue(0, 0.5 * (pid_axis[0].GetMin() + pid_axis[0].GetMax()))) mode = POSCTL_MODE_OFF; if (OutputWriteValue(1, 0.5 * (pid_axis[1].GetMin() + pid_axis[1].GetMax()))) mode = POSCTL_MODE_OFF; gettimeofday (&calib_timestamp, NULL); - gdk_threads_add_idle(cb_thread_posctl, NULL); + NotifyGtk(); }; @@ -813,7 +914,7 @@ void PosCtl::Loop (int posx, int posy) { default: calib_mode = POSCTL_CALIB_MODE_OFF; mode = POSCTL_MODE_OFF; - gdk_threads_add_idle(cb_thread_posctl, NULL); + NotifyGtk(); break; } } @@ -858,7 +959,7 @@ void PosCtl::Loop (int posx, int posy) { axis_history_add(1, axis_pv[1], axis_op[1]); UnLockMutex(); - gdk_threads_add_idle(cb_thread_posctl, NULL); + NotifyGtk(); } else { diff --git a/simpleskycam.ui b/simpleskycam.ui index 38bad78..a61c26d 100644 --- a/simpleskycam.ui +++ b/simpleskycam.ui @@ -993,6 +993,149 @@ 1 + + + True + False + vertical + + + Off + True + False + False + False + True + True + + + False + True + 0 + + + + + RS + True + False + False + False + True + True + cal_mode_off + + + False + True + 1 + + + + + R + True + False + False + False + True + cal_mode_off + + + False + True + 2 + + + + + A1S + True + False + False + False + True + cal_mode_off + + + False + True + 3 + + + + + A1 + True + False + False + False + True + cal_mode_off + + + False + True + 4 + + + + + A2S + True + False + False + False + 1 + True + cal_mode_off + + + False + True + 5 + + + + + A2 + True + False + False + False + True + cal_mode_off + + + False + True + 6 + + + + + F + True + False + False + False + True + cal_mode_off + + + False + True + 7 + + + + + False + True + end + 2 + + False @@ -2159,6 +2302,14 @@ Image Data + + + True + False + Display Calibration Data + + + diff --git a/video.cc b/video.cc index d67df97..ee705b1 100644 --- a/video.cc +++ b/video.cc @@ -31,6 +31,8 @@ extern position_2d video_enterdata_pos; extern detect_movement detectedpos_data; extern Configuration config; +extern struct PosCtl_ThreadData posctl_calib_debug; + void videoctrl_grid_delete (); void videoctrl_grid_build (); @@ -238,6 +240,42 @@ void cb_videoda_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer data) gtk_label_set_text(GTK_LABEL(lbX), txt1); gtk_label_set_text(GTK_LABEL(lbY), txt2); + if (config.GetCalibrationShowData()) { + // printf ("%s:%d posctl_calib_debug.c : %d \t %d -> \t %d \t %d\n", __FILE__, __LINE__, + // posctl_calib_debug.c[0].x, posctl_calib_debug.c[0].y, + // posctl_calib_debug.c[1].x, posctl_calib_debug.c[1].y); + // printf ("%s:%d posctl_calib_debug.a1: %d \t %d -> \t %d \t %d\n", __FILE__, __LINE__, + // posctl_calib_debug.a1[0].x, posctl_calib_debug.a1[0].y, + // posctl_calib_debug.a1[1].x, posctl_calib_debug.a1[1].y); + // printf ("%s:%d posctl_calib_debug.a2: %d \t %d -> \t %d \t %d\n", __FILE__, __LINE__, + // posctl_calib_debug.a2[0].x, posctl_calib_debug.a2[0].y, + // posctl_calib_debug.a2[1].x, posctl_calib_debug.a2[1].y); + if (posctl_calib_debug.c[0].x != -1 && posctl_calib_debug.c[0].y != -1 && + posctl_calib_debug.c[1].x != -1 && posctl_calib_debug.c[1].y != -1) { + cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); + cairo_set_line_width(cr, 1.0); + cairo_move_to(cr, S_X(posctl_calib_debug.c[0].x), S_Y(posctl_calib_debug.c[0].y)); + cairo_line_to(cr, S_X(posctl_calib_debug.c[1].x), S_Y(posctl_calib_debug.c[1].y)); + cairo_stroke(cr); + } + if (posctl_calib_debug.a1[0].x != -1 && posctl_calib_debug.a1[0].y != -1 && + posctl_calib_debug.a1[1].x != -1 && posctl_calib_debug.a1[1].y != -1) { + cairo_set_source_rgb(cr, 1.0, 0.5, 1.0); + cairo_set_line_width(cr, 1.0); + cairo_move_to(cr, S_X(posctl_calib_debug.a1[0].x), S_Y(posctl_calib_debug.a1[0].y)); + cairo_line_to(cr, S_X(posctl_calib_debug.a1[1].x), S_Y(posctl_calib_debug.a1[1].y)); + cairo_stroke(cr); + } + if (posctl_calib_debug.a2[0].x != -1 && posctl_calib_debug.a2[0].y != -1 && + posctl_calib_debug.a2[1].x != -1 && posctl_calib_debug.a2[1].y != -1) { + cairo_set_source_rgb(cr, 1.0, 0.5, 1.0); + cairo_set_line_width(cr, 1.0); + cairo_move_to(cr, S_X(posctl_calib_debug.a2[0].x), S_Y(posctl_calib_debug.a2[0].y)); + cairo_line_to(cr, S_X(posctl_calib_debug.a2[1].x), S_Y(posctl_calib_debug.a2[1].y)); + cairo_stroke(cr); + } + } + #ifdef DEBUG_ANGLES debug_angles_draw(cr); #endif