pid function ... not working yet...

master
Steffen Pohle 3 years ago
parent 41ae9d13df
commit 62de813110

@ -59,6 +59,7 @@ class PosCtl {
struct timeval calib_timestamp;
int calib_mode;
position_2d calib_pos;
position_f_2d target_pos;
void CalibModeStart(int x, int y);
void CalibModeDelta(int x, int y);

20
gui.h

@ -48,6 +48,24 @@ public:
return res;
}
double cosalpha(position_f_2d &pos) {
return (x * pos.x + y * pos.y) / (lenght() * pos.lenght());
}
double sinalpha(position_f_2d &pos) {
return (x * pos.y - y * pos.x) / (lenght() * pos.lenght());
}
double perpendicular(position_f_2d &pos, position_f_2d &base) {
double l;
position_f_2d p = pos - base;
l = sinalpha(p) * p.lenght();
return l;
}
double lenght() { return hypot(x, y); }
double x;
double y;
};
@ -154,6 +172,8 @@ G_MODULE_EXPORT void cb_histogram_show_window (GtkWidget *widget, gpointer data)
G_MODULE_EXPORT void cb_posctl_show (GtkWidget *widget, gpointer data);
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_btnstop (GtkWidget *widget, gpointer data);
G_MODULE_EXPORT void cb_posctl_btncontrol (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);

@ -0,0 +1 @@
<mxfile host="Electron" modified="2023-02-04T00:42:33.956Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/20.3.0 Chrome/104.0.5112.114 Electron/20.1.3 Safari/537.36" etag="-VtwViZtSer4q-7qMUnd" version="20.3.0" type="device"><diagram id="1p0Bprw3xxz6Ckpdy3R8" name="Seite-1">7Vvfc6M2EP5reKwH/UDAY5x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2Nnyd15clo0VAQ+f2DwNBHCfCNQMuJ5Kk3mDEULvMv9lXnZZit7Zf8HzUux+b7vKtXx4jE1FHu4ZY2hhfEX3XR4aOD5Bu7ZwRTde+10zmPnPS6v/v/JyijLepeHMcHUk7NnV2bfLPwl2o3oHEGqVhSeA+K+U8HatL0xy/WHF5uw8QpJR0MbzDEVmOvjetLErJqO/cDOziGDonyZAu25yZRduvjt0rLSrGS+5z/FduA3lSXGI2psRwws9KQ5aikJgKHrvH0/aucZPBuDxFz8vDptm8ZN4/Z62kJ3ZXFnxk5CBPTays5vrKn4GR2Jmr8VPZKcc4lG3Y1rs1AUtFPxgiZpMJvrJQffjxQYbv+HyjhSmgd8NOLp5+A+P0qEd/k8GffoP</diagram></mxfile>

