ControlPanel.cpp

00001 /*
00002 Copyright (C) 2002-2004 Jean-Francois Mercure Burroughs 
00003                         Etienne Lachance
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 Report problems and direct all questions to:
00020 
00021 email: etienne.lachance@polymtl.ca or richard.gourdeau@polymtl.ca
00022 */
00023 
00024 #include "ControlPanel.h"
00025 #include "robot.h"
00026 
00027 #include "CustomEvent.h"
00028 
00029 #if defined __BCPLUSPLUS__ || defined __TURBOC__  || _MSC_VER // Borland, Turbo or MSVC
00030 double rint (double num) {
00031    return floor(num + 0.5);
00032 }
00033 #endif
00034 
00035 KinControlPanel::KinControlPanel(wxWindow* parent, wxWindowID id, //= -1 
00036                                  const wxPoint& pos,   // = wxDefaultPosition
00037                                  const wxSize& size,   // = wxDefaultSize
00038                                  long style,           // = wxTAB_TRAVERSAL
00039                                  const wxString& name, // = "panel"
00040                                  const bool angle_in_degree_)
00041     :wxPanel(parent, id, pos, size, style, name), angle_in_degree(angle_in_degree_)
00042 {
00043     m_STbox_q = 0;
00044     m_model = CModel::Instance();
00045     InitDialog();
00046     m_model->Attach(this);
00047 
00048     m_lboxLog = new wxListBox(this,-1);
00049     m_lboxLog->SetSize(510,5,500,95);
00050     m_logTarget=new boxLogger(m_lboxLog,wxLog::GetActiveTarget());
00051 }
00052 
00057 KinControlPanel::~KinControlPanel()
00058 {
00059     unsigned int i;
00060 
00061     for(i = 0; i < m_Txt_q.size(); i++)
00062         delete m_Txt_q[i];
00063     m_Txt_q.clear();
00064     for(i = 0; i < m_STxt_q.size(); i++)
00065         delete m_STxt_q[i];
00066     m_STxt_q.clear();
00067     for(i = 0; i < m_Btn_q.size(); i++)
00068         delete m_Btn_q[i];
00069     m_Btn_q.clear();
00070 }
00071 
00072 void KinControlPanel::InitSpinButton_q(const int nbspin)
00073 {
00074     int x,y;
00075     unsigned int i;
00076 
00077     wxTextCtrl *tmp1;
00078     wxSpinButton *tmp2;
00079     wxStaticText *tmp3;
00080 
00081     if(m_STbox_q)
00082     {
00083         delete m_STbox_q;
00084         m_STbox_q = 0;
00085     }
00086     for(i = 0; i < m_Btn_q.size(); i++)
00087     {
00088         delete m_Txt_q[i];
00089         delete m_Btn_q[i];
00090         delete m_STxt_q[i];
00091     }
00092     m_Txt_q.clear();
00093     m_Btn_q.clear();
00094     m_STxt_q.clear();
00095     
00096     switch(nbspin)
00097     {
00098         case 0:
00099             break;
00100         case 1:
00101             m_STbox_q = new wxStaticBox(this, -1, _("Kinematics"), 
00102                                         wxPoint(5,0), wxSize(90,50));
00103             x=30;y=20;
00104             tmp1 = new wxTextCtrl(this, Txt_q1,_T(""), wxPoint(x,y), wxSize(45,20), 
00105                                   wxTE_PROCESS_ENTER);
00106             m_Txt_q.push_back(tmp1);
00107             x=70;y=20;
00108             tmp2 = new wxSpinButton(this, Btn_q1, wxPoint(x,y), wxSize(20,20));
00109             m_Btn_q.push_back(tmp2);
00110             x=10;y=20;
00111             tmp3 = new wxStaticText(this, -1, _T("q1"), wxPoint(x,y), wxSize(15,20));
00112             m_STxt_q.push_back(tmp3);
00113             break;
00114 
00115         case 2:
00116             m_STbox_q = new wxStaticBox(this, -1, _("Kinematics"), 
00117                                         wxPoint(5,0), wxSize(90,70));
00118             x=30;y=20;
00119             tmp1 = new wxTextCtrl(this,Txt_q1,_T(""), wxPoint(x,y), wxSize(45,20), 
00120                                   wxTE_PROCESS_ENTER);
00121             m_Txt_q.push_back(tmp1); 
00122             tmp1 = new wxTextCtrl(this, Txt_q2,_T(""), wxPoint(x,y+20), wxSize(45,20), 
00123                                   wxTE_PROCESS_ENTER);
00124             m_Txt_q.push_back(tmp1); 
00125             x=70;y=20;
00126             tmp2 = new wxSpinButton(this, Btn_q1, wxPoint(x,y), wxSize(20,20));
00127             m_Btn_q.push_back(tmp2);
00128             tmp2 = new wxSpinButton(this, Btn_q2, wxPoint(x,y+20), wxSize(20,20));
00129             m_Btn_q.push_back(tmp2);
00130             x=10;y=20;
00131             tmp3 = new wxStaticText(this, -1, _T("q1"), wxPoint(x,y), wxSize(15,20));
00132             m_STxt_q.push_back(tmp3);
00133             tmp3 = new wxStaticText(this, -1, _T("q2"), wxPoint(x,y+20), wxSize(15,20));
00134             m_STxt_q.push_back(tmp3);
00135             break;
00136 
00137         case 3:
00138             m_STbox_q = new wxStaticBox(this, -1, _("Kinematics"), 
00139                                         wxPoint(5,0), wxSize(90,90));
00140             x=30;y=20;
00141             tmp1 = new wxTextCtrl(this, Txt_q1,_T(""), wxPoint(x,y), wxSize(45,20), 
00142                                   wxTE_PROCESS_ENTER);
00143             m_Txt_q.push_back(tmp1); 
00144             tmp1 = new wxTextCtrl(this, Txt_q2,_T(""), wxPoint(x,y+20), wxSize(45,20), 
00145                                   wxTE_PROCESS_ENTER);
00146             m_Txt_q.push_back(tmp1); 
00147             tmp1 = new wxTextCtrl(this, Txt_q3,_T(""), wxPoint(x,y+40), wxSize(45,20), 
00148                                   wxTE_PROCESS_ENTER);
00149             m_Txt_q.push_back(tmp1); 
00150             x=70;y=20;
00151             tmp2 = new wxSpinButton(this, Btn_q1, wxPoint(x,y), wxSize(20,20));
00152             m_Btn_q.push_back(tmp2);
00153             tmp2 = new wxSpinButton(this, Btn_q2, wxPoint(x,y+20), wxSize(20,20));
00154             m_Btn_q.push_back(tmp2);
00155             tmp2 = new wxSpinButton(this ,Btn_q3, wxPoint(x,y+40), wxSize(20,20));
00156             m_Btn_q.push_back(tmp2);
00157             x=10;y=20;
00158             tmp3 = new wxStaticText(this, -1, _T("q1"), wxPoint(x,y), wxSize(15,20));
00159             m_STxt_q.push_back(tmp3);
00160             tmp3 = new wxStaticText(this, -1, _T("q2"), wxPoint(x,y+20), wxSize(15,20));
00161             m_STxt_q.push_back(tmp3);
00162             tmp3 = new wxStaticText(this, -1, _T("q3"), wxPoint(x,y+40), wxSize(15,20));
00163             m_STxt_q.push_back(tmp3);
00164             break;
00165 
00166         case 4:
00167             m_STbox_q = new wxStaticBox(this, -1, _("Kinematics"), 
00168                                         wxPoint(5,0), wxSize(200,100));
00169             x=30;y=20;
00170             tmp1 = new wxTextCtrl(this, Txt_q1,_T(""), wxPoint(x,y), wxSize(45,20), 
00171                                   wxTE_PROCESS_ENTER);
00172             m_Txt_q.push_back(tmp1); 
00173             tmp1 = new wxTextCtrl(this, Txt_q2,_T(""), wxPoint(x,y+20), wxSize(45,20), 
00174                                   wxTE_PROCESS_ENTER);
00175             m_Txt_q.push_back(tmp1); 
00176             tmp1 = new wxTextCtrl(this, Txt_q3,_T(""), wxPoint(x,y+40), wxSize(45,20), 
00177                                   wxTE_PROCESS_ENTER);
00178             m_Txt_q.push_back(tmp1); 
00179             tmp1 = new wxTextCtrl(this, Txt_q4,_T(""), wxPoint(x+100,y), wxSize(45,20), 
00180                                   wxTE_PROCESS_ENTER);
00181             m_Txt_q.push_back(tmp1); 
00182             x=70;y=20;
00183             tmp2 = new wxSpinButton(this, Btn_q1, wxPoint(x,y), wxSize(20,20));
00184             m_Btn_q.push_back(tmp2);
00185             tmp2 = new wxSpinButton(this, Btn_q2, wxPoint(x,y+20), wxSize(20,20));
00186             m_Btn_q.push_back(tmp2);
00187             tmp2 = new wxSpinButton(this, Btn_q3, wxPoint(x,y+40), wxSize(20,20));
00188             m_Btn_q.push_back(tmp2);
00189             tmp2 = new wxSpinButton(this, Btn_q4, wxPoint(x+100,y), wxSize(20,20));
00190             m_Btn_q.push_back(tmp2);
00191             x=10;y=20;
00192             tmp3 = new wxStaticText(this, -1, _T("q1"), wxPoint(x,y), wxSize(15,20));
00193             m_STxt_q.push_back(tmp3);
00194             tmp3 = new wxStaticText(this, -1, _T("q2"), wxPoint(x,y+20), wxSize(15,20));
00195             m_STxt_q.push_back(tmp3);
00196             tmp3 = new wxStaticText(this, -1, _T("q3"), wxPoint(x,y+40), wxSize(15,20));
00197             m_STxt_q.push_back(tmp3);
00198             tmp3 = new wxStaticText(this, -1, _T("q4"), wxPoint(x+100,y), wxSize(15,20));
00199             m_STxt_q.push_back(tmp3);
00200             break;
00201 
00202         case 5:
00203             m_STbox_q = new wxStaticBox(this, -1, _("Kinematics"), 
00204                                         wxPoint(5,0), wxSize(200,100));
00205             x=30;y=20;
00206             tmp1 = new wxTextCtrl(this, Txt_q1,_T(""), wxPoint(x,y), wxSize(45,20), 
00207                                   wxTE_PROCESS_ENTER);
00208             m_Txt_q.push_back(tmp1); 
00209             tmp1 = new wxTextCtrl(this, Txt_q2,_T(""), wxPoint(x,y+20), wxSize(45,20), 
00210                                   wxTE_PROCESS_ENTER);
00211             m_Txt_q.push_back(tmp1); 
00212             tmp1 = new wxTextCtrl(this, Txt_q3,_T(""), wxPoint(x,y+40), wxSize(45,20), 
00213                                   wxTE_PROCESS_ENTER);
00214             m_Txt_q.push_back(tmp1); 
00215             tmp1 = new wxTextCtrl(this, Txt_q4,_T(""), wxPoint(x+100,y), wxSize(45,20), 
00216                                   wxTE_PROCESS_ENTER);
00217             m_Txt_q.push_back(tmp1); 
00218             tmp1 = new wxTextCtrl(this, Txt_q5,_T(""), wxPoint(x+100,y+20), wxSize(45,20), 
00219                                   wxTE_PROCESS_ENTER);
00220             m_Txt_q.push_back(tmp1); 
00221             x=70;y=20;
00222             tmp2 = new wxSpinButton(this, Btn_q1, wxPoint(x,y), wxSize(20,20));
00223             m_Btn_q.push_back(tmp2);
00224             tmp2 = new wxSpinButton(this, Btn_q2, wxPoint(x,y+20), wxSize(20,20));
00225             m_Btn_q.push_back(tmp2);
00226             tmp2 = new wxSpinButton(this, Btn_q3, wxPoint(x,y+40), wxSize(20,20));
00227             m_Btn_q.push_back(tmp2);
00228             tmp2 = new wxSpinButton(this, Btn_q4, wxPoint(x+100,y), wxSize(20,20));
00229             m_Btn_q.push_back(tmp2);
00230             tmp2 = new wxSpinButton(this, Btn_q5, wxPoint(x+100,y+20), wxSize(20,20));
00231             m_Btn_q.push_back(tmp2);
00232             x=10;y=20;
00233             tmp3 = new wxStaticText(this, -1, _T("q1"), wxPoint(x,y), wxSize(15,20));
00234             m_STxt_q.push_back(tmp3);
00235             tmp3 = new wxStaticText(this, -1, _T("q2"), wxPoint(x,y+20), wxSize(15,20));
00236             m_STxt_q.push_back(tmp3);
00237             tmp3 = new wxStaticText(this, -1, _T("q3"), wxPoint(x,y+40), wxSize(15,20));
00238             m_STxt_q.push_back(tmp3);
00239             tmp3 = new wxStaticText(this, -1, _T("q4"), wxPoint(x+100,y), wxSize(15,20));
00240             m_STxt_q.push_back(tmp3);
00241             tmp3 = new wxStaticText(this, -1, _T("q5"), wxPoint(x+100,y+20), wxSize(15,20));
00242             m_STxt_q.push_back(tmp3);
00243             break;
00244 
00245         case 6:
00246             m_STbox_q = new wxStaticBox(this, -1, _("Kinematics"), 
00247                                         wxPoint(5,0), wxSize(200,100));
00248             x=30;y=20;
00249             tmp1 = new wxTextCtrl(this, Txt_q1,_T(""), wxPoint(x,y), wxSize(45,20), 
00250                                   wxTE_PROCESS_ENTER);
00251             m_Txt_q.push_back(tmp1); 
00252             tmp1 = new wxTextCtrl(this, Txt_q2,_T(""), wxPoint(x,y+20), wxSize(45,20), 
00253                                   wxTE_PROCESS_ENTER);
00254             m_Txt_q.push_back(tmp1); 
00255             tmp1 = new wxTextCtrl(this, Txt_q3,_T(""), wxPoint(x,y+40), wxSize(45,20), 
00256                                   wxTE_PROCESS_ENTER);
00257             m_Txt_q.push_back(tmp1); 
00258             tmp1 = new wxTextCtrl(this, Txt_q4,_T(""), wxPoint(x+100,y), wxSize(45,20), 
00259                                   wxTE_PROCESS_ENTER);
00260             m_Txt_q.push_back(tmp1); 
00261             tmp1 = new wxTextCtrl(this, Txt_q5,_T(""), wxPoint(x+100,y+20), wxSize(45,20), 
00262                                   wxTE_PROCESS_ENTER);
00263             m_Txt_q.push_back(tmp1); 
00264             tmp1 = new wxTextCtrl(this, Txt_q6,_T(""), wxPoint(x+100,y+40), wxSize(45,20), 
00265                                   wxTE_PROCESS_ENTER);
00266             m_Txt_q.push_back(tmp1); 
00267             x=70;y=20;
00268             tmp2 = new wxSpinButton(this, Btn_q1, wxPoint(x,y), wxSize(20,20));
00269             m_Btn_q.push_back(tmp2);
00270             tmp2 = new wxSpinButton(this, Btn_q2, wxPoint(x,y+20), wxSize(20,20));
00271             m_Btn_q.push_back(tmp2);
00272             tmp2 = new wxSpinButton(this, Btn_q3, wxPoint(x,y+40), wxSize(20,20));
00273             m_Btn_q.push_back(tmp2);
00274             tmp2 = new wxSpinButton(this, Btn_q4, wxPoint(x+100,y), wxSize(20,20));
00275             m_Btn_q.push_back(tmp2);
00276             tmp2 = new wxSpinButton(this, Btn_q5, wxPoint(x+100,y+20), wxSize(20,20));
00277             m_Btn_q.push_back(tmp2);
00278             tmp2 = new wxSpinButton(this, Btn_q6, wxPoint(x+100,y+40), wxSize(20,20));
00279             m_Btn_q.push_back(tmp2);
00280             x=10;y=20;
00281             tmp3 = new wxStaticText(this, -1, _T("q1"), wxPoint(x,y), wxSize(15,20));
00282             m_STxt_q.push_back(tmp3);
00283             tmp3 = new wxStaticText(this, -1, _T("q2"), wxPoint(x,y+20), wxSize(15,20));
00284             m_STxt_q.push_back(tmp3);
00285             tmp3 = new wxStaticText(this, -1, _T("q3"), wxPoint(x,y+40), wxSize(15,20));
00286             m_STxt_q.push_back(tmp3);
00287             tmp3 = new wxStaticText(this, -1, _T("q4"), wxPoint(x+100,y), wxSize(15,20));
00288             m_STxt_q.push_back(tmp3);
00289             tmp3 = new wxStaticText(this, -1, _T("q5"), wxPoint(x+100,y+20), wxSize(15,20));
00290             m_STxt_q.push_back(tmp3);
00291             tmp3 = new wxStaticText(this, -1, _T("q6"), wxPoint(x+100,y+40), wxSize(15,20));
00292             m_STxt_q.push_back(tmp3);
00293             break;
00294         default:
00295             wxLogMessage(_T("Kinematics panel does not accept dof > 6")); 
00296     }
00297 
00298     int min=-10000,max=10000;
00299     for(i = 0; i < m_Btn_q.size(); i++)
00300     {
00301         m_Btn_q[i]->SetRange(min, max);
00302         m_Btn_q[i]->Enable(TRUE);
00303         m_Txt_q[i]->Enable(TRUE);
00304     }
00305 }
00306 
00307 void KinControlPanel::InitDialog()
00308 {
00309     int x=250, y=20;
00310     m_STbox_inv = new wxStaticBox(this, -1, _("Inverse Kinematics"),
00311                                   wxPoint(x-15,0), wxSize(270,100));
00312     m_STxt_x = new wxStaticText(this, -1, _T("X:"), wxPoint(x,y), wxSize(15,15));
00313     m_Txt_x =new wxTextCtrl(this, Txt_x, _T("0.000"), wxPoint(x+15,y), wxSize(45,20), 
00314                             wxTE_PROCESS_ENTER);
00315     m_Btn_x = new wxSpinButton(this, Btn_x, wxPoint(x+60,y), wxSize(20,20));
00316     
00317     m_STxt_y = new wxStaticText(this, -1, _T("Y:"), wxPoint(x,y+25), wxSize(15,15));
00318     m_Txt_y =new wxTextCtrl(this,Txt_y,_T("0.000"), wxPoint(x+15,y+25), wxSize(45,20), 
00319                             wxTE_PROCESS_ENTER);
00320     m_Btn_y = new wxSpinButton(this,Btn_y, wxPoint(x+60,y+25), wxSize(20,20));
00321     
00322     m_STxt_z = new wxStaticText(this,-1,_T("Z:"), wxPoint(x,y+50), wxSize(15,15));
00323     m_Txt_z =new wxTextCtrl(this,Txt_z,_T("0.000"), wxPoint(x+15,y+50), wxSize(45,20), 
00324                             wxTE_PROCESS_ENTER);
00325     m_Btn_z = new wxSpinButton(this, Btn_z, wxPoint(x+60,y+50), wxSize(20,20));
00326     
00327     x=350;
00328     y=20;
00329     m_STxt_yaw = new wxStaticText(this, -1, _("Yaw:"), wxPoint(x-10,y), 
00330                                   wxSize(30,15));
00331     m_Txt_yaw = new wxTextCtrl(this, Txt_yaw,_T("0.000"), wxPoint(x+25,y), wxSize(45,20), 
00332                                wxTE_PROCESS_ENTER);
00333     m_Btn_yaw = new wxSpinButton(this, Btn_yaw, wxPoint(x+70,y), wxSize(20,20));
00334     
00335     m_STxt_pitch = new wxStaticText(this, -1, _("Pitch:"), wxPoint(x-10,y+25), 
00336                                     wxSize(30,15));
00337     m_Txt_pitch =new wxTextCtrl(this, Txt_pitch, _T("0.000"), wxPoint(x+25,y+25), wxSize(45,20), 
00338                                 wxTE_PROCESS_ENTER);
00339     m_Btn_pitch = new wxSpinButton(this, Btn_pitch, wxPoint(x+70,y+25), wxSize(20,20));
00340     
00341     m_STxt_roll = new wxStaticText(this, -1, _("Roll:"), wxPoint(x-10,y+50), 
00342                                    wxSize(30,15));
00343     m_Txt_roll =new wxTextCtrl(this, Txt_roll, _T("0.000"), wxPoint(x+25,y+50), wxSize(45,20), 
00344                                wxTE_PROCESS_ENTER);
00345     m_Btn_roll = new wxSpinButton(this, Btn_roll, wxPoint(x+70,y+50), wxSize(20,20));
00346     
00347     m_Btn_x->SetValue(0);
00348     m_Btn_y->SetValue(0);
00349     m_Btn_z->SetValue(0);
00350     m_Btn_x->SetRange(-100000,100000);
00351     m_Btn_y->SetRange(-100000,100000);
00352     m_Btn_z->SetRange(-100000,100000);
00353 
00354     m_Btn_yaw->SetValue(0);
00355     m_Btn_pitch->SetValue(0);
00356     m_Btn_roll->SetValue(0);
00357     m_Btn_yaw->SetRange(-100000,100000);
00358     m_Btn_pitch->SetRange(-100000,100000);
00359     m_Btn_roll->SetRange(-100000,100000);
00360 
00361     m_Btn_InvKine = new wxButton(this,Btn_InvKine,_("Start"), 
00362                                  wxPoint(x+100,y), wxSize(40,70));
00363     m_Btn_InvKine->Enable(FALSE);
00364 
00365     UpdateData();
00366 }
00367 
00368 BEGIN_EVENT_TABLE(KinControlPanel, wxPanel)
00369         EVT_SPIN(Btn_q1, KinControlPanel::OnSpinBtn_q)
00370         EVT_SPIN(Btn_q2, KinControlPanel::OnSpinBtn_q) 
00371         EVT_SPIN(Btn_q3, KinControlPanel::OnSpinBtn_q) 
00372         EVT_SPIN(Btn_q4, KinControlPanel::OnSpinBtn_q) 
00373         EVT_SPIN(Btn_q5, KinControlPanel::OnSpinBtn_q) 
00374         EVT_SPIN(Btn_q6, KinControlPanel::OnSpinBtn_q)
00375 
00376         EVT_SPIN(Btn_x, KinControlPanel::OnSpinBtn_inv)
00377         EVT_SPIN(Btn_y, KinControlPanel::OnSpinBtn_inv)
00378         EVT_SPIN(Btn_z, KinControlPanel::OnSpinBtn_inv)
00379         EVT_SPIN(Btn_yaw, KinControlPanel::OnSpinBtn_inv)
00380         EVT_SPIN(Btn_pitch, KinControlPanel::OnSpinBtn_inv)
00381         EVT_SPIN(Btn_roll, KinControlPanel::OnSpinBtn_inv)
00382 
00383         EVT_BUTTON(Btn_InvKine, KinControlPanel::OnInvKine)
00384 
00385         EVT_TEXT_ENTER(Txt_q1, KinControlPanel::OnSpinBtn_q_t)
00386         EVT_TEXT_ENTER(Txt_q2, KinControlPanel::OnSpinBtn_q_t)
00387         EVT_TEXT_ENTER(Txt_q3, KinControlPanel::OnSpinBtn_q_t)
00388         EVT_TEXT_ENTER(Txt_q4, KinControlPanel::OnSpinBtn_q_t)
00389         EVT_TEXT_ENTER(Txt_q5, KinControlPanel::OnSpinBtn_q_t)
00390         EVT_TEXT_ENTER(Txt_q6, KinControlPanel::OnSpinBtn_q_t)
00391 
00392         EVT_TEXT_ENTER(Txt_x, KinControlPanel::OnSpinBtn_inv_t)
00393         EVT_TEXT_ENTER(Txt_y, KinControlPanel::OnSpinBtn_inv_t)
00394         EVT_TEXT_ENTER(Txt_z, KinControlPanel::OnSpinBtn_inv_t)
00395         EVT_TEXT_ENTER(Txt_yaw, KinControlPanel::OnSpinBtn_inv_t)
00396         EVT_TEXT_ENTER(Txt_pitch, KinControlPanel::OnSpinBtn_inv_t)
00397         EVT_TEXT_ENTER(Txt_roll, KinControlPanel::OnSpinBtn_inv_t)
00398 END_EVENT_TABLE()
00399 
00400 
00401 void KinControlPanel::OnSpinBtn_q(wxSpinEvent &event)
00402 {
00403     int id;
00404     double value;
00405 
00406     id = event.GetId() - Btn_q1;
00407     if( (id >= 0) && (id < (int)m_Btn_q.size()) )
00408       {      
00409         if(angle_in_degree)
00410           value = (double) m_Btn_q[id]->GetValue()*SPIN_DEG_INCREMENT;
00411         else
00412           value = (double) m_Btn_q[id]->GetValue()*SPIN_INCREMENT;
00413         
00414         m_Txt_q[id]->SetValue(wxString::Format(_T("%0.3f"), value));
00415         if(angle_in_degree)
00416           value = deg2rad(value);
00417         m_model->Set_q(value,id+1);         
00418       }
00419     UpdateSpinBtn_inv();
00420     m_Btn_InvKine->Enable(FALSE);
00421     m_model->Notify(this);    
00422 }
00423 
00424 void KinControlPanel::OnSpinBtn_inv(wxSpinEvent &event)
00425 {
00426     double x, y, z, yaw, pitch, roll;
00427     int id;
00428 
00429     id = event.GetId() - Btn_x;
00430     if( (id >=0) && (id <= 6) )
00431       {
00432         x     = m_Btn_x->GetValue()*SPIN_INCREMENT;
00433         y     = m_Btn_y->GetValue()*SPIN_INCREMENT;
00434         z     = m_Btn_z->GetValue()*SPIN_INCREMENT;
00435         m_Txt_x->SetValue(wxString::Format(_T("%0.3f"), x));
00436         m_Txt_y->SetValue(wxString::Format(_T("%0.3f"), y));
00437         m_Txt_z->SetValue(wxString::Format(_T("%0.3f"), z));
00438         
00439         if(angle_in_degree)
00440           {
00441             yaw   = m_Btn_yaw->GetValue()*SPIN_DEG_INCREMENT;
00442             pitch = m_Btn_pitch->GetValue()*SPIN_DEG_INCREMENT;
00443             roll  = m_Btn_roll->GetValue()*SPIN_DEG_INCREMENT;
00444           }
00445         else
00446           {
00447             yaw   = m_Btn_yaw->GetValue()*SPIN_INCREMENT;
00448             pitch = m_Btn_pitch->GetValue()*SPIN_INCREMENT;
00449             roll  = m_Btn_roll->GetValue()*SPIN_INCREMENT;
00450           }
00451         
00452         m_Txt_yaw->SetValue(wxString::Format(_T("%0.3f"), yaw));
00453         m_Txt_pitch->SetValue(wxString::Format(_T("%0.3f"), pitch));
00454         m_Txt_roll->SetValue(wxString::Format(_T("%0.3f"), roll));
00455       }
00456     m_Btn_InvKine->Enable(TRUE);        
00457     if(angle_in_degree)
00458     {
00459         yaw = deg2rad(yaw);
00460         pitch = deg2rad(pitch);
00461         roll = deg2rad(roll);
00462     }
00463     m_model->m_target->SetTargetPos(x, y, z, yaw, pitch, roll);
00464     m_model->Notify(this);
00465 }
00466 
00467 void KinControlPanel::OnSpinBtn_q_t(wxCommandEvent &event)
00468 {
00469     int id;
00470     double value;
00471 
00472     id = event.GetId() - Txt_q1;
00473     if( (id >= 0) && (id < (int)m_Btn_q.size()) )
00474       {      
00475         (m_Txt_q[id]->GetValue()).ToDouble(&value);
00476         if(angle_in_degree)
00477           {
00478             m_Btn_q[id]->SetValue((int)(value/SPIN_DEG_INCREMENT));
00479             value = deg2rad(value);
00480           }
00481         else
00482           m_Btn_q[id]->SetValue((int)(value/SPIN_INCREMENT));
00483         m_model->Set_q(value,id+1);
00484       }
00485     UpdateSpinBtn_inv();
00486     m_Btn_InvKine->Enable(FALSE);
00487     m_model->Notify(this);    
00488 }
00489 
00490 void KinControlPanel::OnSpinBtn_inv_t(wxCommandEvent &event)
00491 {
00492     double x, y, z, yaw, pitch, roll;
00493     int id;
00494 
00495     id = event.GetId() - Txt_x;
00496     if( (id >=0) && (id <= 6) )
00497       {
00498         (m_Txt_x->GetValue()).ToDouble(&x);
00499         m_Btn_x->SetValue((int)rint(x/SPIN_INCREMENT));     
00500         (m_Txt_y->GetValue()).ToDouble(&y);
00501         m_Btn_y->SetValue((int)rint(y/SPIN_INCREMENT));     
00502         (m_Txt_z->GetValue()).ToDouble(&z);
00503         m_Btn_z->SetValue((int)rint(z/SPIN_INCREMENT));
00504         
00505         (m_Txt_yaw->GetValue()).ToDouble(&yaw);
00506         (m_Txt_pitch->GetValue()).ToDouble(&pitch);
00507         (m_Txt_roll->GetValue()).ToDouble(&roll);
00508         if(angle_in_degree)
00509           {
00510             m_Btn_yaw->SetValue((int)rint(yaw/SPIN_DEG_INCREMENT));
00511             m_Btn_pitch->SetValue((int)rint(pitch/SPIN_DEG_INCREMENT)); 
00512             m_Btn_roll->SetValue((int)rint(roll/SPIN_DEG_INCREMENT));
00513           }
00514         else
00515           {
00516             m_Btn_yaw->SetValue((int)rint(yaw/SPIN_INCREMENT));
00517             m_Btn_pitch->SetValue((int)rint(pitch/SPIN_INCREMENT)); 
00518             m_Btn_roll->SetValue((int)rint(roll/SPIN_INCREMENT));
00519           }
00520       }
00521     m_Btn_InvKine->Enable(TRUE);        
00522     if(angle_in_degree)
00523     {
00524         yaw = deg2rad(yaw);
00525         pitch = deg2rad(pitch);
00526         roll = deg2rad(roll);
00527     }
00528     m_model->m_target->SetTargetPos(x, y, z, yaw, pitch, roll);
00529     m_model->Notify(this);
00530 }
00531 
00532 void KinControlPanel::UpdateSpinBtn_inv()
00533 {
00534     Matrix Trans;
00535     ColumnVector rpy;
00536 
00537     Trans = m_model->kine();
00538 
00539 // Update x,y,z inverse kinematics spin button with current 
00540 // robot position
00541     m_Btn_x->SetValue((int)(Trans(1,4)/SPIN_INCREMENT));
00542     m_Txt_x->SetValue(wxString::Format(_T("%0.3f"), Trans(1,4)));
00543     m_Btn_y->SetValue((int)(Trans(2,4)/SPIN_INCREMENT));
00544     m_Txt_y->SetValue(wxString::Format(_T("%0.3f"), Trans(2,4)));
00545     m_Btn_z->SetValue((int)(Trans(3,4)/SPIN_INCREMENT));
00546     m_Txt_z->SetValue(wxString::Format(_T("%0.3f"), Trans(3,4)));
00547 
00548 // Update roll, pitch, yaw inverse kinematics spin button with current 
00549 // robot orientation
00550     rpy = irpy(Trans.SubMatrix(1,3,1,3));
00551     if(angle_in_degree)
00552     {
00553         rpy(1) = rad2deg(rpy(1));
00554         rpy(2) = rad2deg(rpy(2));
00555         rpy(3) = rad2deg(rpy(3));
00556     }
00557 
00558     m_Txt_roll->SetValue(wxString::Format(_T("%0.3f"), rpy(3)));
00559     m_Txt_pitch->SetValue(wxString::Format(_T("%0.3f"), rpy(2)));
00560     m_Txt_yaw->SetValue(wxString::Format(_T("%0.3f"), rpy(1)));
00561 
00562     if(angle_in_degree)
00563     {
00564         m_Btn_roll->SetValue((int)(rpy(3)/SPIN_DEG_INCREMENT));
00565         m_Btn_pitch->SetValue((int)(rpy(2)/SPIN_DEG_INCREMENT));
00566         m_Btn_yaw->SetValue((int)(rpy(1)/SPIN_DEG_INCREMENT));
00567     }
00568     else
00569     {
00570         m_Btn_roll->SetValue((int)(rpy(3)/SPIN_INCREMENT));
00571         m_Btn_pitch->SetValue((int)(rpy(2)/SPIN_INCREMENT));
00572         m_Btn_yaw->SetValue((int)(rpy(1)/SPIN_INCREMENT));
00573     }
00574 }
00575 
00586 void KinControlPanel::OnInvKine(wxCommandEvent& event)
00587 {
00588     if(m_model->IsInitialise() == FALSE)
00589         return;
00590     bool converge;
00591     Matrix result;
00592     ColumnVector dest(3);
00593 
00594     if(angle_in_degree)
00595     {
00596         dest(3) = deg2rad((double) m_Btn_roll->GetValue()*SPIN_DEG_INCREMENT);
00597         dest(2) = deg2rad((double) m_Btn_pitch->GetValue()*SPIN_DEG_INCREMENT);
00598         dest(1) = deg2rad((double) m_Btn_yaw->GetValue()*SPIN_DEG_INCREMENT);
00599     }
00600     else
00601     {
00602         dest(3) = (double) m_Btn_roll->GetValue()*SPIN_INCREMENT;
00603         dest(2) = (double) m_Btn_pitch->GetValue()*SPIN_INCREMENT;
00604         dest(1) = (double) m_Btn_yaw->GetValue()*SPIN_INCREMENT;
00605     }
00606 
00607     result=rpy(dest);
00608 
00609     dest(1) = (double) m_Btn_x->GetValue()*SPIN_INCREMENT;
00610     dest(2) = (double) m_Btn_y->GetValue()*SPIN_INCREMENT;
00611     dest(3) = (double) m_Btn_z->GetValue()*SPIN_INCREMENT;
00612     
00613     result(1,4)=dest(1);
00614     result(2,4)=dest(2);
00615     result(3,4)=dest(3);
00616     
00617     m_model->inv_kin(result, 0, m_model->get_dof(), converge);
00618     if(converge==true)
00619     {   
00620         UpdateData();   
00621         wxLogMessage(_("Converged"));   
00622     }
00623     else
00624         wxLogMessage(_("Did not converged"));           
00625 
00626     m_Btn_InvKine->Enable(FALSE);
00627 
00628     m_model->Notify(this);    
00629 }
00630 
00638 void KinControlPanel::UpdateData()
00639 {
00640     int dof = m_model->get_dof();
00641     double value;
00642 
00643     if(dof != (int)m_Btn_q.size())
00644         InitSpinButton_q(dof);
00645 
00646     for(unsigned int i = 0; i < m_Btn_q.size(); i++)
00647     {
00648         value = m_model->get_q(i+1);
00649         if(angle_in_degree)
00650         {
00651             value = rad2deg(value);
00652             m_Btn_q[i]->SetValue((int)(value/SPIN_DEG_INCREMENT));
00653         }
00654         else
00655             m_Btn_q[i]->SetValue((int)(value/SPIN_INCREMENT));
00656         m_Txt_q[i]->SetValue(wxString::Format(_T("%0.3f"), value));     
00657         UpdateSpinBtn_inv();
00658     }
00659 }
00660 
00661 void KinControlPanel::Update(Subject *TheChangedSubject)
00668 {
00669     UpdateData();
00670 }
00671 
00672 void KinControlPanel::set_active_ListBox()
00673 {
00674     wxLog::SetActiveTarget(m_logTarget);
00675 }
00676 
00677 // -------------------------------------------------------------------------------------------------------------
00678 
00679 DynControlPanel::DynControlPanel(wxWindow* parent, wxWindowID id, //= -1 
00680                                  const wxPoint& pos,    // = wxDefaultPosition
00681                                  const wxSize& size,    // = wxDefaultSize
00682                                  long style,            // = wxTAB_TRAVERSAL
00683                                  const wxString & name) // = "panel"
00684   :wxPanel(parent, id, pos, size, style, name)
00685 {
00686     InitDialog();
00687 
00688     m_lboxLog = new wxListBox(this,-1);
00689     m_lboxLog->SetSize(510,5,500,95);
00690     m_logTarget=new boxLogger(m_lboxLog,wxLog::GetActiveTarget());
00691 }
00692 
00693 DynControlPanel::~DynControlPanel()
00694 {
00695 }
00696 
00697 void DynControlPanel::InitDialog()
00698 {
00699   int x = 100, y = 20;
00700 
00701   x = 0;
00702   m_Btn_Select_Controller = new wxButton(this, Btn_DynSelectController, 
00703                                          _("Controller"), 
00704                                          wxPoint(x+100,y), wxSize(60,70));
00705   x = 75;
00706   m_Btn_Select_Trajectory = new wxButton(this, Btn_DynSelectTrajectory, 
00707                                          _("Trajectory"), 
00708                                          wxPoint(x+100,y), wxSize(60,70));
00709   x = 150;
00710   m_Btn_Start = new wxButton(this, Btn_DynStart, _("Start"), 
00711                              wxPoint(x+100,y), wxSize(40,70));
00712   x = 225;
00713   m_Btn_Stop = new wxButton(this, Btn_DynStop, _("Stop"), 
00714                             wxPoint(x+100,y), wxSize(40,70));
00715 
00716   m_Btn_Start->Enable(TRUE);
00717   m_Btn_Stop->Enable(FALSE);
00718   m_Btn_Select_Controller->Enable(TRUE);
00719   m_Btn_Select_Trajectory->Enable(FALSE);
00720 }
00721 
00722 BEGIN_EVENT_TABLE(DynControlPanel, wxPanel)
00723       EVT_BUTTON(Btn_DynSelectController, DynControlPanel::OnSelectController)
00724       EVT_BUTTON(Btn_DynSelectTrajectory, DynControlPanel::OnSelectTrajectory)
00725       EVT_BUTTON(Btn_DynStart, DynControlPanel::OnStart)
00726       EVT_BUTTON(Btn_DynStop, DynControlPanel::OnStop)
00727       EVT_PAINT_DYNAMICS(-1, DynControlPanel::UpdateData)
00728 END_EVENT_TABLE()
00729 
00730 
00731 void DynControlPanel::OnSelectController(wxCommandEvent& event)
00732 {
00733   wxString path, file;
00734   wxFileDialog *dlg = new wxFileDialog(this,  _("Choose a file"), wxGetCwd()+_T("/controller/"), _T(""),  _T("*.*"),  
00735                                          wxOPEN, wxDefaultPosition);
00736 
00737     if(dlg->ShowModal() == wxID_OK)
00738     {
00739         file = dlg->GetPath();
00740 
00741         Control_Select newcontrol(string(file.mb_str()));
00742         Dynamics *dynamics;
00743         dynamics = Dynamics::Instance();
00744         if (dynamics)
00745         {
00746             dynamics->set_controller(newcontrol);
00747 
00748             wxString tempstr;
00749             switch (newcontrol.type)
00750             {
00751                 case PD:
00752                     tempstr = _("Proportional Derivative");
00753                     break;
00754                 case CTM:
00755                     tempstr = _("Computed Torque Method");
00756                     break;
00757                 case RRA:
00758                     tempstr = _("Resolve Rate Acceleration");
00759                     break;
00760                 default:
00761                     tempstr = _T("");
00762                     break;
00763             }
00764 
00765             LogTexte = wxString(_("Controller")) + _T(": ") + tempstr;
00766             wxLogMessage(LogTexte);
00767         }
00768         m_Btn_Select_Trajectory->Enable(TRUE);
00769     }
00770     dlg->Destroy();
00771 }
00772 
00773 void DynControlPanel::OnSelectTrajectory(wxCommandEvent& event)
00774 {
00775     wxString path, file, trajectoryName, path_GLroboop;
00776     wxFileDialog *dlg = new wxFileDialog(this, _("Choose a file"), wxGetCwd()+_T("/trajectory/"), _T(""),  _T("*.*"),  
00777                                          wxOPEN, wxDefaultPosition);
00778 
00779 
00780     if(dlg->ShowModal() == wxID_OK)
00781     {
00782         file = dlg->GetPath();
00783         trajectoryName= dlg->GetFilename();
00784         trajectoryName.Replace(_T(".conf"), _T(""), true);
00785 
00786         Trajectory_Select newtrajectory(string(file.mb_str()));
00787         Dynamics *dynamics;
00788         dynamics = Dynamics::Instance();
00789         if (dynamics)
00790         {
00791             dynamics->set_trajectory(newtrajectory);
00792             dynamics->reset_time();
00793 
00794             wxString tempstr;
00795             switch (newtrajectory.type)
00796             {
00797                 case JOINT_SPACE:
00798                     tempstr = _("Joint Space");
00799                     break;
00800                 case CARTESIAN_SPACE:
00801                     tempstr = _("Cartesian Space");
00802                     break;
00803                 default:
00804                     tempstr = _T("");
00805                     break;
00806             }
00807             LogTexte = wxString(_("Trajectory")) + _T(": ") + tempstr;
00808             wxLogMessage(LogTexte);
00809 
00810             // Erase the contant in the box log.
00811 //          wxString choices[1] = "allo";
00812 //          m_lboxLog->Set(1, choices, NULL);
00813         }
00814 
00815     }
00816     dlg->Destroy();
00817 }
00818 
00819 /*
00820 void DynControlPanel::OnReset(wxCommandEvent& event)
00821 {
00822   m_Btn_Start->Enable(TRUE);
00823   m_Btn_Stop->Enable(FALSE);
00824   m_Btn_Select_Controller->Enable(TRUE);
00825   m_Btn_Select_Trajectory->Enable(FALSE);
00826 
00827  Faire un reset du controleur et de la trajectoire
00828 }
00829 */
00830 
00831 void DynControlPanel::OnStart(wxCommandEvent& event)
00832 {
00833   m_Btn_Start->Enable(FALSE);
00834   m_Btn_Stop->Enable(TRUE);
00835   m_Btn_Select_Controller->Enable(FALSE);
00836   m_Btn_Select_Trajectory->Enable(FALSE);
00837 
00838   Canvas3D *ptrCanvas3D = Canvas3D::Instance();
00839   if(ptrCanvas3D)
00840     ptrCanvas3D->Start();
00841 }
00842 
00843 void DynControlPanel::OnStop(wxCommandEvent& event)
00844 {
00845   m_Btn_Start->Enable(TRUE);
00846   m_Btn_Stop->Enable(FALSE);
00847   m_Btn_Select_Controller->Enable(TRUE);
00848   m_Btn_Select_Trajectory->Enable(TRUE);
00849 
00850   Canvas3D *ptrCanvas3D = Canvas3D::Instance();
00851   if(ptrCanvas3D)
00852     ptrCanvas3D->Stop();
00853 }
00854 
00855 void DynControlPanel::UpdateData()
00856 {
00857 }
00858 
00859 void DynControlPanel::Update(Subject *TheChangedSubject)
00860 {
00861     UpdateData();
00862 }
00863 
00864 void DynControlPanel::set_active_ListBox()
00865 {
00866     wxLog::SetActiveTarget(m_logTarget);
00867 }
00868 
00869 

Generated on Fri Feb 9 08:52:20 2007 for GLroboop An OpenGL Robotics Object Oriented Package in C++ by  doxygen 1.5.1