00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <wx/stattext.h>
00034 #include <wx/statline.h>
00035 #include <wx/checkbox.h>
00036
00037
00038 #include "skin_dashboard/user_interface.h"
00039 #include "skin_dashboard/skin.h"
00040
00041 #include <math.h>
00042 #include <iostream>
00043
00044
00045
00046
00047
00048 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size): wxFrame( NULL, -1, title, pos, size )
00049 {
00050
00051 timer_ = new wxTimer(this, skin_id::ID_TIMER);
00052 timer_->Start(250);
00053 Connect(skin_id::ID_TIMER, wxEVT_TIMER, wxTimerEventHandler(MyFrame::gridUpdate), NULL, this);
00054
00055
00056 menubar = new wxMenuBar;
00057 file = new wxMenu;
00058 file->Append(skin_id::ID_About, wxT("&About..."));
00059 file->AppendSeparator();
00060 file->Append(wxID_EXIT, wxT("&Quit"));
00061 menubar->Append(file, wxT("&File"));
00062 SetMenuBar(menubar);
00063
00064 Connect(skin_id::ID_About, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnAbout));
00065 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnQuit));
00066
00067
00068 wxPanel *panel = new wxPanel(this, -1);
00069
00070
00071
00072 wxStaticText *headline = new wxStaticText(panel, -1, wxT("Sensor Skin Monitor"),wxPoint(15,15));
00073
00074 wxFont headline_font = headline->GetFont();
00075 headline_font.SetWeight(wxBOLD);
00076 headline_font.SetPointSize(15);
00077 headline->SetFont(headline_font);
00078
00079
00080
00081
00082
00083 const wxString col_title_[18] = {wxT("Adr"),wxT("Stat"),wxT("X"),wxT("Ini"),wxT("Limit"),wxT("U1"),wxT("U2"),wxT("U3"),wxT("Dyn"),wxT(""),wxT("SE-NR."),wxT(""),wxT("A"),wxT("B"),wxT("C"),wxT("D"),wxT("E")};
00084 grid = new wxGrid(panel, wxID_ANY, wxPoint(30,85), wxSize(699, 770));
00085 grid->CreateGrid(skind_def::max_sensor_number, 16);
00086
00087 grid->SetColLabelSize(30);
00088 grid->SetRowLabelSize(50);
00089
00090 wxColour label_background_colour;
00091 label_background_colour = grid->GetLabelBackgroundColour();
00092
00093 for(int i = 0; i < skind_def::max_sensor_number ; i++)
00094 {
00095 grid->SetRowSize(i, 20);
00096 grid->SetCellBackgroundColour(i, 8, label_background_colour);
00097 grid->SetCellBackgroundColour(i, 10, label_background_colour);
00098 grid->SetCellBackgroundColour(i, 9, *wxWHITE);
00099 for(int j = 0; j < 16; j++)
00100 {
00101 grid->SetCellAlignment(i, j, wxALIGN_CENTRE, wxALIGN_CENTRE);
00102 }
00103 }
00104
00105 for(int j = 0; j < 8 ; j++)
00106 {
00107 grid->SetColSize(j, 50);
00108 }
00109
00110 grid->SetColSize(8, 25);
00111 grid->SetColSize(9, 80);
00112 grid->SetColSize(10, 25);
00113
00114 for(int i = 11 ; i < 16 ; i++)
00115 {
00116 grid->SetColSize(i, 20);
00117 }
00118
00119
00120 for(int k = 0; k < 16; k++)
00121 {
00122 grid->SetColLabelValue((k),col_title_[k+1]);
00123 }
00124
00125
00126 for(int i = 0; i < skin_dat_.u8sensor_number_ ; i++)
00127 {
00128 grid->SetCellValue(i,9,wxString::Format(wxT("%i"),i+1));
00129 grid->SetCellTextColour(i,9,wxColour(255,255,0));
00130 }
00131
00132
00133 grid->EnableEditing(false);
00134 grid->EnableDragRowSize(false);
00135 grid->EnableDragColSize(false);
00136
00137
00138 grid->SetScrollLineY(20);
00139
00140
00141 wxPoint first_cell_point;
00142 first_cell_point = grid->GetPosition();
00143 wxSize first_cell_size;
00144 first_cell_size.Set(grid->GetRowLabelSize(), grid->GetColLabelSize());
00145 wxColour background_colour = grid->GetLabelBackgroundColour();
00146
00147 wxPanel *cover_first_cell = new wxPanel(panel, wxID_ANY, first_cell_point, first_cell_size, wxSUNKEN_BORDER);
00148 cover_first_cell->SetBackgroundColour(background_colour);
00149
00150 wxStaticText *first_cell_text = new wxStaticText(cover_first_cell, -1, col_title_[0],wxPoint(10, 5), wxDefaultSize);
00151
00152 wxFont grid_label_font = grid->GetLabelFont();
00153 first_cell_text->SetFont(grid_label_font);
00154
00155
00156 wxPanel *cover_col8 = new wxPanel(panel, wxID_ANY, wxPoint(479, first_cell_point.y+28), wxSize(grid->GetColSize(8)+1,grid->GetRowSize(0)*38 + 10 - 28), wxSUNKEN_BORDER);
00157 cover_col8->SetBackgroundColour(background_colour);
00158
00159
00160 wxPanel *cover_col10 = new wxPanel(panel, wxID_ANY, wxPoint(479 + grid->GetColSize(8) + grid->GetColSize(9), first_cell_point.y+28), wxSize(grid->GetColSize(8)+1,grid->GetRowSize(0)*38 + 10 - 28), wxSUNKEN_BORDER);
00161 cover_col10->SetBackgroundColour(background_colour);
00162
00163
00164 wxPanel *textlabel_x_col_bar = new wxPanel(panel, wxID_ANY, wxPoint(479 + grid->GetColSize(8),first_cell_point.y - grid->GetColLabelSize()), wxSize(grid->GetColSize(9) + 1, grid->GetColLabelSize()), wxSUNKEN_BORDER);
00165 textlabel_x_col_bar->SetBackgroundColour(background_colour);
00166
00167 wxStaticText *text_x_col_bar = new wxStaticText(textlabel_x_col_bar, -1, wxT("X Col.Bar"),wxPoint(3, 5), wxDefaultSize);
00168
00169 text_x_col_bar->SetFont(grid_label_font);
00170
00171
00172 wxPanel *textlabel_errorbar = new wxPanel(panel, wxID_ANY, wxPoint(479 + grid->GetColSize(8) + grid->GetColSize(9)+ grid->GetColSize(10),first_cell_point.y - grid->GetColLabelSize()), wxSize(grid->GetColSize(11)*5 + 1, grid->GetColLabelSize()), wxSUNKEN_BORDER);
00173 textlabel_errorbar->SetBackgroundColour(background_colour);
00174
00175 wxStaticText *text_errorbar = new wxStaticText(textlabel_errorbar, -1, wxT("ErrorBar"),wxPoint(16, 5), wxDefaultSize);
00176
00177 text_errorbar->SetFont(grid_label_font);
00178
00179
00180 wxCheckBox *cb_hex_dec = new wxCheckBox(panel, skin_id::ID_HEX, wxT("Hex"), wxPoint(100,55), wxDefaultSize);
00181 Connect(skin_id::ID_HEX, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(MyFrame::OnCheck));
00182 cb_hex_dec->SetValue(false);
00183 bhex_ = cb_hex_dec->GetValue();
00184
00185
00186 wxStaticText *text_status = new wxStaticText(panel, -1, wxT("Status:"),wxPoint(200, 57), wxDefaultSize);
00187 text_status->SetFont(grid_label_font);
00188
00189 text_go_nogo = new wxStaticText(panel, -1, wxT(""),wxPoint(270, 57), wxDefaultSize, wxALIGN_CENTRE);
00190 text_err_noerr = new wxStaticText(panel, -1, wxT(""),wxPoint(320, 57), wxDefaultSize, wxALIGN_CENTRE);
00191
00192
00193
00194
00195 for(int k = 0; k < skind_def::max_sensor_number; k++)
00196 {
00197 if(bhex_)
00198 {
00199 grid->SetRowLabelValue(k,hexadezimal(skin_dat_.u8readadr_lo_+256*skin_dat_.u8readadr_hi_+skind_def::anz_byte_per_sensor*k));
00200 }
00201 else
00202 {
00203 grid->SetRowLabelValue(k, wxString::Format(wxT("%i"),(skin_dat_.u8readadr_lo_+256*skin_dat_.u8readadr_hi_+skind_def::anz_byte_per_sensor*k)));
00204 }
00205 }
00206
00207
00208 publish_data_2_gui();
00209
00210 Centre();
00211
00212 }
00213
00214
00215 void MyFrame::gridUpdate(wxTimerEvent& evt)
00216 {
00217 ros::spinOnce();
00218 std::cout << "OneUpdate" << " \n";
00219 publish_data_2_gui();
00220
00221 if (!ros::ok())
00222 {
00223 Close();
00224 }
00225 }
00226
00227
00228 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
00229 {
00230 Close(true);
00231 }
00232
00233
00234 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
00235 {
00236 wxMessageBox( wxT("..... text text text ....."), wxT("Sensor Skin Monitor"), wxICON_INFORMATION, this );
00237 }
00238
00239
00240 void MyFrame::OnCheck(wxCommandEvent& event)
00241 {
00242 if(bhex_)
00243 {
00244 bhex_ = false;
00245 }
00246 else
00247 {
00248 bhex_ = true;
00249 }
00250 }
00251
00252
00253 wxString MyFrame::hexadezimal(uint32_t conv_value)
00254 {
00255 const wxString ziffern[16] = {wxT("0"),wxT("1"),wxT("2"),wxT("3"),wxT("4"),wxT("5"),wxT("6"),wxT("7"),wxT("8"),wxT("9"),wxT("A"),wxT("B"),wxT("C"),wxT("D"),wxT("E"),wxT("F")};
00256 int i = 0;
00257 wxString ts;
00258
00259 ts = wxT("");
00260 for(i = 3 ; i >= 0 ; i--)
00261 {
00262 ts = ts + ziffern[((conv_value >> (4*i)) & (15))];
00263 }
00264 return ts;
00265 }
00266
00267
00268 void MyFrame::publish_data_2_gui()
00269 {
00270 std::cout << "publish_data_2_gui" << std::endl;
00271
00272
00273 if(skin_dat_.bsens_num_changed == true)
00274 {
00275 grid->ClearGrid();
00276 skin_dat_.bsens_num_changed = false;
00277
00278
00279 for(int i = 0; i < skind_def::max_sensor_number ; i++)
00280 {
00281 grid->SetCellValue(i,9,wxString::Format(wxT("%i"),i+1));
00282 grid->SetCellTextColour(i,9,wxColour(255,255,0));
00283 }
00284
00285
00286 for(int k = skin_dat_.u8sensor_number_; k < skind_def::max_sensor_number; k++)
00287 {
00288 grid->SetCellBackgroundColour(k, 9, *wxWHITE);
00289 grid->SetCellBackgroundColour(k, 11, *wxWHITE);
00290 grid->SetCellBackgroundColour(k, 12, *wxWHITE);
00291 grid->SetCellBackgroundColour(k, 13, *wxWHITE);
00292 grid->SetCellBackgroundColour(k, 14, *wxWHITE);
00293 grid->SetCellBackgroundColour(k, 15, *wxWHITE);
00294 }
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 ros::Time dcurrent_time = ros::Time::now();
00307 if( ( dcurrent_time > (skin_dat_.dtime_subscription_ + ros::Duration((ceil(float(skin_dat_.u8sensor_number_) / 32.0) -1 ) * 0.1 + 0.3))) )
00308 {
00309 skin_dat_.initialize_sensor_data();
00310
00311 text_go_nogo->SetLabel(wxT(""));
00312 text_err_noerr->SetLabel(wxT(""));
00313 }
00314 else
00315 {
00316
00317 if(skin_dat_.bstatus_go_ == true)
00318 {
00319 text_go_nogo->SetLabel(wxT("Go"));
00320 text_go_nogo->SetForegroundColour(*wxGREEN);
00321 }
00322 else
00323 {
00324 text_go_nogo->SetLabel(wxT("NoGo"));
00325 text_go_nogo->SetForegroundColour(*wxRED);
00326 }
00327
00328 if(skin_dat_.bstatus_err_ == false)
00329 {
00330 text_err_noerr->SetLabel(wxT("NoErr"));
00331 text_err_noerr->SetForegroundColour(*wxGREEN);
00332 }
00333 else
00334 {
00335 text_err_noerr->SetLabel(wxT("Err"));
00336 text_err_noerr->SetForegroundColour(*wxRED);
00337 }
00338 }
00339
00340
00341 for(int l = 0; l < skind_def::max_sensor_number; l++)
00342 {
00343 if(bhex_)
00344 {
00345 grid->SetRowLabelValue(l,hexadezimal(skin_dat_.u8readadr_lo_+256*skin_dat_.u8readadr_hi_+skind_def::anz_byte_per_sensor*l));
00346 }
00347 else
00348 {
00349 grid->SetRowLabelValue(l, wxString::Format(wxT("%i"),(skin_dat_.u8readadr_lo_+256*skin_dat_.u8readadr_hi_+skind_def::anz_byte_per_sensor*l)));
00350 }
00351 }
00352
00353 for(int k = 0; k < skin_dat_.u8sensor_number_; k++)
00354 {
00355
00356 for(int j = 0; j < 8; j++)
00357 {
00358
00359 if(bhex_)
00360 {
00361 grid->SetCellValue(k,j,hexadezimal(skin_dat_.u8asensor_data_[k][j]));
00362 }
00363 else
00364 {
00365 grid->SetCellValue(k,j,wxString::Format(wxT("%i"),skin_dat_.u8asensor_data_[k][j]));
00366 }
00367 }
00368
00369
00371
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391 berrcond_[0] = ( (skin_dat_.u8asensor_data_[k][5]) > 32 );
00392 berrcond_[1] = ( (skin_dat_.u8asensor_data_[k][6]) < 16 );
00393 berrcond_[2] = ( ((skin_dat_.u8asensor_data_[k][6]) - (skin_dat_.u8asensor_data_[k][4])) < 16 );
00394 berrcond_[3] = ( ((skin_dat_.u8asensor_data_[k][0]) & 16) > 0 );
00395 berrcond_[4] = ( ((skin_dat_.u8asensor_data_[k][0]) & 32) > 0 );
00396
00397 wxColour errcol;
00398
00399 for(int i = 0; i < 5; i++)
00400 {
00401 errcol = *wxWHITE;
00402 if((skin_dat_.u8sensor_number_ > 0) & (skin_dat_.u8sensor_number_ <= skind_def::max_sensor_number))
00403 {
00404 if( ((skin_dat_.u8asensor_data_[k][0]) & 1) == 1)
00405 {
00406 if(berrcond_[i])
00407 {
00408 errcol = *wxRED;
00409 }
00410 else
00411 {
00412 errcol = *wxGREEN;
00413 }
00414 }
00415 grid->SetCellBackgroundColour(k, i + 11, errcol);
00416 }
00417 }
00418
00419
00420
00421
00422
00423
00425
00427
00428 float tr;
00429 wxColour statcol;
00430
00431 if((skin_dat_.u8asensor_data_[k][3]) != 0)
00432 {
00433 tr = float ( (skin_dat_.u8asensor_data_[k][1]) - (skin_dat_.u8asensor_data_[k][2]) ) / float (skin_dat_.u8asensor_data_[k][3]);
00434 }
00435 else
00436 {
00437 tr = 2;
00438 }
00439
00440
00441 if(tr > 0)
00442 {
00443 if(tr > 1)
00444 {
00445 tr = 1;
00446 }
00447 statcol.Set(int (tr * 255)*65536);
00448 grid->SetCellBackgroundColour(k, 9, statcol);
00449 }
00450 else
00451 {
00452 tr = -tr;
00453 if(tr > 1)
00454 {
00455 tr = 1;
00456 }
00457 statcol.Set(int (tr * 255));
00458 grid->SetCellBackgroundColour(k, 9, statcol);
00459 }
00460 }
00461
00462 grid->ForceRefresh();
00463 }
00464
00465
00466
00467
00468
00469
00470
00471