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 #include "plannerdlg.h"
00028
00029 #include <QLineEdit>
00030 #include <QFileDialog>
00031 #include <QValidator>
00032
00033 #include "robot.h"
00034 #include "mainWindow.h"
00035 #include "graspitGUI.h"
00036 #include "grasp_manager.h"
00037 #include "grasp_tester.h"
00038 #include "grasp_planner.h"
00039 #include "grasp.h"
00040 #include "world.h"
00041 #include "ivmgr.h"
00042 #include "quality.h"
00043 #include "mytools.h"
00044
00053 void PlannerDlg::init()
00054 {
00055 Grasp *grasp;
00056 int a,b,c,d,e;
00057 int density;
00058 double f;
00059 int i;
00060
00061 myGraspManager = new grasp_manager;
00062 myGraspManager->get_graspPlanner()->get_planningParameters(a,b,c,d);
00063 myGraspManager->get_graspTester()->get_testingParameters(e,f);
00064 density = myGraspManager->get_graspPlanner()->get_parameterMode();
00065
00066 densityFactorLine->setText(QString::number(density));
00067 densityFactorLine->setValidator(new QIntValidator(1,100,this));
00068
00069 num360stepsLine->setText(QString::number(a));
00070 num360stepsLine->setValidator(new QIntValidator(1,999,this));
00071
00072 numParPlanesLine->setText(QString::number(b));
00073 numParPlanesLine->setValidator(new QIntValidator(1,999,this));
00074
00075 num180graspsLine->setText(QString::number(c));
00076 num180graspsLine->setValidator(new QIntValidator(1,999,this));
00077
00078 numGraspRotsLine->setText(QString::number(d));
00079 numGraspRotsLine->setValidator(new QIntValidator(1,999,this));
00080
00081 maxNumStepsLine->setText(QString::number(e));
00082 maxNumStepsLine->setValidator(new QIntValidator(1,999,this));
00083
00084 backstepSizeLine->setText(QString::number(f));
00085 backstepSizeLine->setValidator(new QDoubleValidator(0,1000,6,this));
00086
00087 qmComboBox->clear();
00088 grasp = graspItGUI->getIVmgr()->getWorld()->getCurrentHand()->getGrasp();
00089 if (grasp->getNumQM() == 0) GenerateButton->setEnabled(false);
00090 else {
00091 for (i=0;i<grasp->getNumQM();i++)
00092 qmComboBox->insertItem(grasp->getQM(i)->getName());
00093 }
00094 }
00095
00099 void PlannerDlg::destroy()
00100 {
00101 delete myGraspManager;
00102 if (masterFile.isOpen()) masterFile.close();
00103 }
00104
00113 void PlannerDlg::generateGrasps()
00114 {
00115 int a,b,c,d,e;
00116 double f;
00117 int density;
00118
00119 if (automaticCheckBox->isChecked()) {
00120 density = densityFactorLine->text().toInt();
00121 myGraspManager->get_graspPlanner()->set_parameterMode(density);
00122 }
00123 else {
00124 a = num360stepsLine->text().toInt();
00125 b = numParPlanesLine->text().toInt();
00126 c = num180graspsLine->text().toInt();
00127 d = numGraspRotsLine->text().toInt();
00128 myGraspManager->get_graspPlanner()->set_parameterMode(0);
00129 myGraspManager->get_graspPlanner()->set_planningParameters(a,b,c,d);
00130 }
00131 e = maxNumStepsLine->text().toInt();
00132 f = backstepSizeLine->text().toDouble();
00133
00134 myGraspManager->get_graspTester()->set_testingParameters(e,f);
00135 myGraspManager->get_graspTester()->
00136 useQM(qmComboBox->currentItem());
00137 myGraspManager->set_render(visualizeBox->isChecked());
00138
00139 if (automaticCheckBox->isChecked() || filenameLineEdit->text().isEmpty()) {
00140 myGraspManager->generateGrasps();
00141 QObject::connect(myGraspManager->get_graspTester(),SIGNAL(testingComplete()),
00142 this,SLOT(enableShowButton()));
00143 }
00144 else {
00145 if (filenameLineEdit->text().contains("master.txt")) {
00146 masterFile.setName(filenameLineEdit->text());
00147 if (!masterFile.open(QIODevice::ReadOnly)) {
00148 QTWARNING("Could not open master grasp file");
00149 return;
00150 }
00151 stream.setDevice( &masterFile );
00152
00153 QObject::connect(myGraspManager->get_graspTester(),SIGNAL(testingComplete()),
00154 this,SLOT(testGrasps()));
00155 }
00156 else if (myGraspManager->
00157 readCandidateGraspsFile(filenameLineEdit->text())) {
00158 QTWARNING("Could not read grasps from file.");
00159 QObject::connect(myGraspManager->get_graspTester(),SIGNAL(testingComplete()),
00160 this,SLOT(enableShowButton()));
00161 return;
00162 }
00163 }
00164 TestButton->setEnabled(true);
00165 }
00166
00170 void PlannerDlg::showGrasp()
00171 {
00172 myGraspManager->showGrasps(1);
00173 }
00174
00181 void PlannerDlg::newQM()
00182 {
00183 Grasp *grasp=graspItGUI->getIVmgr()->getWorld()->getCurrentHand()->getGrasp();
00184 graspItGUI->getMainWindow()->graspQualityMeasures();
00185 if (grasp->getNumQM()>0) GenerateButton->setEnabled(true);
00186 qmComboBox->clear();
00187 for (int i=0;i<grasp->getNumQM();i++)
00188 qmComboBox->insertItem(grasp->getQM(i)->getName());
00189 }
00190
00195 void PlannerDlg::chooseFile()
00196 {
00197 QString fn(QFileDialog::getOpenFileName(this, QString(), QString(getenv("GRASPIT")), "Text Files (*.txt)") );
00198 if ( !fn.isEmpty() )
00199 filenameLineEdit->setText(fn);
00200 }
00201
00206 void PlannerDlg::chooseSaveFile()
00207 {
00208 QString fn( QFileDialog::getSaveFileName(this, QString(), QString(getenv("GRASPIT")), "Text Files (*.txt)") );
00209 if ( !fn.isEmpty() )
00210 savefileLineEdit->setText(fn);
00211 }
00212
00217 void PlannerDlg::testGrasps()
00218 {
00219 QString planFilename,quadFilename;
00220 World *world = graspItGUI->getIVmgr()->getWorld();
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 if (!masterFile.isOpen()) {
00235 if (!savefileLineEdit->text().isEmpty())
00236 myGraspManager->get_graspTester()->
00237 saveGraspsToFile(savefileLineEdit->text(),false);
00238
00239
00240 myGraspManager->testGrasps();
00241 }
00242 else {
00243
00244 if (stream.atEnd()) {
00245 masterFile.close();
00246 return;
00247 }
00248
00249 if (!savefileLineEdit->text().isEmpty())
00250 myGraspManager->get_graspTester()->
00251 saveGraspsToFile(savefileLineEdit->text(),true);
00252
00253 if (world->getNumGB() > 0)
00254 world->destroyElement(world->getGB(0));
00255 stream >> quadFilename >> planFilename; stream.readLine();
00256
00257
00258 world->importBody("GraspableBody",quadFilename);
00259 world->getHand(0)->getGrasp()->setObject(world->getGB(0));
00260
00261 QFile logfile("grasplog.txt");
00262 if (logfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
00263 QTextStream lout(&logfile);
00264 lout << "Evaluating grasps of "<<
00265 world->getGB(0)->getName() << endl;
00266 logfile.close();
00267 }
00268
00269 if (myGraspManager->
00270 readCandidateGraspsFile(planFilename)) {
00271 QTWARNING("Could not read grasps from file.");
00272 masterFile.close();
00273 return;
00274 }
00275
00276 myGraspManager->testGrasps();
00277 }
00278
00279
00280 }
00281
00285 void PlannerDlg::enableShowButton()
00286 {
00287 ShowButton->setEnabled(true);
00288 }