enable edit of values

master
Steffen Pohle 3 years ago
parent b8308e26ba
commit cf65c10456

@ -4,5 +4,6 @@
# set one of these variables to 0 to disable the function. # set one of these variables to 0 to disable the function.
# #
USE_SVBONY = 1 USE_SVBONY = 1
DEBUG_ANGLES = 1 DEBUG_ANGLES = 0

@ -59,7 +59,6 @@ class PosCtl {
struct timeval calib_timestamp; struct timeval calib_timestamp;
int calib_mode; int calib_mode;
position_2d calib_pos; position_2d calib_pos;
position_f_2d target_pos;
void CalibModeStart(int x, int y); void CalibModeStart(int x, int y);
void CalibModeDelta(int x, int y); void CalibModeDelta(int x, int y);
@ -80,8 +79,9 @@ class PosCtl {
vector_2d calib_axis1; vector_2d calib_axis1;
position_f_2d calib_axis2_v; position_f_2d calib_axis2_v;
vector_2d calib_axis2; vector_2d calib_axis2;
position_f_2d target_pos;
double out[2]; double axis_pv[2];
double axis_op[2];
void LockMutex() { g_mutex_lock(&mutex); }; void LockMutex() { g_mutex_lock(&mutex); };
void UnLockMutex() { g_mutex_unlock(&mutex); }; void UnLockMutex() { g_mutex_unlock(&mutex); };

@ -91,6 +91,8 @@ struct {
void draw_text (cairo_t *cr, int x, int y, float border, std::string text); void draw_text (cairo_t *cr, int x, int y, float border, std::string text);
void draw_printf(cairo_t *cr, int x, int y, float border, char *fmt,...); void draw_printf(cairo_t *cr, int x, int y, float border, char *fmt,...);
#define gtk_entry_set_text_nofocus(__w__,__t__) if (!gtk_widget_has_focus(__w__)) gtk_entry_set_text (GTK_ENTRY(__w__), __t__)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

@ -55,8 +55,7 @@ void axis_history_add(int axis, double diff, double out) {
axis_history[axis][axis_history_pos[axis]].out = out; axis_history[axis][axis_history_pos[axis]].out = out;
} }
#define CALIB_MAXSPEED 1.0
#define CALIB_MAXSPEED 2.0
#define CALIB_DURATION_DELTA 10.0 #define CALIB_DURATION_DELTA 10.0
#define CALIB_DURATION_AXIS (CALIB_DURATION_DELTA / CALIB_MAXSPEED) #define CALIB_DURATION_AXIS (CALIB_DURATION_DELTA / CALIB_MAXSPEED)
@ -407,6 +406,8 @@ void posctl_gui_update() {
char txt[255]; char txt[255];
double kp, ki, kd, mi, ma; double kp, ki, kd, mi, ma;
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
GtkWidget *caliblabel = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_calib_label")); GtkWidget *caliblabel = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_calib_label"));
GtkWidget *btnclib = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_btn_calib")); GtkWidget *btnclib = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_btn_calib"));
@ -436,12 +437,14 @@ void posctl_gui_update() {
GtkWidget *a1_ki = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a1_ki")); GtkWidget *a1_ki = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a1_ki"));
GtkWidget *a1_kd = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a1_kd")); GtkWidget *a1_kd = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a1_kd"));
GtkWidget *a1_out = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_lb_outx")); GtkWidget *a1_out = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_lb_outx"));
GtkWidget *a1_pv = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_lb_dx"));
GtkWidget *a2_min = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a2_min")); GtkWidget *a2_min = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a2_min"));
GtkWidget *a2_max = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a2_max")); GtkWidget *a2_max = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a2_max"));
GtkWidget *a2_kp = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a2_kp")); GtkWidget *a2_kp = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a2_kp"));
GtkWidget *a2_ki = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a2_ki")); GtkWidget *a2_ki = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a2_ki"));
GtkWidget *a2_kd = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a2_kd")); GtkWidget *a2_kd = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_a2_kd"));
GtkWidget *a2_out = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_lb_outy")); GtkWidget *a2_out = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_lb_outy"));
GtkWidget *a2_pv = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_lb_dy"));
posctl.LockMutex(); posctl.LockMutex();
int m = posctl.GetMode(); int m = posctl.GetMode();
@ -491,34 +494,40 @@ void posctl_gui_update() {
gtk_entry_set_text (GTK_ENTRY(e_cal_a2len), txt); gtk_entry_set_text (GTK_ENTRY(e_cal_a2len), txt);
gtk_entry_set_text (GTK_ENTRY(e_posdevice), posctl.GetDevice().c_str()); gtk_entry_set_text (GTK_ENTRY(e_posdevice), posctl.GetDevice().c_str());
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.out[0]);
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.axis_op[0]);
gtk_label_set_text(GTK_LABEL(a1_out), txt); gtk_label_set_text(GTK_LABEL(a1_out), txt);
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.out[1]); strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.axis_op[1]);
gtk_label_set_text(GTK_LABEL(a2_out), txt); gtk_label_set_text(GTK_LABEL(a2_out), txt);
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.axis_pv[0]);
gtk_label_set_text(GTK_LABEL(a1_pv), txt);
strfromd (txt, sizeof(txt-1), (const char *)"%f", posctl.axis_pv[1]);
gtk_label_set_text(GTK_LABEL(a2_pv), txt);
posctl.GetAxisParam(0, &mi, &ma, &kp, &ki, &kd); posctl.GetAxisParam(0, &mi, &ma, &kp, &ki, &kd);
strfromd (txt, sizeof(txt-1), (const char *)"%f", mi); strfromd (txt, sizeof(txt-1), (const char *)"%f", mi);
gtk_entry_set_text (GTK_ENTRY(a1_min), txt); gtk_entry_set_text_nofocus (a1_min, txt);
strfromd (txt, sizeof(txt-1), (const char *)"%f", ma); strfromd (txt, sizeof(txt-1), (const char *)"%f", ma);
gtk_entry_set_text (GTK_ENTRY(a1_max), txt); gtk_entry_set_text_nofocus (a1_max, txt);
strfromd (txt, sizeof(txt-1), (const char *)"%f", kp); strfromd (txt, sizeof(txt-1), (const char *)"%f", kp);
gtk_entry_set_text (GTK_ENTRY(a1_kp), txt); gtk_entry_set_text_nofocus (a1_kp, txt);
strfromd (txt, sizeof(txt-1), (const char *)"%f", ki); strfromd (txt, sizeof(txt-1), (const char *)"%f", ki);
gtk_entry_set_text (GTK_ENTRY(a1_ki), txt); gtk_entry_set_text_nofocus (a1_ki, txt);
strfromd (txt, sizeof(txt-1), (const char *)"%f", kd); strfromd (txt, sizeof(txt-1), (const char *)"%f", kd);
gtk_entry_set_text (GTK_ENTRY(a1_kd), txt); gtk_entry_set_text_nofocus (a1_kd, txt);
posctl.GetAxisParam(1, &mi, &ma, &kp, &ki, &kd); posctl.GetAxisParam(1, &mi, &ma, &kp, &ki, &kd);
strfromd (txt, sizeof(txt-1), (const char *)"%f", mi); strfromd (txt, sizeof(txt-1), (const char *)"%f", mi);
gtk_entry_set_text (GTK_ENTRY(a2_min), txt); gtk_entry_set_text_nofocus (a2_min, txt);
strfromd (txt, sizeof(txt-1), (const char *)"%f", ma); strfromd (txt, sizeof(txt-1), (const char *)"%f", ma);
gtk_entry_set_text (GTK_ENTRY(a2_max), txt); gtk_entry_set_text_nofocus (a2_max, txt);
strfromd (txt, sizeof(txt-1), (const char *)"%f", kp); strfromd (txt, sizeof(txt-1), (const char *)"%f", kp);
gtk_entry_set_text (GTK_ENTRY(a2_kp), txt); gtk_entry_set_text_nofocus (a2_kp, txt);
strfromd (txt, sizeof(txt-1), (const char *)"%f", ki); strfromd (txt, sizeof(txt-1), (const char *)"%f", ki);
gtk_entry_set_text (GTK_ENTRY(a2_ki), txt); gtk_entry_set_text_nofocus (a2_ki, txt);
strfromd (txt, sizeof(txt-1), (const char *)"%f", kd); strfromd (txt, sizeof(txt-1), (const char *)"%f", kd);
gtk_entry_set_text (GTK_ENTRY(a2_kd), txt); gtk_entry_set_text_nofocus (a2_kd, txt);
posctl.UnLockMutex(); posctl.UnLockMutex();
} }
@ -742,8 +751,6 @@ void PosCtl::Loop (int posx, int posy) {
// dist_axis1 --> will control pid_axis2 // dist_axis1 --> will control pid_axis2
// dist_axis2 --> will control pis_axis1 // dist_axis2 --> will control pis_axis1
else if (mode == POSCTL_MODE_CONTROL) { else if (mode == POSCTL_MODE_CONTROL) {
double dist_axis1, out1;
double dist_axis2, out2;
position_f_2d p; position_f_2d p;
double d; double d;
@ -756,21 +763,21 @@ void PosCtl::Loop (int posx, int posy) {
d = calib_axis1_v.perpendicular(calib_axis2_v, p); d = calib_axis1_v.perpendicular(calib_axis2_v, p);
p.x = posx; p.y = posy; p.x = posx; p.y = posy;
dist_axis1 = calib_axis1_v.perpendicular(p, target_pos); axis_pv[0] = calib_axis2_v.perpendicular(p, target_pos);
dist_axis2 = calib_axis2_v.perpendicular(p, target_pos); axis_pv[1] = calib_axis1_v.perpendicular(p, target_pos);
out1 = pid_axis[0].Update(0.0, dist_axis1); axis_op[0] = pid_axis[0].Update(0.0, axis_pv[0]);
out2 = pid_axis[1].Update(0.0, dist_axis2); axis_op[1] = pid_axis[1].Update(0.0, axis_pv[1]);
printf ("%s:%d %s", __FILE__, __LINE__, __FUNCTION__); printf ("%s:%d %s", __FILE__, __LINE__, __FUNCTION__);
printf (" d: %+6.3f ", d); printf (" d: %+6.3f ", d);
printf (" Axis1 [dist:%+6.3f out1:%+6.3f] ", dist_axis1, out1); printf (" Axis1 [dist:%+6.3f out1:%+6.3f] ", axis_pv[0], axis_op[0]);
printf (" Axis2 [dist:%+6.3f out2:%+6.3f]\n", dist_axis2, out2); printf (" Axis2 [dist:%+6.3f out2:%+6.3f]\n", axis_pv[1], axis_op[1]);
OutputWriteValue(0, out2); OutputWriteValue(0, axis_op[0]);
OutputWriteValue(1, out1); OutputWriteValue(1, axis_op[1]);
axis_history_add(0, dist_axis1, out1); axis_history_add(0, axis_pv[0], axis_op[0]);
axis_history_add(1, dist_axis2, out2); axis_history_add(1, axis_pv[1], axis_op[1]);
UnLockMutex(); UnLockMutex();
gdk_threads_add_idle(cb_thread_posctl, NULL); gdk_threads_add_idle(cb_thread_posctl, NULL);

@ -77,6 +77,7 @@ int VideoDev_Simulation::Close() {
free (inframe); free (inframe);
inframe = NULL; inframe = NULL;
} }
simulation.Stop();
return VDEV_STATUS_OK; return VDEV_STATUS_OK;
}; };
@ -199,7 +200,7 @@ Simulation::Simulation() {
// //
// axis movement // axis movement
i = random() % 2; i = 0;
axis[i % 2].defAngle = dAngle + (10.0 * (double)random() / ((double) RAND_MAX)) - 5.0; axis[i % 2].defAngle = dAngle + (10.0 * (double)random() / ((double) RAND_MAX)) - 5.0;
axis[i % 2].defLen = dLen + (3.0 * (double)random() / ((double) RAND_MAX) - 1.5); axis[i % 2].defLen = dLen + (3.0 * (double)random() / ((double) RAND_MAX) - 1.5);
@ -239,6 +240,7 @@ void Simulation::ThreadProcess() {
double dx, dy; double dx, dy;
get_cycletime (&tv); get_cycletime (&tv);
if (running) return;
running = 1; running = 1;
do { do {
@ -272,6 +274,8 @@ void Simulation::ThreadProcess() {
r = running; r = running;
UnLockMutex(); UnLockMutex();
} while (r); } while (r);
running = 0;
} }
void Simulation::Start() { void Simulation::Start() {

Loading…
Cancel
Save