|
|
|
|
@ -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);
|
|
|
|
|
|