From 06d5235c63344bf2279d9fdbe44e6c457f12f0b0 Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Sat, 9 Mar 2024 21:43:46 +0100 Subject: [PATCH] ... --- detect.h | 5 +- gui.h | 5 +- posctl.cc | 46 ++- simpleskycam.ui | 743 ++++++++++++++++++++--------------------- video.cc | 76 +++-- videodev-simulation.cc | 12 +- videodev-simulation.h | 3 +- 7 files changed, 462 insertions(+), 428 deletions(-) diff --git a/detect.h b/detect.h index 2b30a53..7f39848 100644 --- a/detect.h +++ b/detect.h @@ -75,7 +75,8 @@ struct PosCtl_ThreadData { position_2d c[2]; position_2d a1[2]; position_2d a2[2]; - int mode; + position_2d target_pos; + int calib_mode; }; @@ -223,4 +224,6 @@ public: void Thread(); }; +extern struct PosCtl_ThreadData posctl_threaddata; + #endif diff --git a/gui.h b/gui.h index a4fc215..0755562 100644 --- a/gui.h +++ b/gui.h @@ -18,7 +18,8 @@ enum { VID_ENTERDATA_NONE = 0, - VID_ENTERDATA_POS + VID_ENTERDATA_POS, + VID_ENTERDATA_SETDEST }; #define BUILDER_FILE "simpleskycam.ui" @@ -192,6 +193,7 @@ G_MODULE_EXPORT void cb_posctl_show (GtkWidget *widget, gpointer data); G_MODULE_EXPORT void cb_posctl_show_window (GtkWidget *widget, gpointer data); G_MODULE_EXPORT void cb_posctl_btncalib (GtkWidget *widget, gpointer data); G_MODULE_EXPORT void cb_posctl_btnstop (GtkWidget *widget, gpointer data); +G_MODULE_EXPORT void cb_posctl_btnsetdest (GtkWidget *widget, gpointer data); G_MODULE_EXPORT void cb_posctl_btncontrol (GtkWidget *widget, gpointer data); G_MODULE_EXPORT void cb_posctl_entryanglelen (GtkWidget *widget, gpointer data); G_MODULE_EXPORT void cb_posctl_change_entry (GtkWidget *widget, gpointer data); @@ -201,6 +203,7 @@ G_MODULE_EXPORT void cb_posctl_angles_draw (GtkWidget *area, cairo_t *cr, int w, G_MODULE_EXPORT void cb_posctl_axis_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer data); G_MODULE_EXPORT void cb_posctl_track_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer data); + // // menu elements G_MODULE_EXPORT void cb_menu_set_rgbenc (GtkCheckMenuItem *checkmenuitem, gpointer user_data); diff --git a/posctl.cc b/posctl.cc index 4ea2006..f3e6953 100644 --- a/posctl.cc +++ b/posctl.cc @@ -23,6 +23,7 @@ #include "windows.h" #endif +extern int video_enterdata; extern PosCtl posctl; extern Simulation simulation; @@ -46,7 +47,7 @@ struct AxisHistory { struct AxisHistory axis_history[2][AXIS_HISTORY_CNT]; int axis_history_pos[2] = { 0, 0 }; -struct PosCtl_ThreadData posctl_calib_debug; +struct PosCtl_ThreadData posctl_threaddata; void axis_history_add(int axis, double diff, double out) { if (axis > 1 || axis < 0) return; @@ -114,11 +115,19 @@ void cb_menu_set_displaycalibdata(GtkCheckMenuItem *checkmenuitem, gpointer use void cb_posctl_show (GtkWidget *widget, gpointer data) { printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); - posctl_calib_debug.mode = -1; + posctl_threaddata.calib_mode = -1; + posctl_threaddata.target_pos.x = -1; + posctl_threaddata.target_pos.y = -1; posctl_gui_update(); } +void cb_posctl_btnsetdest (GtkWidget *widget, gpointer data) { + video_enterdata = VID_ENTERDATA_SETDEST; +}; + + + void cb_posctl_btn_axismove (GtkWidget *widget, gpointer data) { GtkWidget *btn_ramin = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_btn_ra_min")); GtkWidget *btn_racenter = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_btn_ra_center")); @@ -344,7 +353,7 @@ void cb_posctl_axis_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer da double dx, dy; double aoutmin[2]; double aoutmax[2]; - + char txt[255]; int clienth = gtk_widget_get_allocated_height(area); int clientw = gtk_widget_get_allocated_width(area); @@ -365,8 +374,8 @@ void cb_posctl_axis_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer da cairo_stroke(cr); cairo_set_dash(cr, NULL, 0, 0); - if (dra == area) axis = 0; - else if (ddec == area) axis = 1; + if (dra == area) axis = 1; + else if (ddec == area) axis = 0; else { cairo_move_to(cr, 30, 0); cairo_show_text(cr, (char *)"unknown"); @@ -408,6 +417,7 @@ void cb_posctl_axis_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer da cairo_set_font_size (cr, 10); cairo_move_to(cr, 60, 10); cairo_show_text(cr, (char *)"out"); + // draw elements diff i = axis_history_pos[axis]; cnt = 0; @@ -418,8 +428,8 @@ void cb_posctl_axis_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer da if (dx >= clientw) dx = clientw-1; if (dy >= clienth) dy = clienth-1; - if (dx < 0) dx = 0; - if (dy < 0) dy = 0; + if (dx < 0) dx = 1; + if (dy < 0) dy = 1; if (cnt == 0) cairo_move_to(cr, (int)dx, int(dy)); else cairo_line_to(cr, (int)dx, int(dy)); @@ -429,6 +439,16 @@ void cb_posctl_axis_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer da if (i < 0) i = AXIS_HISTORY_CNT-1; } while (i != axis_history_pos[axis]); cairo_stroke(cr); + + // draw min and max + cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); + cairo_move_to(cr, 0, clienth-7); + snprintf (txt, 255, "%2.2f", aoutmin[axis]); + cairo_show_text(cr, txt); + cairo_move_to(cr, clientw-25, clienth-7); + snprintf (txt, 255, "%2.2f", aoutmax[axis]); + cairo_show_text(cr, txt); + cairo_stroke(cr); }; @@ -571,7 +591,6 @@ void posctl_gui_update() { const gchar *txtptr = gtk_entry_get_text(GTK_ENTRY(e_posdevice)); if (strncmp(txtptr, "SIMULATION", 11) == 0) gtk_widget_show (btnsimreset); else gtk_widget_hide (btnsimreset); - posctl.UnLockMutex(); } @@ -595,10 +614,10 @@ gboolean cb_thread_posctl (gpointer data) { gdk_window_invalidate_rect(gtk_widget_get_window(posctl_rot_da), NULL, true); if (data != NULL) { - posctl_calib_debug = *(struct PosCtl_ThreadData*) data; + posctl_threaddata = *(struct PosCtl_ThreadData*) data; free (data); - switch (posctl_calib_debug.mode) { + switch (posctl_threaddata.calib_mode) { 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); @@ -668,7 +687,10 @@ void PosCtl::Stop() { void PosCtl::NotifyGtk() { int i; struct PosCtl_ThreadData *data = (struct PosCtl_ThreadData*) malloc(sizeof(struct PosCtl_ThreadData)); - threaddata.mode = calib_mode; + threaddata.calib_mode = calib_mode; + threaddata.target_pos.x = target_pos.x; + threaddata.target_pos.y = target_pos.y; + switch (calib_mode) { case(POSCTL_CALIB_MODE_STOP1): for (i = 0; i < 2; i++) { @@ -920,6 +942,7 @@ void PosCtl::Loop (int posx, int posy) { NotifyGtk(); break; } + NotifyGtk(); } // @@ -977,6 +1000,7 @@ void PosCtl::Loop (int posx, int posy) { #ifdef DEBUG_POSCTL lastmode = mode; #endif + }; diff --git a/simpleskycam.ui b/simpleskycam.ui index bca2a0a..034d27d 100644 --- a/simpleskycam.ui +++ b/simpleskycam.ui @@ -221,28 +221,24 @@ True False - True - True True False - True - True vertical top - + True - True - start - start + False + 4 + 0 + in - + True False - start - start + 12 True @@ -250,64 +246,48 @@ start start - + True False - 8 - 8 - 8 - 8 - Helligkeit Grenze: - - - False - True - 0 - - - - - 75 - True - True - start - start - detect-pos-adjbright - on - on - True - 255 - 1 - - - - True - True - 1 - - - - - False - True - 0 - - - - - True - False - vertical - - - Off - True - True - False start start - True - + + + True + False + 8 + 8 + 8 + 8 + Helligkeit Grenze: + + + False + True + 0 + + + + + 75 + True + True + start + start + detect-pos-adjbright + on + on + True + 255 + 1 + + + + True + True + 1 + + False @@ -316,118 +296,55 @@ - - Brightest Point + True - True - False - start - start - True - True - detect-pos-cboff - + False + vertical + + + Off + True + True + False + start + start + True + + + + False + True + 0 + + + + + Brightest Point + True + True + False + start + start + True + True + detect-pos-cboff + + + + False + True + 1 + + False True + 8 1 - - - - - - False - True - 8 - 1 - - - - - - - True - False - start - start - Detect Object - - - - - False - True - 0 - - - - - True - True - start - start - - - True - False - start - start - vertical - - - OFF - True - True - False - True - detect-type-indet1 - - - False - True - 0 - - - - - Brightest Point - True - True - False - start - True - detect-type-indet0 - - - - False - True - 1 - - - - - InputDetectCrossC - True - True - False - start - True - detect-type-indet0 - - - - False - True - 2 - - - - @@ -435,9 +352,7 @@ True False - start - start - Follow Object + Detect @@ -448,27 +363,33 @@ - + True - True - start - start + False + 4 + 0 + in - + True False - start - start - vertical + 12 True False + start + start + vertical - + + OFF True - False - Destination Position: + True + False + True + detect-type-indet1 + False @@ -477,20 +398,15 @@ - + + Brightest Point True - False True - 4 - 4 - 4 - 4 - 4 - 4 - 5 - 5 - 5 - digits + False + start + True + detect-type-indet0 + False @@ -499,100 +415,23 @@ - + + InputDetectCrossC True - False - , - - - False - True - 2 - - - - - True - False True - 4 - 4 - 4 - 4 - 4 - 4 - 5 - 5 - - - False - True - 3 - - - - - Set Dest - True - True - True - 8 - 8 - 8 - 8 - 4 - 4 - - - False - False - end - 4 - - - - - False - True - 0 - - - - - True - False - - - - - - - - - Configuration - True - True - True + False + start + True + detect-type-indet0 + False True - end 2 - - False - True - 1 - - - - - - - @@ -600,9 +439,7 @@ True False - start - start - Position Control + Follow Object @@ -615,7 +452,7 @@ False - True + False 0 @@ -645,6 +482,11 @@ + + True + False + gtk-close + True False @@ -1790,135 +1632,256 @@ vertical 4 - - True - False - Values - - - False - True - 0 - - - - - + True False - 4 - 4 + 0 + in - + True False - Axis RA: + 12 + + + True + False + vertical + + + True + False + Values + + + False + True + 0 + + + + + + True + False + 4 + 4 + + + True + False + Axis RA: + + + 0 + 1 + + + + + True + False + Axis DEC: + + + 0 + 2 + + + + + True + False + d + + + 1 + 0 + + + + + True + False + out + + + 3 + 0 + + + + + True + False + --- + + + + + + 1 + 1 + + + + + True + False + --- + + + + + + 1 + 2 + + + + + True + False + --- + + + + + + 3 + 1 + + + + + True + False + --- + + + + + + 3 + 2 + + + + + + + + + + + + + + + + + False + True + 1 + + + + + + + - - 0 - 1 - - + True False - Axis DEC: + Control Values - - 0 - 2 - + + + False + True + 0 + + + + + True + False + 0 + in - + True False - d + 12 + + + True + False + vertical + 4 + + + True + False + + + Set Position + True + True + True + image-setdest + True + + + + + False + True + 0 + + + + + + + + False + True + 0 + + + + + PV - SP Tracking + True + True + False + True + True + + + False + True + 1 + + + + + + + - - 1 - 0 - - + True False - out - - - 3 - 0 - - - - - True - False - --- - - - - - - 1 - 1 - - - - - True - False - --- - - - + Position - - 1 - 2 - - - - - True - False - --- - - - - - - 3 - 1 - - - - - True - False - --- - - - - - - 3 - 2 - - - - - - - - - - - - - diff --git a/video.cc b/video.cc index ee705b1..b4b4b1c 100644 --- a/video.cc +++ b/video.cc @@ -31,8 +31,6 @@ 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 (); @@ -157,6 +155,38 @@ void cb_videoda_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer data) g_object_unref (pixbuf); + // + // need to draw the new destination? + if (video_enterdata == VID_ENTERDATA_SETDEST) { + color.blue = 1.0; + color.red = 0.0; + color.green = 1.0; + color.alpha = 1.0; + gdk_cairo_set_source_rgba(cr, &color); + + cairo_move_to(cr, S_X(video_enterdata_pos.x)-10, S_Y(video_enterdata_pos.y)-10); + cairo_line_to(cr, S_X(video_enterdata_pos.x)+10, S_Y(video_enterdata_pos.y)+10); + cairo_move_to(cr, S_X(video_enterdata_pos.x)+10, S_Y(video_enterdata_pos.y)-10); + cairo_line_to(cr, S_X(video_enterdata_pos.x)-10, S_Y(video_enterdata_pos.y)+10); + + cairo_stroke(cr); + } + else if (posctl_threaddata.target_pos.x != -1 and posctl_threaddata.target_pos.y != -1) { + color.blue = 0.0; + color.red = 0.0; + color.green = 0.5; + color.alpha = 1.0; + gdk_cairo_set_source_rgba(cr, &color); + + cairo_move_to(cr, S_X(posctl_threaddata.target_pos.x), S_Y(posctl_threaddata.target_pos.y)-5); + cairo_line_to(cr, S_X(posctl_threaddata.target_pos.x), S_Y(posctl_threaddata.target_pos.y)+5); + cairo_move_to(cr, S_X(posctl_threaddata.target_pos.x)-5, S_Y(posctl_threaddata.target_pos.y)); + cairo_line_to(cr, S_X(posctl_threaddata.target_pos.x)+5, S_Y(posctl_threaddata.target_pos.y)); + + cairo_stroke(cr); + } + + // // need to draw the select new position cross if (video_enterdata == VID_ENTERDATA_POS) { @@ -241,37 +271,37 @@ void cb_videoda_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer data) 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) { + // printf ("%s:%d posctl_threaddata.c : %d \t %d -> \t %d \t %d\n", __FILE__, __LINE__, + // posctl_threaddata.c[0].x, posctl_threaddata.c[0].y, + // posctl_threaddata.c[1].x, posctl_threaddata.c[1].y); + // printf ("%s:%d posctl_threaddata.a1: %d \t %d -> \t %d \t %d\n", __FILE__, __LINE__, + // posctl_threaddata.a1[0].x, posctl_threaddata.a1[0].y, + // posctl_threaddata.a1[1].x, posctl_threaddata.a1[1].y); + // printf ("%s:%d posctl_threaddata.a2: %d \t %d -> \t %d \t %d\n", __FILE__, __LINE__, + // posctl_threaddata.a2[0].x, posctl_threaddata.a2[0].y, + // posctl_threaddata.a2[1].x, posctl_threaddata.a2[1].y); + if (posctl_threaddata.c[0].x != -1 && posctl_threaddata.c[0].y != -1 && + posctl_threaddata.c[1].x != -1 && posctl_threaddata.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_move_to(cr, S_X(posctl_threaddata.c[0].x), S_Y(posctl_threaddata.c[0].y)); + cairo_line_to(cr, S_X(posctl_threaddata.c[1].x), S_Y(posctl_threaddata.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) { + if (posctl_threaddata.a1[0].x != -1 && posctl_threaddata.a1[0].y != -1 && + posctl_threaddata.a1[1].x != -1 && posctl_threaddata.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_move_to(cr, S_X(posctl_threaddata.a1[0].x), S_Y(posctl_threaddata.a1[0].y)); + cairo_line_to(cr, S_X(posctl_threaddata.a1[1].x), S_Y(posctl_threaddata.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) { + if (posctl_threaddata.a2[0].x != -1 && posctl_threaddata.a2[0].y != -1 && + posctl_threaddata.a2[1].x != -1 && posctl_threaddata.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_move_to(cr, S_X(posctl_threaddata.a2[0].x), S_Y(posctl_threaddata.a2[0].y)); + cairo_line_to(cr, S_X(posctl_threaddata.a2[1].x), S_Y(posctl_threaddata.a2[1].y)); cairo_stroke(cr); } } diff --git a/videodev-simulation.cc b/videodev-simulation.cc index 9703846..c9a514b 100644 --- a/videodev-simulation.cc +++ b/videodev-simulation.cc @@ -227,12 +227,14 @@ void Simulation::Reset() { axis[i % 2].defAngle = 180.0 + dAngle + (10.0 * (double)rand() / ((double) RAND_MAX)) - 5.0; axis[i % 2].defLen = dLen + ((dLen/2.0) * (double)rand() / ((double) RAND_MAX) - (dLen/4.0)); axis[i % 2].v = 1.0; + axis[i % 2].vdest = 1.0; axis[i % 2].active = 1; i++; axis[i % 2].defAngle = 180.0 + dAngle + (10.0 * (double)rand() / ((double) RAND_MAX)) + 85.0; axis[i % 2].defLen = dLen + ((dLen/2.0) * (double)rand() / ((double) RAND_MAX) - (dLen/4.0)); axis[i % 2].v = 1.0; + axis[i % 2].vdest = 1.0; axis[i % 2].active = 1; // normalize angle between 0..360° @@ -309,6 +311,12 @@ void Simulation::ThreadProcess() { if (posX > w) posX = 0.0; if (posY > h) posY = 0.0; + for (int i = 0; i < 2; i++) { + axis[i].v = axis[i].v * (1.0-SIMULATION_MOTORSPEEDUP) + axis[i].vdest * SIMULATION_MOTORSPEEDUP; + } + // printf ("%s:%d axis %f (%f) %f (%f)\n", __FILE__, __LINE__, axis[0].v, axis[0].vdest, axis[1].v, axis[1].vdest); + + #ifdef DEBUG_POSCTL debug_tofile((char*)"simulation.log", 0, (char*)"%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g\n", dAngle, dLen, x, y, dx[0], dy[0], ms, @@ -347,13 +355,15 @@ void Simulation::SetResolution (int w, int h) { void Simulation::AxisSetValue (int a, double v) { // printf ("%s:%d %s Axis:%d Value:%f\n", __FILE__, __LINE__, __FUNCTION__, a, v); if (a < 0 || a > 1) return; - axis[a].v = v; + axis[a].vdest = v; axis[a].active = 1; } void Simulation::AxisStop() { // printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); + axis[0].vdest = axis[0].v = 0.0; + axis[1].vdest = axis[1].v = 0.0; axis[0].active = 0; axis[1].active = 0; } diff --git a/videodev-simulation.h b/videodev-simulation.h index e85fce5..9792f5f 100644 --- a/videodev-simulation.h +++ b/videodev-simulation.h @@ -26,9 +26,10 @@ #include "gui.h" #include "videodev.h" - +#define SIMULATION_MOTORSPEEDUP 0.01 struct SimAxisCtl { int active; + double vdest; double v; double defLen; double defAngle;