From 651cd8ef37ba075646ff992c979d1e8dba847c47 Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Sun, 8 Jan 2023 21:57:11 +0100 Subject: [PATCH] preparations for position stabilisation --- Makefile | 2 +- configuration.cc | 10 +- gui.cc | 42 +++ gui.h | 8 + posctl.cc | 105 ++++++ simpleskycam.ui | 882 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1046 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 57328c9..e46c355 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ OBJECTS := $(OBJECTS) gui.oo main.oo \ video.oo videoframe.oo \ videodev.oo videodev-v4l2.oo videodev-dumpfile.oo \ convert.oo filter.oo detect.oo histogram.oo pid.oo \ - json.oo configuration.oo ser.oo dng.oo debayer.oo + posctl.oo json.oo configuration.oo ser.oo dng.oo debayer.oo DISTNAME=simpleskycam-$(VERSION) DEPENDFILE=.depend diff --git a/configuration.cc b/configuration.cc index 08b7705..6b3fcc4 100644 --- a/configuration.cc +++ b/configuration.cc @@ -110,7 +110,7 @@ void Configuration::SaveConfig(std::string filename) { // // save windows position - for (i = 0; i < 5; i++) { + for (i = 0; i < 6; i++) { int x, y, w, h, show; string name; @@ -130,6 +130,9 @@ void Configuration::SaveConfig(std::string filename) { case 4: name = "window-histogram"; break; + case 5: + name = "window-posctl"; + break; } @@ -252,7 +255,7 @@ void Configuration::LoadConfig(std::string filename) { // // load windows position - for (i = 0; i < 5; i++) { + for (i = 0; i < 6; i++) { int x, y, w, h, show; string name; @@ -272,6 +275,9 @@ void Configuration::LoadConfig(std::string filename) { case 4: name = "window-histogram"; break; + case 5: + name = "window-posctl"; + break; } if (jp.GetValueInt(name+"_x", &x) && jp.GetValueInt(name+"_y", &y) && diff --git a/gui.cc b/gui.cc index a48503f..5da4b84 100644 --- a/gui.cc +++ b/gui.cc @@ -384,3 +384,45 @@ void cb_input_show_window (GtkWidget *widget, gpointer data) { gtk_widget_show(wnd); }; + +void draw_text (cairo_t *cr, int x, int y, float border, std::string text) { + cairo_pattern_t *t = NULL; + double r, g, b, a; + + t = cairo_get_source(cr); + cairo_pattern_get_rgba(t, &r, &g, &b, &a); + + for (int i = 0; i < 5; i++) { + int dx, dy; + + switch (i) { + case 0: + cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); + dx = -1; + dy = 0; + break; + case 1: + dx = +1; + dy = 0; + break; + case 2: + dx = 0; + dy = -1; + break; + case 3: + dx = 0; + dy = +1; + break; + case 4: + cairo_set_source_rgba(cr, r, g, b, a); + dx = 0; + dy = 0; + break; + } + cairo_move_to (cr, x+dx, y+dy); + cairo_show_text(cr, text.c_str()); + cairo_stroke(cr); + } +}; + + diff --git a/gui.h b/gui.h index 0d69763..56d628c 100644 --- a/gui.h +++ b/gui.h @@ -41,6 +41,8 @@ struct { void displayerror (std::string error); +void draw_text (cairo_t *cr, int x, int y, float border, std::string text); + #ifdef __cplusplus extern "C" { #endif @@ -114,6 +116,12 @@ G_MODULE_EXPORT void cb_histogramda_btnrelease (GtkWidget *widget, gpointer data G_MODULE_EXPORT void cb_histogramda_keypress (GtkWidget *widget, GdkEventKey *event, gpointer data); G_MODULE_EXPORT void cb_histogram_show_window (GtkWidget *widget, gpointer data); +// +// position control elements +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_angles_draw (GtkWidget *area, cairo_t *cr, int w, int h, gpointer data); +G_MODULE_EXPORT void cb_posctl_entryanglelen (GtkWidget *widget, gpointer data); // // menu elements diff --git a/posctl.cc b/posctl.cc index 514b4de..2174df4 100644 --- a/posctl.cc +++ b/posctl.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include "gui.h" #include "filter.h" #include "detect.h" @@ -18,6 +19,9 @@ #include "histogram.h" extern GtkBuilder *_builder_; // work around for threads +GtkWidget *posctl_rot_da = NULL; +// GtkWidget *posctl_axis1_da = NULL; +// GtkWidget *posctl_axis1_da = NULL; void cb_posctl_show_window (GtkWidget *widget, gpointer data) { printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); @@ -27,3 +31,104 @@ void cb_posctl_show_window (GtkWidget *widget, gpointer data) { } +void cb_posctl_btncalib (GtkWidget *widget, gpointer data) { + printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); + + GtkWidget *btn = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_btn_calib")); + gtk_widget_set_sensitive(btn, false); +} + + +void posctl_draw_angle(cairo_t *cr, int cx, int cy, float angle, float lenmax, float lenmi, float lenma, std::string text) { + // + // arrow rot + double dx = sin(angle); + double dy = cos(angle); + + cairo_move_to(cr, cx, cy); + cairo_set_line_width(cr, 1.0); + cairo_line_to(cr, cx + dx * cx * 0.8 * lenmi/lenmax, cy - dy * cy * 0.8 * lenmi/lenmax); + cairo_stroke(cr); + cairo_set_line_width(cr, 4.0); + cairo_move_to(cr, cx + dx * cx * 0.8 * lenmi/lenmax, cy - dy * cy * 0.8 * lenmi/lenmax); + cairo_line_to(cr, cx + dx * cx * 0.8 * lenma/lenmax, cy - dy * cy * 0.8 * lenma/lenmax); + cairo_stroke(cr); + + cairo_set_line_width(cr, 1.0); + + cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size (cr, 11); + cairo_move_to (cr, cx + dx * cx * 0.9, cy - dy * cy * 0.9 + 5); + cairo_show_text(cr, text.c_str()); + cairo_stroke(cr); +} + + +void cb_posctl_angles_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer data) { + int clientw, clienth; + int cx, cy; + double linedash1[] = { 1.0, 4.0 }; +// char txt[255]; + + // + // rotation da + GtkWidget *entry_rot_angle = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_rotangle")); + GtkWidget *entry_rot_len = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_rotlen")); + GtkWidget *entry_axis1_angle = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a1anlge")); + GtkWidget *entry_axis1_lenmi = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a1lenmi")); + GtkWidget *entry_axis1_lenma = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a1lenma")); + GtkWidget *entry_axis2_angle = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a2anlge")); + GtkWidget *entry_axis2_lenmi = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a2lenmi")); + GtkWidget *entry_axis2_lenma = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a2lenma")); + + float rotangle = atof(gtk_entry_get_text(GTK_ENTRY(entry_rot_angle))) * (M_PI / 180); + float rotlen = atof(gtk_entry_get_text(GTK_ENTRY(entry_rot_len))); + float a1angle = atof(gtk_entry_get_text(GTK_ENTRY(entry_axis1_angle))) * (M_PI / 180); + float a1lenmi = atof(gtk_entry_get_text(GTK_ENTRY(entry_axis1_lenmi))); + float a1lenma = atof(gtk_entry_get_text(GTK_ENTRY(entry_axis1_lenma))); + float a2angle = atof(gtk_entry_get_text(GTK_ENTRY(entry_axis2_angle))) * (M_PI / 180); + float a2lenmi = atof(gtk_entry_get_text(GTK_ENTRY(entry_axis2_lenmi))); + float a2lenma = atof(gtk_entry_get_text(GTK_ENTRY(entry_axis2_lenma))); + float lenmax = max(max(max(a1lenmi, a1lenma),max(a2lenmi, a2lenma)), rotlen); + + if (posctl_rot_da == NULL) // should only be called once + posctl_rot_da = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_da_rotation")); + clienth = gtk_widget_get_allocated_height(posctl_rot_da); + clientw = gtk_widget_get_allocated_width(posctl_rot_da); + cx = clientw >> 1; + cy = clienth >> 1; + + // + // draw the background + cairo_set_source_rgb(cr, 0.8, 0.8, 0.8); + cairo_paint(cr); + cairo_fill (cr); + + cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); + cairo_set_dash(cr, linedash1, 2, 0); + cairo_move_to(cr, cx, cy - cy * 0.8); + cairo_line_to(cr, cx, cy + cy * 0.8); + cairo_stroke(cr); + + cairo_move_to(cr, cx - cx * 0.8, cy); + cairo_line_to(cr, cx + cx * 0.8, cy); + cairo_stroke(cr); + cairo_set_dash(cr, NULL, 0, 0); + + // draw angles + cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); + posctl_draw_angle (cr, cx, cy, rotangle, lenmax, 0.0, rotlen, "E"); + cairo_set_source_rgb(cr, 0.0, 1.0, 0.5); + posctl_draw_angle (cr, cx, cy, a1angle, lenmax, a1lenmi, a1lenma, "1"); + cairo_set_source_rgb(cr, 0.0, 0.5, 1.0); + posctl_draw_angle (cr, cx, cy, a2angle, lenmax, a2lenmi, a2lenma, "2"); +}; + + +void cb_posctl_entryanglelen (GtkWidget *widget, gpointer data) { + if (posctl_rot_da == NULL) // should only be called once + 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); +}; + + diff --git a/simpleskycam.ui b/simpleskycam.ui index d2b9c72..b657dbc 100644 --- a/simpleskycam.ui +++ b/simpleskycam.ui @@ -479,6 +479,879 @@ + + True + False + gtk-refresh + + + False + 4 + Position Control + + + + True + False + vertical + 8 + + + True + False + 4 + + + True + False + Calibration + + + + + + + False + True + 0 + + + + + Calibration + True + True + True + image_refresh + True + + + + + False + True + end + 1 + + + + + False + True + 0 + + + + + True + False + 4 + + + True + False + 0 + none + + + True + False + 12 + + + 150 + 150 + True + False + + + + + + + + True + False + Rotation + + + + + False + True + 0 + + + + + + True + False + start + start + 4 + 4 + + + True + True + 6 + 15 + + + + 1 + 2 + + + + + True + True + 6 + 250 + + + + 1 + 1 + + + + + True + True + 6 + 105 + + + + 1 + 3 + + + + + True + False + Angle + + + 1 + 0 + + + + + True + False + Len Min + + + 2 + 0 + + + + + True + False + Earth: + + + 0 + 1 + + + + + True + False + Axis 1 + + + 0 + 2 + + + + + True + False + Axis 2 + + + 0 + 3 + + + + + True + True + center + center + 6 + 25 + + + + 2 + 1 + 2 + + + + + True + True + 6 + -1 + + + + 2 + 2 + + + + + True + True + 6 + 5 + + + + 2 + 3 + + + + + True + False + Len Max + + + 3 + 0 + + + + + True + True + 6 + 15 + + + + 3 + 2 + + + + + True + True + 6 + 10 + + + + 3 + 3 + + + + + + + + False + False + 1 + + + + + False + True + 1 + + + + + True + False + 4 + + + True + False + Position Control + + + + + + + False + True + 0 + + + + + Enabled + True + True + False + True + + + False + True + end + 1 + + + + + False + True + 2 + + + + + True + False + 4 + + + True + False + 0 + none + + + True + False + 12 + + + True + False + 4 + + + 100 + 150 + True + False + + + False + True + 0 + + + + + + True + False + 2 + + + True + False + Min + + + 0 + 0 + + + + + True + False + Max + + + 0 + 1 + + + + + True + False + Kp + + + 0 + 2 + + + + + True + False + Ki + + + 0 + 3 + + + + + True + False + Kd + + + 0 + 4 + + + + + True + True + 4 + + + 1 + 0 + + + + + True + True + 4 + + + 1 + 1 + + + + + True + True + 4 + + + 1 + 2 + + + + + True + True + 4 + + + 1 + 3 + + + + + True + True + 4 + + + 1 + 4 + + + + + False + True + 1 + + + + + + + + + True + False + Axis 1 + + + + + False + True + 0 + + + + + True + False + + + False + True + 1 + + + + + True + False + 0 + none + + + True + False + 12 + + + True + False + 4 + + + 100 + 150 + True + False + + + False + True + 0 + + + + + + True + False + 2 + + + True + False + Min + + + 0 + 0 + + + + + True + False + Max + + + 0 + 1 + + + + + True + False + Kp + + + 0 + 2 + + + + + True + False + Ki + + + 0 + 3 + + + + + True + False + Kd + + + 0 + 4 + + + + + True + True + 4 + + + 1 + 0 + + + + + True + True + 4 + + + 1 + 1 + + + + + True + True + 4 + + + 1 + 2 + + + + + True + True + 4 + + + 1 + 3 + + + + + True + True + 4 + + + 1 + 4 + + + + + False + True + 1 + + + + + + + + + True + False + Axis 2 + + + + + False + True + 2 + + + + + True + False + + + False + True + 3 + + + + + True + False + vertical + 4 + + + True + False + Values + + + False + True + 0 + + + + + + True + False + 4 + 4 + + + True + False + X + + + 0 + 1 + + + + + True + False + Y + + + 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 + + + + + False + True + 4 + + + + + False + True + 3 + + + + + False Histogram @@ -784,6 +1657,15 @@ + + + True + False + _Position Control + True + + +