00001 #ifndef HID_STEPWALK_H
00002 #define HID_STEPWALK_H
00003 #include <WinBasis/WBWin.h>
00004
00005 #if _MSC_VER > 1000
00006 #pragma once
00007 #endif // _MSC_VER > 1000
00008
00009 #include <Device/DVDeviceManager.h>
00010 #include <Device/DVAdBase.h>
00011 #include <Base/Affine.h>
00012
00013 namespace Spr{;
00014 using namespace std;
00015
00016 #define SENSOR4 //センサーが4つのとき
00017
00018 class SPR_DLL HIStepWalk{
00019
00020 class SPR_DLL Sensor{
00021 public:
00022 float offsetMin;
00023 float offsetMax;
00024
00025 float scale;
00026 float rawCur;
00027 float cur;
00028 public:
00029 Vec2f pos;
00030 DVAdBase* ad;
00031 Sensor(){
00032
00033 offsetMin = 0.5f;
00034 offsetMax = 1.0f;
00035 scale = 2.0f;
00036 rawCur = 0;
00037 cur = 0;
00038 ad = NULL;
00039 }
00040 void CalibMin(){
00041 if (ad) rawCur = ad->Voltage();
00042 if (rawCur < offsetMin) offsetMin = rawCur;
00043 }
00044 void CalibMax(){
00045 if (ad) rawCur = ad->Voltage();
00046 if (rawCur > offsetMax) offsetMax = rawCur;
00047 }
00048
00049 float Get(){
00050 if (ad) rawCur = ad->Voltage();
00051 cur = (rawCur - offsetMin) / scale;
00052
00053
00054
00055 return cur;
00056 }
00057
00058
00059
00060
00061
00062
00063 float Get(){
00064 if (ad) rawCur = ad->Voltage();
00065 cur = (rawCur - offset) / scale;
00066 if (cur > 1) cur = 1;
00067 if (cur < 0) cur = 0;
00068 return cur;
00069 }
00070 */
00071 };
00072
00073 public:
00074 Vec2f cogAve, cog, direction;
00075 float inner, resultOfInner[3], memoryOfInner;
00076
00077 HIStepWalk();
00078 virtual ~HIStepWalk();
00079
00080 bool Init(DVDeviceManager& devMan);
00081
00082 void Step(float);
00083 float GetVelocity(){ return walkVel; }
00084 float GetPitch(){ return pitch; }
00085 float GetPitchParam(){ return pitchParam; }
00086 void SetPitchParam(float p){ pitchParam = p; }
00087 Vec2f GetDirection(){ return direction; }
00088 void SetDirection(Vec2f vector){ direction = vector; }
00089 int GetStep(){ return step; }
00090 void Print(std::ostream& os) const;
00091 float GetSensorVoltage(int n){ return sensor[n].Get(); }
00092
00093 void PSenRange();
00094 void PSenMax();
00095 void PSenMin();
00096 void SetCenterOfGravity(Vec2f& centerG);
00097 Vec2f GetCenterOfGravity(){ return centerOfGravity[0]; };
00098 void PSenCal();
00099 bool pSenCal;
00100 bool printForCenterG;
00101 bool rotateSwitch;
00102 void SetThreshold(float t) { threshold = t; }
00103 void CloseSIGGRAPHFile();
00104
00105 void DataOutput(float x, float y, float z);
00106
00107 std::ofstream *dataFileSIGGRAPH;
00108 char* folderName;
00109 char folderNameBack[20];
00110 int fileNameTime;
00111 char fileTime[10];
00112
00113 float jumpPower;
00114 void SetJump(float& jump);
00115
00116
00117 protected:
00118
00119 bool SideStep();
00120 Vec2f walkingDirection;
00121 Vec2f gravityDiff;
00122 int sideStep;
00123 bool frontCheck;
00124 float frontGap;
00125
00126 DWORD dwLastTime;
00127 DWORD dwTime;
00128 int step;
00129 int backStep;
00130 bool BackStep(float value);
00131 float walkVel;
00132 unsigned long dwInterval;
00133 unsigned long dwStepTime;
00134 float pitch;
00135 float pitchParam;
00136 bool flag_SIGGRAPH;
00137 float threshold;
00138
00139 #ifndef SENSOR4
00140 enum {NSENSOR = 3};
00141 #else
00142 enum {NSENSOR = 4};
00143 #endif
00144
00145 Sensor sensor[NSENSOR];
00146
00147
00148 enum {CENTER_OF_GRAVITY_LEN = 6};
00149
00150 Vec2f centerOfGravity[CENTER_OF_GRAVITY_LEN];
00151
00152 float dCenterOfGravity;
00153 };
00154
00155 }
00156
00157 #endif