control pannel is getting to live

master
Steffen Pohle 3 years ago
parent 651cd8ef37
commit a1c39f672c

@ -28,6 +28,12 @@ struct {
} typedef position_2d;
struct {
float x;
float y;
} typedef position_f_2d;
#define DETECT_MOVEMENT_SAMPLES 50
struct {
struct {
@ -122,6 +128,7 @@ 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);
G_MODULE_EXPORT void cb_posctl_axis_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer data);
//
// menu elements

@ -22,6 +22,7 @@ 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 cb_posctl_show_window (GtkWidget *widget, gpointer data) {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
@ -36,39 +37,28 @@ void cb_posctl_btncalib (GtkWidget *widget, gpointer data) {
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);
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__);
}
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];
position_f_2d lpos[5];
float lmax;
position_2d center;
//
// rotation da
@ -83,45 +73,105 @@ void cb_posctl_angles_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer
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);
float a1_angle = atof(gtk_entry_get_text(GTK_ENTRY(entry_axis1_angle))) * (M_PI / 180);
float a1_lenmi = atof(gtk_entry_get_text(GTK_ENTRY(entry_axis1_lenmi)));
float a1_lenma = atof(gtk_entry_get_text(GTK_ENTRY(entry_axis1_lenma)));
float a2_angle = atof(gtk_entry_get_text(GTK_ENTRY(entry_axis2_angle))) * (M_PI / 180);
float a2_lenmi = atof(gtk_entry_get_text(GTK_ENTRY(entry_axis2_lenmi)));
float a2_lenma = atof(gtk_entry_get_text(GTK_ENTRY(entry_axis2_lenma)));
// float lenmax = max(max(max(a1_lenmi, a1_lenma),max(a2_lenmi, a2_lenma)), 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;
center.x = clientw >> 1;
center.y = clienth >> 1;
//
// draw the background
cairo_set_source_rgb(cr, 0.8, 0.8, 0.8);
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
cairo_paint(cr);
cairo_fill (cr);
cairo_set_source_rgb(cr, 0.8, 0.8, 0.8);
cairo_rectangle (cr, 1, 1, clientw - 2, clienth - 2);
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_move_to(cr, center.x, center.y - center.y * 0.8);
cairo_line_to(cr, center.x, center.y + center.y * 0.8);
cairo_stroke(cr);
cairo_move_to(cr, cx - cx * 0.8, cy);
cairo_line_to(cr, cx + cx * 0.8, cy);
cairo_move_to(cr, center.x - center.x * 0.8, center.y);
cairo_line_to(cr, center.x + center.x * 0.8, center.y);
cairo_stroke(cr);
cairo_set_dash(cr, NULL, 0, 0);
// draw angles
//
// calculate angles
lpos[0].x = sin(rotangle) * rotlen;
lpos[0].y = cos(rotangle) * rotlen;
lpos[1].x = lpos[0].x + sin(a1_angle) * a1_lenmi;
lpos[1].y = lpos[0].y + cos(a1_angle) * a1_lenmi;
lpos[2].x = lpos[0].x + sin(a1_angle) * a1_lenma;
lpos[2].y = lpos[0].y + cos(a1_angle) * a1_lenma;
lpos[3].x = lpos[0].x + sin(a2_angle) * a2_lenmi;
lpos[3].y = lpos[0].y + cos(a2_angle) * a2_lenmi;
lpos[4].x = lpos[0].x + sin(a2_angle) * a2_lenma;
lpos[4].y = lpos[0].y + cos(a2_angle) * a2_lenma;
// find maximum
for (int i = 0; i < 5; i++) {
if (i == 0) {
lmax = fabs (lpos[0].x);
if (fabs(lpos[i].y) > lmax) lmax = fabs(lpos[i].y);
} else {
if (fabs(lpos[i].x) > lmax) lmax = fabs(lpos[i].x);
if (fabs(lpos[i].y) > lmax) lmax = fabs(lpos[i].y);
}
}
//
// draw
cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 11);
cairo_set_line_width(cr, 4.0);
// rot
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
posctl_draw_angle (cr, cx, cy, rotangle, lenmax, 0.0, rotlen, "E");
cairo_move_to(cr, center.x, center.y);
cairo_line_to(cr, center.x + float (lpos[0].x * center.x * 0.8 / lmax),
center.y - float (lpos[0].y * center.y * 0.8 / lmax));
cairo_stroke(cr);
cairo_move_to(cr, center.x + float (lpos[0].x * center.x * 0.9 / lmax),
center.y - float (lpos[0].y * center.y * 0.9 / lmax));
cairo_show_text(cr, (char *)"E");
// axis1
cairo_set_source_rgb(cr, 0.0, 1.0, 0.5);
posctl_draw_angle (cr, cx, cy, a1angle, lenmax, a1lenmi, a1lenma, "1");
cairo_move_to(cr, center.x + float (lpos[1].x * center.x * 0.8 / lmax),
center.y - float (lpos[1].y * center.y * 0.8 / lmax));
cairo_line_to(cr, center.x + float (lpos[2].x * center.x * 0.8 / lmax),
center.y - float (lpos[2].y * center.y * 0.8 / lmax));
cairo_stroke(cr);
cairo_move_to(cr, center.x + float (lpos[2].x * center.x * 0.9 / lmax),
center.y - float (lpos[2].y * center.y * 0.9 / lmax));
cairo_show_text(cr, (char *)"1");
// axis2
cairo_set_source_rgb(cr, 0.0, 0.5, 1.0);
posctl_draw_angle (cr, cx, cy, a2angle, lenmax, a2lenmi, a2lenma, "2");
cairo_move_to(cr, center.x + float (lpos[3].x * center.x * 0.8 / lmax),
center.y - float (lpos[3].y * center.y * 0.8 / lmax));
cairo_line_to(cr, center.x + float (lpos[4].x * center.x * 0.8 / lmax),
center.y - float (lpos[4].y * center.y * 0.8 / lmax));
cairo_stroke(cr);
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");
};
@ -132,3 +182,39 @@ void cb_posctl_entryanglelen (GtkWidget *widget, gpointer data) {
};
void cb_posctl_axis_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer data) {
GtkWidget *da1 = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_da_axis1"));
GtkWidget *da2 = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_da_axis2"));
position_2d center;
int clienth = gtk_widget_get_allocated_height(area);
int clientw = gtk_widget_get_allocated_width(area);
center.x = clientw >> 1;
center.y = clienth >> 1;
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
cairo_paint(cr);
cairo_fill (cr);
cairo_set_source_rgb(cr, 0.8, 0.8, 0.8);
cairo_rectangle (cr, 1, 1, clientw - 2, clienth - 2);
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, center.x, center.y - center.y * 0.8);
cairo_line_to(cr, center.x, clienth);
cairo_stroke(cr);
cairo_set_dash(cr, NULL, 0, 0);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 10);
cairo_move_to(cr, 30, 10);
cairo_show_text(cr, (char *)"offset");
if (da1 != area && da2 != area) {
cairo_move_to(cr, 30, 0);
cairo_show_text(cr, (char *)"unknown");
return;
}
};

