From 07f6833add1e8dbe4c68cfe8c68f06eeaebb5b9e Mon Sep 17 00:00:00 2001 From: madbad Date: Thu, 2 Jun 2016 15:09:18 +0000 Subject: [PATCH] Force Feedback: Switch to SDL_HAPTIC_CARTESIAN instead of SDL_HAPTIC_POLAR for force feedback effects git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6426 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 471b2949f757c0da856485f44703a737fe7b5dc3 Former-commit-id: cf6419e1b870fd3687ad91c3f7de0326cf17e0f3 --- src/libs/robottools/rthumandriver.cpp | 10 ++++-- src/libs/tgfclient/control.cpp | 51 +++++++++++++++++---------- src/libs/tgfclient/forcefeedback.cpp | 8 ++--- src/libs/tgfclient/tgfclient.h | 2 +- 4 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/libs/robottools/rthumandriver.cpp b/src/libs/robottools/rthumandriver.cpp index 8cc8c95db..ac07a590e 100644 --- a/src/libs/robottools/rthumandriver.cpp +++ b/src/libs/robottools/rthumandriver.cpp @@ -1178,15 +1178,21 @@ static void common_drive(const int index, tCarElt* car, tSituation *s) } */ force = forceFeedback.updateForce(car, s); - + //force = force * 32767; /* Force feedback hack float multiplier = 4; force = (force + (car->_steerTq*multiplier)) / 2; //make the force smoother */ // if force is below 0 we turn anticlock-wise // if force is over 0 we turn clock-wise - gfctrlJoyConstantForce(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), abs((int)force), force < 0 ? 9000 : 27000 ); +// gfctrlJoyConstantForce(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), abs((int)force), force < 0 ? 9000 : 27000 ); //gfctrlJoyRumble(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), 0.9); +// if (force > 32760) force = 32760; +// if (force < -32760) force = -32760; + + //gfctrlJoyConstantForce(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), 10000, 10000); + + gfctrlJoyConstantForce(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), ((int)force), 0 ); #define GLANCERATE 3 // speed at which the driver turns his head, ~1/3s to full glance newGlance = car->_glance; diff --git a/src/libs/tgfclient/control.cpp b/src/libs/tgfclient/control.cpp index de5e7990d..19fd016e0 100644 --- a/src/libs/tgfclient/control.cpp +++ b/src/libs/tgfclient/control.cpp @@ -312,6 +312,11 @@ gfctrlJoyInit(void) #else #if SDL_MAJOR_VERSION >= 2 memset(&cfx, 0, sizeof(cfx)); + + for(int i = 0;i= 2 if (!Haptics[index]) return; if ((SDL_HapticQuery(Haptics[index]) & SDL_HAPTIC_CONSTANT) == 0) return; - + printf("level = %d \r\n",level); + if(-1 == id[index]) + { cfx[index].type = SDL_HAPTIC_CONSTANT; - cfx[index].constant.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates - cfx[index].constant.direction.dir[0] = dir; // direction of the force - cfx[index].constant.length = 1000; //how log is the effect + //cfx[index].constant.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates + //cfx[index].constant.direction.dir[0] = dir; // direction of the force + cfx[index].constant.direction.type = SDL_HAPTIC_CARTESIAN; + cfx[index].constant.direction.dir[0] = 1; + cfx[index].constant.length = 1000; cfx[index].constant.level = level; // strength: minimum 0 maximum 32767 cfx[index].constant.attack_length = 0; // Takes 0 second (instantly) to get max strength - cfx[index].constant.fade_length = 1000; // Takes 1 second to fade away + cfx[index].constant.fade_length = 0; // Takes 0 second to fade away + //cfx_timeout[index] = SDL_GetTicks() + cfx[index].constant.length; + id[index] = SDL_HapticNewEffect(Haptics[index], &cfx[index]); + SDL_HapticRunEffect(Haptics[index], id[index], SDL_HAPTIC_INFINITY); + } + cfx[index].constant.length = 1000; //how log is the effect + cfx[index].constant.level = level; -#if __WIN32__ - if (SDL_HapticGetEffectStatus(Haptics[index], id[index]) == SDL_TRUE) -#else - // Linux SDL doesn't support checking status at the moment :-( - if (cfx_timeout[index] > SDL_GetTicks()) -#endif +//#if __WIN32__ +// if (SDL_HapticGetEffectStatus(Haptics[index], id[index]) == SDL_TRUE) +//#else +// // Linux SDL doesn't support checking status at the moment :-( +// if (cfx_timeout[index] > SDL_GetTicks()) +//#endif SDL_HapticUpdateEffect(Haptics[index], id[index], &cfx[index]); - else { - SDL_HapticDestroyEffect(Haptics[index], id[index]); - id[index] = SDL_HapticNewEffect(Haptics[index], &cfx[index]); - SDL_HapticRunEffect(Haptics[index], id[index], 1); - } +// else { +// SDL_HapticDestroyEffect(Haptics[index], id[index]); +// id[index] = SDL_HapticNewEffect(Haptics[index], &cfx[index]); +// SDL_HapticRunEffect(Haptics[index], id[index], 1); +// } cfx_timeout[index] = SDL_GetTicks() + cfx[index].constant.length; #endif diff --git a/src/libs/tgfclient/forcefeedback.cpp b/src/libs/tgfclient/forcefeedback.cpp index ba51a10f9..1d116accc 100644 --- a/src/libs/tgfclient/forcefeedback.cpp +++ b/src/libs/tgfclient/forcefeedback.cpp @@ -220,11 +220,11 @@ int ForceFeedbackManager::autocenterEffect(tCarElt* car, tSituation *s){ int sign; //force acting on the front wheels - effectForce = -1 * car->_steerTqAlign * this->effectsConfig["autocenterEffect"]["frontwheelsmultiplier"] / 1000; + effectForce = car->_steerTqAlign * this->effectsConfig["autocenterEffect"]["frontwheelsmultiplier"] / 1000; //force action on the back wheels - effectForce += car->_wheelFy(REAR_RGT) * this->effectsConfig["autocenterEffect"]["rearwheelsmultiplier"] / 1000 ; - effectForce += car->_wheelFy(REAR_LFT) * this->effectsConfig["autocenterEffect"]["rearwheelsmultiplier"] / 1000; + effectForce += car->_wheelFy(REAR_RGT) * this->effectsConfig["autocenterEffect"]["rearwheelsmultiplier"] / 1000 ; + effectForce += car->_wheelFy(REAR_LFT) * this->effectsConfig["autocenterEffect"]["rearwheelsmultiplier"] / 1000; //smooth @@ -239,7 +239,7 @@ int ForceFeedbackManager::autocenterEffect(tCarElt* car, tSituation *s){ //be sure this is a positive number effectForce = effectForce * sign; -// effectForce = (int)((pow((double) effectForce, (double) 1/2) * 120) * sign); + effectForce = (int)((pow((double) effectForce, (double) 1/2) * 120) * sign); return effectForce; diff --git a/src/libs/tgfclient/tgfclient.h b/src/libs/tgfclient/tgfclient.h index 0b028519b..7dfd00bbe 100644 --- a/src/libs/tgfclient/tgfclient.h +++ b/src/libs/tgfclient/tgfclient.h @@ -699,7 +699,7 @@ TGFCLIENT_API tCtrlJoyInfo* GfctrlJoyCreate(void); TGFCLIENT_API void GfctrlJoyRelease(tCtrlJoyInfo* joyInfo); TGFCLIENT_API int GfctrlJoyGetCurrentStates(tCtrlJoyInfo* joyInfo); #if SDL_JOYSTICK -TGFCLIENT_API void gfctrlJoyConstantForce(int index, unsigned int level, int dir); +TGFCLIENT_API void gfctrlJoyConstantForce(int index, int level, int dir); TGFCLIENT_API void gfctrlJoyRumble(int index, float level); TGFCLIENT_API void GfctrlJoySetAxis(int joy, int axis, float value); TGFCLIENT_API void GfctrlJoySetButton(int joy, int button, int value);