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 <QValidator>
00027 #include <QPushButton>
00028 #include <QLineEdit>
00029
00030 #include "world.h"
00031 #include "barrett.h"
00032 #include "barrettHandDlg.h"
00033
00034 #ifdef HARDWARE_LIB
00035 #include "BarrettHand.h"
00036 #include "BarrettHandThread.h"
00037 #endif
00038
00039 void BarrettHandDlg::init()
00040 {
00041 QLineEdit *stepSize = (QLineEdit *) this->child("stepSize", "QLineEdit");
00042 stepSize->setValidator(new QIntValidator(0, 180, stepSize));
00043 withinSimulationUpdate = false;
00044 simulatedHandForContinuousOperation = NULL;
00045 userInteractionOngoing = false;
00046 }
00047
00054 bool BarrettHandDlg::setWorld( World *w )
00055 {
00056 #ifndef HARDWARE_LIB
00057 return false;
00058 #endif
00059 world = w;
00060 if (!world->getCurrentHand()) return false;
00061 if (!world->getCurrentHand()->isA("Barrett")) return false;
00062 mSimBarrett = (Barrett*)world->getCurrentHand();
00063 mRealBarrett = mSimBarrett->getRealHand();
00064 if (!mRealBarrett) return false;
00065 return true;
00066 }
00067
00068 void BarrettHandDlg::initializeHand()
00069 {
00070 #ifdef HARDWARE_LIB
00071 mRealBarrett->HandInitialize(BARRETT_ALL);
00072
00073
00074 #endif
00075 }
00076
00080 void BarrettHandDlg::simulationFromRealHand()
00081 {
00082 #ifdef HARDWARE_LIB
00083 if(withinSimulationUpdate || userInteractionOngoing) return;
00084 withinSimulationUpdate = true;
00085
00086 int realVals[4];
00087 realVals[0] = mRealBarrett->GetFingerPosition(BARRETT_SPREAD);
00088 realVals[1] = mRealBarrett->GetFingerPosition(BARRETT_FINGER1);
00089 realVals[2] = mRealBarrett->GetFingerPosition(BARRETT_FINGER2);
00090 realVals[3] = mRealBarrett->GetFingerPosition(BARRETT_FINGER3);
00091
00092 if(mRealBarrett->GetBreakawayDetected(BARRETT_FINGER1)) {
00093 int breakawayPosition = mRealBarrett->GetBreakawayPosition(BARRETT_FINGER1);
00094 fprintf(stderr, "Finger 1 breakaway at %i\n", breakawayPosition);
00095 }
00096 if(mRealBarrett->GetBreakawayDetected(BARRETT_FINGER2)) {
00097 int breakawayPosition = mRealBarrett->GetBreakawayPosition(BARRETT_FINGER2);
00098 fprintf(stderr, "Finger 2 breakaway at %i\n", breakawayPosition);
00099 }
00100 if(mRealBarrett->GetBreakawayDetected(BARRETT_FINGER3)) {
00101 int breakawayPosition = mRealBarrett->GetBreakawayPosition(BARRETT_FINGER3);
00102 fprintf(stderr, "Finger 2 breakaway at %i\n", breakawayPosition);
00103 }
00104
00105 double dofVals[4];
00106 dofVals[0] = mRealBarrett->InternalToRadians(BARRETT_SPREAD, realVals[0]);
00107 dofVals[1] = mRealBarrett->InternalToRadians(BARRETT_FINGER1, realVals[1]);
00108 dofVals[2] = mRealBarrett->InternalToRadians(BARRETT_FINGER2, realVals[2]);
00109 dofVals[3] = mRealBarrett->InternalToRadians(BARRETT_FINGER3, realVals[3]);
00110 mSimBarrett->forceDOFVals(dofVals);
00111
00112 withinSimulationUpdate = false;
00113 #endif
00114 }
00115
00120 void BarrettHandDlg::realHandFromSimulation()
00121 {
00122 #ifdef HARDWARE_LIB
00123 if(withinSimulationUpdate || userInteractionOngoing) return;
00124 withinSimulationUpdate = true;
00125
00126 double dofVals[4];
00127 mSimBarrett->getDOFVals(dofVals);
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 mRealBarrett->MoveTogether(dofVals);
00138 withinSimulationUpdate = false;
00139 #endif
00140 }
00141
00145 void BarrettHandDlg::toggleContinuousOperation()
00146 {
00147 QString *text;
00148
00149 if(!simulatedHandForContinuousOperation) {
00150 QObject::connect(mSimBarrett, SIGNAL(configurationChanged()), this, SLOT(realHandFromSimulation()));
00151 QObject::connect(mSimBarrett, SIGNAL(userInteractionStart()), this, SLOT(userInteractionStart()));
00152 QObject::connect(mSimBarrett, SIGNAL(userInteractionEnd()), this, SLOT(userInteractionEnd()));
00153 simulatedHandForContinuousOperation = mSimBarrett;
00154 text = new QString("End continuous operation");
00155 } else {
00156 QObject::disconnect(simulatedHandForContinuousOperation, 0, this, 0);
00157 simulatedHandForContinuousOperation = NULL;
00158 text = new QString("Begin continuous operation");
00159 }
00160
00161 QPushButton *button = (QPushButton *) this->child("continuousOperationButton", "QPushButton");
00162 button->setText(*text);
00163 delete text;
00164 }
00165
00172 void BarrettHandDlg::userInteractionStart()
00173 {
00174 userInteractionOngoing = true;
00175 }
00176
00177 void BarrettHandDlg::userInteractionEnd()
00178 {
00179 userInteractionOngoing = false;
00180 realHandFromSimulation();
00181 }
00182
00188 void BarrettHandDlg::smoothButton_clicked()
00189 {
00190 #ifdef HARDWARE_LIB
00191 mRealBarrett->smoothSpreadParams();
00192 #endif
00193 }
00194
00195 void BarrettHandDlg::initSpreadButton_clicked()
00196 {
00197 #ifdef HARDWARE_LIB
00198 mRealBarrett->HandInitialize(BARRETT_SPREAD);
00199 #endif
00200 }