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
00034
00035
00036
00037
00038 #include "setup_screen_widget.h"
00039 #include "setup_assistant_widget.h"
00040
00041 #include <QStackedLayout>
00042 #include <QListWidget>
00043 #include <QListWidgetItem>
00044 #include <QDebug>
00045 #include <QFont>
00046 #include <QLabel>
00047 #include <QPushButton>
00048 #include <QCloseEvent>
00049 #include <QMessageBox>
00050 #include <pluginlib/class_loader.h>
00051
00052 #include <rviz/render_panel.h>
00053 #include <rviz/visualization_manager.h>
00054 #include <rviz/view_manager.h>
00055 #include <rviz/default_plugin/view_controllers/orbit_view_controller.h>
00056 #include <moveit/robot_state_rviz_plugin/robot_state_display.h>
00057
00058 namespace moveit_setup_assistant
00059 {
00060
00061
00062
00063
00064 SetupAssistantWidget::SetupAssistantWidget( QWidget *parent, boost::program_options::variables_map args )
00065 : QWidget( parent )
00066 {
00067 rviz_manager_ = NULL;
00068 rviz_render_panel_ = NULL;
00069
00070
00071 config_data_.reset( new MoveItConfigData() );
00072
00073
00074 if (args.count("debug"))
00075 config_data_->debug_ = true;
00076
00077
00078 QHBoxLayout *layout = new QHBoxLayout();
00079 layout->setAlignment( Qt::AlignTop );
00080
00081
00082 main_content_ = new QStackedLayout();
00083 current_index_ = 0;
00084
00085
00086 middle_frame_ = new QWidget( this );
00087 middle_frame_->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
00088 middle_frame_->setLayout( main_content_ );
00089
00090
00091
00092
00093 ssw_ = new StartScreenWidget( this, config_data_ );
00094 ssw_->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
00095 connect( ssw_, SIGNAL( readyToProgress() ), this, SLOT( progressPastStartScreen() ) );
00096 connect( ssw_, SIGNAL( loadRviz() ), this, SLOT( loadRviz() ) );
00097 main_content_->addWidget(ssw_);
00098
00099
00100 if (args.count( "urdf_path" ))
00101 {
00102 ssw_->urdf_file_->setPath( args["urdf_path"].as<std::string>() );
00103 }
00104 if (args.count( "config_pkg" ))
00105 {
00106 ssw_->stack_path_->setPath( args["config_pkg"].as<std::string>() );
00107
00108
00109 ssw_->select_mode_->btn_exist_->click();
00110 }
00111
00112
00113 nav_name_list_ << "Start";
00114 nav_name_list_ << "Self-Collisions";
00115 nav_name_list_ << "Virtual Joints";
00116 nav_name_list_ << "Planning Groups";
00117 nav_name_list_ << "Robot Poses";
00118 nav_name_list_ << "End Effectors";
00119 nav_name_list_ << "Passive Joints";
00120 nav_name_list_ << "Configuration Files";
00121
00122
00123 navs_view_ = new NavigationWidget( this );
00124 navs_view_->setNavs(nav_name_list_);
00125 navs_view_->setDisabled( true );
00126 navs_view_->setSelected( 0 );
00127
00128
00129 rviz_container_ = new QWidget( this );
00130 rviz_container_->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
00131 rviz_container_->hide();
00132
00133
00134 splitter_ = new QSplitter( Qt::Horizontal, this );
00135 splitter_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00136 splitter_->addWidget( navs_view_ );
00137 splitter_->addWidget( middle_frame_ );
00138 splitter_->addWidget( rviz_container_ );
00139 splitter_->setHandleWidth( 6 );
00140
00141 layout->addWidget( splitter_ );
00142
00143
00144 connect( navs_view_, SIGNAL(clicked(const QModelIndex&)), this, SLOT(navigationClicked(const QModelIndex&)) );
00145
00146
00147 this->setLayout(layout);
00148
00149
00150 this->setWindowTitle("MoveIt Setup Assistant");
00151
00152
00153 QApplication::processEvents();
00154 }
00155
00156
00157
00158
00159 SetupAssistantWidget::~SetupAssistantWidget()
00160 {
00161 if( rviz_manager_ != NULL )
00162 rviz_manager_->removeAllDisplays();
00163 if ( rviz_render_panel_ != NULL )
00164 delete rviz_render_panel_;
00165 if ( rviz_manager_ != NULL )
00166 delete rviz_manager_;
00167 }
00168
00169 void SetupAssistantWidget::virtualJointReferenceFrameChanged()
00170 {
00171 if (rviz_manager_ && robot_state_display_)
00172 {
00173 rviz_manager_->setFixedFrame( QString::fromStdString( config_data_->getRobotModel()->getModelFrame() ) );
00174 robot_state_display_->reset();
00175 }
00176 }
00177
00178
00179
00180
00181 void SetupAssistantWidget::navigationClicked( const QModelIndex& index )
00182 {
00183
00184 moveToScreen( index.row() );
00185 }
00186
00187
00188
00189
00190 void SetupAssistantWidget::moveToScreen( const int index )
00191 {
00192 boost::mutex::scoped_lock slock(change_screen_lock_);
00193
00194 if( current_index_ != index )
00195 {
00196 current_index_ = index;
00197
00198
00199 unhighlightAll();
00200
00201
00202 main_content_->setCurrentIndex( index );
00203
00204
00205 SetupScreenWidget *ssw = qobject_cast< SetupScreenWidget* >( main_content_->widget( index ) );
00206 ssw->focusGiven();
00207
00208
00209 navs_view_->setSelected( index );
00210 }
00211 }
00212
00213
00214
00215
00216 void SetupAssistantWidget::progressPastStartScreen()
00217 {
00218
00219
00220
00221 dcw_ = new DefaultCollisionsWidget( this, config_data_);
00222 main_content_->addWidget( dcw_ );
00223 connect( dcw_, SIGNAL( highlightLink( const std::string& ) ), this, SLOT( highlightLink( const std::string& ) ) );
00224 connect( dcw_, SIGNAL( highlightGroup( const std::string& ) ), this, SLOT( highlightGroup( const std::string& ) ) );
00225 connect( dcw_, SIGNAL( unhighlightAll() ), this, SLOT( unhighlightAll() ) );
00226
00227
00228 vjw_ = new VirtualJointsWidget( this, config_data_ );
00229 main_content_->addWidget(vjw_);
00230 connect( vjw_, SIGNAL( isModal( bool ) ), this, SLOT( setModalMode( bool ) ) );
00231 connect( vjw_, SIGNAL( highlightLink( const std::string& ) ), this, SLOT( highlightLink( const std::string& ) ) );
00232 connect( vjw_, SIGNAL( highlightGroup( const std::string& ) ), this, SLOT( highlightGroup( const std::string& ) ) );
00233 connect( vjw_, SIGNAL( unhighlightAll() ), this, SLOT( unhighlightAll() ) );
00234 connect( vjw_, SIGNAL( referenceFrameChanged() ), this, SLOT( virtualJointReferenceFrameChanged() ) );
00235
00236
00237 pgw_ = new PlanningGroupsWidget( this, config_data_ );
00238 main_content_->addWidget(pgw_);
00239 connect( pgw_, SIGNAL( isModal( bool ) ), this, SLOT( setModalMode( bool ) ) );
00240 connect( pgw_, SIGNAL( highlightLink( const std::string& ) ), this, SLOT( highlightLink( const std::string& ) ) );
00241 connect( pgw_, SIGNAL( highlightGroup( const std::string& ) ), this, SLOT( highlightGroup( const std::string& ) ) );
00242 connect( pgw_, SIGNAL( unhighlightAll() ), this, SLOT( unhighlightAll() ) );
00243
00244
00245 rpw_ = new RobotPosesWidget( this, config_data_ );
00246 main_content_->addWidget(rpw_);
00247 connect( rpw_, SIGNAL( isModal( bool ) ), this, SLOT( setModalMode( bool ) ) );
00248 connect( rpw_, SIGNAL( highlightLink( const std::string& ) ), this, SLOT( highlightLink( const std::string& ) ) );
00249 connect( rpw_, SIGNAL( highlightGroup( const std::string& ) ), this, SLOT( highlightGroup( const std::string& ) ) );
00250 connect( rpw_, SIGNAL( unhighlightAll() ), this, SLOT( unhighlightAll() ) );
00251
00252
00253 efw_ = new EndEffectorsWidget( this, config_data_ );
00254 main_content_->addWidget(efw_);
00255 connect( efw_, SIGNAL( isModal( bool ) ), this, SLOT( setModalMode( bool ) ) );
00256 connect( efw_, SIGNAL( highlightLink( const std::string& ) ), this, SLOT( highlightLink( const std::string& ) ) );
00257 connect( efw_, SIGNAL( highlightGroup( const std::string& ) ), this, SLOT( highlightGroup( const std::string& ) ) );
00258 connect( efw_, SIGNAL( unhighlightAll() ), this, SLOT( unhighlightAll() ) );
00259
00260
00261 pjw_ = new PassiveJointsWidget( this, config_data_ );
00262 main_content_->addWidget(pjw_);
00263 connect( pjw_, SIGNAL( isModal( bool ) ), this, SLOT( setModalMode( bool ) ) );
00264 connect( pjw_, SIGNAL( highlightLink( const std::string& ) ), this, SLOT( highlightLink( const std::string& ) ) );
00265 connect( pjw_, SIGNAL( highlightGroup( const std::string& ) ), this, SLOT( highlightGroup( const std::string& ) ) );
00266 connect( pjw_, SIGNAL( unhighlightAll() ), this, SLOT( unhighlightAll() ) );
00267
00268
00269 cfw_ = new ConfigurationFilesWidget( this, config_data_ );
00270 main_content_->addWidget(cfw_);
00271
00272
00273 for( int i = 0; i < nav_name_list_.count(); ++i)
00274 {
00275 navs_view_->setEnabled( i, true );
00276 }
00277
00278
00279 navs_view_->setDisabled( false );
00280
00281
00282 rviz_container_->show();
00283
00284
00285 if( config_data_->debug_)
00286 {
00287 moveToScreen(3);
00288 }
00289 }
00290
00291
00292
00293
00294 void SetupAssistantWidget::updateTimer()
00295 {
00296 ros::spinOnce();
00297 }
00298
00299
00300
00301
00302 void SetupAssistantWidget::loadRviz()
00303 {
00304
00305 rviz_render_panel_ = new rviz::RenderPanel();
00306 rviz_render_panel_->setMinimumWidth( 200 );
00307 rviz_render_panel_->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
00308
00309 rviz_manager_ = new rviz::VisualizationManager( rviz_render_panel_ );
00310 rviz_render_panel_->initialize( rviz_manager_->getSceneManager(), rviz_manager_ );
00311 rviz_manager_->initialize();
00312 rviz_manager_->startUpdate();
00313
00314
00315 rviz_manager_->setFixedFrame( QString::fromStdString( config_data_->getRobotModel()->getModelFrame() ) );
00316
00317
00318 robot_state_display_ = new moveit_rviz_plugin::RobotStateDisplay();
00319 robot_state_display_->setName( "Robot State" );
00320
00321 rviz_manager_->addDisplay( robot_state_display_, true );
00322
00323
00324 robot_state_display_->subProp("Robot State Topic")->setValue(QString::fromStdString( MOVEIT_ROBOT_STATE ));
00325
00326
00327 robot_state_display_->subProp("Robot Description")->setValue(QString::fromStdString( ROBOT_DESCRIPTION ));
00328
00329
00330 rviz::ViewController* view = rviz_manager_->getViewManager()->getCurrent();
00331 view->subProp( "Distance" )->setValue( 4.0f );
00332
00333
00334 QHBoxLayout *rviz_layout = new QHBoxLayout();
00335 rviz_layout->addWidget( rviz_render_panel_ );
00336 rviz_container_->setLayout( rviz_layout );
00337
00338 rviz_container_->show();
00339 }
00340
00341
00342
00343
00344 void SetupAssistantWidget::highlightLink( const std::string& link_name )
00345 {
00346 const robot_model::LinkModel *lm = config_data_->getRobotModel()->getLinkModel(link_name);
00347 if (lm->getShape())
00348 robot_state_display_->setLinkColor( link_name, QColor(255, 0, 0) );
00349 }
00350
00351
00352
00353
00354 void SetupAssistantWidget::highlightGroup( const std::string& group_name )
00355 {
00356
00357 if (!config_data_->getRobotModel()->hasJointModelGroup( group_name ))
00358 return;
00359
00360 const robot_model::JointModelGroup *joint_model_group =
00361 config_data_->getRobotModel()->getJointModelGroup( group_name );
00362 if (joint_model_group)
00363 {
00364 const std::vector<const robot_model::LinkModel*> &link_models = joint_model_group->getLinkModels();
00365
00366 for( std::vector<const robot_model::LinkModel*>::const_iterator link_it = link_models.begin();
00367 link_it < link_models.end(); ++link_it )
00368 highlightLink( (*link_it)->getName() );
00369 }
00370 }
00371
00372
00373
00374
00375 void SetupAssistantWidget::unhighlightAll()
00376 {
00377
00378 const std::vector<std::string> &links = config_data_->getRobotModel()->getLinkModelNamesWithCollisionGeometry();
00379
00380
00381 if( links.empty() )
00382 {
00383 return;
00384 }
00385
00386
00387 if( !rviz_manager_ || !robot_state_display_)
00388 {
00389 return;
00390 }
00391
00392
00393 for( std::vector<std::string>::const_iterator link_it = links.begin();
00394 link_it < links.end(); ++link_it )
00395 {
00396 if( (*link_it).empty() )
00397 continue;
00398
00399 robot_state_display_->unsetLinkColor( *link_it );
00400 }
00401
00402 }
00403
00404
00405
00406
00407 void SetupAssistantWidget::closeEvent( QCloseEvent * event )
00408 {
00409
00410 if( !config_data_->debug_ )
00411 {
00412 if( QMessageBox::question( this, "Exit Setup Assistant",
00413 QString("Are you sure you want to exit the MoveIt Setup Assistant?"),
00414 QMessageBox::Ok | QMessageBox::Cancel)
00415 == QMessageBox::Cancel )
00416 {
00417 event->ignore();
00418 return;
00419 }
00420 }
00421
00422
00423 event->accept();
00424 }
00425
00426
00427
00428
00429 bool SetupAssistantWidget::notify( QObject * reciever, QEvent * event )
00430 {
00431 QMessageBox::critical( this, "Error", "An error occurred and was caught by Qt notify event handler.", QMessageBox::Ok);
00432
00433 return false;
00434 }
00435
00436
00437
00438
00439 void SetupAssistantWidget::setModalMode( bool isModal )
00440 {
00441 navs_view_->setDisabled( isModal );
00442
00443 for( int i = 0; i < nav_name_list_.count(); ++i)
00444 {
00445 navs_view_->setEnabled( i, !isModal );
00446 }
00447 }
00448
00449
00450 }