@ -594,7 +594,9 @@
<child>
<object class="GtkEntry" id="posctl_entry_a1anlge">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="editable">False</property>
<property name="width-chars">6</property>
<property name="text" translatable="yes">15</property>
<signal name="changed" handler="cb_posctl_entryanglelen" swapped="no"/>
@ -607,7 +609,9 @@
<child>
<object class="GtkEntry" id="posctl_entry_rotangle">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="editable">False</property>
<property name="width-chars">6</property>
<property name="text" translatable="yes">250</property>
<signal name="changed" handler="cb_posctl_entryanglelen" swapped="no"/>
@ -620,7 +624,9 @@
<child>
<object class="GtkEntry" id="posctl_entry_a2anlge">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="editable">False</property>
<property name="width-chars">6</property>
<property name="text" translatable="yes">105</property>
<signal name="changed" handler="cb_posctl_entryanglelen" swapped="no"/>
@ -688,9 +694,11 @@
<child>
<object class="GtkEntry" id="posctl_entry_rotlen">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="editable">False</property>
<property name="width-chars">6</property>
<property name="text" translatable="yes">25</property>
<signal name="changed" handler="cb_posctl_entryanglelen" swapped="no"/>
@ -704,9 +712,11 @@
<child>
<object class="GtkEntry" id="posctl_entry_a1lenmi">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="editable">False</property>
<property name="width-chars">6</property>
<property name="text" translatable="yes">-1</property>
<property name="text" translatable="yes">5</property>
<signal name="changed" handler="cb_posctl_entryanglelen" swapped="no"/>
</object>
<packing>
@ -717,9 +727,11 @@
<child>
<object class="GtkEntry" id="posctl_entry_a2lenmi">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="editable">False</property>
<property name="width-chars">6</property>
<property name="text" translatable="yes">5</property>
<property name="text" translatable="yes">14</property>
<signal name="changed" handler="cb_posctl_entryanglelen" swapped="no"/>
</object>
<packing>
@ -741,7 +753,9 @@
<child>
<object class="GtkEntry" id="posctl_entry_a1lenma">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="editable">False</property>
<property name="width-chars">6</property>
<property name="text" translatable="yes">15</property>
<signal name="changed" handler="cb_posctl_entryanglelen" swapped="no"/>
@ -754,9 +768,11 @@
<child>
<object class="GtkEntry" id="posctl_entry_a2lenma">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="editable">False</property>
<property name="width-chars">6</property>
<property name="text" translatable="yes">10</property>
<property name="text" translatable="yes">30</property>
<signal name="changed" handler="cb_posctl_entryanglelen" swapped="no"/>
</object>
<packing>
@ -851,6 +867,7 @@
<property name="height-request">150</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<signal name="draw" handler="cb_posctl_axis_draw" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@ -1032,6 +1049,7 @@
<property name="height-request">150</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<signal name="draw" handler="cb_posctl_axis_draw" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>

Loading…
Cancel
Save