ScorbotConsole.qt.H

00001 #ifndef ROBOTS_SCORBOT_SCORBOTCONSOLE_H
00002 #define ROBOTS_SCORBOT_SCORBOTCONSOLE_H
00003 
00004 #include <Ice/Ice.h>
00005 #include <QtGui/QtGui>
00006 #include <QtCore/QThread>
00007 #include "Component/ModelComponent.H"
00008 #include "Robots/Scorbot/Scorbot.ice.H"
00009 #include "Qt4/ImageGraphicsItem.qt.H"
00010 #include "QtUtil/ImageConvert4.H"
00011 
00012 class ScorbotInterfaceThread;
00013 
00014 // ######################################################################
00015 class ScorbotConsole : public QMainWindow, public ModelComponent
00016 {
00017   Q_OBJECT;
00018 
00019   public:
00020     ScorbotConsole(OptionManager& mgr, 
00021         const std::string& descrName = "ScorbotConsole",
00022         const std::string& tagName   = "ScorbotInterface");
00023 
00024                 ~ScorbotConsole();
00025 
00026                 void stop1();
00027                 void start2();
00028                 QMap<ScorbotIce::JointType, QString> jointStringMap;
00029                 void plotLine(std::vector<float> plot, PixRGB<byte> color);
00030 
00031   public slots:
00032                 void gotEncoderVal(int joint, int val);
00033                 void gotPWMVal(int joint, float val);
00034                 void gotTargetPos(int joint, int val);
00035                 void gotGravityCompensation(float comp);
00036                 void pidAxisSelected(int index);
00037                 void setPIDVals();
00038                 void resetEncoders();
00039                 void setPosition(int joint);
00040                 void toggleMotorsEnabled();
00041                 void addData(QString plotName, double data);
00042                 void updatePlots();
00043                 void printPosCode(); //!< Prints some hacky C++ to stdout
00044 
00045   private:
00046                 void saveParams();
00047                 void loadParams();
00048 
00049                 ScorbotInterfaceThread *itsScorbotThread;
00050                 QMap<ScorbotIce::JointType, QLabel*>      encoderLbls;
00051                 QMap<ScorbotIce::JointType, QLabel*>      pwmLbls;
00052                 QMap<ScorbotIce::JointType, QLineEdit*>   encoderEdits;
00053                 QMap<ScorbotIce::JointType, QLineEdit*>   durationEdits;
00054                 QMap<ScorbotIce::JointType, QPushButton*> setPosButtons;
00055 
00056                 QComboBox *itsAxisComboBox;
00057 
00058                 QLineEdit *pGainEdit, *iGainEdit, *dGainEdit, *maxIEdit, *maxPWMEdit,
00059                           *pwmOffsetEdit, *foreArmMassEdit, *upperArmMassEdit, *gravityCompScaleEdit;
00060           QLabel *gravityCompLbl;
00061 
00062                 QPushButton* enableMotorsButton;
00063 
00064                 QMap<QString, std::vector<float> > plotData;
00065                 QMap<QString, PixRGB<byte> > plotDataColor;
00066                 QMap<QString, bool> plotDataCheck;
00067                 QGraphicsView* itsGraphicsView;
00068                 QGraphicsScene* itsGraphicsScene;
00069                 ImageGraphicsItem* itsImageDisplay;
00070 
00071                 bool itsMotorsEnabled;
00072 
00073                 size_t itsMaxPlotLength;
00074 
00075                 QSettings* itsSettings;
00076 
00077 
00078                 Ice::CommunicatorPtr ic;
00079                 ScorbotIce::ScorbotPrx itsScorbot;
00080 };
00081 
00082 // ######################################################################
00083 class ScorbotInterfaceThread : public QThread
00084 {
00085         Q_OBJECT;
00086         public:
00087 
00088                 ScorbotInterfaceThread(ScorbotConsole* window, ScorbotIce::ScorbotPrx *scorbot) :
00089                         itsScorbot(scorbot), itsWindow(window), sleepTime(3) 
00090         {
00091 
00092         }
00093 
00094                 bool running;
00095 
00096                 void run()
00097                 {
00098                         running = true;
00099                         while(running)
00100                         {
00101                                 //Update the current encoder values
00102                                 ScorbotIce::encoderValsType encoders = (*itsScorbot)->getEncoders();
00103                                 ScorbotIce::encoderValsType::iterator encIdx = encoders.begin();
00104                                 for(; encIdx != encoders.end(); ++encIdx)
00105                                         emit(gotEncoderVal((int)encIdx->first, encIdx->second));
00106                                 
00107                                 //Update the current PWM values
00108                                 ScorbotIce::pwmValsType PWMs = (*itsScorbot)->getPWMs();
00109                                 ScorbotIce::pwmValsType::iterator pwmIdx = PWMs.begin();
00110                                 for(; pwmIdx != PWMs.end(); ++pwmIdx)
00111                                         emit(gotPWMVal((int)pwmIdx->first, pwmIdx->second));
00112 
00113                                 //Update the target velocity and position values for the current joint
00114                                 int32 targetPos, targetVel;
00115                                 float gravityCompensation;
00116                                 (*itsScorbot)->getTuningVals(itsSelectedJoint, targetPos, targetVel, gravityCompensation);
00117 
00118                                 emit(gotTargetPos((int)itsSelectedJoint, targetPos));
00119                                 emit(gotGravityCompensation(gravityCompensation));
00120 
00121 
00122                                 emit(updatedAllValues());
00123                                 this->msleep(100);
00124                         }
00125                 }
00126 
00127                 void setSelectedJoint(ScorbotIce::JointType joint) { itsSelectedJoint = joint; }
00128 
00129         signals:
00130                 void gotEncoderVal(int, int);
00131                 void gotPWMVal(int, float);
00132                 void gotTargetPos(int, int);
00133                 void gotGravityCompensation(float);
00134 
00135                 void updatedAllValues();
00136 
00137         private:
00138                 ScorbotIce::ScorbotPrx *itsScorbot;
00139                 ScorbotConsole* itsWindow;
00140                 ScorbotIce::JointType itsSelectedJoint;
00141                 int sleepTime;
00142 
00143 };
00144 
00145 #endif // ROBOTS_SCORBOT_SCORBOTCONSOLE_H
00146 
Generated on Sun May 8 08:05:56 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3