@ -55,6 +55,21 @@ void cb_posctl_btncalib (GtkWidget *widget, gpointer data) {
}
void cb_posctl_btnstop (GtkWidget *widget, gpointer data) {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
posctl.Stop();
posctl_gui_update();
}
void cb_posctl_btncontrol (GtkWidget *widget, gpointer data) {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
posctl.StartControl();
posctl_gui_update();
}
void cb_posctl_show (GtkWidget *widget, gpointer data) {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
posctl_gui_update();
@ -299,7 +314,8 @@ void posctl_gui_update() {
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 *cbenable = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_enablectl"));
GtkWidget *btnstop = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_btn_stop"));
GtkWidget *btncontrol = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_btn_control"));
GtkWidget *e_cal_rotangle = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_rotangle"));
GtkWidget *e_cal_rotlen = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "posctl_entry_rotlen"));
@ -336,13 +352,14 @@ void posctl_gui_update() {
if (m == POSCTL_MODE_OFF) {
gtk_widget_set_sensitive(btnclib, true);
gtk_widget_set_sensitive(btncontrol, true);
gtk_widget_set_sensitive(btnstop, false);
gtk_widget_set_sensitive(btn_a1min, true);
gtk_widget_set_sensitive(btn_a1center, true);
gtk_widget_set_sensitive(btn_a1max, true);
gtk_widget_set_sensitive(btn_a2min, true);
gtk_widget_set_sensitive(btn_a2center, true);
gtk_widget_set_sensitive(btn_a2max, true);
gtk_widget_set_sensitive(cbenable, true);
gtk_widget_set_sensitive(e_posdevice, true);
gtk_label_set_label(GTK_LABEL(caliblabel), (char *) "");
}
@ -351,7 +368,8 @@ void posctl_gui_update() {
gtk_label_set_label(GTK_LABEL(caliblabel), (char *) "running");
}
gtk_widget_set_sensitive(btnclib, false);
gtk_widget_set_sensitive(cbenable, false);
gtk_widget_set_sensitive(btncontrol, false);
gtk_widget_set_sensitive(btnstop, true);
gtk_widget_set_sensitive(btn_a1min, false);
gtk_widget_set_sensitive(btn_a1center, false);
gtk_widget_set_sensitive(btn_a1max, false);
@ -457,6 +475,9 @@ void PosCtl::StartControl() {
printf ("%s:%d mode is not off, can't start control.\n", __FILE__, __LINE__);
return;
}
printf ("%s:%d %s start controlling Target:%f , %f\n", __FILE__, __LINE__, __FUNCTION__,
target_pos.x, target_pos.y);
pid_axis[0].Start();
pid_axis[1].Start();
mode = POSCTL_MODE_CONTROL;
@ -606,6 +627,44 @@ void PosCtl::Loop (int posx, int posy) {
gdk_threads_add_idle(cb_thread_posctl, NULL);
}
}
//
// dist_axis1+axis2 should contain the lot distance to the
// of the calibrated axis vector with the starting point at target_pos
// if the current position is below the axis line, the distance must be negative.
//
// this distance must be controlled by the PID axis controller.
// dist_axis1 --> will control pid_axis2
// dist_axis2 --> will control pis_axis1
else if (mode == POSCTL_MODE_CONTROL) {
double dist_axis1, out1;
double dist_axis2, out2;
position_f_2d p;
LockMutex();
// calculate
// dist_axis < 0.0 pid should increase the output.
// > 0.0 pid should decrease the output
p.x = posx; p.y = posy;
dist_axis1 = calib_axis1_v.perpendicular(p, target_pos);
dist_axis2 = calib_axis2_v.perpendicular(p, target_pos);
out1 = pid_axis[0].Update(0.0, dist_axis2);
out2 = pid_axis[1].Update(0.0, dist_axis1);
OutputWriteValue(0, out1);
OutputWriteValue(1, out2);
UnLockMutex();
}
else {
LockMutex();
target_pos.x = posx;
target_pos.y = posy;
UnLockMutex();
}
};
@ -698,6 +757,7 @@ 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 (isnan(value)) return -1;
if (device_type == POSCTL_DEVTYPE_SIM) {
simulation.AxisSetValue(axis, value);
return 0;

@ -645,10 +645,10 @@
</object>
</child>
</object>
<object class="GtkImage" id="image_refresh">
<object class="GtkImage" id="image_control">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="stock">gtk-refresh</property>
<property name="stock">gtk-execute</property>
</object>
<object class="GtkWindow" id="window-posctl">
<property name="can-focus">False</property>
@ -684,15 +684,44 @@
</packing>
</child>
<child>
<object class="GtkButton" id="posctl_btn_calib">
<property name="label" translatable="yes">Calibration</property>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image_refresh</property>
<property name="always-show-image">True</property>
<signal name="activate" handler="cb_posctl_btncalib" swapped="no"/>
<signal name="pressed" handler="cb_posctl_btncalib" swapped="no"/>
<property name="can-focus">False</property>
<child>
<object class="GtkButton" id="posctl_btn_stop">
<property name="label">gtk-stop</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
<property name="always-show-image">True</property>
<signal name="activate" handler="cb_posctl_btnstop" swapped="no"/>
<signal name="pressed" handler="cb_posctl_btnstop" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="posctl_btn_calib">
<property name="label" translatable="yes">Calibration</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image_refresh</property>
<property name="always-show-image">True</property>
<signal name="activate" handler="cb_posctl_btncalib" swapped="no"/>
<signal name="pressed" handler="cb_posctl_btncalib" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -956,12 +985,15 @@
</packing>
</child>
<child>
<object class="GtkCheckButton" id="posctl_enablectl">
<property name="label" translatable="yes">Enabled</property>
<object class="GtkButton" id="posctl_btn_control">
<property name="label" translatable="yes">Start Control</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="draw-indicator">True</property>
<property name="receives-default">True</property>
<property name="image">image_control</property>
<property name="always-show-image">True</property>
<signal name="activate" handler="cb_posctl_btncontrol" swapped="no"/>
<signal name="pressed" handler="cb_posctl_btncontrol" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@ -1712,6 +1744,11 @@
</object>
</child>
</object>
<object class="GtkImage" id="image_refresh">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="stock">gtk-refresh</property>
</object>
<object class="GtkWindow" id="window-histogram">
<property name="can-focus">False</property>
<property name="title" translatable="yes">Histogram</property>

@ -601,6 +601,9 @@ void cb_vidctrl_entry_change (GtkWidget *widget, gpointer data) {
};
/*
*
*/
void cb_videoda_motionevent (GtkWidget *widget, GdkEvent *event, gpointer data) {
int dw, dh, sw, sh;
float sar, dar;

Loading…
Cancel
Save