D:/Projekte/Super-Yano/Super-Yano/RobotControl.h

gehe zur Dokumentation dieser Datei
00001 
00002 #pragma once
00003 
00004 using namespace System;
00005 using namespace System::Xml;
00006 using namespace System::Threading;
00007 using namespace System::Runtime::InteropServices;
00008 
00009 
00010 [DllImport("Facedetect.dll")] 
00011 extern "C" int getNumberOfFaces( void );  
00012 [DllImport("Facedetect.dll")] 
00013 extern "C" double getMajorFaceRelativeX( void );  
00014 [DllImport("Facedetect.dll")] 
00015 extern "C" double getMajorFaceRelativeY( void );  
00016 [DllImport("Facedetect.dll", CharSet=CharSet::Ansi)] 
00017 extern "C" int getMajorFacePosX( void );  
00018 [DllImport("Facedetect.dll", CharSet=CharSet::Ansi)] 
00019 extern "C" int getMajorFacePosY( void );  
00020 [DllImport("Facedetect.dll", CharSet=CharSet::Ansi)] 
00021 extern "C" int getVideoSizeX( void );  
00022 [DllImport("Facedetect.dll", CharSet=CharSet::Ansi)] 
00023 extern "C" int getVideoSizeY( void );  
00024 
00026 ref struct Servo 
00027 {
00028         public: int minValue, maxValue, startValue, currentValue, neutralValue;
00029         public: String^ servoName; 
00030 
00034         public: Servo() 
00035                         {
00036                                 servoName = "";
00037                                 minValue = 500;
00038                                 maxValue = 2500;
00039                                 startValue = 1500;
00040                                 neutralValue = 1500;
00041                                 currentValue = 1500;
00042                         }
00043 
00051         public: Servo(String^ name, int minV, int maxV, int startV) 
00052                         {
00053                                 servoName = name;
00054                                 minValue = minV;
00055                                 maxValue = maxV;
00056                                 startValue = startV;
00057                                 //neutralValue = startV;
00058                                 neutralValue = ((maxValue - minValue) / 2) + minValue;
00059                                 currentValue = startV;
00060                         }
00061 };
00062 
00064 ref class RobotControl
00065 {
00066 
00067 
00068 //Konstanten
00069 public: static const int LEFT  = 1;
00070                 static const int TOP = 1;
00071                 static const int RIGHT = 0;
00072                 static const int BOTTOM = 0;
00073                 static const int CENTER = 2;
00074 
00075                 static const int STOPPED = 0;
00076                 static const int RUNNING = 1;
00077                 static const int PAUSED  = 2;
00078 
00079                 //emotional constants
00080                 static const int SURPRISED = 0;   // überrascht
00081                 static const int HAPPY     = 1;   // zufrieden
00082                 static const int ANGRY     = 2;   // ärgerlich
00083                 static const int CONTENT   = 3;   // offen, aufnehmend
00084                 static const int STERN     = 4;   // ernst, abweisend
00085                 static const int FEAR      = 5;   // ängstlich
00086                 static const int SAD       = 6;   // traurig
00087 
00088                 static int used_eye;
00089 
00090 //Variablen
00091 private: static array<double>^ emotion;   // Emotionsarray - zu jeder Emotion steht hier der aktuelle Faktor
00092 private: static array<Servo^>^ servos;
00093 private: static bool isSerialPort;
00094 private: static int visemeCount;
00095 private: static System::String^ serial_port_name;
00096 private: static System::String^ serial_port_received_data = "";
00097 
00098 private: static int blinkingState;
00099 private: static int earTremorState;
00100 private: static int visualAdjustmentThreadState;
00101 private: static bool isMouthMovement;
00102 
00103 private:
00104         static int ear_l;
00105         static int ear_r;
00106         static int lid_l;
00107         static int lid_r;
00108         static int eye_l;
00109         static int eye_r;
00110         static int brows;
00111         static int mouth;
00112         static int jaw;
00113         static int turn;
00114         static int pitch;
00115 
00116 
00117 //Komponenten
00118 private: static System::ComponentModel::IContainer^  components;
00119 private: static System::IO::Ports::SerialPort^ serial_Port;
00120 private: static SpeechLib::_ISpeechVoiceEvents_VisemeEventHandler^ spVisemeEventHandler;
00121 private: static Threading::Thread^ blinkThread;
00122 private: static Threading::Thread^ earTremorThread;
00123 private: static Threading::Thread^ visualAdjustmentThread;
00124 
00125 //Methoden
00126 
00127 public:  static void construct(System::String^ port_name);
00128 
00129         //static methods
00130 private: static void blink(void);
00131 private: static void earTremorISR(void);
00132 private: static void visualAdjustmentThreadISR(void);
00133 
00134         //serial Port
00135 public:  static void serialPort_DataReceived(System::Object^  sender, System::IO::Ports::SerialDataReceivedEventArgs^  e);
00136 public:  static System::String^ getComPortName(void);
00137 public:  static array<System::String^, 1>^ getComPortNames(void);
00138 private: static System::String^ findComport(System::String^ start_port_for_search);
00139 
00140         //servo stuff
00141 public:  static System::String^ getServoDescription(int servoNumber);
00142 public:  static int getServoMinValue(int servoNumber);
00143 public:  static int getServoMaxValue(int servoNumber);
00144 public:  static int getServoStartValue(int servoNumber);
00145 private: static void initiateServoSettings(void);
00146 private: static void setServoValue(int servo_nr, int servo_speed, int servo_value);
00147 
00148         //general stuff
00149 public:  static void setMouthSilentViseme(void);
00150 public:  static void setServosEnable(bool enabled);
00151 public:  static void setBlinkingThreadPaused(bool paused);
00152 public:  static void setEarTremorThreadPaused(bool paused);
00153 public:  static void setVisualAdjustmentThreadPaused(bool paused);
00154 public:  static void setMouthMovementEnabled(bool enabled);
00155 public:  static void initiateRobot(void);
00156 public:  static void setCamera(int camera);
00157 public:  static void showDisplay(String^ text);
00158 public:  static SpeechLib::_ISpeechVoiceEvents_VisemeEventHandler^ getVisemeEventHandler(void);
00159 
00160    //internal methods
00161 private: static void setEyeOpen(int eye, bool eyeOpened);
00162 private: static void readServoSettings(void);
00163 private: static void speechVisemeEvent(int streamNumber, System::Object^ streamPosition, int duration, SpeechLib::SpeechVisemeType nextVisemeID, SpeechLib::SpeechVisemeFeature feature, SpeechLib::SpeechVisemeType currentVisemeId);
00164 
00165 
00171 public: static void destroy()
00172 {
00173         blinkingState = STOPPED;
00174         earTremorState = STOPPED;
00175         visualAdjustmentThreadState = STOPPED;
00176         blinkThread->Join();
00177         earTremorThread->Join();
00178         visualAdjustmentThread->Join();
00179 
00180 
00181         if(isSerialPort == true)
00182         {
00183                 try
00184                 {
00185                         if (!serial_Port->IsOpen) serial_Port->Open();
00186                         serial_Port->WriteLine("U!SCSBR"+"\0");
00187                         Threading::Thread::Sleep(1500);
00188                         serial_Port->Close();
00189                         serial_Port->BaudRate = 2400;
00190                         serial_Port->Open();
00191                         serial_Port->WriteLine("U!SCVER?");
00192                 }
00193                 catch (Exception^ )
00194                 {
00195                         serial_Port->Close();
00196                         isSerialPort = false;
00197                 }
00198         }
00199 
00200         if (serial_Port->IsOpen) serial_Port->Close();
00201         
00202 
00203         if (components)
00204     {
00205       delete components;
00206         }
00207 }
00208 
00209 };
00210 

Erzeugt am Mon Jun 4 16:39:20 2007 für Super-Yano von  doxygen 1.5.2