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 #include "gfoDlg.h"
00027
00028 #include <QInputDialog>
00029
00030 #include "graspitGUI.h"
00031 #include "ivmgr.h"
00032 #include "robot.h"
00033 #include "grasp.h"
00034 #include "body.h"
00035 #include "matrix.h"
00036 #include "mainWindow.h"
00037
00038
00039 #include "mcGrip.h"
00040 #include "humanHand.h"
00041
00042 #include "debug.h"
00043
00044 #define PROF_ENABLED
00045 #include "profiling.h"
00046
00047 GFODlg::GFODlg(MainWindow *mw, Hand *h, QWidget *parent) : mMainWindow(mw), mHand(h), QDialog(parent)
00048 {
00049 setupUi(this);
00050 statusLabel->setText("Status: optimization off");
00051 optimizationTypeBox->insertItem("Contact force existence");
00052 optimizationTypeBox->insertItem("Contact force optimization");
00053 optimizationTypeBox->insertItem("Grasp force existence");
00054 optimizationTypeBox->insertItem("Grasp force optimization");
00055 optimizationTypeBox->insertItem("Compliant joint equilibrium");
00056 optimizationTypeBox->insertItem("DOF force equilibrium");
00057 if (mHand->isA("McGrip")) {
00058 optimizationTypeBox->insertItem("McGrip tendon route");
00059 optimizationTypeBox->insertItem("McGrip joint equilibrium");
00060 }
00061 QObject::connect(exitButton, SIGNAL(clicked()), this, SLOT(exitButtonClicked()));
00062 QObject::connect(mHand, SIGNAL(configurationChanged()), this, SLOT(handConfigurationChanged()));
00063 QObject::connect(optimizationOnBox, SIGNAL(clicked()), this, SLOT(optimizationOnBoxClicked()));
00064 }
00065
00066 GFODlg::~GFODlg()
00067 {
00068 mMainWindow->clearContactsList();
00069 }
00070
00071 void
00072 GFODlg::optimizationOnBoxClicked()
00073 {
00074 if (!optimizationOnBox->isChecked()) {
00075 statusLabel->setText("Status: optimization off");
00076 } else {
00077 runOptimization();
00078 }
00079 }
00080
00081 void
00082 GFODlg::handConfigurationChanged()
00083 {
00084 if (!optimizationOnBox->isChecked()) {
00085 return;
00086 }
00087 runOptimization();
00088 }
00089
00090 void
00091 GFODlg::runOptimization()
00092 {
00093 mHand->getGrasp()->update();
00094 if (mHand->getGrasp()->getObject()) {
00095 mHand->getGrasp()->getObject()->resetExtWrenchAcc();
00096 }
00097
00098 if (optimizationTypeBox->currentText()=="Grasp force existence") {
00099 graspForceOptimization(Grasp::GRASP_FORCE_EXISTENCE);
00100 } else if (optimizationTypeBox->currentText()=="Grasp force optimization") {
00101 graspForceOptimization(Grasp::GRASP_FORCE_OPTIMIZATION);
00102 } else if (optimizationTypeBox->currentText()=="Contact force existence") {
00103 graspForceOptimization(Grasp::CONTACT_FORCE_EXISTENCE);
00104 } else if (optimizationTypeBox->currentText()=="Contact force optimization") {
00105 graspForceOptimization(Grasp::CONTACT_FORCE_OPTIMIZATION);
00106 } else if (optimizationTypeBox->currentText()=="Compliant joint equilibrium") {
00107 compliantEquilibriumOptimization(false);
00108 } else if (optimizationTypeBox->currentText()=="DOF force equilibrium") {
00109 compliantEquilibriumOptimization(true);
00110 } else if (optimizationTypeBox->currentText()=="McGrip tendon route") {
00111 tendonRouteOptimization();
00112 } else if (optimizationTypeBox->currentText()=="McGrip joint equilibrium") {
00113 mcgripEquilibrium();
00114 } else {
00115 DBGA("Unkown option selected in optimization box");
00116 }
00117 }
00118
00119 void
00120 GFODlg::displayResults(int result)
00121 {
00122 if (result < 0) {
00123 statusLabel->setText("Status: optimization error");
00124 mMainWindow->clearContactsList();
00125 } else if (result > 0) {
00126 mMainWindow->clearContactsList();
00127 statusLabel->setText("Status: problem unfeasible");
00128 } else {
00129 statusLabel->setText("Status: optimization successful");
00130 graspItGUI->getIVmgr()->drawDynamicForces();
00131
00132
00133 graspItGUI->getIVmgr()->drawUnbalancedForces();
00134 mMainWindow->updateContactsList();
00135 }
00136 }
00137
00138 void
00139 GFODlg::mcgripEquilibrium()
00140 {
00141 if (!mHand->isA("McGrip")) {
00142 DBGA("Hand is not a McGrip!");
00143 return;
00144 }
00145 int result = static_cast<McGrip*>(mHand)->jointTorqueEquilibrium();
00146 displayResults(result);
00147 }
00148
00149 void GFODlg::tendonRouteOptimization()
00150 {
00151 if (!mHand->isA("McGrip")) {
00152 DBGA("Hand is not a McGrip!");
00153 return;
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163 Matrix p(8,1);
00164 double obj;
00165 int result = static_cast<McGripGrasp*>(mHand->getGrasp())->tendonAndHandOptimization(&p, obj);
00166 DBGA("p matrix:\n" << p);
00167 displayResults(result);
00168
00169
00170
00171
00172
00173
00174
00175 }
00176
00177 void
00178 GFODlg::compliantEquilibriumOptimization(bool useDynamicDofForce)
00179 {
00180 Matrix tau(mHand->staticJointTorques(useDynamicDofForce));
00181 int result = mHand->getGrasp()->computeQuasistaticForces(tau);
00182 displayResults(result);
00183 }
00184
00185 void
00186 GFODlg::graspForceOptimization(int computation)
00187 {
00188 Matrix tau(Matrix::ZEROES<Matrix>(mHand->getNumJoints(),1));
00189 int result = mHand->getGrasp()->computeQuasistaticForcesAndTorques(&tau, computation);
00190 if (!result) {
00191 DBGA("Optimal joint torques:\n" << tau);
00192 }
00193 displayResults(result);
00194 }