From 54dde79ad83dcd012838eff0c9c5e935170bfb1a Mon Sep 17 00:00:00 2001 From: Paul Dino Jones Date: Thu, 30 May 2024 18:03:26 +0000 Subject: [PATCH] Fix wheel slip calculations --- src/monocoque/devices/sounddevice.c | 10 +++++----- src/monocoque/devices/usbhapticdevice.c | 10 +++++----- src/monocoque/gameloop/gameloop.c | 26 ++++++++++++------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/monocoque/devices/sounddevice.c b/src/monocoque/devices/sounddevice.c index c6cd05e..9a8009c 100644 --- a/src/monocoque/devices/sounddevice.c +++ b/src/monocoque/devices/sounddevice.c @@ -45,21 +45,21 @@ int sounddev_tyreslip_update(SimDevice* this, SimData* simdata) double play = 0; if (this->tyre == FRONTLEFT || this->tyre == FRONTS || this->tyre == ALLFOUR) { - play += simdata->wheelslip[0]; + play += (1.0 - simdata->wheelslip[0]); } if (this->tyre == FRONTRIGHT || this->tyre == FRONTS || this->tyre == ALLFOUR) { - play += simdata->wheelslip[1]; + play += (1.0 - simdata->wheelslip[1]); } if (this->tyre == REARLEFT || this->tyre == REARS || this->tyre == ALLFOUR) { - play += simdata->wheelslip[2]; + play += (1.0 - simdata->wheelslip[2]); } if (this->tyre == REARRIGHT || this->tyre == REARS || this->tyre == ALLFOUR) { - play += simdata->wheelslip[3]; + play += (1.0 - simdata->wheelslip[3]); } - if (play > 0) + if (play > .40) { sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency * play; sounddevice->sounddata.curr_duration = sounddevice->sounddata.duration; diff --git a/src/monocoque/devices/usbhapticdevice.c b/src/monocoque/devices/usbhapticdevice.c index b1c8713..c5ae3d1 100644 --- a/src/monocoque/devices/usbhapticdevice.c +++ b/src/monocoque/devices/usbhapticdevice.c @@ -19,19 +19,19 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat { if (usbhapticdevice->tyre == FRONTLEFT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR) { - play += simdata->wheelslip[0]; + play += (1.0 - simdata->wheelslip[0]); } if (usbhapticdevice->tyre == FRONTRIGHT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR) { - play += simdata->wheelslip[1]; + play += (1.0 - simdata->wheelslip[1]); } if (usbhapticdevice->tyre == REARLEFT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR) { - play += simdata->wheelslip[2]; + play += (1.0 - simdata->wheelslip[2]); } if (usbhapticdevice->tyre == REARRIGHT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR) { - play += simdata->wheelslip[3]; + play += (1.0 - simdata->wheelslip[3]); } } break; @@ -42,7 +42,7 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat if (play != usbhapticdevice->state) { - if(play > 0) + if(play > .40) { fprintf(usbhapticdevice->handle, "%i\n", usbhapticdevice->value1); fflush(usbhapticdevice->handle); diff --git a/src/monocoque/gameloop/gameloop.c b/src/monocoque/gameloop/gameloop.c index ebedf3f..2a068db 100644 --- a/src/monocoque/gameloop/gameloop.c +++ b/src/monocoque/gameloop/gameloop.c @@ -324,10 +324,10 @@ int tester(SimDevice* devices, int numdevices) simdata->rpms = 100; simdata->maxrpm = 8000; simdata->abs = 0; - simdata->wheelslip[0] = 0; - simdata->wheelslip[1] = 0; - simdata->wheelslip[2] = 0; - simdata->wheelslip[3] = 0; + simdata->wheelslip[0] = 1; + simdata->wheelslip[1] = 1; + simdata->wheelslip[2] = 1; + simdata->wheelslip[3] = 1; sleep(3); fprintf(stdout, "Setting rpms to 1000\n"); @@ -347,20 +347,20 @@ int tester(SimDevice* devices, int numdevices) sleep(3); simdata->abs = 0; - fprintf(stdout, "Setting Wheelslip to 1\n"); - simdata->wheelslip[0] = 1; - simdata->wheelslip[1] = 1; - simdata->wheelslip[2] = 1; - simdata->wheelslip[3] = 1; + fprintf(stdout, "Setting Wheelslip to 0, no traction\n"); + simdata->wheelslip[0] = 0; + simdata->wheelslip[1] = 0; + simdata->wheelslip[2] = 0; + simdata->wheelslip[3] = 0; for (int x = 0; x < numdevices; x++) { devices[x].update(&devices[x], simdata); } sleep(3); - simdata->wheelslip[0] = 0; - simdata->wheelslip[1] = 0; - simdata->wheelslip[2] = 0; - simdata->wheelslip[3] = 0; + simdata->wheelslip[0] = 1; + simdata->wheelslip[1] = 1; + simdata->wheelslip[2] = 1; + simdata->wheelslip[3] = 1; fprintf(stdout, "Shifting into first gear\n"); simdata->gear = 2;