From 539e49b28f9ed1364a2e0b5a8a5bdb495e87b65e Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Mon, 25 Mar 2024 23:29:58 +0100 Subject: [PATCH] trying 2 step calibration and justify of the output values, but not working yet --- configuration.cc | 17 +- configuration.h | 5 +- detect.h | 21 +- gui.cc | 35 + gui.h | 4 +- posctl.cc | 329 +++++- simpleskycam.h | 4 +- simpleskycam.ui | 2685 +++++++++++++++++++++++++++------------------- 8 files changed, 1919 insertions(+), 1181 deletions(-) diff --git a/configuration.cc b/configuration.cc index bbe359e..8618ffc 100644 --- a/configuration.cc +++ b/configuration.cc @@ -15,6 +15,7 @@ extern PosCtl posctl; Configuration::Configuration() { debugpath = NULL; readdumppath = NULL; + destpath = "./"; }; @@ -99,6 +100,7 @@ void Configuration::SaveConfig(std::string filename) { __FILE__, __LINE__, i, amin, amax, akp, aki, akd); jp.AddObject("posctl_axis" + to_string(i), jaxis); } + jp.AddObject("posctl_filter", posctl.GetFilter()); jp.AddObject("posctl_device", posctl.GetDevice()); posctl.UnLockMutex(); @@ -107,6 +109,10 @@ void Configuration::SaveConfig(std::string filename) { jp.AddObject("histogram_log", histogram_log); jp.AddObject("debayer_mode", debayer_mode); + // + // save destination path + jp.AddObject("destination_path", destpath); + // // save button config for (i = 0; i < BTN_PRESET_MAX; i++) { @@ -218,7 +224,7 @@ void Configuration::LoadConfig(std::string filename) { // // load posctl - double amin, amax, akp, aki, akd; + double amin, amax, akp, aki, akd, f; JSONParse jaxis; posctl.LockMutex(); @@ -236,6 +242,10 @@ void Configuration::LoadConfig(std::string filename) { } if (jp.GetValue("posctl_device", &vstr)) posctl.SetDevice(vstr); + if (jp.GetValueDouble("posctl_filter", &f)) + posctl.SetFilter(f); + jp.AddObject("posctl_filter", posctl.GetFilter()); + posctl.UnLockMutex(); jp.GetValueInt("histogram_log", &i); @@ -244,6 +254,11 @@ void Configuration::LoadConfig(std::string filename) { jp.GetValueInt("debayer_mode", &i); SetDebayerMode(i); + if (jp.GetValue("destination_path", &destpath)) { + GtkWidget *entry = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "input_entry_destpath")); + gtk_entry_set_text(GTK_ENTRY(entry), destpath.c_str()); + } + // // start streaming if a device was selected. // diff --git a/configuration.h b/configuration.h index c3b041d..8ce3bb0 100644 --- a/configuration.h +++ b/configuration.h @@ -19,7 +19,7 @@ class Configuration { private: int histogram_log = 1; // logarithmic or linear scale int calibration_showdata = 0; // needed for debugging calibration - + std::string destpath; // destination path JSONParse config; std::string GetDefaultFileName(); list presetbtn[BTN_PRESET_MAX]; @@ -39,6 +39,9 @@ public: void SetDebayerMode(int trueorfalse); + void SetDestPath (std::string dest) { destpath = dest; }; + std::string GetDestPath() { return destpath; }; + void SetHistogramLog(int trueorfalse); int GetHistogramLog() { return histogram_log; }; diff --git a/detect.h b/detect.h index 2127d41..53a5d77 100644 --- a/detect.h +++ b/detect.h @@ -49,7 +49,9 @@ enum { enum { POSCTL_MODE_OFF = 0, POSCTL_MODE_CALIB, - POSCTL_MODE_CONTROL + POSCTL_MODE_CONTROL, + POSCTL_MODE_2STEPINIT, + POSCTL_MODE_2STEP }; enum { @@ -70,6 +72,14 @@ enum { }; +struct PosCtl_2Step_Data { + double pv[2]; + double op[2]; + double npv[2]; + double ppv[2]; + double nop[2]; + double pop[2]; +}; struct PosCtl_ThreadData { position_2d c[2]; @@ -96,10 +106,15 @@ class PosCtl { int calib_mode; position_2d calib_pos; position_f_2d pos; + double npv[2]; + double ppv[2]; + double nop[2]; + double pop[2]; double posfilter; struct PosCtl_ThreadData threaddata; // will be copied to gtk thread void NotifyGtk(); + void NotifyGtk2Step(); void CalibModeStart(int x, int y); void CalibModeDelta(int x, int y); @@ -135,11 +150,15 @@ class PosCtl { void Stop (); void StartCalibration (); void StartControl (); + void Start2Step (); + void Stop2Step (); + void Reset2Step (); int GetMode () { return mode; }; void SetAxisParam (int axis, double min, double max, double k, double i, double d); void GetAxisParam (int axis, double *min, double *max, double *k, double *i, double *d); void SetDevice(std::string d); void SetFilter(double f) { posfilter = f; }; + double GetFilter() { return posfilter; }; std::string GetDevice() { return device; }; void Loop (int posx, int posy, double dt); diff --git a/gui.cc b/gui.cc index 132d807..fbee58c 100644 --- a/gui.cc +++ b/gui.cc @@ -360,6 +360,40 @@ void cb_detect_show_window (GtkWidget *widget, gpointer data) { }; +/* + * setup destination path + */ +void cb_input_btnsetdestpath (GtkWidget *widget, gpointer data) { + GtkBuilder *builder = (GtkBuilder *) data; + GtkWindow *window = GTK_WINDOW (gtk_builder_get_object (builder, "windows-input")); + GtkWidget *dialog; + GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; + gint res; + + printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); + dialog = gtk_file_chooser_dialog_new ("Open Folder", + window, + action, + "_Cancel", + GTK_RESPONSE_CANCEL, + "_Open", + GTK_RESPONSE_ACCEPT, + NULL); + + res = gtk_dialog_run (GTK_DIALOG (dialog)); + if (res == GTK_RESPONSE_ACCEPT) { + char *filename; + GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog); + filename = gtk_file_chooser_get_filename (chooser); + config.SetDestPath(filename); + GtkWidget *entry = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "input_entry_destpath")); + gtk_entry_set_text(GTK_ENTRY(entry), filename); + + g_free (filename); + } + gtk_widget_destroy (dialog); +}; + void cb_input_show_window (GtkWidget *widget, gpointer data) { printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); @@ -420,3 +454,4 @@ void draw_printf(cairo_t *cr, int x, int y, float border, char *fmt,...) { draw_text (cr, x, y, border, buffer); }; + diff --git a/gui.h b/gui.h index 0755562..4bb1116 100644 --- a/gui.h +++ b/gui.h @@ -155,7 +155,7 @@ G_MODULE_EXPORT void cb_input_show_window (GtkWidget *widget, gpointer data); G_MODULE_EXPORT void cb_input_btncapture (GtkWidget *widget, gpointer data); G_MODULE_EXPORT void cb_input_btnsnapshot (GtkWidget *widget, gpointer data); G_MODULE_EXPORT void cb_input_btnscale (GtkWidget *widget, gpointer data); - +G_MODULE_EXPORT void cb_input_btnsetdestpath (GtkWidget *widget, gpointer data); // // filter detect or image data @@ -202,6 +202,8 @@ G_MODULE_EXPORT void cb_posctl_btnsimreset (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_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); +G_MODULE_EXPORT void cb_posctl_btn2stepstartstop (GtkWidget *widget, gpointer data); +G_MODULE_EXPORT void cb_posctl_btn2stepreset (GtkWidget *widget, gpointer data); // diff --git a/posctl.cc b/posctl.cc index 311d00d..180966a 100644 --- a/posctl.cc +++ b/posctl.cc @@ -127,6 +127,30 @@ void cb_posctl_btnsetdest (GtkWidget *widget, gpointer data) { }; +/* + * calibrate adjust control output.. + */ +void cb_posctl_btn2stepstartstop (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_2stepctl")); + if (posctl.GetMode() == POSCTL_MODE_2STEP || posctl.GetMode() == POSCTL_MODE_2STEPINIT) { + posctl.Stop2Step(); + gtk_button_set_label(GTK_BUTTON(btn), "Start"); + } + else { + posctl.Start2Step(); + gtk_button_set_label(GTK_BUTTON(btn), "Stop"); + } +}; + + +void cb_posctl_btn2stepreset (GtkWidget *widget, gpointer data) { + printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); + posctl.Reset2Step(); + +} + + 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")); @@ -261,43 +285,49 @@ void cb_posctl_angles_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer cairo_set_font_size (cr, 11); // rot - lpos.x = -sin(rotangle) * rotlen * 4.0; - lpos.y = -cos(rotangle) * rotlen * 4.0; - cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); - cairo_set_line_width(cr, 4.0); - cairo_move_to(cr, center.x, center.y); - cairo_line_to(cr, center.x + lpos.x, center.y + lpos.y); - cairo_stroke(cr); - cairo_set_line_width(cr, 0.5); - cairo_move_to(cr, center.x - lpos.x * 100.0, center.y - lpos.y * 100.0); - cairo_line_to(cr, center.x + lpos.x * 100.0, center.y + lpos.y * 100.0); - cairo_stroke(cr); + if (!isnan(rotangle) && !isnan(rotlen)) { + lpos.x = -sin(rotangle) * rotlen * 4.0; + lpos.y = -cos(rotangle) * rotlen * 4.0; + cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); + cairo_set_line_width(cr, 4.0); + cairo_move_to(cr, center.x, center.y); + cairo_line_to(cr, center.x + lpos.x, center.y + lpos.y); + cairo_stroke(cr); + cairo_set_line_width(cr, 0.5); + cairo_move_to(cr, center.x - lpos.x * 100.0, center.y - lpos.y * 100.0); + cairo_line_to(cr, center.x + lpos.x * 100.0, center.y + lpos.y * 100.0); + cairo_stroke(cr); + } // axis1 - lpos.x = sin(ra_angle) * ra_len * 4.0; - lpos.y = cos(ra_angle) * ra_len * 4.0; - cairo_set_source_rgb(cr, 0.0, 0.75, 0.3); - cairo_set_line_width(cr, 4.0); - cairo_move_to(cr, center.x, center.y); - cairo_line_to(cr, center.x + lpos.x, center.y + lpos.y); - cairo_stroke(cr); - cairo_set_line_width(cr, 0.5); - cairo_move_to(cr, center.x - lpos.x * 100.0, center.y - lpos.y * 100.0); - cairo_line_to(cr, center.x + lpos.x * 100.0, center.y + lpos.y * 100.0); - cairo_stroke(cr); + if (!isnan(ra_angle) && !isnan(ra_len)) { + lpos.x = sin(ra_angle) * ra_len * 4.0; + lpos.y = cos(ra_angle) * ra_len * 4.0; + cairo_set_source_rgb(cr, 0.0, 0.75, 0.3); + cairo_set_line_width(cr, 4.0); + cairo_move_to(cr, center.x, center.y); + cairo_line_to(cr, center.x + lpos.x, center.y + lpos.y); + cairo_stroke(cr); + cairo_set_line_width(cr, 0.5); + cairo_move_to(cr, center.x - lpos.x * 100.0, center.y - lpos.y * 100.0); + cairo_line_to(cr, center.x + lpos.x * 100.0, center.y + lpos.y * 100.0); + cairo_stroke(cr); + } // axis2 - lpos.x = sin(dec_angle) * dec_len * 4.0; - lpos.y = cos(dec_angle) * dec_len * 4.0; - cairo_set_source_rgb(cr, 0.0, 0.3, 0.75); - cairo_set_line_width(cr, 4.0); - cairo_move_to(cr, center.x, center.y); - cairo_line_to(cr, center.x + lpos.x, center.y + lpos.y); - cairo_stroke(cr); - cairo_set_line_width(cr, 0.5); - cairo_move_to(cr, center.x - lpos.x * 100.0, center.y - lpos.y * 100.0); - cairo_line_to(cr, center.x + lpos.x * 100.0, center.y + lpos.y * 100.0); - cairo_stroke(cr); + if (!isnan(dec_angle) && !isnan(dec_len)) { + lpos.x = sin(dec_angle) * dec_len * 4.0; + lpos.y = cos(dec_angle) * dec_len * 4.0; + cairo_set_source_rgb(cr, 0.0, 0.3, 0.75); + cairo_set_line_width(cr, 4.0); + cairo_move_to(cr, center.x, center.y); + cairo_line_to(cr, center.x + lpos.x, center.y + lpos.y); + cairo_stroke(cr); + cairo_set_line_width(cr, 0.5); + cairo_move_to(cr, center.x - lpos.x * 100.0, center.y - lpos.y * 100.0); + cairo_line_to(cr, center.x + lpos.x * 100.0, center.y + lpos.y * 100.0); + cairo_stroke(cr); + } // // draw position relative to the target @@ -320,18 +350,24 @@ void cb_posctl_angles_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer cairo_stroke(cr); // draw distance to axis - lpos.x = sindeg(posctl.calib_axis1.a) * posctl.axis_pv[AXIS_DEC] * pscale; - lpos.y = cosdeg(posctl.calib_axis1.a) * posctl.axis_pv[AXIS_DEC] * pscale; - cairo_move_to(cr, center.x + p.x, center.y + p.y); - cairo_line_to(cr, center.x + p.x + lpos.x, center.y + p.y + lpos.y); - cairo_stroke(cr); + if (!isnan(posctl.calib_axis1.a) && !isnan(posctl.axis_pv[AXIS_DEC])) { + lpos.x = sindeg(posctl.calib_axis1.a+90.0) * posctl.axis_pv[AXIS_DEC] * pscale; + lpos.y = cosdeg(posctl.calib_axis1.a+90.0) * posctl.axis_pv[AXIS_DEC] * pscale; + cairo_set_source_rgb(cr, 0.5, 1.0, 0.5); + cairo_move_to(cr, center.x + p.x, center.y + p.y); + cairo_line_to(cr, center.x + p.x + lpos.x, center.y + p.y + lpos.y); + cairo_stroke(cr); + } // draw distance to axis - lpos.x = sindeg(posctl.calib_axis2.a) * posctl.axis_pv[AXIS_RA] * pscale; - lpos.y = cosdeg(posctl.calib_axis2.a) * posctl.axis_pv[AXIS_RA] * pscale; - cairo_move_to(cr, center.x + p.x, center.y + p.y); - cairo_line_to(cr, center.x + p.x + lpos.x, center.y + p.y + lpos.y); - cairo_stroke(cr); + if (!isnan(posctl.calib_axis2.a) && !isnan(posctl.axis_pv[AXIS_RA])) { + lpos.x = sindeg(posctl.calib_axis2.a+90.0) * posctl.axis_pv[AXIS_RA] * pscale; + lpos.y = cosdeg(posctl.calib_axis2.a+90.0) * posctl.axis_pv[AXIS_RA] * pscale; + cairo_set_source_rgb(cr, 0.5, 0.5, 1.0); + cairo_move_to(cr, center.x + p.x, center.y + p.y); + cairo_line_to(cr, center.x + p.x + lpos.x, center.y + p.y + lpos.y); + cairo_stroke(cr); + } }; @@ -453,6 +489,43 @@ void cb_posctl_axis_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer da }; +/* + * add result to the table + */ +void posctl_2step_gui_update( double axis_pv[2], double axis_op[2], + double npv[2], double nop[2], double ppv[2], double pop[2]) { + + GtkWidget *lramin = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_2s_ramin")); + GtkWidget *lramax = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_2s_ramax")); + GtkWidget *ldecmin = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_2s_decmin")); + GtkWidget *ldecmax = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_2s_decmax")); + GtkWidget *lraout = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_2s_raout")); + GtkWidget *ldecout = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_2s_decout")); + + char txt[255]; + + // min + snprintf (txt, 255, "%2.5f [%2.5f]", npv[AXIS_RA], nop[AXIS_RA]); + gtk_label_set_text(GTK_LABEL(lramin), txt); + snprintf (txt, 255, "%2.5f [%2.5f]", npv[AXIS_DEC], nop[AXIS_DEC]); + gtk_label_set_text(GTK_LABEL(ldecmin), txt); + + // max + snprintf (txt, 255, "%2.5f [%2.5f]", ppv[AXIS_RA], pop[AXIS_RA]); + gtk_label_set_text(GTK_LABEL(lramax), txt); + snprintf (txt, 255, "%2.5f [%2.5f]", ppv[AXIS_DEC], pop[AXIS_DEC]); + gtk_label_set_text(GTK_LABEL(ldecmax), txt); + + // output + snprintf (txt, 255, "%2.5f [%2.5f]", axis_pv[AXIS_RA], axis_op[AXIS_RA]); + gtk_label_set_text(GTK_LABEL(lraout), txt); + snprintf (txt, 255, "%2.5f [%2.5f]", axis_pv[AXIS_DEC], axis_op[AXIS_DEC]); + gtk_label_set_text(GTK_LABEL(ldecout), txt); + + cb_posctl_entryanglelen(NULL, NULL); +} + + /* * posctl gui update */ @@ -502,6 +575,8 @@ void posctl_gui_update() { GtkWidget *dec_out = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_lb_out_dec")); GtkWidget *dec_pv = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_lb_d_dec")); + GtkWidget *pos_filter = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_inputfilter")); + posctl.LockMutex(); int m = posctl.GetMode(); @@ -589,12 +664,32 @@ void posctl_gui_update() { strfromd (txt, sizeof(txt-1), (char *)"%f", kd); gtk_entry_set_text_nofocus (dec_kd, txt); + strfromd (txt, sizeof(txt-1), (char *)"%f", posctl.GetFilter()); + gtk_entry_set_text (GTK_ENTRY(pos_filter), txt); + 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(); } +/* + * callback from the detect thread. + * the gtk/gui updates must and will be processed in a separate gui thread + */ +gboolean cb_thread_posctl_2step (gpointer data) { + struct PosCtl_2Step_Data *d = (struct PosCtl_2Step_Data *) data; + posctl_gui_update(); + + if (data) { + posctl_2step_gui_update(d->pv, d->op, d->npv, d->nop, d->ppv, d->pop); + free (data); + } + + return false; +}; + + /* * callback from the detect thread. @@ -654,7 +749,7 @@ gboolean cb_thread_posctl (gpointer data) { } } - return false; + return false; }; @@ -681,8 +776,32 @@ PosCtl::PosCtl() { */ void PosCtl::Stop() { printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); + LockMutex(); mode = POSCTL_MODE_OFF; NotifyGtk(); + for (int i = 0; i < 2; i++) { + npv[i] = NAN; + ppv[i] = NAN; + nop[i] = NAN; + pop[i] = NAN; + } + UnLockMutex(); +} + + +void PosCtl::NotifyGtk2Step() { + struct PosCtl_2Step_Data *data = (struct PosCtl_2Step_Data*) malloc (sizeof(struct PosCtl_2Step_Data)); + + for (int i = 0; i < 2; i++) { + data->pv[i] = axis_pv[i]; + data->op[i] = axis_op[i]; + data->npv[i] = npv[i]; + data->ppv[i] = ppv[i]; + data->nop[i] = nop[i]; + data->pop[i] = pop[i]; + } + + gdk_threads_add_idle(cb_thread_posctl_2step, (gpointer) data); } @@ -923,9 +1042,13 @@ double PosCtl::filteredvalue(double old_value, double new_value, double dt, doub * Loop, if new data is aviable{ */ void PosCtl::Loop (int pos_x, int pos_y, double dt) { + position_f_2d p; pos.x = PosCtl::filteredvalue(pos.x, pos_x, dt, posfilter); pos.y = PosCtl::filteredvalue(pos.y, pos_y, dt, posfilter); + p.x = pos.x; p.y = pos.y; + axis_pv[AXIS_RA] = calib_axis2_v.perpendicular(p, target_pos); + axis_pv[AXIS_DEC] = calib_axis1_v.perpendicular(p, target_pos); #ifdef DEBUG_POSCTL static int lastmode = -1; @@ -974,17 +1097,11 @@ void PosCtl::Loop (int pos_x, int pos_y, double dt) { // dist_axis1 --> will control pid_axis2 // dist_axis2 --> will control pis_axis1 else if (mode == POSCTL_MODE_CONTROL) { - position_f_2d p, target_p; - LockMutex(); // calculate // dist_axis < 0.0 pid should increase the output. // > 0.0 pid should decrease the output - target_p.x = target_pos.x; target_p.y = target_pos.y; - p.x = pos.x; p.y = pos.y; - axis_pv[AXIS_RA] = calib_axis2_v.perpendicular(p, target_pos); - axis_pv[AXIS_DEC] = calib_axis1_v.perpendicular(p, target_pos); axis_op[AXIS_RA] = pid_axis[AXIS_RA].Update(0.0, axis_pv[AXIS_RA]); axis_op[AXIS_DEC] = pid_axis[AXIS_DEC].Update(0.0, axis_pv[AXIS_DEC]); @@ -1008,6 +1125,14 @@ void PosCtl::Loop (int pos_x, int pos_y, double dt) { NotifyGtk(); } + else if (mode == POSCTL_MODE_2STEP || mode == POSCTL_MODE_2STEPINIT) { + LockMutex(); + + NotifyGtk2Step(); + + UnLockMutex(); + } + else { LockMutex(); target_pos.x = pos.x; @@ -1024,6 +1149,108 @@ void PosCtl::Loop (int pos_x, int pos_y, double dt) { }; +/* + * + */ + +void PosCtl::Reset2Step() { + LockMutex(); + mode = POSCTL_MODE_OFF; + + for (int i = 0; i < 2; i++) { + npv[i] = NAN; + ppv[i] = NAN; + nop[i] = NAN; + pop[i] = NAN; + } + posctl_2step_gui_update(axis_pv, axis_op, npv, nop, ppv, pop); + + UnLockMutex(); + NotifyGtk(); +}; + + +/* + * set current pos as target + * if npv and ppv == NAN set min pos for both axes + * min and max values will be read from the PID objects + */ +void PosCtl::Start2Step() { + int found1 = 0, found2 = 0, i; + LockMutex(); + + for (i = 0, found2 = 0, found1 = 0; i < 2; i++) { + if (isnan(npv[i]) && isnan(ppv[i])) found1 = 1; + if (isnan(npv[i]) || isnan(ppv[i])) found2 = 1; + } + if (found1) { + mode = POSCTL_MODE_2STEPINIT; + for (i = 0; i < 2; i++) { + axis_op[i] = pid_axis[1-i].GetMin(); + OutputWriteValue(i, axis_op[i]); + } + } + else if (found2) { + for (i = 0; i < 2; i++) { + axis_op[i] = pid_axis[1-i].GetMax(); + OutputWriteValue(i, axis_op[i]); + } + mode = POSCTL_MODE_2STEPINIT; + } + else mode = POSCTL_MODE_2STEP; + + target_pos = pos; + printf ("%s:%d %s axis_op: (%f %f)\n", __FILE__, __LINE__, __FUNCTION__, axis_op[0], axis_op[1]); + posctl_2step_gui_update(axis_pv, axis_op, npv, nop, ppv, pop); + + UnLockMutex(); +}; + + + + +/* + * with each cycle, caclulate an output between p and n values. + */ +void PosCtl::Stop2Step() { + double axisnew_op[2] = { NAN, NAN }; + int i; + LockMutex(); + + // + // check if we got better values + for (int i = 0; i < 2; i++) { + if (axis_pv[i] < 0.0 && (isnan(npv[i]) || axis_pv[i] > npv[i])) { + npv[i] = axis_pv[i]; + nop[i] = axis_op[i]; + } + if (axis_pv[i] > 0.0 && (isnan(ppv[i]) || axis_pv[i] < ppv[i])) { + ppv[i] = axis_pv[i]; + pop[i] = axis_op[i]; + } + } + + // need to calculate new step + if (mode == POSCTL_MODE_2STEP) { + for (i = 0; i < 2; i++) { + axisnew_op[i] = (nop[i] + pop[i]) / 2.0; + OutputWriteValue(i, axisnew_op[i]); + } + } + + printf ("%s:%d %s axis \t_op:\t%f\t%f \t_pv:\t%f\t%f \t new:\t%f\t%f\n", __FILE__, __LINE__, __FUNCTION__, + axis_op[0], axis_op[1], axis_pv[0], axis_pv[1], axisnew_op[0], axisnew_op[1]); + + mode = POSCTL_MODE_OFF; + + posctl_2step_gui_update(axis_pv, axis_op, npv, nop, ppv, pop); + for (i = 0; i < 2; i++) axis_op[i] = axisnew_op[i]; + + UnLockMutex(); +}; + + + void PosCtl::SetDevice (std::string d) { printf ("%s:%d %s new device:%s\n", __FILE__, __LINE__, __FUNCTION__, d.c_str()); @@ -1129,7 +1356,6 @@ int PosCtl::ReadTTY (char * inbuf, int length) { } else { inbuf[len] = 0; - //printf ("%s:%d %s receive: '%s'\n", __FILE__, __LINE__, __FUNCTION__, inbuf); } #else ssize_t len; @@ -1168,7 +1394,6 @@ int PosCtl::ReadTTY (char * inbuf, int length) { int PosCtl::OutputWriteValue (int axis, double value) { char outbuf[255]; - // printf ("%s:%d %s Axis %d Value:%f\n", __FILE__, __LINE__, __FUNCTION__, axis, value); if (device_type == POSCTL_DEVTYPE_SIM) { simulation.AxisSetValue(axis, value); diff --git a/simpleskycam.h b/simpleskycam.h index 38e3db0..1805fc4 100644 --- a/simpleskycam.h +++ b/simpleskycam.h @@ -9,8 +9,8 @@ extern void errorexit(char *fmt, ...); extern void calc_vec2anglelen(position_f_2d *p, vector_2d *v); -#define sindeg(_angle_) sin((M_PI * _angle_ / 180.0)) -#define cosdeg(_angle_) cos((M_PI * _angle_ / 180.0)) +#define sindeg(_angle_) sin((M_PI * (_angle_) / 180.0)) +#define cosdeg(_angle_) cos((M_PI * (_angle_) / 180.0)) #endif diff --git a/simpleskycam.ui b/simpleskycam.ui index f6594e7..5bf5859 100644 --- a/simpleskycam.ui +++ b/simpleskycam.ui @@ -518,16 +518,14 @@ True False + 10 + 6 4 True False - Calibration - - - - + Device: False @@ -536,64 +534,19 @@ - + True - False - - - gtk-stop - True - True - True - True - True - - - - - False - True - 0 - - - - - Calibration - True - True - True - image_refresh - True - - - - - False - True - end - 1 - - + True + 15 + /dev/ttyUSB0 + - False + True True - end 1 - - - True - False - - - False - True - end - 2 - - False @@ -605,249 +558,128 @@ True False - 4 - - - True - False - 0 - none - - - True - False - 12 - - - 150 - 150 - True - False - - - - - - - - True - False - Rotation - - - - - False - True - 0 - - + vertical - - + True False - start - start - 4 - 4 - - - True - False - True - False - 6 - 15 - - - - 1 - 2 - - - - - True - False - True - False - 6 - 250 - - - - 1 - 1 - - - - - True - False - True - False - 6 - 105 - - - - 1 - 3 - - - - - True - False - Angle - - - 1 - 0 - - - - - True - False - Len - - - 2 - 0 - - - - - True - False - Earth: - - - 0 - 1 - - - - - True - False - RA Axis - - - 0 - 2 - - + 4 True False - DEC Axis - - - 0 - 3 - - - - - True - False - True - center - center - False - 6 - 25 - - - - 2 - 1 - - - - - True - False - True - False - 6 - 5 - - - - 2 - 2 - - - - - True - False - True - False - 6 - 14 - + Calibration + + + + - 2 - 3 + False + True + 0 - + True False - NAN ° + + + gtk-stop + True + True + True + True + True + + + + + False + True + 0 + + + + + Calibration + True + True + True + image_refresh + True + + + + + False + True + end + 1 + + - 3 - 2 - 2 + False + True + end + 1 - + True False - NAN ° - 3 - 1 + False + True + end + 2 - - - - - - False - False - 1 + True + 0 True False - vertical + 4 - - Off + True - False False - False - True - True + 0 + none + + + True + False + 12 + + + 150 + 150 + True + False + + + + + + + + True + False + Rotation + + False @@ -856,198 +688,385 @@ - - 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 - - - - - RAS + + True - False False - False - True - cal_mode_off - - - False - True - 3 - - - - - RA - True - False - False - False - True - cal_mode_off - - - False - True - 4 - - - - - DECS - True - False - False - False - 1 - True - cal_mode_off - - - False - True - 5 - - - - - DEC - True - False - False - False - True - cal_mode_off + start + start + 4 + 4 + + + True + False + True + False + 6 + 15 + + + + 1 + 2 + + + + + True + False + True + False + 6 + 250 + + + + 1 + 1 + + + + + True + False + True + False + 6 + 105 + + + + 1 + 3 + + + + + True + False + Angle + + + 1 + 0 + + + + + True + False + Len + + + 2 + 0 + + + + + True + False + Earth: + + + 0 + 1 + + + + + True + False + RA Axis + + + 0 + 2 + + + + + True + False + DEC Axis + + + 0 + 3 + + + + + True + False + True + center + center + False + 6 + 25 + + + + 2 + 1 + + + + + True + False + True + False + 6 + 5 + + + + 2 + 2 + + + + + True + False + True + False + 6 + 14 + + + + 2 + 3 + + + + + True + False + NAN ° + + + 3 + 2 + 2 + + + + + True + False + NAN ° + + + 3 + 1 + + + + + True + True + start + center + 6 + + + + 2 + 5 + 2 + + + + + True + False + end + center + Input Filter: + + + 0 + 5 + 2 + + + + + + + + + + + + + + + + + + + + False - True - 6 + False + 1 - - F + True - False False - False - True - cal_mode_off - - - False - True - 7 - - - - - False - True - end - 2 - - - - - False - True - 1 - - - - - True - False - 4 - - - True - False - Position Control - - - - - - - False - True - 0 - - - - - True - False - - - Reset Simulation - True - True - image_question - True - - - - - False - True - 0 - - - - - Start Control - True - True - True - image_control - True - - + 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 + + + + + RAS + True + False + False + False + True + cal_mode_off + + + False + True + 3 + + + + + RA + True + False + False + False + True + cal_mode_off + + + False + True + 4 + + + + + DECS + True + False + False + False + 1 + True + cal_mode_off + + + False + True + 5 + + + + + DEC + 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 - 1 + 2 False True - end 1 @@ -1055,234 +1074,32 @@ False True - 2 + 1 - + True - False - vertical - - - True - False - 10 - 6 - 4 - - - True - False - Device: - - - False - True - 0 - - - - - True - True - 15 - /dev/ttyUSB0 - - - - True - True - 1 - - - - - False - True - 0 - - + True True False - 4 + vertical True False - vertical 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 - 6 - - - - 1 - 0 - - - - - True - True - 6 - - - - 1 - 1 - - - - - True - True - 6 - - - - 1 - 2 - - - - - True - True - 6 - - - - 1 - 3 - - - - - True - True - 6 - - - - 1 - 4 - - - - - False - True - 1 - - - - - - - - - True - False - RA Axis - - + Position Control + + + + False @@ -1294,17 +1111,15 @@ True False - 4 - True - - Min - True + + Reset Simulation True True + image_question True - - + + False @@ -1313,234 +1128,283 @@ - - C + + Start Control True True True - - + image_control + True + + False True + end 1 - - - Max - True - True - True - - - - - False - True - 2 - - False True - 1 - - - - - False - True - 0 - - - - - True - False + end + 1 + + False True - 1 + 2 True False - vertical 4 - + True False - 0 - none + vertical + 4 - + True False - 12 + 0 + none - + True False - 4 - - - 100 - 150 - True - False - - - - False - True - 0 - - + 12 - - + True False - 2 - - - True - False - Min - - - 0 - 0 - - - - - True - False - Max - - - 0 - 1 - - - - - True - False - Kp - - - 0 - 2 - - + 4 - + + 100 + 150 True False - Ki + - 0 - 3 + False + True + 0 - + + True False - Kd - - - 0 - 4 - - - - - True - True - 6 - - - - 1 - 0 - - - - - True - True - 6 - - - - 1 - 1 - - - - - True - True - 6 - - - - 1 - 2 - - - - - True - True - 6 - - - - 1 - 3 - - - - - True - True - 6 - + 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 + 6 + + + + 1 + 0 + + + + + True + True + 6 + + + + 1 + 1 + + + + + True + True + 6 + + + + 1 + 2 + + + + + True + True + 6 + + + + 1 + 3 + + + + + True + True + 6 + + + + 1 + 4 + + - 1 - 4 + False + True + 1 - - False - True - 1 - + + + True + False + RA Axis + + + + False + True + 0 + - - + + True False - DEC Axis + 4 + True + + + Min + True + True + True + True + + + + + False + True + 0 + + + + + C + True + True + True + + + + + False + True + 1 + + + + + Max + True + True + True + + + + + False + True + 2 + + + + False + True + 1 + @@ -1549,20 +1413,192 @@ 0 + + + True + False + + + False + True + 1 + + True False + vertical 4 - True - - Min + True - True - 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 + 6 + + + + 1 + 0 + + + + + True + True + 6 + + + + 1 + 1 + + + + + True + True + 6 + + + + 1 + 2 + + + + + True + True + 6 + + + + 1 + 3 + + + + + True + True + 6 + + + + 1 + 4 + + + + + False + True + 1 + + + + + + + + + True + False + DEC Axis + + False @@ -1571,13 +1607,56 @@ - - C + True - True - True - - + False + 4 + True + + + Min + True + True + True + + + + + False + True + 0 + + + + + C + True + True + True + + + + + False + True + 1 + + + + + Max + True + True + True + + + + + False + True + 2 + + False @@ -1585,384 +1664,680 @@ 1 - - - Max - True - True - True - - - - - False - True - 2 - - False True - 1 + 2 - - - - False - True - 2 - - - - - True - False - - - False - True - 3 - - - - - True - False - vertical - 4 + + + + True + False + + + False + True + 3 + + - + True False - 0 - in + vertical + 4 - + True False - 12 + 0 + in - + True False - vertical - - - True - False - Values - - - False - True - 0 - - + 12 - - + True False - 4 - 4 - - - True - False - Axis RA: - - - 0 - 1 - - - - - True - False - Axis DEC: - - - 0 - 2 - - - - - True - False - d - - - 1 - 0 - - + vertical True False - out + Values - 3 - 0 + 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 + + + + + + + + + + + + + + - 1 - 1 + False + True + 1 - - True - False - --- - - - - - - 1 - 2 - + + + + + + + + True + False + Control Values + + + + + False + True + 0 + + + + + True + False + 0 + in + + + True + False + 12 + + + True + False + vertical + 4 - + True False - --- - - - + + + Set Position + True + True + True + image-setdest + True + + + + + False + True + 0 + + + + + - 3 - 1 + False + True + 0 - + + PV - SP Tracking True - False - --- - - - + True + False + True + True - 3 - 2 + False + True + 1 - - - - - - - - - - - False - True - 1 - - - - + + + True + False + Position + + + + False + True + 1 + - - - True - False - Control Values - - - False - True - 0 + False + True + 4 + + + + + False + True + 3 + + + + + + + True + False + Continues Ctrl + + + False + + + + + True + False + 8 + 8 + vertical + 8 + + + True + False + True + + + Reset + True + True + True + + + + + False + False + 0 + + + + + Start + True + True + True + + + + + False + False + 1 + + + + + + + + False + False + 0 + + + + + + True + False + center + center + 4 + 4 + + + True + False + PV [OP] + + + 0 + 0 + + + + + True + False + Current + + + + + + 6 + 0 + + + + + True + False + RA out + + + 6 + 2 + + + + + True + False + center + center + RA max + + + 4 + 2 + + + + + True + False + Max + + + + + + 4 + 0 + + + + + True + False + Min + + + + + + 2 + 0 + + + + + True + False + center + center + RA min + + + 2 + 2 + + + + + True + False + center + center + RA Axis + + + + + + 0 + 2 + + + + + True + False + + + 1 + 0 + 4 + + + + + True + False + + + 3 + 0 + 4 + + + + + True + False + + + 5 + 0 + 4 + + + + + True + False + center + center + DEC Axis + + + + + + 0 + 3 + + + + + True + False + center + DEC min + + + 2 + 3 + + + + + True + False + center + center + DEC max + + + 4 + 3 + + + + + True + False + center + center + DEC out + + + 6 + 3 + + + + + True + False + + + 0 + 1 + + + + + True + False + + + 2 + 1 + + + + + True + False + + + 4 + 1 + + + + + True + False + + + 6 + 1 + + + False + True + 1 + + + + + True + True + in - + True False - 0 - in - + True - False - 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 - - - - - True - False - - - True - False - Input Filter: - - - False - True - 0 - - - - - True - True - 6 - - - - False - True - 1 - - - - - False - True - 2 - - - + True + + - - - True - False - Position - - - - False - True - 1 - - False + True True - 4 + 2 - False - True 1 + + + True + False + 2 Step Ctl + + + 1 + False + + + + + + + + False True - 3 + 4 - + + True False - Histogram - - - - True - True - GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK | GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK | GDK_SCROLL_MASK | GDK_TOUCH_MASK | GDK_SMOOTH_SCROLL_MASK | GDK_TOUCHPAD_GESTURE_MASK | GDK_TABLET_PAD_MASK - - - - - - - + gtk-floppy False @@ -1978,7 +2353,7 @@ True True vertical - 3 + 4 True @@ -2170,6 +2545,53 @@ 0 + + + True + False + 8 + 8 + 8 + + + + + + True + True + 64 + + + True + True + 1 + + + + + ... + True + True + True + image_saveass + right + True + + + + + False + True + 2 + + + + + False + True + 1 + + True @@ -2185,12 +2607,29 @@ True True - 1 + 2 + + False + Histogram + + + + True + True + GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK | GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK | GDK_SCROLL_MASK | GDK_TOUCH_MASK | GDK_SMOOTH_SCROLL_MASK | GDK_TOUCHPAD_GESTURE_MASK | GDK_TABLET_PAD_MASK + + + + + + + + False 350