|
|
|
@ -11,6 +11,7 @@
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include "gui.h"
|
|
|
|
|
#include "pid.h"
|
|
|
|
|
#include "filter.h"
|
|
|
|
|
#include "detect.h"
|
|
|
|
|
#include "configuration.h"
|
|
|
|
@ -18,12 +19,17 @@
|
|
|
|
|
#include "videodev.h"
|
|
|
|
|
#include "histogram.h"
|
|
|
|
|
|
|
|
|
|
extern PosCtl posctl;
|
|
|
|
|
|
|
|
|
|
extern GtkBuilder *_builder_; // work around for threads
|
|
|
|
|
GtkWidget *posctl_rot_da = NULL;
|
|
|
|
|
// GtkWidget *posctl_axis1_da = NULL;
|
|
|
|
|
// GtkWidget *posctl_axis1_da = NULL;
|
|
|
|
|
double linedash1[] = { 1.0, 4.0 };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void posctl_gui_update();
|
|
|
|
|
|
|
|
|
|
void cb_posctl_show_window (GtkWidget *widget, gpointer data) {
|
|
|
|
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
|
|
|
|
@ -35,23 +41,12 @@ 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);
|
|
|
|
|
|
|
|
|
|
printf ("%s:%d %s disable all axis motors\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
printf ("%s:%d %s wait 5 or 10 seconds\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
printf ("%s:%d %s set minimum axis 1\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
printf ("%s:%d %s wait 5 or 10 seconds\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
printf ("%s:%d %s set maximum axis 1\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
printf ("%s:%d %s wait 5 or 10 seconds\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
printf ("%s:%d %s set minimum axis 2\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
printf ("%s:%d %s wait 5 or 10 seconds\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
printf ("%s:%d %s set maximum axis 2\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
printf ("%s:%d %s wait 5 or 10 seconds\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
printf ("%s:%d %s calculation rotation angle for each axis\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
printf ("%s:%d %s set axis in config file and use it for corrections\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
}
|
|
|
|
|
// GtkWidget *btn = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_btn_calib"));
|
|
|
|
|
// gtk_widget_set_sensitive(btn, false);
|
|
|
|
|
|
|
|
|
|
posctl.StartCalibration();
|
|
|
|
|
posctl_gui_update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cb_posctl_angles_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer data) {
|
|
|
|
|
int clientw, clienth;
|
|
|
|
@ -171,7 +166,6 @@ void cb_posctl_angles_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer
|
|
|
|
|
cairo_move_to(cr, center.x + float (lpos[4].x * center.x * 0.9 / lmax),
|
|
|
|
|
center.y - float (lpos[4].y * center.y * 0.9 / lmax));
|
|
|
|
|
cairo_show_text(cr, (char *)"2");
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -218,3 +212,109 @@ void cb_posctl_axis_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer da
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* posctl gui update
|
|
|
|
|
*/
|
|
|
|
|
void posctl_gui_update() {
|
|
|
|
|
GtkWidget *btnclib = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_btn_calib"));
|
|
|
|
|
GtkWidget *cbenable = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_enablectl"));
|
|
|
|
|
|
|
|
|
|
posctl.LockMutex();
|
|
|
|
|
int m = posctl.GetMode();
|
|
|
|
|
|
|
|
|
|
if (m == POSCTL_MODE_OFF) {
|
|
|
|
|
gtk_widget_set_sensitive(btnclib, true);
|
|
|
|
|
gtk_widget_set_sensitive(cbenable, true);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
gtk_widget_set_sensitive(btnclib, false);
|
|
|
|
|
gtk_widget_set_sensitive(cbenable, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 (gpointer data) {
|
|
|
|
|
posctl_gui_update();
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PosCtl::PosCtl() {
|
|
|
|
|
mode = POSCTL_MODE_OFF;
|
|
|
|
|
test_t1 = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* stop the control or the calibration
|
|
|
|
|
*/
|
|
|
|
|
void PosCtl::Stop() {
|
|
|
|
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
|
mode = POSCTL_MODE_OFF;
|
|
|
|
|
gdk_threads_add_idle(cb_thread_posctl, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PosCtl::StartCalibration() {
|
|
|
|
|
printf ("%s:%d\n", __FILE__, __LINE__);
|
|
|
|
|
if (mode != POSCTL_MODE_OFF) {
|
|
|
|
|
printf ("%s:%d mode is not off, can't start calibration.\n", __FILE__, __LINE__);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mode = POSCTL_MODE_CALIB;
|
|
|
|
|
test_t1 = time (NULL);
|
|
|
|
|
gdk_threads_add_idle(cb_thread_posctl, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PosCtl::StartControl() {
|
|
|
|
|
if (mode != POSCTL_MODE_OFF) {
|
|
|
|
|
printf ("%s:%d mode is not off, can't start control.\n", __FILE__, __LINE__);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pid_axis[0].Start();
|
|
|
|
|
pid_axis[1].Start();
|
|
|
|
|
mode = POSCTL_MODE_CONTROL;
|
|
|
|
|
gdk_threads_add_idle(cb_thread_posctl, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* get and set PID parameter, no mutex lock
|
|
|
|
|
* the access to the data should be already locked by the curren tthread
|
|
|
|
|
*/
|
|
|
|
|
void PosCtl::SetAxisParam ( int axis, double min, double max,
|
|
|
|
|
double k, double i, double d) {
|
|
|
|
|
|
|
|
|
|
if (axis < 0 || axis > 1) return;
|
|
|
|
|
pid_axis[axis].SetParam(min, max, k, i, d);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void PosCtl::GetAxisParam ( int axis, double *min, double *max,
|
|
|
|
|
double *k, double *i, double *d) {
|
|
|
|
|
|
|
|
|
|
if (axis < 0 || axis > 1) return;
|
|
|
|
|
pid_axis[axis].GetParam(min, max, k, i, d);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Loop, if new data is aviable
|
|
|
|
|
*/
|
|
|
|
|
void PosCtl::Loop (int posx, int posy) {
|
|
|
|
|
time_t t = time(NULL);
|
|
|
|
|
|
|
|
|
|
// FIXME:: only for testing gui function
|
|
|
|
|
if ((t - test_t1) > 5) {
|
|
|
|
|
mode = POSCTL_MODE_OFF;
|
|
|
|
|
gdk_threads_add_idle(cb_thread_posctl, NULL);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|