PWiiController.H
00001 #ifndef PWIICONTROLLER_H_DEFINED
00002 #define PWIICONTROLLER_H_DEFINED
00003
00004 #ifdef HAVE_LIBWIIMOTE
00005 extern "C" {
00006 #define _ENABLE_TILT
00007 #define _ENABLE_FORCE
00008 #include <wiimote.h>
00009 #include <wiimote_api.h>
00010 }
00011 #endif
00012
00013 #include <pthread.h>
00014 #include "Component/ModelComponent.H"
00015 #include "Component/ModelParam.H"
00016 #include "rutz/shared_ptr.h"
00017 #include "Util/Types.H"
00018 #include "Util/WorkThreadServer.H"
00019 #include "Util/JobWithSemaphore.H"
00020 #include "Controllers/PID.H"
00021
00022 #include "Image/Image.H"
00023 #include "Image/Pixels.H"
00024 #include "Util/Angle.H"
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class PWiiController : public ModelComponent
00036 {
00037 public:
00038
00039
00040
00041
00042
00043 PWiiController(OptionManager& mgr,
00044 const std::string& descrName = "PWiiController",
00045 const std::string& tagName = "PWiiController");
00046
00047
00048 ~PWiiController();
00049
00050
00051 bool connectWiimote();
00052
00053
00054 bool updateWiimote();
00055
00056 bool setMotor1Speed(int speed);
00057 bool setMotor2Speed(int speed);
00058 bool setMotor1Dir(int dir);
00059 bool setMotor2Dir(int dir);
00060 bool setTransVel(int transVel);
00061 bool setRotVel(int rotVel);
00062
00063
00064
00065 int* getMotor1SpeedPtr() { return &itsMotor1Speed; }
00066 int* getMotor2SpeedPtr() { return &itsMotor2Speed; }
00067 int* getMotor1DirPtr() { return &itsMotor1Dir; }
00068 int* getMotor2DirPtr() { return &itsMotor2Dir; }
00069 int* getTransVelPtr() { return &itsTransVel; }
00070 int* getRotVelPtr() { return &itsRotVel; }
00071 int* getXAccelPtr() { return &itsXAccel; }
00072 int* getYAccelPtr() { return &itsYAccel; }
00073 int* getZAccelPtr() { return &itsZAccel; }
00074 int* getBatteryPtr() { return &itsBatteryStatus; }
00075 Image<PixRGB<byte> >* getIRImagePtr() { return &itsIRImage ; }
00076
00077 bool getConnectionStatus() { return itsConnectionStatus; }
00078
00079 void start2();
00080
00081 private:
00082 void paramChanged(ModelParamBase* const param, const bool valueChanged, ParamClient::ChangeStatus* status);
00083 void updateIRImage();
00084
00085
00086 int itsMotor1Speed;
00087 int itsMotor2Speed;
00088 int itsMotor1Dir;
00089 int itsMotor2Dir;
00090 int itsTransVel;
00091 int itsRotVel;
00092
00093 int itsXAccel;
00094 int itsYAccel;
00095 int itsZAccel;
00096
00097 int itsIR1X;
00098 int itsIR1Y;
00099 int itsIR1Size;
00100
00101 int itsIR2X;
00102 int itsIR2Y;
00103 int itsIR2Size;
00104
00105 int itsIR3X;
00106 int itsIR3Y;
00107 int itsIR3Size;
00108
00109 int itsIR4X;
00110 int itsIR4Y;
00111 int itsIR4Size;
00112
00113 int itsBatteryStatus;
00114 bool itsConnectionStatus;
00115
00116 Image<PixRGB<byte> > itsIRImage;
00117
00118 NModelParam<int> paramCurrentTransVel;
00119 NModelParam<int> paramCurrentRotVel;
00120
00121 NModelParam<int> paramMotor1Speed;
00122 NModelParam<int> paramMotor2Speed;
00123 NModelParam<int> paramMotor1Dir;
00124 NModelParam<int> paramMotor2Dir;
00125 NModelParam<bool> paramDrawIR;
00126 NModelParam<bool> paramConnected;
00127
00128 wiimote_t itsWiimote;
00129
00130 rutz::shared_ptr<WorkThreadServer> itsThreadServer;
00131
00132
00133
00134
00135 };
00136
00137
00138 #endif